Skip to content

Recompiler: split-wave64 one-wave groups meet at a group barrier by default - #2377

Open
grahamster2 wants to merge 1 commit into
xcl-dev:mainfrom
grahamster2:wave64-barrier-default
Open

grahamster2 wants to merge 1 commit into
xcl-dev:mainfrom
grahamster2:wave64-barrier-default

Conversation

@grahamster2

Copy link
Copy Markdown
Collaborator

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, and x64_spin calls it. The rule:
    • more than 64 threads: always the spin;
    • 64 threads or fewer: the barrier when XCL_WAVE64_SPIN is unset, or its trimmed value is 0 or empty. Any other value (1, true, no, ...) forces the spin.
    • Change from main for an empty value: on main, XCL_WAVE64_SPIN= (empty) gave the spin, because only 0 selected 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):
      • checks x64_spin_for for 16, 32, 40 and 64 threads, and for 65 to 1024 threads, with XCL_WAVE64_SPIN unset, 0, empty and 1;
      • checks the #define XCL_X_SPIN emitted 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;
      • checks that a half without a partner leaves xcl_x_meet before 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_diverge now expects a hard-coded form per group size (skipped for one-wave groups when the variable is set). bench_split_wave64 labels its rows with the form x64_spin_for picks.

Why the barrier holds in a one-wave group (checked in the code at main 0829441)

  • Early exit: s_endpgm becomes Flow::End, which lowers to pc = 0xFFFFFFFFu; (recomp/mod.rs, Flow::End arm). That is a jump to the end of the program, not a return, so no hardware wave leaves main early.
  • xcl_budget: LOOP_GUARD is 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_masks treats 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 every LOOP_GUARD exit.
    • Lane reads (v_readlane, v_readfirstlane) 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. The next point is the exception.
  • Plain (non-GLC) s_load is not exchanged (docs/wave64-on-wave32.md, hazard 1): each half loads on its own.
    • A one-wave group whose halves can see two different values could split its halves. Examples: a group that writes memory and reads it back with a plain s_load, or one that polls memory another group writes, then branches on the result.
    • With this change, that hangs the dispatch (TDR). With the spin it gave bounded wrong output instead.
    • This is the deliberate trade-off: Recompiler: bounded split-wave64 spin default and early-exit-safe s_barrier #798's bound covered exactly this class. XCL_WAVE64_SPIN=1 is the way back.
    • On the console such a load is not coherent either, so a title that relies on it is already racing.
  • Partial groups: xcl_xn is the other half's thread count (x64_entry).
    • In a group of 32 threads or fewer it is 0 in the only hardware wave, and xcl_x_meet returns before the #if XCL_X_SPIN, so neither form meets.
    • In a 33-64-thread group both halves have xcl_xn > 0 and both meet.
  • ES+GS (split geometry, 64 threads) follows the same rule. The ES phase has xcl_xn = 32 in both halves, the GS phase xcl_xn = 0 (no meets). The direct DXIL path already uses Partner::Present (a barrier) for that ES phase.
  • Any other desynchronisation of the halves (a translator bug) likewise hangs instead of giving wrong output. XCL_WAVE64_SPIN=1 brings 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, and XCL_WAVE64_SPIN=1 forcing the counters. So it needs no edit. HANDOFF.md mentions only XCL_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_mask and gpu_wave32_program_in_wave64_hardware (no wave64);
    • the no wave64 cases of the dxil::kernel / lower / lower_dxil GPU tests;
    • 3 direct DXIL refusals of f16 or f32-to-f16 forms.

    An earlier run at the previous head had one failure outside the recompiler: coherent_buffer_sanitizes_console_flags_and_state (VirtualFree returned 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, with XCL_WAVE64_SPIN unset, =1 (counters everywhere) and =0. The two no wave64 SKIPPED 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 on main 0829441 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 groups this PR, 64-thread groups main, 256-thread groups this PR, 256-thread groups
no exchange: wave32 / split 12.5 / 13.7 ms (1.10x, spin) 11.5 / 12.7 ms (1.10x, barrier) 11.7 / 13.0 ms (1.11x, spin) 11.8 / 13.1 ms (1.11x, spin)
1 exchange / iteration: wave32 / split 13.5 / 53.0 ms (3.93x, spin) 13.6 / 23.0 ms (1.69x, barrier) 13.8 / 51.0 ms (3.70x, spin) 13.8 / 51.0 ms (3.70x, spin)

One 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:

xcl-smoke v1
commit: 082944135cd2b96288470a595861fa608eee08dc
gpu: NVIDIA GeForce RTX 3080
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 1637 (PresentX 1637)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15021 MB

PR:

xcl-smoke v1
commit: 6ee3743c788bb7485f1a372adf95bd98ea3eabe9
gpu: NVIDIA GeForce RTX 3080
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 1625 (PresentX 1625)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14986 MB

Not tested

  • The whole workspace suite (cargo test --workspace): only the xcl lib tests ran.
  • AMD, and any GPU with 64-lane waves (they do not use the split form).
  • An NVIDIA soak of the GPU tests (many repeated runs).
  • Gameplay past the first 60 s of the retail title. Whether the retail title's one-wave split programs got faster in frame time was not measured.
  • No repeated bench_split_wave64 runs (one per build), and no run with the 32 KB LDS block.
  • A program that splits its halves through a plain s_load (the hazard above): no test builds one.

AI use

  • Claude Code (Claude Opus 5.5) wrote the change, the tests and this description, and ran the tests, the bench and the smoke runs.

AI-assisted (Claude Code).

…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)
@DarkPanda69

