Repository navigation
A ! runs on the GPU under WSL2: a CUDA device without concurrent managed access gets a twin of the corpus - #1078
MattCozendey wants to merge 11 commits into
Conversation
…the register cap The previous merge of feature/cuda-twin was reverted; this one takes the refactored series (bendlang#1078) and the main it sits on. Where the two met: v3's two-word Env, then the park registers' defines; the _WIN32 pool group, then the POSIX trap for a twin; main's process_drain after process_run's _WIN32 group; the README's watchdog line for Windows and WSL; main.ts builds the lane on Windows (no !win on bangs). The connecting commit's pool_fault hook and setenv still stand. comp.ts's cap goes to 74000, process_run.c's to 5000. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Tested
Turns and copies were counted from outside with an LD_PRELOAD shim that forwards
The new test doesn't exercise what its comment describes. def gens(+n: Nat, +x: U32) -> Tr:
match n:
case 0n:
Lf{x}
case 1n+p:
l = gens(p, U32.shl(x))
r = gens(p, U32.inc(U32.shl(x)))
Nd{l, r}with Not tested here: the default |
|
Thank you for the review and the shim. You are correct.
I got the same numbers on WSL2 (RTX 4050 Laptop, driver 610.62):
2088344 uses your fix: I also tested two items from your list:
Not tested: native Linux, Metal, the gates. |
|
Nice to see the twin on CUDA. It's the design from my HIP lane (#891), and I think
I ran your CUDA host code over HIP on an RX 7800 XT under WSL2, through a small
I opened MattCozendey#1 against your branch.
Each commit stands alone, so take just commit 1 if the ttok budget is tight (it's +600). It would be great if you could check it on the 4050, since that's the configuration where the race should actually land. |
…'s is off the linker's path
WSL keeps the driver's libcuda in /usr/lib/wsl/lib, which the loader finds
through ld.so.conf but ld does not search for -lcuda: a ! program failed
to build there ("cannot find -lcuda") instead of running on the cores.
$CUDA_HOME/lib64/stubs goes after the other -L paths, so a driver's
libcuda on them still wins; the stub's soname is libcuda.so.1, and the
loader maps the driver's at run time. The same holds for a machine that
builds with the toolkit and no driver.
On WSL (Ubuntu 24.04, CUDA 13.3, clang 22, RTX 4050 Laptop), without
LIBRARY_PATH: tests/run/gpu_turns builds, ldd names
/usr/lib/wsl/lib/libcuda.so.1, and --gpu off prints its line. Not run:
native Linux.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…us gets a twin Under WDDM (WSL2, and native Windows) a device reports no concurrent managed access: a managed block is made resident whole at each launch, and the CUDA lane's one managed corpus the size of VRAM took the video memory manager down (bugcheck 0x10E on an RTX 4050 Laptop). The probe refused such a device, so a ! there ran on the cores. Such a device (a discrete Pascal or later) now gets a twin: device memory as large as the host's corpus. Every Loc is an index and the host never runs during a turn, so a turn copies up what it can touch and down after it. The heap is lazy, in 2 MB chunks: after a turn each is stale (no access); a host touch downloads it clean (read-only), a host write makes it dirty, and the next turn uploads only the dirty ones. The host's corpus is two mappings of one section, so a fault fills its chunk through the second while the first still traps; the trap runs on a 1 MB signal stack, as it calls CUDA. The twin's span stops an eighth of the free memory (at least 512 MB) short of it. A pass the display driver's watchdog stops fails with its own message. The .gpu is read whole, without mmap, on every host. A twin fills a window's frame on the cores. A device with concurrent managed access keeps the managed corpus, its span and its signal stack; Metal is untouched, and the Linux CPU build's assembly is main's. tests/run/gpu_turns pins three ! turns with the host rebuilding a device-built tree between them. comp.ts's cap goes from 64000 to 66500. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…river's watchdog WDDM (WSL2, native Windows) stops a launch past about 2 s (the TDR; the RTX 4050 Laptop reports kernel exec timeout 1), and a drain runs each lane's whole subtree in one launch. A twin's program is now built with -DBEND_PARK: a lane past its budget parks at its next jump (WL_GO, the emitter's WL_JMP with the K registers it fills), return or self-jump: the K registers go on its own stack, its fid, seq, rn, K and depth into two words under the stack, and it replies TERM_HOLE. A later pass 1 resumes it before its ring (monk_step takes no ring task then, and its join deals across the bag); a grow pass skips it. gpu_pass relaunches drains while H_PARKED counts a parked lane. The budget is GPU_WALL (250 ms) over the waves of groups the device fits at once, timed by %globaltimer from each group's start. A pure spin_N's loop cannot park: one pure loop in a ! must end within the watchdog, which the README states. Linux and Metal: the host's WL_GO and WL_AGAIN(F, K) expand as WL_JMP and WL_AGAIN(F) did, and the plain device program is main's. The twin's program is not held to the plain one's register count: on WSL2 (RTX 4050) queens runs in 13.9 s at size 18 against 15.7 to 17.8 s with the cap, whose spills cost more than the groups it kept. comp.ts's cap goes from 66500 to 68500. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the register cap) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A fork on the host sends every later ! to the cores (bendlang#1065): with h = gen(10n, 3) the last flip! and sum! ran on the CPU, and the turn that mixes a host-built tree with a device-built one was never checked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2088344 to
6a9914d
Compare
… take racing a push no longer reads a dead task gpu_rings copied each ring's live slots, [get, put), and nothing else. A slot one side pushed and took between two syncs never crossed, so the other side kept that slot's word from an older lap; when that side's put came round to it, a take racing the push read the old word as the new lap's and took a dead task (found by Matheus Costa on bendlang#1078, with the fix on his HIP lane, bendlang#891). gpu_rings now keeps each ring's put at the last sync (from) and copies [from, put), or [get, put) when get is older: the slots taken since cross with their own lap. The fix stays in the twin's host code: no mend, no kernel, and Linux, Metal and the managed CUDA program are as before. An audit comparing both sides' lap words after each sync (WSL2, RTX 4050 Laptop, CUBE_LOG 7) found stale host slots on every sync, 468,960 on gpu_turns and 22.1M on a tree of 2^20 leaves folded 24 times on the device and 24 on the host; none with the fix, and every answer as before. Times within run noise on both (medians of 5). Co-Authored-By: Matheus Costa <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@costamatheus97 Thank you. You are right, and the race still holds after this branch's rebase onto 2.0.29. On WSL2 with an RTX 4050 Laptop (CUBE_LOG 7), I ran an audit of both sides' lap words after each sync. It found stale host slots on every sync:
Every answer was still right, so the race did not land in these runs, but the stale slots are there. I have committed the fix to this PR's branch in a twin-only form, with you as co-author. It lands with my next push, together with the rebase onto 2.0.29. I'll review commits 2–6 shortly. |
… hot Every twin copy goes through gpu_alias, and a step of it that has carried twice its size is pinned with cuMemHostRegister (2 GiB at most; a refusal ends pinning). A copy is cut at the steps, since CUDA refuses one across two registrations. A pinned copy runs about twice as fast as a pageable one and a pin costs about two copies, so a loop that crosses the seam each frame pins its heap in a few frames, and a single run pins nothing. The steps are 8 MiB: natively on Windows, a 64 MiB pin stalled a frame 10 to 22 ms, an 8 MiB one about 2. WSL2, RTX 4050 Laptop, medians of 5: Slash Boss's probe frame (SLASH_PROBE=300) goes from 42.9 to 35.3 ms (draw 29.1 to 24.0), its output unchanged; fold24, a tree of 2^24 leaves, gpu_turns and queens at size 18 hold. Only a twin runs this code: Metal, and CUDA with managed memory, are untouched. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@costamatheus97 As promised, I reviewed commits 2–6. Thank you for them, and for taking the time to port them from your HIP lane. I measured each prefix of MattCozendey#1 on the RTX 4050 Laptop (WSL2, NVIDIA, no shim), on
This PR now also pins the twin's copies (commit 5 in the description): Slash Boss's probe frame goes from 42.9 to 35.3 ms on WSL2. That speeds up the copies themselves, so it doesn't overlap with 2–6. For now, 2–6 stay out of #1078, to keep its scope, and its claim that Linux and Metal are untouched, easy to review. Commit 6 in particular looks like a good fit for later work on the twin's sync cost. |
|
Re-tested the current head
This isn't a stress test of the ring race. I didn't run the lap audit or a host-binning workload, only these programs. |
…rn's planes cross whole The ring fix (9d4eaef) copied every slot plane some ring wrote since the last sync. At CUBE_LOG 7 the rings are 128 MiB of planes, and a busy turn touches most of them: Slash Boss's probe frame went from 29.2 to 33.6 ms on WSL2 (RTX 4050), 13.2 to 17.6 natively on Windows, where syncs come each frame. The sync copies the live planes again, and the side a copy lands on mends the slots the other took since the last sync: each gets its lap and no task, as a take leaves it (ring_mend, after the mend on Matheus Costa's HIP lane). Down the host mends its own copy; up ring_mend_dev, a lane a ring, mends the device's, launched only when the host took some. The kernel is under BEND_PARK and the helper in the CUDA host and the twin's program only, so Linux, Metal and the managed CUDA program are as before. WSL2, RTX 4050 Laptop, medians of 5: Slash's probe frame 29.4 ms (18.5 ms draw), against 29.2 without a fix and 33.6 copying the planes; fold24, a tree of 2^24 leaves and gpu_turns hold. The lap audit finds no stale slot on either side after any sync in gpu_turns, fold24 and Slash (without a fix, Slash leaves 209M on the host and 24.8M on the device over 240 syncs), and Slash's output is the same in every run. Co-Authored-By: Matheus Costa <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01G3htSNrQ8QKbP6S7zmTV9B
|
A correction on the ring fix, and a follow-up (@costamatheus97, @SiliconState). I said the twin-only fix's times were within noise. That was wrong for busy programs. It copied every slot plane some ring wrote since the last sync. At CUBE_LOG 7 that's up to 128 MiB per sync, and a program that syncs every frame pays it each time: Slash Boss's probe frame on WSL2 went from 29.2 ms without a fix to 33.6 ms with it. @SiliconState's shim saw the same cost from outside, as the extra 0.6 to 15.5 MiB of downloads per run. I had only timed programs with a few dozen syncs. Commit 6 (
Unlike commit 1 as written, the kernel and its helper sit under WSL2, RTX 4050 Laptop, medians of 5 interleaved runs:
So the device side does go stale in a real program. My earlier runs, all on small programs, only ever showed the host side. @SiliconState, thank you for re-testing on the 5090. Your pinning numbers match what I see here. At |
|
@MattCozendey Thank you for checking this on the 4050, and for measuring 2–6 on real NVIDIA hardware. The mend under Here is the particles demo: https://github.com/costamatheus97/bend/tree/723084baaa0267ee086f5c223c60b8a0084961d7/demos/app_particles_2d Only bun bend2/main.ts demos/app_particles_2d/main.bend -o /tmp/particles
PARTICLES_SCALE=65536 PARTICLES_PROBE=24 PARTICLES_BIN=host /tmp/particles --threads 16 --gpu 3GB
The race failures I saw were at 65536 with host binning on 16 threads. Your commit 3 result makes sense. A 256 KB chunk downloads less per fault but takes more faults. My guess, which I haven't measured, is that a fault and a copy cost less relative to bytes on rocdxg than on your driver, so the smaller downloads won here and the extra faults cost more there. If the particles numbers show the same split, the chunk size may need to depend on the platform rather than be fixed. I agree with keeping 2–6 out of #1078. I'll close MattCozendey#1, and once #1078 lands, I can open the prefetch (6) against main as its own PR. |
… the host's pages alone A twin's lanes allocated in the host's pages, so every turn made nearly every chunk the host held stale, and the host downloaded all of it again: Slash Boss's probe took 17.8 GiB of downloads over 300 frames on WSL2. The heap now splits (BEND_SPLIT): the host's pages from the bottom, the lanes' from the top, a node of the lanes the host frees going back to them and one of the host's a lane frees coming back, up to 4096 a turn (past it the side that frees keeps the node: a walk that rebuilds what it reads reuses it while it's in cache). A turn stales only the chunks it changed (twin_sum's two sums before and after), the sync walks only the chunks the host holds, a chunk the host writes each turn stays dirty, and a slice of the clean ones cools each up. Split, the chunks are 256 KiB (64 KiB made a walk's faults cost more, 2 MiB lost Slash a millisecond). A window's frame fills on the device on a twin too. The only shared code it touches is the allocator's (heap_alloc_miss, heap_free, bank_at), each change under #if BEND_SPLIT, which only a twin's NVRTC program sets, or TWIN_SPLIT, the CUDA host build's: the CPU build, Metal and the managed CUDA program compile as before, and in the CUDA host build a managed device never takes the split's branches. WSL2, RTX 4050 Laptop, medians of 5 interleaved runs against the head before: Slash Boss's probe frame 29.9 -> 14.2 ms; particles (Matheus Costa's demo) 22.9 -> 15.3 ms at 16K with host binning, 52.9 -> 40.7 at 64K, 171.8 -> 123.4 at 262K, and 39.5 -> 35.7, 63.6 -> 60.6, 184.6 -> 173.7 with device binning; gpu_turns holds (0.31 -> 0.32 s); a tree of 2^24 leaves 1.07 -> 1.33 s and a 2^20 tree folded 24 times on each side 0.66 -> 0.76 s, which walk everything the device built. Every output is the same as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01G3htSNrQ8QKbP6S7zmTV9B
|
Thank you for the careful twin and the numbers. We closed #1066 for capacity reasons: a device-resident copy of the corpus is a second memory model that we cannot maintain. Note: an AI wrote this reply after I made the decision. If anything here is wrong, reply and I will review it myself. |
|
Thanks for the review. I could mantain this myself, as it's neatly separated from the surrounding code and poses no risk to it; but if you insist I will just keep it on my own fork. |
… take racing a push no longer reads a dead task gpu_rings copied each ring's live slots, [get, put), and nothing else. A slot one side pushed and took between two syncs never crossed, so the other side kept that slot's word from an older lap; when that side's put came round to it, a take racing the push read the old word as the new lap's and took a dead task (found by Matheus Costa on bendlang#1078, with the fix on his HIP lane, bendlang#891). gpu_rings now keeps each ring's put at the last sync (from) and copies [from, put), or [get, put) when get is older: the slots taken since cross with their own lap. The fix stays in the twin's host code: no mend, no kernel, and Linux, Metal and the managed CUDA program are as before. An audit comparing both sides' lap words after each sync (WSL2, RTX 4050 Laptop, CUBE_LOG 7) found stale host slots on every sync, 468,960 on gpu_turns and 22.1M on a tree of 2^20 leaves folded 24 times on the device and 24 on the host; none with the fix, and every answer as before. Times within run noise on both (medians of 5). Co-Authored-By: Matheus Costa <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
… take racing a push no longer reads a dead task gpu_rings copied each ring's live slots, [get, put), and nothing else. A slot one side pushed and took between two syncs never crossed, so the other side kept that slot's word from an older lap; when that side's put came round to it, a take racing the push read the old word as the new lap's and took a dead task (found by Matheus Costa on bendlang#1078, with the fix on his HIP lane, bendlang#891). gpu_rings now keeps each ring's put at the last sync (from) and copies [from, put), or [get, put) when get is older: the slots taken since cross with their own lap. The fix stays in the twin's host code: no mend, no kernel, and Linux, Metal and the managed CUDA program are as before. An audit comparing both sides' lap words after each sync (WSL2, RTX 4050 Laptop, CUBE_LOG 7) found stale host slots on every sync, 468,960 on gpu_turns and 22.1M on a tree of 2^20 leaves folded 24 times on the device and 24 on the host; none with the fix, and every answer as before. Times within run noise on both (medians of 5). Co-Authored-By: Matheus Costa <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
… take racing a push no longer reads a dead task gpu_rings copied each ring's live slots, [get, put), and nothing else. A slot one side pushed and took between two syncs never crossed, so the other side kept that slot's word from an older lap; when that side's put came round to it, a take racing the push read the old word as the new lap's and took a dead task (found by Matheus Costa on bendlang#1078, with the fix on his HIP lane, bendlang#891). gpu_rings now keeps each ring's put at the last sync (from) and copies [from, put), or [get, put) when get is older: the slots taken since cross with their own lap. The fix stays in the twin's host code: no mend, no kernel, and Linux, Metal and the managed CUDA program are as before. An audit comparing both sides' lap words after each sync (WSL2, RTX 4050 Laptop, CUBE_LOG 7) found stale host slots on every sync, 468,960 on gpu_turns and 22.1M on a tree of 2^20 leaves folded 24 times on the device and 24 on the host; none with the fix, and every answer as before. Times within run noise on both (medians of 5). Co-Authored-By: Matheus Costa <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
… take racing a push no longer reads a dead task gpu_rings copied each ring's live slots, [get, put), and nothing else. A slot one side pushed and took between two syncs never crossed, so the other side kept that slot's word from an older lap; when that side's put came round to it, a take racing the push read the old word as the new lap's and took a dead task (found by Matheus Costa on bendlang#1078, with the fix on his HIP lane, bendlang#891). gpu_rings now keeps each ring's put at the last sync (from) and copies [from, put), or [get, put) when get is older: the slots taken since cross with their own lap. The fix stays in the twin's host code: no mend, no kernel, and Linux, Metal and the managed CUDA program are as before. An audit comparing both sides' lap words after each sync (WSL2, RTX 4050 Laptop, CUBE_LOG 7) found stale host slots on every sync, 468,960 on gpu_turns and 22.1M on a tree of 2^20 leaves folded 24 times on the device and 24 on the host; none with the fix, and every answer as before. Times within run noise on both (medians of 5). Co-Authored-By: Matheus Costa <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
… take racing a push no longer reads a dead task gpu_rings copied each ring's live slots, [get, put), and nothing else. A slot one side pushed and took between two syncs never crossed, so the other side kept that slot's word from an older lap; when that side's put came round to it, a take racing the push read the old word as the new lap's and took a dead task (found by Matheus Costa on bendlang#1078, with the fix on his HIP lane, bendlang#891). gpu_rings now keeps each ring's put at the last sync (from) and copies [from, put), or [get, put) when get is older: the slots taken since cross with their own lap. The fix stays in the twin's host code: no mend, no kernel, and Linux, Metal and the managed CUDA program are as before. An audit comparing both sides' lap words after each sync (WSL2, RTX 4050 Laptop, CUBE_LOG 7) found stale host slots on every sync, 468,960 on gpu_turns and 22.1M on a tree of 2^20 leaves folded 24 times on the device and 24 on the host; none with the fix, and every answer as before. Times within run noise on both (medians of 5). Co-Authored-By: Matheus Costa <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
… take racing a push no longer reads a dead task gpu_rings copied each ring's live slots, [get, put), and nothing else. A slot one side pushed and took between two syncs never crossed, so the other side kept that slot's word from an older lap; when that side's put came round to it, a take racing the push read the old word as the new lap's and took a dead task (found by Matheus Costa on bendlang#1078, with the fix on his HIP lane, bendlang#891). gpu_rings now keeps each ring's put at the last sync (from) and copies [from, put), or [get, put) when get is older: the slots taken since cross with their own lap. The fix stays in the twin's host code: no mend, no kernel, and Linux, Metal and the managed CUDA program are as before. An audit comparing both sides' lap words after each sync (WSL2, RTX 4050 Laptop, CUBE_LOG 7) found stale host slots on every sync, 468,960 on gpu_turns and 22.1M on a tree of 2^20 leaves folded 24 times on the device and 24 on the host; none with the fix, and every answer as before. Times within run noise on both (medians of 5). Co-Authored-By: Matheus Costa <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
… take racing a push no longer reads a dead task gpu_rings copied each ring's live slots, [get, put), and nothing else. A slot one side pushed and took between two syncs never crossed, so the other side kept that slot's word from an older lap; when that side's put came round to it, a take racing the push read the old word as the new lap's and took a dead task (found by Matheus Costa on bendlang#1078, with the fix on his HIP lane, bendlang#891). gpu_rings now keeps each ring's put at the last sync (from) and copies [from, put), or [get, put) when get is older: the slots taken since cross with their own lap. The fix stays in the twin's host code: no mend, no kernel, and Linux, Metal and the managed CUDA program are as before. An audit comparing both sides' lap words after each sync (WSL2, RTX 4050 Laptop, CUBE_LOG 7) found stale host slots on every sync, 468,960 on gpu_turns and 22.1M on a tree of 2^20 leaves folded 24 times on the device and 24 on the host; none with the fix, and every answer as before. Times within run noise on both (medians of 5). Co-Authored-By: Matheus Costa <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
… take racing a push no longer reads a dead task gpu_rings copied each ring's live slots, [get, put), and nothing else. A slot one side pushed and took between two syncs never crossed, so the other side kept that slot's word from an older lap; when that side's put came round to it, a take racing the push read the old word as the new lap's and took a dead task (found by Matheus Costa on bendlang#1078, with the fix on his HIP lane, bendlang#891). gpu_rings now keeps each ring's put at the last sync (from) and copies [from, put), or [get, put) when get is older: the slots taken since cross with their own lap. The fix stays in the twin's host code: no mend, no kernel, and Linux, Metal and the managed CUDA program are as before. An audit comparing both sides' lap words after each sync (WSL2, RTX 4050 Laptop, CUBE_LOG 7) found stale host slots on every sync, 468,960 on gpu_turns and 22.1M on a tree of 2^20 leaves folded 24 times on the device and 24 on the host; none with the fix, and every answer as before. Times within run noise on both (medians of 5). Co-Authored-By: Matheus Costa <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
… take racing a push no longer reads a dead task gpu_rings copied each ring's live slots, [get, put), and nothing else. A slot one side pushed and took between two syncs never crossed, so the other side kept that slot's word from an older lap; when that side's put came round to it, a take racing the push read the old word as the new lap's and took a dead task (found by Matheus Costa on bendlang#1078, with the fix on his HIP lane, bendlang#891). gpu_rings now keeps each ring's put at the last sync (from) and copies [from, put), or [get, put) when get is older: the slots taken since cross with their own lap. The fix stays in the twin's host code: no mend, no kernel, and Linux, Metal and the managed CUDA program are as before. An audit comparing both sides' lap words after each sync (WSL2, RTX 4050 Laptop, CUBE_LOG 7) found stale host slots on every sync, 468,960 on gpu_turns and 22.1M on a tree of 2^20 leaves folded 24 times on the device and 24 on the host; none with the fix, and every answer as before. Times within run noise on both (medians of 5). Co-Authored-By: Matheus Costa <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
… take racing a push no longer reads a dead task gpu_rings copied each ring's live slots, [get, put), and nothing else. A slot one side pushed and took between two syncs never crossed, so the other side kept that slot's word from an older lap; when that side's put came round to it, a take racing the push read the old word as the new lap's and took a dead task (found by Matheus Costa on bendlang#1078, with the fix on his HIP lane, bendlang#891). gpu_rings now keeps each ring's put at the last sync (from) and copies [from, put), or [get, put) when get is older: the slots taken since cross with their own lap. The fix stays in the twin's host code: no mend, no kernel, and Linux, Metal and the managed CUDA program are as before. An audit comparing both sides' lap words after each sync (WSL2, RTX 4050 Laptop, CUBE_LOG 7) found stale host slots on every sync, 468,960 on gpu_turns and 22.1M on a tree of 2^20 leaves folded 24 times on the device and 24 on the host; none with the fix, and every answer as before. Times within run noise on both (medians of 5). Co-Authored-By: Matheus Costa <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
… take racing a push no longer reads a dead task gpu_rings copied each ring's live slots, [get, put), and nothing else. A slot one side pushed and took between two syncs never crossed, so the other side kept that slot's word from an older lap; when that side's put came round to it, a take racing the push read the old word as the new lap's and took a dead task (found by Matheus Costa on bendlang#1078, with the fix on his HIP lane, bendlang#891). gpu_rings now keeps each ring's put at the last sync (from) and copies [from, put), or [get, put) when get is older: the slots taken since cross with their own lap. The fix stays in the twin's host code: no mend, no kernel, and Linux, Metal and the managed CUDA program are as before. An audit comparing both sides' lap words after each sync (WSL2, RTX 4050 Laptop, CUBE_LOG 7) found stale host slots on every sync, 468,960 on gpu_turns and 22.1M on a tree of 2^20 leaves folded 24 times on the device and 24 on the host; none with the fix, and every answer as before. Times within run noise on both (medians of 5). Co-Authored-By: Matheus Costa <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
WONTFIX tells Windows users to use WSL, and a user there expects
!to usethe GPU. Today it does not build (
cannot find -lcuda), or, withLIBRARY_PATHset, it runs on the cores without a message. This PR makesthe WONTFIX advice true.
Terms
(
CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS). With it, the host andthe device can use one managed allocation at the same time; the CUDA lane
on main needs it for its corpus. A GPU under WSL2 reports 0, so main's
probe refuses it.
memory, and a second copy of it (the twin) lives in VRAM. A
!turncopies what it can touch to the twin before it runs, and back after.
runs under, stops any single GPU launch after about 2 s (the TDR).
stops; the next launch resumes it. So no launch reaches the watchdog,
however long the whole
!runs.Why it is safe, and why it is needed
1. Linux: nothing changes for existing users
On native Linux, the CPU build is byte-identical to main's, and a CUDA
device with managed access takes main's path and main's device program.
clang -O3 -S) is byte-identical to main's forthe 16 runtime benches and the 19
!tests that compile.if (gpu_twin). On adevice with managed access those branches never run.
program at
--gpu-build) gets main's options, and the program's textdiffers from main's only where it compiles out or expands to main's
macros (point 2). Its cubin is byte-identical to main's for the same 35
programs.
2. Metal: no Metal code changed
No Metal code changed; every shared change compiles out or expands to
main's text on Metal. Please confirm on the minis (test and perf gates).
parking lane saves:
WL_GO(F, K)expands toWL_JMP(F)andWL_AGAIN(F, K)tocontinue, as before.#if BEND_PARK, which only the twin's NVRTCbuild sets.
gpu_twinis#defined asfalseoutside CUDA, soPOOL_ALT(thesignal stack's size, larger for a twin) is
SIGSTKSZ, andgpu_sync(a twin's copies around a turn) does nothing.
H_PARKEDandH_BUDGET(LINE + 1,LINE + 2)are read and written only by the twin and parking code.
3. WSL:
!now builds and runs on the GPUlibcudaagainst the toolkit's stub, which comes afterthe other
-Lpaths; its soname islibcuda.so.1, so at run time theloader loads the driver's library.
synced lazily, in 2 MB chunks: after a turn, the host downloads a chunk
only when it touches it (a page fault), and the next turn uploads only
the chunks the host wrote. So data that stays on the device is not
copied back and forth.
!tests that compile pass on WSL2 (RTX 4050, CUDA 13.3), bydefault, with
--gpu offand with--gpu 512MB.4. Why parking is needed, despite the comment on #1012
!with no parallelism onMetal. Here the program is parallel, and Windows' display driver (WDDM,
which every WSL2 GPU uses) stops any launch after about 2 s. The
maintainer's fixes do apply, but they give up the GPU:
!on WSL to the cores, soWSL users would still not have the GPU for real work (point 5).
would stop the program instead of finishing it.
!finish on the GPU under a 2 s limit.
(
-DBEND_PARK). Metal and Linux with managed access run main's deviceprogram.
constant and no build knob. The budget is time, read from
%globaltimer.queensat size 18 ran about 12 s on theGPU with no driver reset. With the budget forced down to 0.2 ms, so that
lanes parked every few thousand steps, 2,501 rounds of parking and
resuming gave the same results as the cores (RTX 4050 Laptop, under
WDDM).
5. WONTFIX sends Windows users to WSL
WONTFIX says "Use WSL", and a user there expects
!to use the GPU. Todayit does not build, or it runs on the cores without a message. This PR
makes the WONTFIX advice true.
The commits
!program links libcuda against the toolkit's stub where thedriver's is off the linker's path.
!runs on a CUDA device without concurrent managed access: the corpusgets a twin.
driver's watchdog.
take racing a push no longer reads a dead task (the race found by
@costamatheus97; twin-only).
hot.
turn's planes cross whole (it replaces commit 4's copy, which cost a
busy program about 15%, with @costamatheus97's mend; twin-only).
host's pages alone.
Review notes
and every change is behind an
#if.heap_alloc_miss,heap_freeandbank_atchange only underBEND_SPLIT, which only a twin's NVRTC programsets, or
TWIN_SPLIT, the CUDA host build's. The CPU build's assembly andthe managed CUDA program's cubin are byte-identical to main's; Metal
sets neither (
TWIN_SPLITis 0 off CUDA; not built here); in the CUDAhost build a managed device never takes the split's branches.
touch of a stale chunk causes that fault, on the thread that touched it.
reports no concurrent managed access; everything else is main's.
!on AMD GPUs: an experimental HIP/ROCm lane works #891). It follows the samedesign on the CUDA driver API; a shared twin layer is possible if HIP
merges.
gpu_twin, not on the watchdog attribute. A Linuxdesktop that shows X on the GPU does not get it yet.
loops as a plain C loop (
spin_N, fromemit_native), which has no pointwhere a lane can stop and save its state. One such loop in a
!muststill end within 2 s, and the README states this. For that case, a
warning or a CPU fallback (A ! call with no available parallelism holds the GPU indefinitely and crashes macOS (WindowServer watchdog) #942) is the right fix.
Request
Please run the gates (test and perf) on the minis for Metal, and on a
native Linux CUDA machine if one is available. These were not tested here.
Evidence
On the branch rebased onto Bend 2.0.29 (
574b6d39); times are medians of 5runs, with the range.
clang 20 -O3 -S), 16 runtime benches and 19!tests!tests on WSL2 (RTX 4050): default,--gpu off,--gpu 512MBqueenssize 18 on WSL2gpu_turnswith a tree of 2^24 leaves, four!turns, WSL2queenssize 18 (2,501 resume rounds), the 2^24 tree (4), 5!testsgpu_turns, a 2^20 tree folded 24 times on each side, and Slash Boss's probeSLASH_PROBE=300), WSL2, before and after commit 5Not tested: Metal, native Linux CUDA, the perf gate.
🤖 Generated with Claude Code