Repository navigation
Recompiler: split-wave64 one-wave groups can meet at a group barrier (opt-in, XCL_WAVE64_BARRIER=1) - #2377
Recompiler: split-wave64 one-wave groups can meet at a group barrier (opt-in, XCL_WAVE64_BARRIER=1)#2377grahamster2 wants to merge 1 commit into
Conversation
|
Update for head
An NVIDIA soak of the split-wave64 GPU tests (listed as untested), on an Ampere RTX 3060, plus the change on an AMD driver with the split form forced. No failures. Head Soak, RTX 3060 (driver 32.0.16.1088, 32-lane waves, so the split form by default): Paired against
On both cards the only differences are the 2 new tests ( Not tested: the whole workspace suite, frame time in a title, a soak longer than 10 runs. |
|
Independent AMD RDNA4 (native wave64) full workspace + retail-title smoke report on exact head Tested
Regression run (60 s retail-title smoke, (Matched Not tested
AI use
|
|
On an RTX 3080 10 GB with NVIDIA driver 621.01, I reproduced the single-wave speedup on the current PR head Tested Windows 11, i7-9700F, Rust 1.100.0 MSVC, release, DXC 1.9.2609.5. I used the same executable for both modes. A used the default group barrier for 64-thread groups. B forced the counters with
The 256-thread case used counters in both configurations. Nine focused correctness tests also passed with CommandsBuilt with Not tested Game frame rate, other adapters and the full workspace suite. OpenAI Codex (GPT-6.2 Astra Extra High) ran the tests and drafted this report. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
bmjask
left a comment
There was a problem hiding this comment.
P1: this makes a known split-wave64 divergence hazard a default GPU hang. For <=64-thread groups, emit.rs:5975-5985 selects unbounded GroupMemoryBarrierWithGroupSync in xcl_x_meet. A plain non-GLC s_load is not exchanged and can produce different scalar values in the two emulated halves; the PR description acknowledges this. The prior counter form eventually abandoned the exchange, but the new default can deadlock the dispatch/TDR. XCL_WAVE64_SPIN=1 is an opt-in escape hatch, not a safe default, and tests cover only synchronized early scalar end. Keep the bounded form by default or gate the barrier on proof/feature support, with a non-hanging regression or rejection test. The current Windows build/test check also fails and needs repair/re-run.
…(XCL_WAVE64_BARRIER=1) In the HLSL split-wave64 form a group of one console wave (64 threads or fewer) is just the two 32-lane halves, and they take the same branches (on exchanged, wave-uniform state), so both reach every exchange. The counter spin they use by default (xcl-dev#798) costs about 2.3x the group barrier per exchange on Ampere (xcl-dev#1244), but the barrier is unbounded: a pair that desynchronises (a plain scalar load that sees two values) hangs the dispatch, where the counters give up after a bounded wait. So the counters stay the default and the barrier is opt-in: XCL_WAVE64_BARRIER=1 (or XCL_WAVE64_SPIN=0, as before) selects it for groups of 64 threads or fewer; XCL_WAVE64_SPIN set to any other value still forces the counters and wins. Groups of several console waves always use the counters. x64_spin_for holds the rule and is unit tested; XCL_WAVE64_BARRIER bypasses the shader cache like XCL_WAVE64_SPIN. A GPU test covers one-wave groups that end early under the barrier.
…e-wave groups meet at a group barrier by default Taken as it is for a test on a title. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> # Conflicts: # crates/xcl/src/gpu/recomp/emit.rs
6ee3743 to
0c44653
Compare
|
@bmjask thanks, you were right and I took the first option: the barrier is no longer the default. Head is now 0c44653, rebased on current
What I did not add: a test for the hang itself. No test builds a program whose halves split through a plain The failing "Build and test" run was Smoke pair on the new head (default settings, 60 s): 1640 frames against 1642 on AI use: Claude Code (Claude Sonnet 5.5) wrote this reply. |
|
Independent desktop NVIDIA verification of PR #2377 at head Environment
Targeted release tests & build (
|
| Command | Result |
|---|---|
cargo test --release -p xcl --lib split_wave64_meet_form_by_group_size -- --nocapture (default env, 3 runs) |
1 passed; 0 failed; 0 ignored; 1337 filtered out × 3 (0.00s × 3, 0 skipped) |
cargo test --release -p xcl --lib gpu_split_wave64_one_wave_groups_end_early -- --nocapture (default env, 3 runs) |
1 passed; 0 failed; 0 ignored; 1337 filtered out × 3 (0.32s, 0.29s, 0.27s, 0 skipped; live RTX 4060 counter-spin path) |
cargo test --release -p xcl --lib gpu::recomp::pso:: (default env, 3 runs) |
27 passed; 0 failed; 1 ignored; 1310 filtered out × 3 (0.08s × 3, 0 skipped; includes shader_cache_bypasses_debug_overrides covering XCL_WAVE64_BARRIER and console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk) |
XCL_WAVE64_BARRIER=1 cargo test --release -p xcl --lib gpu_split_wave64_one_wave_groups_end_early -- --nocapture (opt-in barrier, 3 runs) |
1 passed; 0 failed; 0 ignored; 1337 filtered out × 3 (0.29s, 0.25s, 0.25s, 0 skipped; live RTX 4060 group-barrier path) |
XCL_WAVE64_BARRIER=1 cargo test --release -p xcl --lib gpu::recomp:: -- --test-threads=4 (opt-in barrier, 3 runs) |
402 passed; 1 failed; 20 ignored; 915 filtered out × 3 (6.49s, 6.13s, 6.17s; 23 SKIPPED notices across 13 distinct tests — no wave64 on Wave32-only Ada and #1426 per-lane refusals; 0 GPU execution failures; see cache-bypass test note below) |
cargo build --release -p xcl |
Clean build (1m 09s, exit 0, 0 new warnings) |
Observation on gpu::recomp:: with process-wide XCL_WAVE64_BARRIER=1: All 402 other tests in gpu::recomp:: (including every split-wave64 GPU test) passed 3/3 under XCL_WAVE64_BARRIER=1. The sole failure (3/3) was gpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk at crates/xcl/src/gpu/recomp/pso.rs:1970:9 (assert_eq!(cache.lock().unwrap().entries.len(), 1) observed 0). That directly confirms PR #2377's intentional addition of "XCL_WAVE64_BARRIER" to the shader-cache debug-override bypass list (pso.rs:908); the same test passes 3/3 in the default environment (gpu::recomp::pso:: 27/27). (Minor test-ergonomics note: unlike line 1979's XCL_TRANSLATED_CACHE guard, line 1970 does not skip when a debug-override env var disables caching.)
Paired quiet 60 s retail smoke (title: 29640639)
Exact parent & merge-base (b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7, cached baseline on the same machine):
xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1518 (PresentX 1518)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14018 MB
PR #2377 (0c446533681f07cf43e91479a7abf869e2aab28e, default flags — counter spin):
xcl-smoke v1
commit: 0c446533681f07cf43e91479a7abf869e2aab28e
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1590 (PresentX 1590)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13987 MB
PR #2377 (0c446533681f07cf43e91479a7abf869e2aab28e, opt-in XCL_WAVE64_BARRIER=1):
xcl-smoke v1
commit: 0c446533681f07cf43e91479a7abf869e2aab28e
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1615 (PresentX 1616)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14033 MB
Runtime log observations (xcl.log & report.json)
- Both PR Recompiler: split-wave64 one-wave groups can meet at a group barrier (opt-in, XCL_WAVE64_BARRIER=1) #2377 smokes logged
9222lines and0[ERROR]/ device-removal / panic lines, with228background pipelines (0failures) and1024+translated compute dispatches (0skipped). - Default run (
XCL_WAVE64_BARRIERunset):D3D12.X: compute PSO with the translated console CS (98748 B DXIL, 1 ms, the driver's blob of an earlier build);dxil_cache:460hits,0misses,0compilations;19489 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample13986 MB committed by the process; video memory 6115 MB local, 4651 MB non-local. - Opt-in
XCL_WAVE64_BARRIER=1run:D3D12.X: compute PSO with the translated console CS (92296 B DXIL, 968 ms)— DXIL shrank from98748 Bto92296 B(-6452 B,-6.5%), compiling cleanly fresh (dxil_cache:459hits,1miss,1compilation,0compilation failures), confirming live barrier emission and shader-cache bypass on a retail compute shader with0hangs or timeouts across1024+dispatches (0skipped) and19615+draws (0skipped); last memory sample14032 MB committed by the process; video memory 6115 MB local, 4683 MB non-local.
Limits of coverage
- Both default counter-spin and opt-in
XCL_WAVE64_BARRIER=1one-wave group-barrier paths were directly exercised on desktop RTX 4060 in unit/GPU tests (3/3) and paired 60 s retail smokes (0hangs,0device removals,0crashes). - Frame-count and peak-commit differences between single 60 s runs reflect normal startup/compilation variance rather than a measured per-exchange throughput delta; the ignored
bench_split_wave64microbenchmark was not run. - As documented by the PR,
XCL_WAVE64_BARRIER=1stays opt-in because a desynchronized scalar-load pair could still hang an unbounded barrier in shaders not exercised during this 60 s retail window; Wave64-onlygpu::recomp::tests self-skipped on Wave32-only Ada.
AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
In the HLSL split-wave64 form, a group of one console wave (64 threads or fewer) is just the two 32-lane halves of that wave. They meet through the bounded counter spin (
XCL_X_SPIN 1) by default since #798, which costs about 2.3x the group barrier per exchange on Ampere (see #1244: RTX 3080 and RTX 3070 numbers). This PR adds an opt-in for the cheaper group barrier on one-wave groups, as the direct DXIL translator already does for 33-64-thread groups (Partner::Present, #1426). The default does not change: the counter spin stays, and the barrier needsXCL_WAVE64_BARRIER=1.An earlier head of this PR made the barrier the default. bmjask's review (P1) pointed out that the barrier is unbounded: a pair that desynchronises (a plain non-GLC
s_loadthat sees two values, hazard 1 indocs/wave64-on-wave32.md) would hang the dispatch until a TDR, where the counters give up after a bounded wait and give wrong output instead. So the barrier is now something you ask for.Design discussion: #1244 (last comments).
What is in it
crates/xcl/src/gpu/recomp/emit.rs:x64_spin_for(threads, spin, barrier)picks the meet form, andx64_spincalls it withXCL_WAVE64_SPINandXCL_WAVE64_BARRIER. The rule:XCL_WAVE64_SPINset to0(trimmed) gives the barrier, as onmain; set to anything else, including empty (as onmain), it forces the counters. WithXCL_WAVE64_SPINunset,XCL_WAVE64_BARRIERset to anything but empty or0gives the barrier; otherwise the counters (the default).XCL_WAVE64_SPINkeeps its current meaning exactly,XCL_WAVE64_BARRIER=1is a second way to the same barrier, andXCL_WAVE64_SPIN=1wins overXCL_WAVE64_BARRIER=1.crates/xcl/src/gpu/recomp/pso.rs:XCL_WAVE64_BARRIERjoins the variables that bypass the shader cache (cache_allowed, and its test). Without it a cached counter-form shader would be served with the variable set, or the reverse.docs/wave64-on-wave32.md("Synchronisation"): says the barrier for one console wave is opt-in, why, and how the two variables interact.crates/xcl/src/gpu/recomp/tests.rs:split_wave64_meet_form_by_group_size(unit test):x64_spin_forfor 16, 32, 40 and 64 threads with every combination ofXCL_WAVE64_SPIN(unset,0,0, empty,1) andXCL_WAVE64_BARRIER(unset, empty,0,1,1) that the rule distinguishes, and for 65 to 1024 threads; the emitted#define XCL_X_SPIN 1for 64x1x1, 8x8x1, 4x4x4, 40, 32, 16, 256 and 8x8x4 groups (hard-coded, so checked in any environment for several-wave groups and when neither variable is set for the rest); and that a half without a partner leavesxcl_x_meetbefore either form.gpu_split_wave64_one_wave_groups_end_early(GPU test): 64-, 48- and 40-thread groups make an exchange, then odd groups end early on a scalar branch and even ones exchange again and store. It checks the form it expects (the counters, or the barrier whenXCL_WAVE64_BARRIERasks for it) and that no half is left waiting. With the default settings it covers the counter form; the barrier form runs when the variable is set (see Tested).gpu_split_wave64_waves_divergeexpects the counters unless a variable asks for the barrier in the 64-thread case.bench_split_wave64labels its rows with the formx64_spin_forpicks.Why the barrier holds in a one-wave group, and when it does not (checked in the code at
main0829441; this part has not been touched since)s_endpgmbecomesFlow::End, which lowers topc = 0xFFFFFFFFu;(recomp/mod.rs,Flow::Endarm). That is a jump to the end of the program, not areturn, so no hardware wave leavesmainearly.xcl_budget:LOOP_GUARDis a per-lane counter that both halves start at the same value and decrement once per loop iteration. Branches are on SGPRs, SCC, VCCZ or EXECZ.x64_maskstreats any whole read of a mask as needing the exchange; lane reads and GLC/DLC scalar loads are exchanged. So the halves branch the same way and spend their budgets equally, as long as the SGPRs they branch on are the same.s_load, which is not exchanged: each half loads on its own. A one-wave group whose halves can see two different values (a group that writes memory and reads it back with a plains_load, or one that polls memory another group writes, then branches on the result) can split its halves. With the barrier that hangs the dispatch (TDR); with the counters it gives bounded wrong output. That is why the barrier is opt-in. On the console such a load is not coherent either, so a title that relies on it is already racing.xcl_xnis 0 in the only hardware wave, andxcl_x_meetreturns before the#if XCL_X_SPIN, so neither form meets. In a 33-64-thread group both halves havexcl_xn > 0and both meet.xcl_xn = 32in both halves, the GS phasexcl_xn = 0(no meets).Tested
0c44653(rebased onmainb49be18),cargo test -p xcl --lib: 1311 passed, 0 failed, 27 ignored, 24 SKIPPED lines (theno wave64GPU cases and three direct DXIL refusals of f16 or f32-to-f16 forms).cargo test -p xcl --lib gpu::recomp::tests: 169 passed, 0 failed, 17 ignored withXCL_WAVE64_SPINandXCL_WAVE64_BARRIERunset, withXCL_WAVE64_BARRIER=1(the barrier form everywhere it applies, including the early-end test), withXCL_WAVE64_SPIN=1and withXCL_WAVE64_SPIN=0.XCL_WAVE64_BARRIER=1orXCL_WAVE64_SPIN=1set: 1310 passed, 1 failed in each,pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk. That is the shader cache being bypassed by the variable on purpose (the same for the existingXCL_WAVE64_SPIN), not a recompiler failure.a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier(left: 3, right: 1) on the previous head, which was based on amainfrom before Tests: check divergent block barriers in a_bridged_mask_write #2420 changed that test. It passes on this head, rebased on currentmain, in every run above. I did not rerun the old head to confirm it was that test's staleness and not the barrier default; the head is rebased and the default is gone either way.bench_split_wave64(cargo test --release -p xcl --lib bench_split_wave64 -- --ignored --nocapture, 2^18 threads x 32768 iterations, GPU timestamps, median of 9). It ran onmain0829441 and on this PR's earlier head 34d2583, which selected the barrier for one-wave groups; the barrier code path is the oneXCL_WAVE64_BARRIER=1selects now, but I did not rerun the bench on this head.main, 64-thread groups (counters)main, 256-thread groupsOne run each. 256-thread groups always spin, as intended.
Regression run
The smoke run is with the default settings, which give the same recompiler output as
main(the counters). A run withXCL_WAVE64_BARRIER=1on this head showed 1634 frames, no device removal, no crash, peak commit 14849 MB (not a second block, one 60 s run).main:
PR:
One 60 s run each, so a gap of a few frames is not meaningful.
Not tested
cargo test --workspace): only thexcllib tests ran.XCL_WAVE64_BARRIER=1makes the retail title's one-wave split programs faster in frame time.s_load(the hazard above): no test builds one, so there is no regression test that the default does not hang on it, only the argument that the counters are bounded.bench_split_wave64runs, no bench on this head, and no run with the 32 KB LDS block.AI use
AI-assisted (Claude Code).