Repository navigation
Recompiler: split-wave64 one-wave groups meet at a group barrier by default - #2377
grahamster2 wants to merge 1 commit into
Conversation
…arrier 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. Since xcl-dev#798 they met through the bounded counter spin there too, which costs about 2.3x the group barrier per exchange on Ampere (xcl-dev#1244: 13.2 ms vs 5.7 ms on an RTX 3080 in bench_split_wave64, 64-thread groups, one exchange per iteration; 3.6x vs 1.55x wave32 on an RTX 3070). x64_spin_for picks the form: groups of more than one console wave keep the counters (a barrier would wait for other console waves); one-wave groups now get the barrier, as the direct DXIL translator does (Partner::Present, xcl-dev#1426). XCL_WAVE64_SPIN=1 forces the counters everywhere, for debugging a desynchronised pair (wrong output instead of a hang); =0 keeps the barrier, as before. Assisted-by: Claude Code (Claude Opus 5.5)
|
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
|
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. Since #798 they meet through the bounded counter spin (
XCL_X_SPIN 1) by default, which costs about 2.3x the group barrier per exchange on Ampere (see #1244: RTX 3080 and RTX 3070 numbers). This PR proposes making the group barrier the default meet for one-wave groups, as the direct DXIL translator already does for 33-64-thread groups (Partner::Present, #1426). Groups of several console waves keep the counter spin.This is a proposal, not a settled decision. On #1244, upipibi agreed that a separate PR fits, and said that whether the barrier becomes the default is the maintainers' call. It is on by default here because that is where the speedup is. If you prefer the spin as the default and the barrier as an opt-in, that is a one-line change in
x64_spin_for.Design discussion: #1244 (last comments).
What is in it
crates/xcl/src/gpu/recomp/emit.rs:x64_spin_for(threads, env)picks the meet form, andx64_spincalls it. The rule:XCL_WAVE64_SPINis unset, or its trimmed value is0or empty. Any other value (1,true,no, ...) forces the spin.mainfor an empty value: onmain,XCL_WAVE64_SPIN=(empty) gave the spin, because only0selected the barrier. Now it gives the barrier, like unset.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, and for 65 to 1024 threads, withXCL_WAVE64_SPINunset,0, empty and1;#define XCL_X_SPINemitted for 64x1x1, 8x8x1, 4x4x4, 40, 32, 16, 256 and 8x8x4 groups. The value is hard-coded: the multi-wave groups are checked in any environment, the one-wave groups only when the variable is unset;xcl_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.gpu_split_wave64_waves_divergenow expects a hard-coded form per group size (skipped for one-wave groups when the variable is set).bench_split_wave64labels its rows with the formx64_spin_forpicks.Why the barrier holds in a one-wave group (checked in the code at
main0829441)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 (a branch on VCCZ, any SALU or SMEM operand) as needing the exchange. It counts what is live after everyLOOP_GUARDexit.v_readlane,v_readfirstlane) and GLC/DLC scalar loads are exchanged.s_loadis not exchanged (docs/wave64-on-wave32.md, hazard 1): each half loads on its own.s_load, or one that polls memory another group writes, then branches on the result.XCL_WAVE64_SPIN=1is the way back.xcl_xnis the other half's thread count (x64_entry).xcl_x_meetreturns before the#if XCL_X_SPIN, so neither form meets.xcl_xn > 0and both meet.xcl_xn = 32in both halves, the GS phasexcl_xn = 0(no meets). The direct DXIL path already usesPartner::Present(a barrier) for that ES phase.XCL_WAVE64_SPIN=1brings the spin back for debugging it.docs/wave64-on-wave32.md("Synchronisation") already describes this split: a barrier for one console wave per group, counters for several, andXCL_WAVE64_SPIN=1forcing the counters. So it needs no edit.HANDOFF.mdmentions onlyXCL_WAVE64_SPIN=1, which this keeps.Tested
NVIDIA GeForce RTX 3080 10 GB (driver 610.88, 32-lane waves only, so the split form), AMD Ryzen 5 7600X, Windows 11 Pro 10.0.26200, rustc 1.94.0. Debug build for the tests, release for the bench and smoke.
cargo test -p xcl --lib: 1205 passed, 0 failed, 26 ignored. There are 24 SKIPPED lines in all:gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64);no wave64cases of thedxil::kernel/lower/lower_dxilGPU tests;An earlier run at the previous head had one failure outside the recompiler:
coherent_buffer_sanitizes_console_flags_and_state(VirtualFreereturned 0). It passed when rerun alone and in this run.cargo test -p xcl --lib gpu::recomp::tests: 159 passed, 0 failed, 17 ignored each, withXCL_WAVE64_SPINunset,=1(counters everywhere) and=0. The twono wave64SKIPPED tests above are skipped in each run.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 previous head 34d2583, whose runtime code (emit.rs) is the same as the current head's; only the tests changed since.main, 64-thread groupsmain, 256-thread groupsOne run each. 256-thread groups still spin, as intended, and run at the same speed as on
main.Regression run
The PR's head shows 1625 frames against
main's 1637 (99%), well within the 80% bar. Each block is one 60 s run, so a gap this small is not meaningful. An earlier pair at the previous head gave 1579 against 1638 (96%).main:
PR:
Not tested
cargo test --workspace): only thexcllib tests ran.bench_split_wave64runs (one per build), and no run with the 32 KB LDS block.s_load(the hazard above): no test builds one.AI use
AI-assisted (Claude Code).