Split wave64: masks read only lane by lane stay in their half #94
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!94
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/94/head"
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?
@hexgeon1 on GitHub · 2026-11-23 10:50 UTC · original
hexgeon1:wave64-local-masks→main· +898 −50 · 7 files · 1 commits · merged 2026-11-23 11:02 UTCSplit wave64: masks read only lane by lane are not exchanged
In the split wave64 form (#67), every mask write (
v_cmp*, carry-outs) exchanges the two wave32 halves' ballots so that both hold the whole 64-bit mask. Many masks are never read whole: av_cndmask_b32selector or the carry-in ofv_add_co_ci/v_sub(rev)_co_cionly reads the reading lane's own bit, which its own half already has. This PR finds those masks and gives them the half's own ballot word (xcl_x_ballot_local) instead of an exchange. That covers every 64-bit address add and every select. #67 lists this as its next step.How it works
gpu/recomp/x64_masks.rsis a backward liveness pass over the SGPRs. A register is whole-live after an instruction when some path may read its whole value before it is written again. A mask written to registers that are not whole-live stays in its half. Both halves make the same static choice, so their exchange counts stay in step.After a local mask the halves hold different values in those registers, so a missed whole read lets them diverge: wrong results, or exchanges that no longer pair up. For that reason the rules follow what the emitter does, not only the ISA operand tables:
s_cmov*ands_cmovkdon't: they write only when a condition holds.s_addk,s_mulkands_bitset*don't: they read the old value first.s_movreldands_movrelsd_2don't: they writes[dst + m0].s_movrels*: reads every register from its base up to s123, VCC included.src_vccz/src_execz;s_getpc/s_add/s_setpc) counts as a plain branch.LOOP_GUARD): a loop can be left where its budget is checked. That is at its top, or, in thepcdispatcher form, before every block, which ends the program. Whatever is live after the loop, or at the end, therefore counts as live before each instruction in the loop. The loop ranges come from the translator's own merge, now one function:loop_ranges()inrecomp/mod.rs.falsemask ofv_div_scale). Either way both halves hold the same value.s_setpc) has no liveness pass and exchanges every other mask as before.XCL_X64_ALL_MASKS=1exchanges every mask, for comparison. On RDNA,XCL_SPLIT_WAVE64=1(ba905cf) runs the split form there too.Cost
bench_split_wave64(#67's benchmark) now does two things differently:runner::dispatch_timed). Before, it took the wall-clock time of a wholerunner::dispatch: pipeline creation, buffer creation, uploads, submission and the CPU's wait. That overhead is the same for wave32 and wave64, so it pulled every ratio towards 1; #67's 5070 Ti figures were measured that way.Measured on an RTX 3090 (driver 617.14): three runs with
XCL_X64_ALL_MASKS=1and five with the default. Each figure is wave64 split GPU time ÷ wave32 GPU time:v_readfirstlaneThe wave32 baseline is 11.4–14.1 ms. The 4–16 % that remains with no exchange at all is the rest of the split form (64-bit masks, assigning console threads at the start); I haven't measured it further.
What the benchmark does and doesn't show: its loop mask is exactly the kind this pass keeps local, so the result is close to guaranteed by construction. It shows that the exchange is gone and what an exchange costs, which matters most in the counter-paired form. It doesn't show how much real shaders gain: that depends on how many of their masks are read only lane by lane (see Not checked). It is also one synthetic loop on one GPU.
Still exchanged: readlane / readfirstlane,
ds_bpermute, coherent scalar loads, and masks read whole.Tests
x64_masks::tests, 16 unit tests:s_movrels/s_movreld/s_movrelsd_2, SMEM offset, SDWA S0 / S1);gpu_split_wave64_lane_local_masks: a select and a 64-bit carry chain whose masks have bits in both halves, checked lane by lane, plus a check that all four masks are emitted local. Putting the local word in the wrong half makes it fail.gpu_split_wave64_masks_read_whole_after_partial_writes:Without the rules it fails with "the halves ended with different SGPRs".
gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves: four console waves per group (256 and 8 × 8 × 4), so the counter-paired form.The new unit tests for the partial-write rules and for the loop exits fail without their fixes. I checked this by running them against earlier versions of the pass.
Workspace, release, RTX 3090 on Windows 10 with the D3D12 Agility SDK 1.616.1, on
697dbb1:no wave64:gpu_wave32_program_in_wave64_hardwareand the native half ofgpu_geometry_wave32_prefix_count_over_a_mask.XCL_WAVE64_SPIN=1, thegputests give 224 passed, 0 failed.Other open PRs
s_round_mode/s_setreg*, now onmain): itss_setreg_b32only reads its SGPR, and the pass counts that read as whole, so a mask feeding it is still exchanged.recomp/mod.rsnext toloop_ranges(). It is textual only; #83 already conflicts withmainin three other files.mainin five files; this PR adds none.Not checked
XCL_X64_ALL_MASKS=1: 38 exchanged).XCL_SPLIT_WAVE64=1.cur_pc(emits nothing) andxcl_x_ballot_localonly take effect in the split form. It was not dumped and compared.🤖 Generated with Claude Code
github-bot referenced this pull request2026-11-26 04:19:41 +00:00
@ivall on GitHub · 2026-11-23 11:03 UTC · original
Merged – thanks, this is the step #67 named. Checked on AMD, which you couldn't: Checked on Windows 11 with an RX 9070 (RDNA4, MSVC build):
cargo test --workspacegreen with the retail samples (shader pack, console DLLs, texture archive), natively and withXCL_SPLIT_WAVE64=1.Real compute shaders in the split form: XDefiant run on the RX 9070 with
XCL_SPLIT_WAVE64=1, so every wave64 compute and mesh program of the title goes through the split form with your local masks – its title screen renders right, no translation errors, no device removal. (On the first, cold-cache run the UI stayed incomplete until a restart; that is XCL's known cold-cache issue with pipelines recorded behind a stand-in, also seen without the split form.)