Repository navigation
A ! call's long sequential loop parks between launches, so no dispatch holds the GPU (#942) - #1012
MattCozendey wants to merge 6 commits into
Conversation
bf13668 to
2dd7716
Compare
…holds the GPU (bendlang#942) A ! call with no parallelism ran its whole chain inside one dispatch, which never returned and tripped the display's GPU watchdog. Each lane now gets FUEL * 4096 steps per launch. When they run out, work_loop pushes its bank and fid | rn | seq onto the lane's stack, copies the stack to the heap and deals it as a frontier task (TAG_PRK). The next pass 1 takes it back onto any lane's stack. A device self-loop hands every 4096th turn back to the switch, so the check covers it too. Pass 0 skips parked tasks, and a lane stops its pass 1 once it has parked, so each launch runs a task's chain once at most. The fuel lives in the lane's alc block, one word past ALC_LEN. A native spin (a flat def's loop) still runs whole inside its step. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…chdog is tighter FUEL keeps 64 unless the host build defines it. The host passes its value to the device compiler (NVRTC's -D, Metal's preprocessor macros), and the CUDA cache key hashes it, so a .gpu built under another budget is compiled again, not loaded. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…in, so the device can park it A spin (a flat def's native loop) runs whole inside one device step, so a long sequential loop under a ! still held its launch. bendlang#942's program is all spins: fill, bfs and fold each run 2^28 turns. carb_book now walks from the bang targets, and a looping def with no loop above it (a fork tree is one) is no longer flat. It compiles as a segment, whose self-loop parks when the lane's fuel runs out. An inner loop stays a spin: it runs once per turn of the loop above it, which cannot afford a segment's call. The broad version of this rule (every loop a bang reaches) cost kmeans 3x and raytrace 1.6x on the cores. This one leaves all 16 runtime benches' emitted C unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…p keeps its kernel Parking at the top of work_loop stored the whole register bank there, which kept every bank register live through the loop: queens went from 94 to 106 registers and tree-bitonic from 72 to 80. Parking at every loop's self-jump was worse (queens 120). Now the loops the spin rule already finds (a tail loop a bang reaches under no other loop) are the only park sites. At the jump, WL_PARK stores just the jump's N words, then F | N << 16 | seq << 24. The loop top and WL_SPIN are main's again. PARKS says whether a program has a park site. Without one, the resume, the fuel word and its checks compile out, and the layout is main's. All 16 runtime benches have none, so their preprocessed C (cores and device) is main's up to constant spelling, and their bend_dev registers match main's exactly. bendlang#942's fill, bfs and fold each park at their jump. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lang#942) bendlang#942 found an explicit --gpu 8GB wired whole: only the default went through gpu_span. gpu_span now answers the device's limit (Metal's recommended working set under its largest buffer, CUDA's total memory). Both the asked span and the default stop there, and an asked span over it says so on stderr. Metal's default stays 2GB. The cores' span is unchanged. This bounds one process. Several GPU programs running at once can still sum past the machine's memory. Co-Authored-By: Claude Opus 5.5 <[email protected]>
carb_park walks from the bang targets and stops at a loop, since everything under a loop keeps its flatness and gets no park. That drops the walk's under flag, its string keys and a FLATS.clear() that nothing needed (flatness is first asked at emission). corpus_setup's span choice moves to gpu_fit, where an asked span over the device is simply bytes > top. The emitted C of the 16 runtime benches, the 8 ! tests and bendlang#942's program is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2dd7716 to
867f36a
Compare
|
Thanks for taking on #942, and for the detailed write-up of what you could and couldn't verify. I'm going to close this one, but part of it is worth landing separately. The The parking mechanism is too much for what it fixes. It adds a new task tag, a park/resume path in The program in #942 is a
If you'd like to work on one of those, a new PR would be welcome. If you think long sequential chains should really be split across launches on the GPU, please open an issue first. That's a runtime design decision we'd want to make together before any code. |
|
GPU-cap change: #1047 |
This should fix the Mac crash in #942. Nothing here has run on a GPU, so I'm asking a maintainer to confirm it on a Mac (see the end).
The problem
In #942, a
!call with no parallelism never finished its command buffer, and WindowServer's watchdog took the session down. That program's work is three long sequential loops:fillandfoldover 2^28 cells, and a BFS over the same grid. Each loop compiled to a native spin (emit_native), a C loop that runs whole inside one step ofwork_loop. So the whole run happened inside one dispatch.The change
Which loops change (00bfaba, a squeeze in the last commit).
carb_parkwalks the call graph from the bang targets and stops at a loop. A loop it reaches with no other loop above it (a fork tree counts as a loop) is a top loop.Parking (0f0771d, 308bf77). Each top loop's self-jump emits
WL_PARK(N, F, words). Every 4096 jumps it spends one unit of the lane's fuel (FUEL= 64 per launch, so about 262k turns).F | N << 16 | seq << 24onto the lane's stack. Out of line,wl_parkcopies the stack to the heap and deals it as a frontier task taggedTAG_PRK, bumpingH_CURSORsocube_runlaunches again.work_looptakes aTAG_PRKtask back onto any lane's stack.alcblock, pastALC_LEN, where the host keepsALC_COLD.Programs with no top loop pay nothing.
#define PARKSsays whether a program has any park site. Without one, the resume path, the fuel word and its checks compile out, and the corpus layout is main's.2 * 32against(2 * 32 + 0)).bend_devregister counts under NVRTC match main's exactly.Where parks go. An earlier version parked at the top of
work_loop. That stored the whole register bank there and cost up to +12 registers (queens 94→106). Parking at every loop's jump was worse (queens 120). Park sites only at top loops is what keeps everything else at main's kernel.The
--gpuspan is bounded (633dbdf). #942 found that an explicit--gpu 8GBwas wired whole, because only the default went throughgpu_span.gpu_spannow returns the device's limit: Metal's recommended working set under its largest buffer, or CUDA's total memory.bend: --gpu is over the device's NMB; using thaton stderr.A build knob (9000e4b).
-DFUEL=nsets the budget for a host whose GPU watchdog is tighter than macOS's. The host passes it to the device compiler (NVRTC-D, Metal preprocessor macro), and it's part of the CUDA.gpucache key.What I verified
None of this ran on a GPU.
fill,bfsandfoldcompile as segments with one park site each. The kernel compiles with NVRTC 13.3 forsm_89(72 registers, no spills).!tests compile with NVRTC, also with-DFUEL=16. There are no new warnings and no spills. Every program without a park site has main's register count. The two that have one:symreg66→72 (same occupancy, since registers are allocated in eights) andgpu_reach_closure_list55→58.clang -fsyntax-only -Wallpasses for the CUDA host lane and the cores lane, with and without-DFUEL=16, including the span cap.gpu_span.comp.tsis 63,489 tokens.What I could not verify
!call, and the interpreter lane can't do that inside the 5 s alarm. No gate test parks.bend p1.bend -o p1 && ./p1 --gpu 2GB)? It should print1635505109without the display freezing.Limits
!with no parallelism is left for a follow-up. With this change, such a call no longer holds the GPU, so the warning would only be about performance.🤖 Generated with Claude Code