Skip to content

Docs: the GPU build recipe (CUDA search order, nvrtc.h as the marker, lib64 vs lib, +RTS --gpu-build, the silent CPU fallback) exists only in cli_build's comment #1863

Closed

Description

@adeerkhan

What is missing

The guide documents what bangs (\!) mean (GUIDE.md: "\!` runs on GPU", and "A machine without a GPU runs `!` on the CPU (still in parallel)"), and README says `!` needs clang 19+ / Metal or CUDA 12 — but how a build actually reaches the GPU lane is written down only in a source comment (bend2/main.ts, cli_build):

  • the search order: $CUDA_HOME, $CUDA_PATH, /usr/local/cuda, /opt/cuda (Arch's), first one that holds include/nvrtc.h;
  • the library layout: lib64 first, lib as nix lays them (-L $cuda/lib64 -L $cuda/lib -lcuda -lnvrtc);
  • the build runs the binary once with +RTS --gpu-build to write the GPU program — so the loader needs libnvrtc.so.13 at build time, from LD_LIBRARY_PATH when it is not a system library;
  • and the line the comment ends with: else the ! runs on the cores — silently. A `! `` program with no toolkit found builds as CPU, links no CUDA library, and nothing in the output says which lane ran.

Why it matters (what it cost us)

Reverse-engineering this produced two filed bugs on the consuming side: nuxyel/BendTorch#10 — its make gpu hardcoded LD_LIBRARY_PATH=$(CUDA_HOME)/lib (broken for every lib64 toolkit, the exact layout cli_build links first), and with no toolkit its gate printed "on the GPU" for a run that had linked zero CUDA libraries. Nothing in our docs or theirs could tell the user: (1) which paths to set, (2) that nvrtc.h is the marker file, (3) that the runtime loader also needs the NVRTC library, (4) how to verify which lane a binary was built for (today: ldd and hope).

Repro of the silent fallback (this machine, no toolkit anywhere)

$ unset CUDA_HOME CUDA_PATH
$ bend demo/anything_with_bangs.bend -o prog   # exit 0, no message
$ ldd prog | grep -c -E 'nvrtc|libcuda'
0

Proposal

A short "Building for the GPU" section (guide, or README's compilation bullets) stating:

  1. the search order and the nvrtc.h marker (cli_build already comments it);
  2. lib64/lib layouts and that a user-unpacked toolkit works if CUDA_HOME names it;
  3. the runtime loader: LD_LIBRARY_PATH=$cuda/lib64 (or an installed driver + libnvrtc) or the binary dies with libnvrtc.so.13: cannot open shared object file;
  4. which lane ran: either document \ldd x | grep nvrtc as the check, or have the build print one line (gpu: CUDA at /path vs gpu: no toolkit, building CPU) — the comment already knows; the user never sees it.

The comment at cli_build is accurate and good; this is about promoting it to user-facing docs and making the fallback visible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions