Repository navigation
Conversation
…s share A loop that never ends on the GPU is a TDR. The direct DXIL translator already guards every loop it emits: each guest loop head (every target of a retreating CFG edge, so every cycle, also in the compact form's dispatcher) counts down the lane's budget (VAR_BUDGET, 65 536) and, in the plain form of a compute program, each loop entry's own count (the dispatch's share, IO_LOOP_BUDGET, 1024..65 536 a lane); the loops the lowering makes itself are bounded too (CAS loops 4096 rounds, the split form's spin exchange and the safe barrier 2^20 polls). At 0 the lane goes to the program's end; the budget is the same in every lane of a console wave and in both halves of a split one (they pass the same heads, the share is the dispatch's), so the wave leaves as a whole, and a multi-wave group's safe barrier stops counting it there (safe_barrier_exit), so no wave waits at a barrier for it. Going to the end rather than past the loop also never enters another loop. What was missing is a bound on the lane's whole loop work that follows the dispatch: nested loops (an inner loop's count starts afresh at each entry), loops one after another, and every loop of the compact form (large programs, which has no per-entry count) could still spend the lane's 65 536 passes - 31 s at the 0.47 ms a pass measured for a retail loop in a 262 144-thread dispatch on an RTX 3060 Ti. A compute lane's budget now starts at LOOP_SHARE_ENTRIES (4) loop entries of its share, at most the lane's guard: 65 536 for small dispatches and indirect ones (share unknown) as before, 4096 for large ones (~1.9 s at that rate in the worst case, a single runaway loop of the plain form still ends after one share). Four entries keep what working programs run (the tests' three full entries of a loop under a share, as the HLSL path). Switches (read once; non-default values get their own translated-cache identity): - XCL_DXIL_LOOP_GUARD=<n>: the passes a lane may run in all (default 65 536, also the most one loop entry gets); 0 emits no loop guard. - XCL_DXIL_LOOP_SHARE=0: the lane's budget does not follow the dispatch. The guard does not report that it fired: the translator has no feedback buffer for it, and adding one is more plumbing than this safety net should carry. The HLSL path and graphics stages keep their budgets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The compact form put the epilogue's register loads in the latch, but a compute program's entry gate also branches to exit, so a read there became a phi whose gate operand was a load the gate path never passes (invalid DXIL, "Instruction does not dominate all uses"). On main the epilogue read that meets this is the safe barrier's exit (safe_barrier_exit reads VAR_BAR_ALIVE) in a multi-wave group of a compact compute program with S_BARRIER. We found it in our builds with gpu_direct_compute_lane_budget_follows_the_dispatch, whose epilogue reads one more register there. Release builds do not validate, so compute shaders of the compact form could reach the driver invalid. The compact form keeps the registers in local variables, which hold their values on every way into exit. The epilogue now goes into an end block that no SSA edge enters and loads them there, so no read becomes such a phi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review (head e13653d, diff read, not a merge-check; checks red):
Fine: by reading, both new tests would fail without the first commit (4091 vs 10 000; no share-budget select in the disassembly). The AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
Test report (not a merge-check: AI-written and posted by Foniass without a human check of each point. |
bmjask
left a comment
There was a problem hiding this comment.
Review of e13653d7: 2 finding(s) (1 high, 1 medium), most severe first.
- High
crates/xcl/src/gpu/dxil/lower.rs:54: LOOP_SHARE_ENTRIES = 4 caps a lane's total loop-head passes across all loops, nested ones included, at 4 x share, so in large dispatches working nested loops are silently cut off and the lane jumps to the program's end, skipping its late.... (inline) - Medium
crates/xcl/src/gpu/dxil/lower.rs:58: Four shares were picked to fit under the TDR limit, but at the PR's own measured rate (4096 x 0.47 ms = 1.93 s) the margin under Windows' 2 s timeout is about 3%, so a slightly heavier loop body or other queued GPU work still removes the.... (inline)
These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
| /// 3060 Ti in a 262 144-thread dispatch (`recomp::DISPATCH_LOOP_PASSES`), 31 s for 65 536 and | ||
| /// 1.9 s for these 4 × 1024. Four entries keep what a working program runs (the tests' | ||
| /// three full entries of a loop under a share, `counted_loops(1024, 3)`, as the HLSL path). | ||
| pub const LOOP_SHARE_ENTRIES: u32 = 4; |
There was a problem hiding this comment.
High: LOOP_SHARE_ENTRIES = 4 caps a lane's total loop-head passes across all loops, nested ones included, at 4 x share, so in large dispatches working nested loops are silently cut off and the lane jumps to the program's end, skipping its later stores. A 1920x1080 compute pass with 8x8 groups (32 400 groups) gets share = 2^28/32400/64, clamped to 1024, so budget = 4096. A legitimate shader with an outer loop over 32 lights and an inner 128-step march spends 32*129 = 4128 head passes, exceeds 4096, leaves to end partway through the last light, and never writes its output. The PR notes the guard doesn't report when it fires, so this shows up only as corrupted output. Counting per loop entry (as the HLSL path's xcl_cap does), or applying the share only to loops without a per-entry count, would leave working programs alone.
|
|
||
| /// `XCL_DXIL_LOOP_GUARD=<n>`: the loop passes a lane of a direct DXIL program may run in all | ||
| /// (`VAR_BUDGET`'s start, default `LOOP_BUDGET`), and the most a compute loop's entry gets; | ||
| /// `0` emits no loop guard at all (a loop that never ends then hangs the GPU). Read once; a |
There was a problem hiding this comment.
Medium: Four shares were picked to fit under the TDR limit, but at the PR's own measured rate (4096 x 0.47 ms = 1.93 s) the margin under Windows' 2 s timeout is about 3%, so a slightly heavier loop body or other queued GPU work still removes the device. A runaway compact-form loop (which has no per-entry count) in a 262 144-thread dispatch whose body costs 0.5 ms a pass instead of 0.47 ms runs for 2.05 s, past the timeout, which is the failure the PR sets out to prevent. A larger margin (two shares, or a bound derived from a time target) would make the fix hold.
Requested by Prime
In the direct DXIL translator, a compute lane's loops were bounded per loop entry by the dispatch's share (1024 to 65 536 passes a thread), but the lane's total was still 65 536 passes. Nested loops (each entry of an inner loop starts a fresh count), loops one after another, and every loop of the compact form (programs of 20 000 instructions and more, which count no entry) could spend all of them. On an RTX 3060 Ti 8 GB a retail loop in a 262 144-thread dispatch took 0.47 ms a pass, so 65 536 passes would be about 31 s, far past the 2 s Windows waits before it removes the device. A compute lane's whole loop budget now starts at four entries of its dispatch's share, at most 65 536: large dispatches get 4096 passes (about 1.9 s at that rate in the worst case), small and indirect dispatches keep 65 536 as before. The lane then goes to the program's end, as it already did at 0. A second commit fixes invalid DXIL in the compact form's compute epilogue: on main it shows in a multi-wave group of a compact compute program with
S_BARRIER, whose safe barrier exit reads a register after the entry gate's path joins. We found it with the new GPU test in our builds, where the epilogue reads one more register.Related: #2793 gives each loop region its own budget in the HLSL path and in the direct translator's plain and compact forms; it touches the same budget code in
gpu/dxil/kernel.rs,compact.rsandlower.rs, so whichever lands second needs a rebase and a look at how the two caps combine. #1976 addsXCL_SHADER_LOOP_LIMIT, which also makes the direct translator's loop limit configurable, likeXCL_DXIL_LOOP_GUARDhere.What is in it (two commits)
crates/xcl/src/gpu/dxil/lower.rs:LOOP_SHARE_ENTRIES(4),loop_guard()(XCL_DXIL_LOOP_GUARD),loop_share_wanted()(XCL_DXIL_LOOP_SHARE), andInit::budget, the lane budget's first value when it is not the constant; a unit test of the guard's parsing.crates/xcl/src/gpu/dxil/kernel.rs:dispatch_loop_cap(the dispatch's share, split out ofloop_passes) andshare_budget(four shares, at most the guard), made once in the entry block for both forms;loop_guard_tagfor the cache identity, with a unit test. The compact form's epilogue now goes into an end block that no SSA edge enters and loads the registers there, so a read in it no longer becomes a phi of a load the entry gate's path never passes ("Instruction does not dominate all uses").crates/xcl/src/gpu/dxil/compact.rs: loop heads count down the budget only when the guard is on; comments on where reads load.crates/xcl/src/gpu/recomp/pso.rs,crates/xcl/src/shaders.rs: non-default switch values get their own translated-cache identity.crates/xcl/src/gpu/dxil/core_tests.rs:direct_compute_lane_budget_follows_the_dispatch_share(the budget in the disassembly, both forms) andgpu_direct_compute_lane_budget_follows_the_dispatch(passes run on the GPU with and without a share).README.md: the loop budget paragraph.Tested
cargo check -p xcl --lib --tests --target x86_64-pc-windows-gnupasses. The test suite was not run on this exact branch.Regression run
Not tested
scripts/smoke.ps1on this branch; AMD.Switches
XCL_DXIL_LOOP_SHARE(default on):=0leaves a compute lane the guard's passes in all, as before.XCL_DXIL_LOOP_GUARD(default 65 536): the passes a lane may run in all, also the most one loop entry gets;=0emits no loop guard at all.AI use
🤖 Generated with Claude Code