Repository navigation
Description
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 smokeThen, 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 2What 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:
- On WSL, add
/usr/lib/wsl/libto the link search whenlibcuda.soexists (or use the toolkit stub for link-time only). - Preserve the probe failure reason and distinguish no driver, no device, no managed memory, no concurrent managed access, and context failure.
- 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
costamatheus97 commentedon Sep 25, 2026
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:
hipMalloc). Host and device never access the same memory at the same time.mprotect-ed on the host and downloaded lazily on first touch;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:
cuMemAllocplus 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.
SiliconState commentedon Sep 26, 2026
Update: no fix on main yet.
11c65a2still fails withcannot find -lcudawithoutLIBRARY_PATH.PR #1078 (
c357d59) covers point 1: it adds the toolkit'slib64/stubs, and the binary resolves/usr/lib/wsl/lib/libcuda.so.1at run time. It also accepts this GPU through a VRAM twin:--gpu 512MBruns on the 5090 instead of failing.Points 2 and 3 remain open on both main and the PR:
gpu_probestill 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 withCUDA_VISIBLE_DEVICES=).!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.
Bend 2.0.32: the issue triage, root fixes, one verdict everywhere
VictorTaelin commentedon Sep 27, 2026
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).