Recompiler: a compute loop's passes shrink with the dispatch's size #2291
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2291
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Prime1997 on GitHub · 2026-11-25 12:29 UTC · original
Prime1997:contrib/dispatch-loop-budget→main· +198 −8 · 5 files · 1 commits · openRequested by Prime · project thread
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
@upipibi on GitHub · 2026-11-25 12:51 UTC · original
@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.
@oni-swr on GitHub · 2026-11-25 13:19 UTC · original
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.
@Lum7nt on GitHub · 2026-11-25 13:10 UTC · original · edited 2026-11-25 13:19 UTC
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.
@nnonno91 on GitHub · 2026-11-25 14:52 UTC · original
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.
@Prime1997 on GitHub · 2026-11-25 16:33 UTC · original
@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.
@DavidM1911 on GitHub · 2026-11-25 17:29 UTC · original
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!
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.