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. |
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).