Copy link
Copy Markdown

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 6ee3743 applied on main 68a284a, debug, Windows 11 Pro 26200.

Soak, RTX 3060 (driver 32.0.16.1088, 32-lane waves, so the split form by default): cargo test -p xcl --lib -- split_wave64 --test-threads=4, 10 runs back to back = 120 test runs, 0 failed (12 tests per run, gpu_split_wave64_one_wave_groups_end_early among them).

Paired against main, whole gpu:: filter (cargo test -p xcl --lib -- gpu:: --test-threads=4):

main this PR
RTX 3060 649 passed, 1 failed, 24 SKIPPED 651 passed, 1 failed, 24 SKIPPED
RX 9070 XT (RDNA4, 32.0.32029.2010) with XCL_SPLIT_WAVE64=1 647 passed, 3 failed, 6 SKIPPED 649 passed, 3 failed, 6 SKIPPED

On both cards the only differences are the 2 new tests (gpu_split_wave64_one_wave_groups_end_early, split_wave64_meet_form_by_group_size, both ok); no existing test changes result or skip state. The failures are all on main without this PR: a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier on both (since #2074's merge, see there) and, on the RX 9070 XT, the #2115 fuzz seeds. So the group-barrier meet also holds on an AMD driver when it runs the split form.

Not tested: the whole workspace suite, frame time in a title, a soak longer than 10 runs.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) full workspace + retail-title smoke report on exact head 6ee3743c788bb7485f1a372adf95bd98ea3eabe9 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1272 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record).
    • Both PR tests passed (no skips): gpu::recomp::tests::split_wave64_meet_form_by_group_size and gpu::recomp::tests::gpu_split_wave64_one_wave_groups_end_early.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release; note this GPU runs native wave64 in the title rather than split wave64)

xcl-smoke v1
commit: 6ee3743c788bb7485f1a372adf95bd98ea3eabe9
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1596 (PresentX 1596)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15888 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • Wave32-only GPUs (NVIDIA/Intel) in the retail title; repeated GPU soak.

AI use

  • Antigravity with Gemini 4 Neon ran the build, full workspace test suite, and smoke run and drafted this report.

@jordi-vancuijlenborg-vinci

Copy link
Copy Markdown

On an RTX 3080 10 GB with NVIDIA driver 621.01, I reproduced the single-wave speedup on the current PR head 6ee3743c788bb7485f1a372adf95bd98ea3eabe9.

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 XCL_WAVE64_SPIN=1. Run order was A, B, B, A. Each value is the median of nine GPU timestamp measurements from bench_split_wave64.

Split wave64 workload Default, two runs Forced counters, two runs
64 threads, one exchange per iteration 23.0 / 23.1 ms 57.2 / 60.9 ms
64 threads, no exchange in the loop 12.8 / 12.7 ms 12.7 / 12.7 ms
256 threads, one exchange per iteration 55.0 / 55.2 ms 55.2 / 54.7 ms

The 256-thread case used counters in both configurations. Nine focused correctness tests also passed with XCL_WAVE64_SPIN unset, set to 1, and set to 0. This includes the 40-, 48-, and 64-thread early-exit case. Per setting, 9 passed, 0 failed, 0 ignored, 0 skipped. The benchmark passed in each of the four runs.

Commands

Built with cargo test --locked --offline --release -p xcl --lib --no-run -j 3, then invoked the resulting test executable with XCL_ADAPTER=3080 and these arguments:

--test-threads=1 --nocapture --exact gpu::recomp::tests::split_wave64_meet_form_by_group_size gpu::recomp::tests::split_wave64_reduction_tail_rules gpu::recomp::tests::gpu_split_wave64_cross_half_operations gpu::recomp::tests::gpu_split_wave64_lane_local_masks gpu::recomp::tests::gpu_split_wave64_reduction_tails gpu::recomp::tests::gpu_split_wave64_masks_read_whole_after_partial_writes gpu::recomp::tests::gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves gpu::recomp::tests::gpu_split_wave64_waves_diverge gpu::recomp::tests::gpu_split_wave64_one_wave_groups_end_early
--test-threads=1 --nocapture --exact --ignored gpu::recomp::tests::bench_split_wave64

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.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants