mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:25:53 +01:00
[PR #2119] shaders: coalesce and inline wave64 x_round exchanges (SHADER-W64-XROUND-BARRIERS) #2125
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2125
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2119
Author: @robot00f
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:perf/w64-xround-barriers📝 Commits (1)
72d722ashaders: coalesce and inline wave64 x_round exchanges (SHADER-W64-XROUND-BARRIERS)📊 Changes
7 files changed (+1026 additions, -178 deletions)
View changed files
📝
docs/design.md(+1 -1)📝
runtime/test/shaders/check.py(+3 -1)➕
runtime/test/shaders/cs_w64x_xround_coalesce.asm(+117 -0)📝
scripts/run_gpu_tests.py(+2 -1)📝
tests/semantic/test_wave64_emulate_opt.py(+5 -6)➕
tests/semantic/test_wave64_xround_barriers.py(+462 -0)📝
tools/rdna2spirv.py(+436 -169)📄 Description
Claimed in the coordination issue as:
SHADER-W64-XROUND-BARRIERS(https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7172190888; follow-up to https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159151871 and https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159367489)What and why
Coalesces wave-wide Workgroup exchanges and eliminates helper-call / modulo overhead in
Gen.x_round(emulate_inlineintools/rdna2spirv.py) under--wave64-emulateon 32-wide GPUs, while keeping%x_bufbyte-identical ((2*L + 6*W + 7)dwords):Gen._x_round_inline:%x_pre_*_fnOpFunctionCalls (CGSCC inliner cloning across hundreds of callsites increased NVVM compile time by+12%to+21%vs inline).%x_itthrough0..5(lcm(2, 3) = 6, preserving bothit & 1parity andit % 3ring-slot indexing) with zeroOpUMods and omits the two dead scheduler-word resetOpAtomicStores on multi-wave workgroups whenevermini_blocksandtail_blocksare empty.0x948(ImageMemory | WorkgroupMemory | UniformMemory | AcquireRelease) to0x108(WorkgroupMemory | AcquireRelease) whenever"mem"is clean inx_dirty(and inx_order_barrierwhen only"lds"is dirty).Any-vote and first-lane caching (x_vcache,x_flcache,x_vkeys):Anyvotes and first-active-lane indices acrossscc_from_mask,branch_condition,wave_mask,v_readfirstlane_b32, and DPPfi:0within a basic block, and preservesx_genacross internalOpSelectionMergeregions (buffer_load,buffer_store,ds_*,_emit_rfl_run) that do not write%active,%vcc,%vcc_hi, or%sgpr.Anyfrom a cached(lo, hi)mask in 2 ALU ops ((lo | hi) != 0,0barriers,0atomics); whenbranch_conditionreuses a cachedAnyvote whilex_dirtyis non-empty, emits a barex_order_barrier()to preservewave64_emulate_opt.py'ssb_clears_dirtyinvariant.x_vkeysregistration inmask_dstto full-wave masks (n == 2SGPR pairs and fullvccin wave64) so 32-bit half-mask writes never alias 64-bitx_vcacheentries._pending_scc_voteinemulate_inline):scc_from_mask/scc_any_halfvotes until%sccis read/overwritten or a label/merge/barrier/branch/%pcstore occurs.branch_conditionon the same mask (1OpAtomicOr,1barrier), with another 1-bitg_voteon a distinct mask (2 -> 1barrier via 2-wordbits=(p_bit, bit2)), with adata-onlyx_round(v_readlane_b32,ds_bpermute_b32,ds_swizzle_b32,quad_any, DPPfi:1,2 -> 1barrier viadata + bits), or withx_order_barrier(2 -> 1barrier), and drops the vote (0barriers) if%sccis overwritten before being read.v_readfirstlane_b32runs (Gen._emit_rfl_run):firstonce (0barriers if already inx_flcache/x_mcache, else1round on item 0) and transfers up to 64 remaining values per wave from the single running lanewave_lane == firstacross oneOpControlBarrier(4 -> 2or1round barriers for V# scalarization,8 -> 2or1for T# scalarization, piggybacking any pending SCC vote into the same barrier).NVVM ablation note (
#1608): Reproducing the 192-VGPR unfolded binaryif/elseScreenProbesshape on GTX 1050 Ti (sp_tree_156:464.1 KiB,156barriers ->4.168 s;sp_tree_324:898.7 KiB,324barriers ->12.224 s) and stripping all middleOpControlBarrierinstructions (NO_BARS) leavesvkCreateComputePipelinestime unchanged (12.13 s -> 12.22 s, and4.91 s -> 4.88 son 320-barrier loops). Thus the ~11 s baseline on pure unfoldedsaveexectrees is dominated by%pc-guardedOpSelectionMergeblock splitting (SROA/Mem2RegPhi webs across 192 VGPRs) +%x_pre_*_fncloning rather thanOpControlBarrieritself; where cross-lane votes, mask reads, andv_readfirstlane_b32runs coalesce (probe_80/probe_160), cutting exchange blocks in half cuts NVVM compile time by-68.5%to-69.6%(3.2x–3.3xfaster).Tested
Cold
vkCreateComputePipelinesbenchmarks (vk_pipeline_check --jobs 1,__GL_SHADER_DISK_CACHE=0, uniqueOpStringnonce per trial, 3 trials each, exactorigin/mainvs this PR):origin/mainbarriers /OpFunctionCall/OpUModOpFunctionCall/OpUModorigin/mainmedian (3runs)3runs)probe_80(80 live-SCCsaveexec+execz+ 4xreadfirstlane+readlaneblocks)641/640/5(555.0 KiB)321/0/0(554.8 KiB)6.062 s([6.369, 6.062, 6.030])1.907 s([1.679, 2.144, 1.907])-68.5%(3.18x)probe_160(160 probe/waterfall blocks)1,281/1,280/5(1,100.9 KiB)641/0/0(1,101.9 KiB)17.433 s([17.338, 17.710, 17.433])5.296 s([5.310, 5.296, 5.121])-69.6%(3.29x)sp_tree_156(192-VGPR unfolded binaryif/elsetree, dead-SCC votes only)156/339/4(464.1 KiB)156/184/0(529.8 KiB)4.168 s([4.168, 3.750, 4.587])3.649 s([3.789, 3.635, 3.649])-12.5%sp_tree_324(192-VGPR unfolded binaryif/elsetree, dead-SCC votes only)324/699/4(898.7 KiB)324/376/0(1,036.5 KiB)12.224 s([14.261, 12.181, 12.224])11.479 s([11.853, 11.479, 11.279])-6.1%GPU execution (
LEONIDA_W64_EMULATE=1,subgroup 32..32):vk_compute_test cs_w64x_xround_coalesce.spv 1 dump: 3/3 runs0 mismatches,out[0..7] = 147 308 1832 444 625 1335 2379 332.cs_dpp_w64, all 20cs_w64x_*,cs_w64x_partial,cs_w64x_partial_scmp,cs_wave64_ballot, andcs_wavemask) translate, passspirv-val, and match expected outputs before (23/23) and after (24/24).CPU semantic, translator, and repository checks:
python -I tests/semantic/test_wave64_xround_barriers.py(9/9, 40/64/128-thread forward & reverse workgroup interpreter +spirv-val)python -I tests/semantic/test_wave64_emulate_opt.py(33/33),test_wave64_emulate_barriers.py(13/13),test_loop_ballot_barrier.py(15/15),test_cs_shared_memory_limit.py(15/15),test_w64x_scalar_load_order.py(5/5)python -I tests/test_shader_checks.py(88/88),test_ci_registration.py(16/16),test_text_write_line_endings.py(3/3),test_docs_*.py,scripts/check_no_game_data.py(exit 0).GPUs tested: NVIDIA GeForce GTX 1050 Ti (Pascal, 4 GB), driver 582.28, Vulkan 1.4.312, Windows 10 Pro 10.0.19045
AI-assisted: yes (Antigravity, Gemini 4 Carbon)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.