Recompiler: a split-wave64 bitwise mask tree exchanges once, at its end #1597
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1597
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1597"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@MiguelMachado-dev on GitHub · 2026-11-24 18:06 UTC · original
MiguelMachado-dev:recomp/x64-mask-coalesce→main· +932 −36 · 4 files · 3 commits · openStacked 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(#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
@upipibi on GitHub · 2026-11-24 18:52 UTC · original
Read
b71f7eeagainst the ISA. The split-form side holds up:lane_wise_salu64has only ops whose two dwords don't mix: not/and/or/xor/andn2/orn2/nand/nor/xnor, ands_wqm_b64(its 4-lane quads never straddle lane 32). Shifts,s_brev_b64,s_bfe_*64,s_bitreplicate,s_ff*/s_bcnt*aren't in it, which is right, since they move or count bits across the boundary.One wording point: the description says
s_cmov/s_cselectare not tree ops, butlane_wise_salu64classes them withs_mov_b64(lane-wise, nosccwrite). That is only safe while thesccthey read is the same in both halves, i.e. never derived from a local, unsynced tree value. The rule that a livesccmakes the op whole-live seems to give that. If so, a comment there saying it is the guarantee would help the next reader.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.
@futurepro62 on GitHub · 2026-11-24 18:55 UTC · original
Full-suite run, since this PR has no test report yet. Tested exact head
b71f7ee(on its base9e3831e).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form: 787 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.gpu_split_wave64_bitwise_lane_masks,gpu_split_wave64_predicated_exec_masks,gpu_split_wave64_bitwise_mask_tree_exchanges_once,saveexec_needs_whole_inputs_only_for_a_whole_read,a_bitwise_tree_read_whole_exchanges_once_at_its_end,a_compare_read_whole_outside_the_tree_keeps_its_exchange,bitwise_mask_chain_for_selector_needs_no_exchange,bitwise_mask_with_live_scc_keeps_exchange,bitwise_mask_feeding_whole_read_keeps_exchange,cselect_and_cmov_b64_propagate_lane_masks_and_keep_scc_uniform,vccz_operand_and_odd_alignment_in_bitwise_ops_keep_exchange,loop_exit_reading_scc_keeps_exchange_inside_loop.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 788 passed, 0 failed, 41 ignored. SKIPPED:heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).heap_window_out_of_memory_falls_back_to_the_switch_formwas skipped with--skip. It fails on main9e3831etoo, not because of this PR: underXCL_REQUIRE_GPU=mesh,runner::skip_testturns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (XCL_HEAP_WINDOWSunset). Reported as #1651.Not tested
AI use
@ScaryFr92 on GitHub · 2026-11-24 18:56 UTC · original
Tested #1597 at
b71f7ee(with #1596 and #1111 below it) on Ampere: 788 passed, 0 failed, 41 ignored; the 8 split-wave64 GPU tests pass withXCL_REQUIRE_GPU=wave64.Tested
x86_64-pc-windows-msvc; DXC 1.9.2602.17 (Windows SDK 10.0.26100); debug build, clean tree atb71f7ee.cargo build --workspace && cargo test --workspace -- --test-threads=4: 788 passed, 0 failed, 41 ignored (same counts as the RTX 5080 run in the description, which used DXC 1.8).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).XCL_REQUIRE_GPU=wave64:cargo test -p xcl --lib gpu::recomp::tests::gpu_split_wave64 -- --test-threads=1: 8 passed, 0 failed, 0 skipped, includinggpu_split_wave64_bitwise_mask_tree_exchanges_onceandgpu_split_wave64_predicated_exec_masks.Not tested
AI use
@DavidM1911 on GitHub · 2026-11-24 20:12 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
@MiguelMachado-dev on GitHub · 2026-11-24 20:57 UTC · original
@MatyEjsr thanks for finding this, and for the reproduction. The fix is in
6acbfb1(squashed into this PR's commit). It is the fallback you suggested: with no other half,xcl_x_sync_maskkeeps the word this half computed for the missing one instead of 0.New GPU test,
gpu_split_wave64_bitwise_mask_tree_in_a_partial_wave: a wave64 group of 32 threads withs_nor_b64of two compares, read bys_bcnt1and byscc. On an RTX 5080 it fails without the fix (s_bcnt116, expected 48) and passes with it. At6acbfb1:cargo test -p xcl --lib gpu_split_wave64 -- --test-threads=1gives 9 passed, and the whole suite gives 789 passed, 0 failed, 41 ignored.AI use: Claude Code (Claude Opus 5.5) wrote the fix, the test and this comment.
@qcdaark on GitHub · 2026-11-25 06:23 UTC · original
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
XCL_WAVE64_SPIN=0.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.
test-1428tree,c160d86+ #640 + #1428 + #1323, with this PR's three commits cherry-picked on top (ce0eeec,524b25c,6acbfb1, no conflicts).CS_DepthProcessingHBO, recordb78fa10b425b8e54(Aftermath, see #675).XCL_PSO_WAIT_MS=50 XCL_PSO_TRACE=1 XCL_ACTIVITY=1 XCL_NETWORK=0 XCL_PRESS_A_AT=25,35,45 XCL_RUN_SECONDS=420. The translated cache is keyed by the translator source, so the programs were translated again with this PR.0x887a0006at 154 s, then0x80000003at+0x2474606XCL_WAVE64_SPIN=00x887a0006at 221 s, then the process ends with the same status+0x2474606after the device removal is the same signature as the HBO hang runs on this card. Aftermath was off for these two runs, so I can't say which program was in flight this time.A build note for the rebase: this PR removes
x64_masks::by_pc, butmainstill calls it incrates/xcl/src/gpu/dxil/kernel.rs(direct DXIL,lw.whole_live = …by_pc(insts, kernel)), and my older tree calls it there too. To build, I kept aby_pcthat returnssolve's liveness without the mask trees, since the direct path does not emitxcl_x_sync_mask. That patch is attached asbuild-fix.patch.Attached (user name removed):
xcl.logandreport.jsonfor both runs.AI use: Claude Code (Claude Opus 5.5) built the tree, ran the title and wrote this; I checked it before posting.
build-fix.patch
runA-pr1597-default-report.json
runA-pr1597-default-xcl.log
runB-pr1597-spin0-report.json
runB-pr1597-spin0-xcl.log
@grahamster2 on GitHub · 2026-11-25 06:32 UTC · original
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,xcl shaders --export-hlsl, RTX 3080 as the 32-lane device). There are 25,352 exchanges, and 22,825 of them (90 %) arexcl_x_ballot: av_cmpmask exchanged on its way throughs_and/s_or/s_xor_b64intos_and_saveexec_b64/s_cbranch_execz. That is the mask-tree pattern this PR folds into one exchange at the end. 4.7k of the exchanges sit inside loops.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
bench_split_wave64/bench_compute_lds_blockloops on the 3080 and post the numbers here.AI-assisted (Claude Code, Claude Opus 5.5); counts and timings from runs on my machine.
@MatyEjsr on GitHub · 2026-11-24 20:12 UTC · original · edited 2026-11-25 10:31 UTC
Updated verification of PR #1597 at head commit
6acbfb1f4d57e5d914161dde56faaf28da18f973on NVIDIA GeForce RTX 3090 (split-wave64). Confirmed that the partial-wavexcl_x_sync_maskbug fromb71f7eeis fixed.Environment
x86_64-pc-windows-msvc, debug build), DXC 1.9.2602.17 (21d28f72) +dxil.dll1.9.2602.17Tested
cargo build --workspace -j 8: ok (13.27s, 0 errors)cargo test --workspace -j 8 -- --test-threads=4 --nocapture: 789 passed (784 executed + 5 SKIPPED), 0 failed, 41 ignoredgpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask(no wave64)gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware(no wave64)test_title_draws_with_a_root_signature_under_the_debug_layer(no d3d12SDKLayers.dll)heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows)uploads_start_from_each_subresources_state(no D3D12 debug layer,0x887A002D)cargo test -p xcl --lib x64_masks -- --test-threads=4 --nocapture: 25 passed, 0 failed, 0 ignored (0.00s)XCL_REQUIRE_GPU=wave64 cargo test -p xcl --lib gpu_split_wave64 -- --test-threads=1: 9 passed, 0 failed, 0 ignored, 0 skipped (0.67s)gpu_split_wave64_bitwise_mask_tree_in_a_partial_wave,gpu_split_wave64_bitwise_mask_tree_exchanges_once,gpu_split_wave64_bitwise_lane_masks, andgpu_split_wave64_predicated_exec_masks.Code review & follow-up notes
6acbfb1):xcl_x_sync_maskincrates/xcl/src/gpu/recomp/emit.rsnow falls back toselect(xcl_half != 0u, lo, hi)whenxcl_x_meet()is false, preserving the absent-half word computed by inverting or uniform-combining tree ops on unpaired partial waves (xcl_xn == 0u), andgpu_split_wave64_bitwise_mask_tree_in_a_partial_wavecovers boths_bcnt1_i32_b64(48) andscc(s_cselect_b32= 77) on a[32, 1, 1]wave64 dispatch.tree_opinstructions (S_MOV_B64,S_NOT_B64,S_WQM_B64, and the 8 binary bitwiseS_*_B64ops) go throughEm::salu64, wherexcl_x_sync_maskruns beforesccderivation andwrite64. Inx64_masks::analyze,live_outis only cleared insideexchange_atwhenleaves.len() >= 2alongside insertingnodeintoplan.sync, so any tree dropped withwhole = falsesafely retains per-leaf exchanges.main(568e7db) with conflicts inemit.rs,mod.rs,tests.rs, andx64_masks.rs(including #10907bea019block-level liveness and39ef551), andcrates/xcl/src/gpu/dxil/kernel.rsonmainstill callsx64_masks::by_pc(insts, kernel)which this PR removes. Keeping aby_pchelper or updatingdxil/kernel.rswill be needed when rebasing ontomain.Not tested
main.AI use
6acbfb1diff andx64_masks.rs/emit.rs, ran the workspace build and tests on the hardware above, and drafted and audited this report.@Raghav314 on GitHub · 2026-11-25 19:09 UTC · original
@MiguelMachado-dev this PR carried onto current
main3f27770, on top of the #1596 port (comment there):Raghav314/xclx64/exec-local-mask-trees, commitb31b96a, with you as co-author.How it maps onto
main:x64_masks::analyze_splitreturnsPlan { whole_live, sync }: the split-mode liveness, then your per-block tree walk. A block ends after every branch and wherever a jump lands, as in your PR.whole_live_out_modenow also returns wheresccis live, and the successor computation is shared.xcl_x_sync_maskinsalu64as you wrote it, with the same fallback that keeps the half's own word when there is no other half.Lw::sync_maskdoes the same exchange insalu64, through the split form's exchange slot. It uses 2 words: the value, and a word telling a met partner apart from an absent one, for the same fallback. The compact form's block key includes it.split_wave64_reduction_tail_rulesis new onmainand countsxcl_x_meet() ?in the prelude, which now has one more helper (3 → 4).Tests (RTX 4090, 617.14):
Lw::sync_mask, the direct run gives (27, 11) for (37, 77).gpu_split_wave64_bitwise_lane_masksis updated as in your PR.a_bridged_mask_write…, the same on plainmain), 26 ignored.Cold driver build, direct DXIL, split wave64, heap windows (4), NVIDIA implicit caches off, one process each:
062468c09af883b973fb752d7f62c3a5That is a smaller step than #1596's (
main: 20.4 s and 33.2 s). These programs have few multi-compare trees read whole. Full numbers are on #2088.Not tested: a title run; AMD (split only).
AI use: Claude Code (Claude Opus 5.5) ported the change, ran the tests and timings, and wrote this for @Raghav314.
@grahamster2 on GitHub · 2026-11-25 19:29 UTC · original
Counts and timings for the port on current
main, as promised above.I counted the static exchanges in the split-form HLSL of the wave64 compute programs in a retail title's shader pack (
xcl shaders --export-hlsl --split 1, one export per build, the RTX 3080 as the 32-lane device). 356 of the 374 programs I used earlier come out in split form on thismain; the same 356 are counted in every column. The counter now also countsxcl_x_sync_mask(calls, so the new helper's exchanges are included in the totals (and shown on their own below).mainmainxcl_x_ballotshare of exchangesxcl_x_sync_maskexchangesPer program, #1597 against the column before it: 179 of 356 programs got fewer exchanges, 177 got the same number, none got more. In loops: 57 programs fewer, none more. Against
mainthe three columns together: 212 programs fewer, 144 the same, none more. The largest single-program reduction from #1597 alone is 75 %.On the benchmark (
cargo test --release -p xcl --lib -- --ignored bench_split_wave64 --nocapture, RTX 3080, median of 9 per cell, two runs per build), nothing moves, which is expected: its loop has onev_cmpread lane by lane and no bitwise mask tree.bench_split_wave64, wave64 split vs wave32v_cmp+v_cndmask, 64 threadsv_readfirstlane(1 exchange / iteration), 64 threadsbench_compute_lds_blockdoes not exist onmain3f27770, so I did not run it.Method:
main3f27770,577b075(the #1111 and #1596 ports),b31b96a(this PR on top), from Raghav314'sx64/exec-local-mask-trees, release builds, a fresh worktree for each. These are static counts in the emitted HLSL, not run time.Not tested: a title run, the run-time effect of the lower count on the hang from #675, AMD, and the direct DXIL form's exchange count (only the HLSL export was counted).
AI-assisted (Claude Code, Claude Opus 5.5); counts and timings from runs on my machine.
@DavidM1911 on GitHub · 2026-11-26 05:48 UTC · original
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.@bmjask on GitHub · 2026-11-25 21:31 UTC · original · reviewed
No concrete source defect found. Conservative tree analysis, final one-time both-word synchronization, and partial-wave fallback preserve mask semantics; focused coverage is strong. This dirty/non-mergeable stack needs rebase/current Windows CI, AMD/native-wave64 validation, and title smoke that reaches changed split-wave code. Docs claiming only lane-wise reads can skip exchange are now stale and should be updated when behavior changes. I found no blocker beyond evidence/readiness.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.