Skip to content

WSL2 NVIDIA: ! build cannot find -lcuda; a present unsupported GPU is reported as missing and fallback is silent #1064

Closed

Description

@SiliconState

What you did

From a clean archive of current main commit 47bed75adedd6d6dd811721905f06569bf465f85, on WSL2 with CUDA 13.1/NVRTC installed:

$HOME/.bun/bin/bun bend2/main.ts smoke.bend -o smoke

Then, as a diagnostic workaround only:

LIBRARY_PATH=/usr/lib/wsl/lib \
  $HOME/.bun/bin/bun bend2/main.ts smoke.bend -o smoke

./smoke --threads 2
./smoke --gpu on --threads 2
./smoke --gpu 512MB --threads 2
./smoke --gpu off --threads 2

What happened

The default build fails:

/usr/bin/x86_64-linux-gnu-ld.bfd: cannot find -lcuda: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: clang failed to build smoke

WSL exposes the driver library at /usr/lib/wsl/lib/libcuda.so, but cli_build only passes the CUDA toolkit's lib64 and lib directories. Supplying LIBRARY_PATH=/usr/lib/wsl/lib makes the exact same build succeed.

The linked binary then behaves as follows:

$ ./smoke --threads 2
65536

$ ./smoke --gpu on --threads 2
bend: --gpu on, but this binary found no GPU device

$ ./smoke --gpu 512MB --threads 2
bend: --gpu on, but this binary found no GPU device

$ ./smoke --gpu off --threads 2
65536

There is a CUDA device. A Driver API capability probe reports:

name                                      NVIDIA GeForce RTX 5090
CU_DEVICE_ATTRIBUTE_MANAGED_MEMORY        1
CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS 0

The current gpu_probe folds initialization, device discovery, the required managed-memory capability, context setup and success into one Boolean. Refusing this GPU is correct for the current shared-corpus CUDA runtime; reporting that no device exists is not. The default run also silently executes the marked call on CPU, making it difficult to know that requested GPU work never used the GPU.

Requested fixes:

  1. On WSL, add /usr/lib/wsl/lib to the link search when libcuda.so exists (or use the toolkit stub for link-time only).
  2. Preserve the probe failure reason and distinguish no driver, no device, no managed memory, no concurrent managed access, and context failure.
  3. When a binary with reachable ! calls falls back because a present GPU lacks a required capability, print a clear one-time note, or provide an explicit status/diagnostic mode.

This is current on 47bed75; older Bend 1 WSL issues were closed during the Bend 2 repository transition and do not cover this runtime.

The file

import Base

def pow2(+n: Nat) -> U32:
  match n:
    case 0n:
      1
    case 1n+p:
      a b = pow2(p) pow2(p)
      (a + b : U32)

def main() -> IO(Unit):
  do IO<Unit>:
    IO.print(U32.show(pow2!(16n)))

bend --version

The current source prints bend 2.0.27 via bend version; commit tested: 47bed75adedd6d6dd811721905f06569bf465f85.

uname -sm

Linux x86_64 — Ubuntu 26.04 on WSL2, kernel 6.18.33.2-microsoft-standard-WSL2, RTX 5090, Windows NVIDIA driver 610.62, CUDA toolkit 13.1.

clang --version (first line)

Ubuntu clang version 21.1.8 (6ubuntu1)

Activity

  1. costamatheus97 commented on Sep 25, 2026

    @costamatheus97
    Contributor

    The core blocker here is the missing concurrent managed access (CONCURRENT_MANAGED_ACCESS 0), not the missing driver library. The CUDA lane keeps one corpus in managed memory that the CPU and GPU both touch. WSL2 doesn't let the host access managed memory while a kernel may be running, so the CUDA runtime correctly refuses this GPU. Only the message and the fallback are misleading.

    I'm supporting an AMD lane at and ran into the same limitation on WSL2, since ROCm through librocdxg has no shared or HMM memory there either. I worked around it by not sharing memory at all:

    • A device twin. The corpus has a copy in VRAM (hipMalloc). Host and device never access the same memory at the same time.
    • Explicit syncs at the edges of a ! call. Entering a ! call uploads what the host changed. The passes then run entirely on the twin. Leaving brings back what the device changed. Between calls, the host works on its own copy only.
    • Only the changes move. The heap is tracked in 256 KB chunks:
      • device stores into old memory mark their chunk in a write map, and the host fetches only those chunks back;
      • chunks the device may have changed are mprotect-ed on the host and downloaded lazily on first touch;
      • host writes to clean chunks are trapped the same way, so the next call uploads only dirty chunks.

    The protocol is modelled and its coherence laws proven in Bend in demos/proof_gpu_coherence.

    The cost is a fixed sync overhead per ! call. On an RX 7800 XT under WSL2, an empty call costs a few hundred microseconds, and an input that's been uploaded once stays resident across calls. That's fine for ! calls that do real work. It's worse than true shared memory for very chatty programs. In exchange, it needs nothing from the platform beyond plain device allocations and copies. That's why it works on WSL2, and it should work on any GPU without concurrent managed access.

    The same design could give the CUDA lane a fallback for exactly this case: cuMemAlloc plus explicit copies when the probe finds managed memory without concurrent access, instead of refusing the device. It's a larger change than the diagnostics requested here, so it probably deserves its own issue. I'm happy to help port it, since the protocol and the write-map marking are lane-agnostic apart from the allocation and copy calls.

    Separately, the AMD lane has the same diagnostic gaps as points 2 and 3. Its probe also returns a single boolean, and it shares the "found no GPU device" message and the silent CPU fallback. A shared fix, with a per-lane probe reason and a one-time note on fallback, would cover both lanes.

  2. SiliconState commented on Sep 26, 2026

    @SiliconState
    Author

    Update: no fix on main yet. 11c65a2 still fails with cannot find -lcuda without LIBRARY_PATH.

    PR #1078 (c357d59) covers point 1: it adds the toolkit's lib64/stubs, and the binary resolves /usr/lib/wsl/lib/libcuda.so.1 at run time. It also accepts this GPU through a VRAM twin: --gpu 512MB runs on the 5090 instead of failing.

    Points 2 and 3 remain open on both main and the PR:

    • gpu_probe still returns one Boolean. With --gpu on, every device it still refuses (no visible device, an integrated or pre-Pascal GPU without concurrent managed access, a context failure) gets --gpu on, but this binary found no GPU device (the no-device case checked on the PR with CUDA_VISIBLE_DEVICES=).
    • Nothing reports a fallback: the default mode drops to the cores silently when the probe fails, and on the PR a ! after a parallel host phase runs on the cores without a word (A parallel host phase makes later ! calls silently run on CPU instead of GPU #1065).

    @costamatheus97, agreed: a per-lane probe reason plus a one-time fallback note would cover the HIP lane too.

  3. VictorTaelin commented on Sep 27, 2026

    @VictorTaelin
    Contributor

    Fixed in Bend 2.0.32 (573002f): --gpu on names why a CUDA GPU is unusable (WSL2 lacks concurrent managed access). A WSL2 GPU stays CPU-only: see WONTFIX (#1066).

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