Recompiler: a compute loop's passes shrink with the dispatch's size #2281
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2291"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-25T12:29:38Z.
Requested by Prime
A lane may run 65 536 loop passes before
LOOP_GUARDends its loops, so that console code looping on a count XCL gave it wrong does not keep the GPU busy. The bound is per lane, so the work it allows grows with the dispatch:WindNew:CS_AdvectFromParentStep(a542b07e605c8fd7) runs as 16 x 16 x 16 groups of 64 threads, and with a loop count that never comes that is about 31 s on an RTX 3060 Ti, where Windows removes the device after 2 s (the open dispatch of #1452; measurements in this comment). With this change every entry of a loop in a compute program has its own count of passes that shrinks with the dispatch's size, so a loop that runs away on its own ends in time. Part of #1452.What is in it
crates/xcl/src/gpu/recomp/mod.rs:IO_LOOP_BUDGET(io slot 113, free in the trap-temp range),DISPATCH_LOOP_PASSES(2^28),dispatch_loop_budget(groups); the two loop emitters askEm::loop_guardfor what goes before a loop and at its top.crates/xcl/src/gpu/recomp/emit.rs:Em::loop_guard. In a compute program a loop getsuint xcl_nK = xcl_cap;before it andif (xcl_nK == 0u) break; xcl_nK--;in front of the existing guard; the entry point setsxcl_cap = clamp(slot / threads per group, 1024, 65536)when the slot is not 0. The lane's budget of 65 536 for all its loops stays, so loops inside one another are not cut to one loop's share. Other stages and programs without a loop emit the HLSL they did.crates/xcl/src/hle/d3d12x/bind.rs,console_list.rs: a direct dispatch writes its share (2^28 / groups) into the slot. An indirect dispatch leaves 0: 65 536 as before.crates/xcl/src/gpu/recomp/tests.rs:dispatch_loop_budget_shrinks_with_the_groups,only_compute_programs_with_a_loop_read_the_dispatch_loop_budget(no GPU),gpu_compute_loop_passes_follow_the_dispatch.Up to 4096 lanes nothing changes. At 16 x 16 x 16 groups of 64 threads one entry of a loop ends after 1024 passes.
Tested
cargo test -p xcl --lib -- gpu_compute_loop_passes_follow_the_dispatch dispatch_loop_budget_shrinks only_compute_programs_with_a_loop: 3 passed, 0 failed, no SKIPPED. The GPU test runs a loop that never ends as a wave32 and as a split wave64 program: it stops after 65 536 passes with the slot at 0, after 5000 and 1024 for shares of that size, and entered three times it runs 3 x 1024.cargo test --workspace -- --test-threads=4: 1157 passed, 0 failed, 46 ignored (SKIPPED GPU tests: 25 – 20 need 64-lane waves, 3 are cases the direct per-lane form refuses,heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows),pso_measurement_compiles_an_exact_synthetic_record(needs Windows Developer Mode)).Regression run
Seeded 60 s runs without input (the same copied profile and shader cache for each, release builds from clean checkouts of the two commits,
XCL_HEAP_WINDOWS=1 XCL_LAZY_PSO=1 XCL_LAZY_COMPUTE=1 XCL_PSO_PRELOAD=0 XCL_DXC_THREADS=2). The main run is from earlier the same day, not back to back.main:
PR:
Not tested
AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-25T12:51:21Z.
@Prime1997 A heads-up from our #1284 (
XCL_LOOP_BUDGET, mergeable, headf3eb053). It isn't a duplicate, but the two meet in the same place:xcl_budgetthatLOOP_GUARDcounts down configurable:XCL_LOOP_BUDGETswaps the prelude's1u << 16for any whole number from 1. This PR adds a per-loopxcl_capin front of that guard, defaulting to1u << 16and clamped to1024..=1u << 16(emit.rs:4699,:4873at4bad505). With both merged, raisingXCL_LOOP_BUDGETabove 65 536 would no longer let a single loop in a compute program run longer, becausexcl_capwould end it first. Lowering it still works, becauseLOOP_GUARDfires first.git merge-treeof the two heads stops inrecomp/emit.rsandrecomp/mod.rs.If the upper bound of the clamp (and
xcl_cap's default) tookloop_budget()from #1284 instead of a literal1u << 16, the two would compose. Whichever merges second needs that. I'm happy to rebase #1284 onto this one if it lands first.AI-assisted (Claude Code). Read from the two diffs only; nothing run.
upstream-sync referenced this pull request2026-11-25 14:08:43 +00:00
Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-25T13:19:11Z.
AMD RDNA3 (native wave64) test report for exact head
4bad50562dd5e1f7c3a26602367904a695296892, as pushed (not merged onto currentmain).Tested
cargo build --workspace: okdispatch_loop_budget_shrinks_with_the_groups,only_compute_programs_with_a_loop_read_the_dispatch_loop_budget,gpu_compute_loop_passes_follow_the_dispatch: 3 passed, 0 failed (the GPU one ran, not skipped)cargo test --workspace --no-fail-fast -- --test-threads=4: 1156 passed, 1 failed, 46 ignored (summed over all test binaries)1a0bbe3` with `cargo test -p xcl --lib fuzz_validate_and_gpu_1`, so it is pre-existing on RDNA3, not caused by this PR.Not tested
scripts/smoke.ps1regression run (synthetic GPU/unit tests only)main; other GPUs (NVIDIA / Intel / RDNA2 / RDNA4)XCL_LOOP_BUDGET) mentioned in the commentsAI use: Claude Code (Claude Sonnet 5.5) ran the build and tests and wrote this report; the numbers are from the runs above.
Imported from ivall/xcl. Originally posted by Lum7nt on 2026-11-25T13:10:09Z.
AMD targeted tests on clean head
4bad50562dd5e1f7c3a26602367904a695296892: Windows 11 build 26300, Radeon RX 9070 XT (driver32.0.32029.2010), Rust 1.100.0 MSVC, DXC/DXIL 1.9.2609.5, release profile. SetXCL_ADAPTER=9070 XT,XCL_REQUIRE_GPU=wave64. For each filter below I rancargo test --offline --locked --release -p xcl --lib <filter> -- --nocapture --test-threads=1:gpu_compute_loop_passes_follow_the_dispatch: 1 passed, 0 failed, 0 ignored.dispatch_loop_budget_shrinks_with_the_groups: 1 passed, 0 failed, 0 ignored.only_compute_programs_with_a_loop_read_the_dispatch_loop_budget: 1 passed, 0 failed, 0 ignored.No SKIPPED messages. The first is the small single-group GPU fixture covering wave32 and wave64 program options and the different loop limits; the other two are CPU checks.
60 s retail smoke comparison: clean release builds; PR run first, then main. Same title,
XCL_ADAPTER=9070 XT,XCL_HEAP_WINDOWS=1,XCL_PSO_PRELOAD=0; no automated input. The PR produced 254 frames versus main’s 1556 (16.3%, below the 80% comparison threshold), with zero recorded crashes or device removals. This single pair is order-sensitive and does not establish a cause or a reproducible regression; caches and profile state were not reset between runs. The last three PR present intervals recovered to 11, 59, 60.Main:
PR:
Not tested: the large wind dispatch, progression past the loading hang, full workspace, or a controlled cache/profile comparison.
Repeat after main: Same settings and no reset; PR/main/PR run order. The repeated PR run showed 1577 frames, compared with 1556 on main. This makes the first result non-reproducible in this sequence but does not identify its cause.
AI use: OpenAI Codex (GPT-6; exact variant unavailable) ran the tests and smoke pair and drafted this report.
Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-25T14:52:59Z.
Independent Radeon iGPU and RTX 5090 check of
4bad50562dd5e1f7c3a26602367904a695296892, including the first two budgets on either side of the floor at 1,024 passes.Tested
cargo test --locked -p xcl --lib -- dispatch_loop_budget --nocapture --test-threads=1gave 2 passed, 0 failed on the unchanged head.cargo test --locked -p xcl --lib gpu_compute_loop_passes_follow_the_dispatch -- --nocapture --test-threads=1gave 1 passed, 0 failed on each adapter selected byXCL_ADAPTER. The cases ran in wave32 and logical wave64 on both GPUs. All other cases in the fixture also passed, including repeated loop entry. Zero ignores or skips in all runs. The two temporary cases were removed.Not tested
A retail dispatch, indirect dispatch behavior in an end-to-end run, the parent and the full workspace suite.
AI use
OpenAI Codex (GPT-6.2 Sol) added the temporary boundary cases, ran the checks and wrote this report.
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-25T16:33:56Z.
@upipibi agreed, and thanks for reading both diffs. The two compose the way you describe: the cap's default and the clamp's upper bound are the prelude's literal 65 536 only because
loop_budget()is not onmain. If #1284 lands first I rebase and takeloop_budget()in both places; if this one lands first, that is the same two-line change in your rebase.Thanks @Lum7nt, @oni-swr and @nnonno91 for the runs on AMD (native wave64 included) and the boundary cases at 1024 / 1025 passes.
Two updates from my side:
mainmoved under this (3f4495a, #2080 changedtranslated_dispatch), so the PR shows a conflict. The rebased commit is ready (bind_abi(…, Some([x, y, z])), then the dispatch chain asmainhas it; targeted tests 3 passed, workspace suite 1278 passed, 0 failed, 46 ignored on the RTX 3060 Ti). I push it together with its regression run so the description never names a head it was not run on.bind_abiwrites it for 16 x 16 x 16 groups, one a542 dispatch with a count that never comes takes 511 ms (271 ms for 2048 groups, 121 ms for 1024). Counts of 0 / 64 / 256 take 1.0 / 6.8 / 23 ms as before.0x887a0006); one alone was not. So if a title issues several runaway dispatches in a row, this is not enough on its own. The same reasoning says a dispatch thatmainnow runs in slabs (#2080) should keep the whole dispatch's size for the slot, which the rebase does.AI use: Claude Code (Claude Fable 5.2) wrote this and ran the measurements on Prime's machine.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T17:29:47Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-29T04:36:17Z.
Independent synthetic RTX 3080 Ti check of #2291 head
4bad505and its exact parent1a0bbe3. Windows 11 build 26300, NVIDIA 621.35, Ryzen 7 9800X3D, rustc 1.99.1, DXC 1.8.2502.11. A finite synthetic RDNA2 compute loop increments until its own target of 1,025, then stores the count. On the PR head, the GPU returned 1,025 with slot 113 = 0 and 1,024 with slot 113 =dispatch_loop_budget([16,16,16]). The same test on the parent returned 1,025 with both slot values. Command on each:cargo test --offline --locked -j 4 -p xcl --lib gpu_finite_loop_keeps_its_result_above_the_dispatch_share -- --test-threads=1 --nocapture; head 0 passed, 1 failed, parent 1 passed, 0 failed, no ignores or skips.The fixture launches only one group and supplies the slot value that production calculates for a 16×16×16-group, 64-thread dispatch. It verifies the per-lane HLSL behavior without making a large dispatch or claiming a title result. This demonstrates a valid finite loop can silently produce a different output under the new default cap. The existing endless-loop test proves the cutoff works, but cannot establish output parity for valid counts above it. I would keep the dispatch-sized cutoff out of the default correctness path. For the reported world-load hang, #2205 can help trace the count passed to the affected dispatch; the value the GPU actually consumes and its producer ordering still need verification. A general threshold cannot distinguish stale input from a valid long loop. Current-main integration, the full suite and clean-head smoke still need rechecking.
Failing PR-head GPU regression (passes on its parent with slot 113 = 65,536)
AI use: Codex (GPT-6.2 Sol) built and ran both GPU checks and wrote this report; Codex (GPT-6.2 Astra) independently traced the loop-cap and dispatch paths.
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-29T22:46:03Z.
Review: COMMENTED
Critical review of current head
4bad5056. Blocking semantic regression: the dispatch-size cap can terminate a valid finite loop before its expected 1,025th iteration in a 16×16×16 dispatch. The independent GPU fixture passed on the parent and failed on this head when the per-dispatch budget was active. A watchdog heuristic must not change a shader's correct result based on dispatch size. Please make the reduced cap opt-in/diagnostic or prove a safe bound for the affected program, and retain the finite-loop regression. This branch also conflicts with main. No local GPU run.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:17:02Z.
Review (head
4bad5056, diff read, not a merge-check; it conflicts with main, so not built or run):2536d2ff(cherry-picked via #3203).Em::loop_guard,IO_LOOP_BUDGET(slot 113),dispatch_loop_budgetand the three tests are on main as written here; main then added the same budget to the direct DXIL translator (d9a247bd) and an off switch,XCL_DISPATCH_LOOP_BUDGET=0(a0b82da2).Fine: the per-entry counter leaves nested loops the lane's full budget, and indirect dispatches keep 65,536. Recommendation: close as superseded by
2536d2ff.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:51:53Z.
Closing as superseded: this change is already on
main(2536d2ff). PR's changed lines are identical to main2536d2ff'a compute loop's passes shrink with the dispatch's size' (compared line by line, no difference)Two independent checks found this: Foniass's close list on #1607 and ours against current
main. If something here is still missing onmain, say so and reopen it, or ask and I will.AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.
Pull request closed