Repository navigation
Description
Part of #2935 and #3074 (stage 4). Follows the "multi-wave64 exchange requires converged group control flow" family in #3224.
Problem. On a 32-lane host, the direct path runs a guest wave64 as two host wave32s, one per half (src/gfx1013_direct_compute.inl, initialize and exchange_halves).
- A 64-bit lane mask (VOPC, carry-out), a lane read across halves (
v_readlane,v_readfirstlane), and every LDS operation make the two halves meet through@waveExchangeand group barriers. - When a group holds more than one guest wave (more than 64 threads), the guest waves can branch differently. Their halves then reach a different number of group barriers. So
translaterefuses any program that has both a branch and one of those synchronizing instructions (src/gfx1013_compute_native.cpp, the "multi-wave64 exchange requires converged group control flow" gate). - Leyukaka measured this on direct compute: untranslated compute shaders of a start-up run ranked by dispatches, with first refusals on main #3224 with shader: read the wave size of slot 67 compute requests from .sa #3006 applied: 55 programs and 1,150,184 dispatches stop at this refusal. Replacing the whole-program gate with a per-branch check up to the post-dominator lets 1 of the 55 compile. The others synchronize inside branches that differ between guest waves, so a narrower gate will not recover them.
The barriers are the problem, and they come from splitting one guest wave across two host waves. NVIDIA adapters only run 32-lane waves, and the in-box WARP runs 4, so a native WaveSize(64) module is not an option there.
Proposal: lane pairs. Map guest wave64 w to one host wave32 and give each host thread guest lanes j and j + 32.
- A 64-bit mask is two
WaveActiveBallots in the same host wave, one per lane set. It needs no shared memory and no barrier, so it is valid inside any branch. v_readlane/v_readfirstlane/ DPP /v_permlane*become aWaveReadLaneAton the low or high register set. Lanekof the high half is the second set of threadk - 32.- EXEC predication stays per guest lane: each thread keeps two
active()predicates, one per lane, and an instruction is emitted once per lane under its own predicate. - Guest waves never wait for each other except at the guest's own
s_barrier. That turns the multi-wave64 group into the case the wave32 path already handles, in which every host wave is a whole guest wave. - LDS: the per-operation barrier between halves goes away, because both halves run in one host wave. The order of the two lane writes within one instruction has to match the guest. The existing wave32 path already relies on the order of LDS accesses within one wave.
Costs and open questions.
- Per host thread, the VGPR count doubles and the group size halves (
numthreads= guest threads / 2). Occupancy drops, and some programs may exceed the register budget. The census will measure how many VGPRs each program uses. - Code size: each vector instruction is emitted twice. This is a mechanical change in the emitter, but it touches the whole vector lowering. A first version could apply the layout only to the programs this gate refuses and keep
exchange_halvesfor converged programs. - Thread IDs: the guest
v0/v1/v2of lanej + 32must come from the guest's lane numbering, not the host's (logical = wave*32 + laneininitialize). - Hardware with 64-lane waves (RDNA, and WARP 1.0.22 with its bvh_wave64_warp: WARP 1.0.22 misroutes non-uniform WaveReadLaneAt reads across lane blocks at forced widths above 8 #145 lane-read defect) could instead declare
WaveSize(64)and skip both schemes. That is a separate option and not part of this proposal.
Stages.
- Census (I'm taking this). On shader: read the wave size of slot 67 compute requests from .sa #3006 locally, measure for the 55 programs, with counts and instruction shapes only and the compiler commit stated: group size, the kinds of synchronizing instruction inside divergent branches, VGPR use (to see whether doubling fits), and LDS use.
- Prototype. A source-built
.c67wave64 fixture with 128 threads (two guest waves) in which a VOPC and av_readlanesit inside a branch that only one guest wave takes. It is lowered with lane pairs and checked against a CPU model on hardware (RTX 4090) and on app-local WARP 1.0.22, which runs native wave32 compute (docs: measure native wave32 compute on app-local WARP 1.0.22 (#3160 stage 1) #3166). Negative controls: the same fixture is refused onmain, and a mutant that swaps the two lane sets mismatches. - Integration only after a maintainer agrees with the design, in focused PRs: masks and lane reads first, then LDS, then DPP/permlane.
This depends on #3006 (wave size from .sa). Without it, main compiles these programs as wave32 and they never reach this gate.
Environment: Windows 11 build 26300, NVIDIA GeForce RTX 4090 (driver 32.0.16.1088, 32-lane waves only), Windows SDK 10.0.26100, plus WARP 1.0.22 app-local.
AI-assisted.
Activity
Not-Saii commentedon Nov 28, 2026
Stage 1 (census) results. Short version: lane pairs fit the register budget and the cross-lane shapes of all 55 programs. But 10 of them (70% of these dispatches) have a shape the proposal doesn't cover yet: a guest wave leaves the program early, and the waves still running then meet at an
s_barrier.Setup
main86beae95with shader: read the wave size of slot 67 compute requests from .sa #3006 atecd2646a(a fast-forward), plus a local env-gated diagnostic at the gate intranslate_program. The diagnostic is not in any PR.2e12dd8e), run withcompile_dxil --jobs 8 gfx1013-direct-cs@36 --requests. Leyukaka's count used 882 requests.compute census keyvalue per key in that run, so they are smaller than the issue's: 314,168 here against 1,150,184.Who reaches the gate.
Method for "can differ between guest waves". This is a forward taint over SGPRs, VCC, EXEC and SCC, with union at joins.
v_cmpx/carry-out destinations,v_readlane/v_readfirstlane, thetg_sizeentry SGPR (it holds the wave index),s_getreg, and scalar loads from tainted addresses.[next, target), widened over an if/elses_branchor a loop latch; backward[target, branch).ifrestores it, for example, so "differs" below means "not shown uniform".Group size
Branches (all 55 programs)
Synchronizing instructions. Programs having the kind / with it in any conditional region / with it in a differing region; instruction counts in the same three columns.
v_cmpx(writes EXEC)v_readfirstlane_b32s_barrierv_readlane_b32, constant lanev_permlanex16_b32ds_appendv_writelane_b32None of these occur:
v_readlane_b32with an SGPR lane index,v_permlane16_b32,ds_swizzle_b32,ds_permute_b32,ds_bpermute_b32.v_readfirstlane_b32(902),v_cmp_lt_f32(896),ds_read_b64(777),ds_write_b128(523),v_cmp_gt_f32(382),v_cmpx_ne_i32(357),ds_read2_b32(279),v_cmp_nlt_f32(279),v_cmp_eq_i32(246),v_cmp_class_f32(241).s_barrierafter a per-wave exit. In 10 programs (220,275 dispatches) ans_barriersits after a differing branch whose taken side reachess_endpgmwithin a few instructions.v_readfirstlaneresult (128×1×1 ×3, 256×1×1).This reads as a real shape, not taint imprecision. A wave with no lanes left ends, and the waves still running meet at the barrier; on the guest a wave that has ended no longer counts toward
s_barrier.Lane pairs map each guest wave to one host wave. Such a host wave would
returnwhile the rest of the group later callsGroupMemoryBarrierWithGroupSync. I don't know of a D3D12 guarantee for a group barrier after some of the group's threads have returned. So these programs need one more piece before lane pairs cover them. Two possible pieces:The split-halves scheme has the same problem.
DPP, permlane and lane reads.
quad_perm, 16row_mirror/row_half_mirrorand 8row_shr, all within one 16-lane row.v_permlanex16toggles row bit 4, as in the existing lowering, so it stays within one 32-lane half.j/j + 32in one thread, each of these, and each constant-lanev_readlane, becomes aWaveReadLaneAton one register set.v_readfirstlane_b32, the most common shape, needs both sets: the first active lane is in the low set if any low lane is active, otherwise in the high set. That's oneWaveActiveAnyTrue(or ballot) per set plus a select.ds_append(1 program, 8 dispatches) needs one LDS atomic per guest wave, counting the active lanes of both sets.VGPRs.
.saVGPR granule field (4 VGPRs per granule in wave64). The highest decoded VGPR index falls in the top granule in 46 of 55 programs and is never above the allocation. With 8-register granules it would never reach the top granule, so 4 is the reading that fits.allocas, so the real host register use is up to the driver and hasn't been measured. numthreads halves.LDS (bytes, programs)
@waveStartsrank array thatinitializeuses for multi-wave groups. Its wave index would have to come from somewhere other than LDS.Other refusals after this gate (diagnostic only:
lowercalled with the gate skipped; DXC validation and the binding checks afterlowerwere not run)v_fma_f16high-halfop_sel3 (203,076, direct compute: lower op_sel on VOP3 v_fma_f16 #3233/compute: lower op_sel on VOP3 v_fma_f16 in direct compute #3234), "unsupported wave64 scalar operation" 2,s_bcnt1_i32_b64source 1, typed 2D image atomic 1.Verdict.
v_readfirstlaneandds_appendwith one select or atomic over both sets.s_barrierafter a per-wave exit (220,275 dispatches, including the heaviest). The proposal needs an answer for a guest wave that ends while the rest of the group still has barriers ahead.I haven't measured host register pressure or occupancy. The stage 2 fixture should add a variant in which one guest wave exits before an
s_barrier.AI-assisted.
Not-Saii commentedon Nov 28, 2026
Rerun of the stage 1 census on current
main, following R0Y00's note on #3224 about exact SHAs and per-key first refusals.Setup
maine3633742(includes shader: read the wave size of slot 67 compute requests from .sa #30067364e6a9, runtime: name each refused condition of a compute output buffer #3229, compute: lower op_sel on VOP3 v_fma_f16 in direct compute #3234 and compute: accept clamp on SDWA v_cvt_f32_f16 #3203), plus the same local env-gated diagnostic. The diagnostic is not in any PR.2e12dd8e: 878 untranslated slot 67 compute requests, run withcompile_dxil --jobs 8 gfx1013-direct-cs@36 --requests.compute census keyvalue per key. None of these dispatches were translated in that run.Result. The same 55 programs stop first at "multi-wave64 exchange requires converged group control flow", and every statistic in my comment above is unchanged. Only the refusal after the gate moved, because of #3234:
v_fma_f16op_selprograms are past that refusal. One now gets through lowering (39,410 dispatches). The other two (163,666, both 4×64×1) now stop at "unsupported local DS opcode 166" (ds_read_u16_d16).lowerwere not run.Per-program table. Rows are numbered by dispatches; shader keys are left out (AGENTS.md).
mainis the gate for every row..sa.v_cmpx; lds: LDS access;v_readfirstlane; rl: constant-lanev_readlane; wl:v_writelane;s_barrier; plx16:v_permlanex16; append:ds_append.s_barrierafter a differing branch whose taken side reachess_endpgm.ds_read_u16_d16)ds_read_u16_d16)AI-assisted.
Not-Saii commentedon Nov 28, 2026
Stage 2 plan (prototype fixture) for the lane-pair layout. I'm posting this for comment before writing code. Nothing here is implemented yet.
Goal. Show on hardware and on app-local WARP 1.0.22 that one host wave32 per guest wave64 gives the guest result for the shapes the census found inside differing branches:
v_cmpx, lane reads,v_readfirstlane, LDS, DPP andv_permlanex16;None of the 55 captured programs is expected to compile after stage 2. That is stage 3.
Scope of the prototype emitter
exchange_halves.<name>"). Programs it can't handle stay refused rather than translated wrongly, and a census rerun shows coverage directly.numthreadsis guest threads / 2.j) and the high set (lanej + 32). SGPRs stay single, since one host wave is one guest wave.s126/s127(EXEC) ands106/s107(VCC) map directly onto the two sets: sethis active when bitlaneof word126 + his set.h=WaveActiveBallot(active(h) && cond(h)).x, written todst + h. No groupshared memory and no barrier.v_cmpx: writes EXEC the same way.v_readlanewith constant lanek:WaveReadLaneAt(set[k >= 32], k & 31).v_readfirstlane: read the low set atfirstbitlow(exec_lo)whenexec_lo != 0, otherwise the high set atfirstbitlow(exec_hi).quad_perm, row shifts, mirrors) andv_permlanex16: the existing wave32 lowering, once per set. Every census shape stays inside one 32-lane set.s_barrier:GroupMemoryBarrierWithGroupSync, as today.v0..v2come fromlogical = wave * 64 + 32 * h + lane. The guest wave index comes from the same rank asinitialize's@waveStarts. A rank that doesn't use LDS (needed by the census program at 32 KB) is left for later.Fixtures. Source-built
.c67requests encoded as instruction words, liketests/native_slot67_wave_size_check.py..sawave32 bit clear), 128 threads, two guest waves, and thetg_sizeentry SGPR.write_requestand compiled withcompile_dxil ... gfx1013-direct-cs@0 --requests.native_store_replay ... --direct(hardware) and--direct-warp(WARP), two groups.mask_readlanetg_sizewave field: only guest wave 1 runs av_cmponv0writing an SGPR pair, thenv_readlaneof lane 40readfirstlane_highexec_lois 0 (lanes 32–63 only), thenv_readfirstlanelds_divergentds_write_b32/ds_read_b32across lanesjandj + 32; then a group-uniforms_barrierand a cross-wave LDS readdpp_permlane_divergentrow_shr:1,row_mirrorandv_permlanex16on a lane-ID valueexit_before_barrier(measurement)s_endpgmthrough an EXECZ skip; waves 1 and later write LDS,s_barrier, then read a neighbour's wordF5 needs 256 threads (4 guest waves), so that more than one wave meets at the barrier. With the gate in place it is refused everywhere. A local option emits the early
s_endpgmasreturn, so the result can be measured.Negative controls
main: F1–F5 are refused with "multi-wave64 exchange requires converged group control flow". This runs in a_controlstest with no GPU.v_readlanelane changed from 40 to 8, and F2 withexec_lonon-zero, must both mismatch their unmodified expectations. That shows the high set is really read.split-wave64/two-wave64cases) still compiles throughexchange_halves, and its output is unchanged.Tests (one
tests/cmake/native_wave64_lane_pairs.cmake)native_wave64_lane_pairs_controls: compile and refusal checks, no GPU.native_wave64_lane_pairs_hardware: RTX 4090; skip 77 without SM 6.6 or 32-lane waves.native_wave64_lane_pairs_warp: app-local WARP 1.0.22, configured withOFFSCREEN_WARP_DIR(docs: measure native wave32 compute on app-local WARP 1.0.22 (#3160 stage 1) #3166). It skips with 77 on the in-box 4-lane WARP.Reported with the results: the compiler commit; the adapter, driver, Windows build and debug-layer state for each GPU run; each control's first mismatch; and any skip, counted separately. Then a rerun of the 878-request census, counting how many of the 55 the prototype mode admits and their first remaining lane-pair refusal.
Open questions for a maintainer
exchange_halveskept for converged ones?returnfollowed byGroupMemoryBarrierWithGroupSyncin the remaining waves. This depends on driver behaviour that D3D12 doesn't, as far as I know, specify, so F5 would only measure it.Which is acceptable, if any?
AI-assisted.
tedin7 commentedon Nov 28, 2026
Read the proposal, the census and the stage 2 plan. The layout matches what we were about to try ourselves (one host wave32 per guest wave64, guest lanes j and j+32 per thread), so +1 on the direction. A few points I'd want the prototype to pin down, roughly in order of how quietly they can go wrong:
Thread-to-lane mapping is not guaranteed. D3D12 doesn't promise that host wave
wholdsSV_GroupIndex32w .. 32w+31, or thatWaveGetLaneIndex() == SV_GroupIndex % 32. The whole scheme (guest lane numbering,v0/v1/v2, ballot bit order) depends on it. I'd derive the guest lane fromWaveGetLaneIndex()and the guest wave from something wave-uniform, and add a cheap check (WaveActiveAllTruethat the group index matches the assumed layout) that fails loudly instead of drawing garbage. The fixture should include a group shape where this could plausibly differ (e.g. 2D/3Dnumthreadssuch as 4×64×1 and 8×8×8 from the census).Declare
[WaveSize(32)]. Without it, AMD desktop RDNA may run the shader as wave64 and the lane-pair layout breaks. With it, PSO creation fails cleanly on hardware that can't do 32.Keep host lanes converged around every wave op.
WaveActiveBallot,WaveReadLaneAtandWaveReadLaneFirstmust sit in host control flow that only depends on wave-uniform values (SGPRs, EXEC==0 tests). Per-guest-lane predication has to be data masking (active(h) ? x : old), never an HLSLifaround a wave intrinsic. This also covers reads of lanes whose EXEC bit is 0, which are defined on RDNA but undefined in DXIL inside divergent flow.Early exit before a barrier (your 10 programs, 70% of the dispatches). A guest wave that hits
s_endpgmmust not leave the host group while others still callGroupMemoryBarrierWithGroupSync. The usual fix is a per-waveexitedflag: the wave stops executing guest instructions but keeps arriving at every remaining barrier until the program's natural end, with all its writes masked off. That keeps the barrier count equal across waves, which is what the gate was protecting.v_readfirstlanewith EXEC == 0 returns lane 0 on RDNA. The plan's "low set at firstbitlow(exec_lo), else high set" needs that third case.Two lane writes per instruction to the same LDS address. The order must reproduce the guest's (for a same-address write within one DS instruction the hardware keeps one lane's value; I'd check which one in the RDNA2 ISA guide and lock it with a fixture where both sets of a thread write the same address).
VOPC/
v_cmpxwrite the whole mask. Bits of inactive lanes become 0, not "unchanged"; the ballot ofactive(h) && cond(h)gives that, so it's just worth a negative control.On the census: we see the same family on our side (multi-wave compute groups with masks/LDS/readfirstlane in branches that differ between waves), so once there's a stage-2 fixture we can run it on an RTX 3070 Ti as a second real GPU, and run the stage-3 emitter over our own request set and report per-key first refusals the same way you did.
AI-assisted; commands listed were executed locally.
Not-Saii commentedon Nov 28, 2026
@tedin7 thanks for the review. I built the stage 2 prototype and ran it. Results first, then your seven points.
Build under test.
mainfdb6faaaplus a local change that is not pushed yet. Windows 11 build 26300, NVIDIA GeForce RTX 4090 (driver 32.0.16.1088, 32-lane waves only), Windows SDK 10.0.26100, debug layer not enabled. The fixture programs were assembled with LLVM 15.0.7 for gfx1013 wave64 and are embedded as words.What the prototype does. Lane pairs apply only to wave64 requests that the "converged group control flow" gate refuses. Everything else keeps split halves. The emitter did not need a second vector lowering: split halves already pick the EXEC and mask word through one value (
upper_half), so each vector instruction is emitted twice with that value constant and with a second set of VGPR storage, and scalar writes are held until both sets have read their operands. Five places differ: the ballot,v_readlane,v_readfirstlane, the per-LDS barrier (gone) and the thread ids. Hostnumthreadsis (guest threads / 2, 1, 1), and the module declaresWaveSize(32).Early exit before
s_barrier(open question 2). I took neither (a) nor (b). When a group has more than one guest wave and some path reachess_endpgmwithout passing ans_barrier, the program gets one barrier site in a loop. A wave runs to its nexts_barrieror tos_endpgm, stores where to resume and goes to that site. There lane 0 publishes whether the wave has ended, the group meets, every thread reads all waves' words, and a second barrier closes those reads. A wave that has ended keeps coming back until all of them have. Every thread reaches the same barrier the same number of times, so nothing depends on what a driver does after areturn. Programs whose barriers no wave can skip keep the plain barrier. Ans_barrierinside a guest loop is refused for now.Fixture.
tests/native_wave64_lane_pairs_check.py, registered asnative_wave64_lane_pairs_controls(no GPU) andnative_wave64_lane_pairs_hardware. Both pass. Each program is compared with a small CPU model over all 2,064 output words, guards included.mask_readlanev_readlaneof lane 40readfirstlane_highv_cmpxleaves lanes 32–63 of the last wave, EXECZ skip,v_readfirstlane; a compare that is true for every lane then gives low word 0lds_divergentds_writeandds_readacross lanes j and 63−j, then an unconditionals_barrierand a cross-wave readdpp_permlane_divergentrow_shr:1,row_mirrorandv_permlanex16inside the branchgroup_shape_2d,group_shape_3dv0,v1,v2, stored at an address computed from those idsreadfirstlane_emptyv_readfirstlanewith EXEC set to 0 returns lane 0lds_same_addressexit_before_barrier2d6dad19refuses the same requests.mask_readlane: word 264, got0xffffffff, expected0x00001fff),v_readlaneof lane 8 checked against the lane-40 expectation, and the model in which wave 0 had not left (exit_before_barrier: word 8, got the0x69696969fill).2d6dad19).Cost. Straight-line synthetic programs that both layouts accept, 65,535 groups × 16 dispatches, GPU timestamps, median of 5 runs. Two earlier full runs on
2d6dad19were within 7% of these numbers. Outputs are identical between the layouts in every row.v_cndmask, LDS write and read,v_readfirstlaneevery round (441 instructions)timingmode runs two similar programs at 128 threads, checks them against CPU models under both layouts, and gave 0.33 (12.07 → 3.95 ms) and 0.86 (7.43 → 6.36 ms).For question 1, my reading of these numbers: lane pairs wherever a wave64 program has masks, lane reads or LDS, and split halves kept for single-wave groups without them, where the halves never exchange anyway. One GPU and synthetic programs, so I'd want a second adapter before fixing that rule.
Your points.
WaveGetLaneIndex()and the guest wave from a wave-uniform rank (WaveActiveMinof the flat thread id), not fromSV_GroupIndex. With lane pairs the host group is always one-dimensional, and the guest shape only enters the id arithmetic, which the two shape programs cover. What stays assumed is that every host wave is full. I did not add an in-shader check, because a compute shader has nowhere to report it. The fixtures compare every word.WaveSize(32)is declared. I checked it in the module dump.select(active, new, old). The only per-lane host branches wrap memory side effects, and the wave operations sit outside them.exit_before_barrier.readfirstlane_emptypasses. It also showed that split halves onmainreturn lane 32 here (64 threads: got0x2005, expected0x5), so that one assertion is skipped under split. It is a separate bug and is not fixed in this change.lds_same_addresslocks the host order: the second lane set is written last, so lane j+32 wins. I have not confirmed that the guest keeps the same lane, so the ISA guide check is still open. Under split the two halves race, so this is asserted for lane pairs only.readfirstlane_high, with a negative control that expects the low word unchanged.Not done.
--direct-warpmode yet. No other adapter, no debug layer, no dispatch through the stand-in.exit_before_barriershows that the loop works on this driver. It does not show that a plainreturnwould have failed.The layout switch used for the measurements is an environment variable outside the cache key, so it has to go before a PR. I can push the branch if you want to run the fixture on the 3070 Ti.
AI-assisted.
Leyukaka commentedon Nov 28, 2026
Review of the lane-pair design and the stage 2 results, from the code on
main052abe6fand the HLSL docs.Early exit before a barrier. Microsoft's
GroupMemoryBarrierWithGroupSyncpage: "The behavior of calls to this function that are within diverging branches of a thread group are undefined." The rendezvous loop avoids this, and it has only run on the RTX 4090.LDS inside one guest instruction. Each lane set's access is under its own per-thread branch (
src/gfx1013_direct_compute.inl1163). "Low set, then high set" orders lanesjandj + 32of one thread only. Lanejof one thread against lanek + 32of another, or against another thread's low set, is a groupshared race with no barrier between them.lds_same_addresschecks only the same-thread case.DPP and permlane on WARP. These lowerings pass a per-lane index to
WaveReadLaneAt(inl4080 and 4138). On WARP 1.0.22 such a read returned the wrong lane in #3320 (lane 30 where lane 14 was named), while an RTX GPU returned the named lane. Running DPP/permlane once per lane set keeps that, so a WARP pass ofdpp_permlane_divergentneeds a wave32 control of the same DPP before it counts.Where the dispatches are. Of the 10 early-exit rows in the stage 1 table, rows 1 and 10 then stop at
ds_read_u16_d16(#3330 adds it) and rows 3, 4 and 7 at descriptor addressing. Lane pairs alone admit the rows whose only cross-lane shapes are compares,v_cmpxand carry-out: 5, 44, 48 and 50.A first PR that would be provable now:
v_cmpx, carry-out,v_readlanewith a constant lane, andv_readfirstlane;s_barrier, DPP/permlane,ds_appendand atomics refused with their own reason;Existing bug on
main. With guest EXEC 0, the splitv_readfirstlane(inl3196-3200) selectscandidates[1], the upper half's lane 0, which is guest lane 32. You noted this in your stage 2 results. Are you fixing it, or should I open a separate PR?compute: order LDS accesses within a lane-pair wave with a ballot