Repository navigation
Recompiler: a split-wave64 bitwise mask tree exchanges once, at its end - #1597
MiguelMachado-dev wants to merge 3 commits into
Conversation
x64_masks kept EXEC whole-live everywhere, so every v_cmpx and every s_*_saveexec_b64 / s_*_wrexec_b64 exchanged the two halves' masks, and so did the compares feeding them. Every VALU reads EXEC lane by lane (the emitter's lanebit), and DPP, ds_swizzle and v_permlane(x)16 read it for a source lane in the reader's own half, so EXEC needs the whole value only where the program reads it whole: s_cbranch_exec(n)z, src_execz, a scalar operand, v_readfirstlane (first active lane) and ds_(b)permute (lanes of the other half). The last three are not in the operand tables and are now added in uses(). EXEC is now a mask like the others in the liveness: no longer live at every instruction or at the end of a compute program (the kernel runner still reads every SGPR at the end). An even-aligned saveexec / wrexec needs whole inputs only when the new EXEC or its scc is read whole, and whole EXEC alone when only the saved old EXEC is; odd pairs keep reading their operands whole. The emitter lets EXEC (s126) take the local ballot. Three tests from the bitwise-mask change relied on EXEC being always live; they now read EXEC whole after the write. Assisted-by: Claude Code (Claude Opus 5.5)
|
Read
One wording point: the description says I haven't run it (the RTX 5080 run covers the 32-lane case). AI use: Claude Code (Claude Opus 5.5) read the change and wrote this. |
|
Full-suite run, since this PR has no test report yet. Tested exact head Tested
Not tested
AI use
|
|
Tested #1597 at Tested
Not tested
AI use
|
|
Updated verification of PR #1597 at head commit Environment
Tested
Code review & follow-up notes
Not tested
AI use
|
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
Compares combined by 64-bit bitwise ops into a mask that is read whole (s_bcnt1, saveexec, a live scc, ...) each exchanged the two halves' ballots, although the combination is lane-wise and only its result needs both halves. Within one basic block, x64_masks now follows such trees: when two or more compares or carries feed a tree of lane-wise s_*_b64 ops (not s_cmov / s_cselect) and nothing else reads them, the compares keep the local ballot and the tree's last op exchanges its result once with xcl_x_sync_mask (salu64, before scc is derived from it). A block ends after every branch, conditional or not, and where any jump lands: ending one only at branch targets would let a compare read whole on the taken side of a conditional branch be made local by a tree on the fall-through side. LOOP_GUARD runs only at block starts. gpu_split_wave64_bitwise_lane_masks expected the two compares under a live scc to exchange; they now stay local and the s_and_b64 exchanges. With no other half (a partial wave, xcl_xn == 0), xcl_x_sync_mask keeps the word the half computed for the absent one: its compare bits are 0, but an inverting tree op (s_nor_b64, s_not_b64, ...) sets them, and a fallback of 0 gave a wrong s_bcnt1 and scc. gpu_split_wave64_bitwise_mask_tree_in_a_partial_wave covers it (16 instead of 48 without the fallback). Assisted-by: Claude Code (Claude Opus 5.5)
b71f7ee to
6acbfb1
Compare
|
@MatyEjsr thanks for finding this, and for the reproduction. The fix is in New GPU test, AI use: Claude Code (Claude Opus 5.5) wrote the fix, the test and this comment. |
|
Retail data point on RTX 3070 Ti (split-wave64): with this PR the world-load GPU hang from #675 is still there, 2 of 2 runs, with the default spin meet and with Setup: RTX 3070 Ti 8 GB, driver 621.24, Ryzen 9 7900X, 32 GB, Windows 11 26300, release. Retail 1.0.2.1 from #675.
A build note for the rebase: this PR removes Attached (user name removed): AI use: Claude Code (Claude Opus 5.5) built the tree, ran the title and wrote this; I checked it before posting. |
|
Some numbers on why this one matters for the split-wave64 cost on NVIDIA. I counted the static exchanges in the split-form HLSL of the 374 wave64 compute programs in a retail title's shader pack (main cbc296a, The other open exchange PRs, each cherry-picked onto the same main and counted the same way:
None of them touches the ballots. On the 3080 an exchange costs about 3x a native loop iteration in the one-wave-group spin form (numbers in #1244 and #675), so the ballots are where the time goes. This branch is based 491 commits behind main and doesn't cherry-pick cleanly, so I couldn't count it. Once it's rebased on current main, I'm happy to run the same count (total, in loops, per program) and the AI-assisted (Claude Code, Claude Opus 5.5); counts and timings from runs on my machine. |
Stacked on #1596, which is stacked on #1111; only the top commit (
6acbfb1, +328 / −9 with its tests) belongs here. The diff againstmainalso carries those two PRs, which is why it is over 800 lines. Part of #1269.Compares that 64-bit bitwise ops combine into a mask that is read whole (
s_bcnt1, a saveexec, a livescc, …) each exchanged the two halves' ballots. The combination is lane-wise, so only its result needs both halves. Within one basic block,x64_masksnow follows such trees. When two or more compares or carries feed a tree of lane-wises_*_b64ops (nots_cmov/s_cselect) and nothing else reads them, the compares keep the local ballot. The tree's last op exchanges its result once, withxcl_x_sync_mask, beforesccis derived from it.A block ends after every branch, conditional or not, and wherever a jump lands. Ending one only at branch targets would be unsafe: a tree on the fall-through side could make local a compare that the taken side of a conditional branch reads whole.
LOOP_GUARDruns only at block starts.What is in it
crates/xcl/src/gpu/recomp/x64_masks.rs: the liveness solution is shared (solve), andanalyzereturnsPlan { whole_live, sync }.by_pcis gone; its one caller now usesanalyze.crates/xcl/src/gpu/recomp/emit.rs:x64_sync;salu64exchanges the result at those pcs; thexcl_x_sync_maskhelper. In a partial wave with no other half, the helper keeps the word this half computed for the missing one.crates/xcl/src/gpu/recomp/mod.rs: usesanalyze.a_bitwise_tree_read_whole_exchanges_once_at_its_endanda_compare_read_whole_outside_the_tree_keeps_its_exchange. The latter covers a compare that is read whole after the tree, copied to a whole-live pair, or read on the taken side of a conditional branch. With the old block rule (blocks split only at branch targets), the branch case fails.gpu_split_wave64_bitwise_mask_tree_exchanges_once:s_bcnt1of ans_and_b64of two compares, andsccof ans_and_b64whose match is in the upper half only. 4 local compares, 2 syncs, and whole-wave results in both halves.gpu_split_wave64_bitwise_mask_tree_in_a_partial_wave: a wave64 group of 32 threads, so there is no upper half. It runss_nor_b64of two compares, read bys_bcnt1and byscc. The compares' bits in the missing half are 0, buts_nor_b64sets them, and the helper used to replace that word with 0:s_bcnt1gave 16 instead of 48. @MatyEjsr found this and reproduced it on an RTX 3090 (comment on this PR).gpu_split_wave64_bitwise_lane_masks(Recompiler: propagate split-wave64 lane-local masks through 64-bit bitwise SALU ops #1111) expected the two compares under a livesccto exchange. They now stay local and thes_and_b64exchanges; thesccresult it checks is unchanged.Measured with the same temporary local test as the PR below this one (all wave64 CS / MS programs of the retail 1.0.2.1
shaders.rpf, split form, 4 windows). An exchange here is a mask write that usesxcl_x_ballot, or anxcl_x_sync_mask:main9e3831e524b25cb71f7ee524b25c, −34.2 % onmain)HLSL over the 10 490 programs: 2 648.5 MB → 2 652.9 MB (+0.17 %).
These numbers were measured at
b71f7ee.6acbfb1changes only whatxcl_x_sync_maskreturns when there is no other half, not where the exchanges go; they were not measured again.docs/wave64-on-wave32.md:41says a mask skips the exchange only when it "is only read lane by lane". After this change that is no longer the whole rule. The doc is not edited here.Tested
cargo build --workspace && cargo test --workspace -- --test-threads=4at6acbfb1: 789 passed, 0 failed, 41 ignored.gpu_split_wave64_bitwise_mask_tree_in_a_partial_wavewithout thexcl_x_sync_maskfix: failed (s_bcnt116, expected 48). With it,cargo test -p xcl --lib gpu_split_wave64 -- --test-threads=1: 9 passed, 0 failed.gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).Regression run
Each block is the second of two back-to-back 60 s runs of the same build (the first one filled the shader and driver caches).
main:
PR:
Not tested
AI use