Skip to content

direct compute: run each guest wave64 in one host wave32 (two lanes per thread) instead of exchanging halves (proposal) #3237

Backlog

Description

@Not-Saii

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 @waveExchange and 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 translate refuses 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 a WaveReadLaneAt on the low or high register set. Lane k of the high half is the second set of thread k - 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_halves for converged programs.
  • Thread IDs: the guest v0/v1/v2 of lane j + 32 must come from the guest's lane numbering, not the host's (logical = wave*32 + lane in initialize).
  • 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.

  1. 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.
  2. Prototype. A source-built .c67 wave64 fixture with 128 threads (two guest waves) in which a VOPC and a v_readlane sit 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 on main, and a mutant that swaps the two lane sets mismatches.
  3. 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

  1. Not-Saii commented on Nov 28, 2026

    @Not-Saii
    ContributorAuthor

    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

    • Compiler: main 86beae95 with shader: read the wave size of slot 67 compute requests from .sa #3006 at ecd2646a (a fast-forward), plus a local env-gated diagnostic at the gate in translate_program. The diagnostic is not in any PR.
    • Inputs: the 878 untranslated slot 67 compute requests from one 300 s start-up run (2e12dd8e), run with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests. Leyukaka's count used 882 requests.
    • Dispatch counts are the last compute census key value 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.

    • Sources: VOPC/v_cmpx/carry-out destinations, v_readlane/v_readfirstlane, the tg_size entry SGPR (it holds the wave index), s_getreg, and scalar loads from tainted addresses.
    • A conditional branch differs when the value it tests is tainted. Its region is structural: forward [next, target), widened over an if/else s_branch or a loop latch; backward [target, branch).
    • This over-approximates. EXEC stays tainted after a divergent if restores it, for example, so "differs" below means "not shown uniform".
    • Smoke-tested on three synthetic wave64 programs with 128 threads (compare under a divergent EXECZ, compare under a uniform EXECZ, carry-out under a uniform EXECZ).

    Group size

    Group Guest waves Programs Dispatches
    16×16×1 4 34 71,212
    256×1×1 4 7 11,040
    1024×1×1 16 4 11,654
    128×1×1 2 3 41,799
    4×64×1 4 2 163,666
    8×16×1 2 2 2,230
    192×1×1, 256×2×1, 8×8×8 3, 8, 8 1 each 12,567

    Branches (all 55 programs)

    • 1,241 EXECZ/EXECNZ branches, of which 1,237 differ; every program has at least one.
    • 348 SCC branches, of which 171 differ, in 32 programs.
    • 16 VCCZ branches, all of which differ, in 15 programs.
    • 32 loops, of which 20 have a differing exit, in 13 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.

    Kind Programs Instructions
    VOPC writing a mask (VCC or SGPR pair) 52 / 49 / 46 2,643 / 2,490 / 2,439
    v_cmpx (writes EXEC) 49 / 35 / 32 685 / 590 / 565
    LDS read/write/atomic 35 / 35 / 34 2,418 / 2,353 / 2,208
    v_readfirstlane_b32 28 / 24 / 23 957 / 903 / 902
    s_barrier 36 / 13 / 10 185 / 76 / 59
    DPP 9 / 6 / 6 78 / 58 / 43
    v_readlane_b32, constant lane 9 / 5 / 5 28 / 20 / 20
    v_permlanex16_b32 8 / 4 / 4 10 / 5 / 5
    carry-out 3 / 1 / 1 7 / 3 / 3
    ds_append 1 / 1 / 1 2 / 2 / 2
    v_writelane_b32 1 / 1 / 1 10 / 10 / 10

    None of these occur: v_readlane_b32 with an SGPR lane index, v_permlane16_b32, ds_swizzle_b32, ds_permute_b32, ds_bpermute_b32.

    • Most common shapes in differing regions: 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).
    • Where the sync sits: 52 programs (273,158 dispatches) have a synchronizing instruction in a differing region.
      • 1 has none in any conditional region.
      • 2 have one only under branches the taint shows uniform. A per-branch gate would have to prove that before compiling them.

    s_barrier after a per-wave exit. In 10 programs (220,275 dispatches) an s_barrier sits after a differing branch whose taken side reaches s_endpgm within a few instructions.

    • 6 programs: an EXECZ skip after a compare (4×64×1 ×2, 256×1×1, 256×2×1, 1024×1×1 ×2).
    • 4 programs: an SCC branch on a v_readfirstlane result (128×1×1 ×3, 256×1×1).
    • None are in loops.

    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 return while the rest of the group later calls GroupMemoryBarrierWithGroupSync. 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:

    • an exiting wave keeps running, with no lanes active, through every barrier the running waves still reach; or
    • a barrier built on a groupshared count of running waves.

    The split-halves scheme has the same problem.

    DPP, permlane and lane reads.

    • The DPP is 54 quad_perm, 16 row_mirror/row_half_mirror and 8 row_shr, all within one 16-lane row.
    • v_permlanex16 toggles row bit 4, as in the existing lowering, so it stays within one 32-lane half.
    • With lanes j / j + 32 in one thread, each of these, and each constant-lane v_readlane, becomes a WaveReadLaneAt on 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 one WaveActiveAnyTrue (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.

    • The guest allocation comes from the .sa VGPR 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.
    • Allocation (programs, dispatches): 8 (4, 4,733), 16 (8, 12,638), 24 (11, 23,155), 32 (11, 210,266), 40 (4, 4,272), 48 (4, 42,755), 56 (2, 2,230), 64 (11, 14,119).
    • Doubled, the largest is 128 guest VGPRs per host thread, before the SGPR copies and the emitter's temporaries. The emitter declares registers as uncapped allocas, so the real host register use is up to the driver and hasn't been measured. numthreads halves.

    LDS (bytes, programs)

    • 0: 20 programs.
    • 512 to 4,608: 25 programs.
    • 6,144 to 16,384: 9 programs.
    • 32,768: 1 program (10 dispatches). That one is at the D3D12 32 KB groupshared limit, which leaves no room for the @waveStarts rank array that initialize uses for multi-wave groups. Its wave index would have to come from somewhere other than LDS.

    Other refusals after this gate (diagnostic only: lower called with the gate skipped; DXC validation and the binding checks after lower were not run)

    Verdict.

    • Fits: VGPRs at most 128 per host thread, every DPP/permlane/constant-lane read inside one 32-lane set, and v_readfirstlane and ds_append with one select or atomic over both sets.
    • Fits, plus one change: 42 programs (52,883 dispatches) have no barrier after a per-wave exit. They also need no change beyond the proposal, except the one at 32 KB LDS, which needs a wave index without LDS.
    • Not covered yet: the 10 programs with an s_barrier after 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.
    • Lane pairs not needed: 3 programs (41,010). They have no synchronizing instruction in a region the taint calls differing.

    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.

  2. Not-Saii commented on Nov 28, 2026

    @Not-Saii
    ContributorAuthor

    Rerun of the stage 1 census on current main, following R0Y00's note on #3224 about exact SHAs and per-key first refusals.

    Setup

    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:

    • The three v_fma_f16 op_sel programs 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).
    • 19 of the 55 now get through lowering with the gate skipped (70,526 dispatches), up from 18 (31,116). DXC validation and the binding checks after lower were not run.

    Per-program table. Rows are numbered by dispatches; shader keys are left out (AGENTS.md).

    • The first refusal on main is the gate for every row.
    • "VGPRs" is the guest allocation from .sa.
    • The sync kinds count only instructions in a region whose branch condition was not shown uniform across guest waves:
      • cmp: VOPC mask; cmpx: v_cmpx; lds: LDS access;
      • rfl: v_readfirstlane; rl: constant-lane v_readlane; wl: v_writelane;
      • bar: s_barrier; plx16: v_permlanex16; append: ds_append.
    • "Barrier after per-wave exit" marks an s_barrier after a differing branch whose taken side reaches s_endpgm.
    # Group Waves VGPRs LDS B Sync kinds in a differing region Barrier after per-wave exit Next refusal (gate skipped) Dispatches
    1 4x64x1 4 32 2,048 cmp, cmpx, lds, bar EXECZ unsupported local DS opcode 166 (ds_read_u16_d16) 161,966
    2 16x16x1 4 48 16,384 none - lowers 39,410
    3 128x1x1 2 32 3,584 cmp, cmpx, lds, rfl, rl, bar, dpp, plx16 SCC (lane read) direct descriptor address outside bound table 21,505
    4 128x1x1 2 32 3,584 cmp, cmpx, lds, rfl, rl, bar, dpp, plx16 SCC (lane read) direct descriptor address outside bound table 17,140
    5 1024x1x1 16 16 0 cmp, cmpx - lowers 9,414
    6 256x2x1 8 24 6,144 cmp, cmpx, lds, rfl, bar EXECZ lowers 9,414
    7 128x1x1 2 32 3,584 cmp, cmpx, lds, rfl, rl, bar, dpp, plx16 SCC (lane read) direct descriptor address outside bound table 3,154
    8 256x1x1 4 24 2,560 cmp, lds, rfl - unsupported wave64 scalar operation 3,152
    9 16x16x1 4 64 8,192 cmp, lds - lowers 3,152
    10 4x64x1 4 32 2,048 cmp, cmpx, lds, bar EXECZ unsupported local DS opcode 166 (ds_read_u16_d16) 1,700
    11 256x1x1 4 32 4,608 cmp, cmpx, lds, rfl, bar EXECZ invalid s_ff1_i32_b64 source 1,590
    12 192x1x1 3 40 6,656 cmp, cmpx, lds - lowers 1,577
    13 16x16x1 4 32 4,096 cmp, lds, rfl - packed image addressing 1,576
    14 16x16x1 4 8 0 cmpx, rfl - invalid s_bcnt1_i32_b64 source 1,576
    15 8x8x8 8 8 0 none - lowers 1,576
    16 16x16x1 4 32 4,096 cmp, lds, rfl - packed image addressing 1,576
    17 16x16x1 4 64 8,192 lds - lowers 1,576
    18 256x1x1 4 40 1,536 cmp, cmpx, lds, bar, dpp SCC (lane read) direct image opcode or descriptor modifiers 1,576
    19 256x1x1 4 16 8,192 cmp, lds, rfl - direct image opcode or descriptor modifiers 1,576
    20 16x16x1 4 24 10,240 cmp, cmpx, lds - direct image opcode or descriptor modifiers 1,576
    21 16x16x1 4 16 4,096 cmp, lds - direct image opcode or descriptor modifiers 1,576
    22 16x16x1 4 24 512 cmp, lds - unbound numeric SGPR sN 1,576
    23 16x16x1 4 24 2,048 cmp, cmpx, lds - lowers 1,576
    24 16x16x1 4 24 0 cmp, cmpx - unbound numeric SGPR sN 1,576
    25 256x1x1 4 8 0 cmpx - unsupported wave64 scalar operation 1,576
    26 16x16x1 4 64 8,192 cmp, lds - lowers 1,576
    27 16x16x1 4 24 10,240 cmp, lds - packed image addressing 1,576
    28 256x1x1 4 24 512 lds, dpp - invalid s_ff1_i32_b64 source 1,546
    29 16x16x1 4 64 0 cmp, cmpx, rfl - direct descriptor address outside bound table 1,115
    30 8x16x1 2 56 0 cmp, cmpx, rfl - invalid s_ff1_i32_b64 source 1,115
    31 16x16x1 4 64 0 cmp, cmpx, rfl - direct descriptor address outside bound table 1,115
    32 16x16x1 4 64 0 cmp, cmpx, rfl - direct descriptor address outside bound table 1,115
    33 16x16x1 4 48 0 cmp, cmpx - direct descriptor address outside bound table 1,115
    34 16x16x1 4 64 0 cmp, cmpx, rfl, rl, wl - direct descriptor address outside bound table 1,115
    35 16x16x1 4 48 0 cmp, cmpx, rfl - invalid s_ff1_i32_b64 source 1,115
    36 8x16x1 2 56 0 cmp, cmpx - direct descriptor address outside bound table 1,115
    37 1024x1x1 16 40 3,584 cmp, cmpx, lds, rfl, bar EXECZ invalid s_ff1_i32_b64 source 1,115
    38 16x16x1 4 64 0 cmp, cmpx, rfl - invalid s_ff1_i32_b64 source 1,115
    39 16x16x1 4 64 0 cmp, cmpx, rfl - invalid s_ff1_i32_b64 source 1,115
    40 16x16x1 4 64 0 cmp, cmpx, rfl - direct descriptor address outside bound table 1,115
    41 16x16x1 4 24 512 cmp, cmpx, lds, rfl, rl, dpp, plx16 - lowers 1,115
    42 1024x1x1 16 48 3,584 cmp, cmpx, lds, rfl, bar EXECZ invalid s_ff1_i32_b64 source 1,115
    43 16x16x1 4 32 4,096 cmp, lds - lowers 43
    44 16x16x1 4 24 0 cmp - lowers 40
    45 16x16x1 4 16 4,096 lds - unbound numeric SGPR sN 32
    46 256x1x1 4 16 0 none - lowers 24
    47 1024x1x1 16 64 32,768 cmp, cmpx, lds, rfl - direct descriptor address outside bound table 10
    48 16x16x1 4 32 0 cmp, carry - lowers 8
    49 16x16x1 4 16 512 cmp, lds, append - unbound numeric SGPR sN 8
    50 16x16x1 4 24 0 cmp, cmpx - lowers 8
    51 16x16x1 4 32 3,072 cmp, lds - unsupported typed 2D image atomic operands 8
    52 16x16x1 4 8 512 lds - lowers 5
    53 16x16x1 4 16 2,048 cmp, lds - lowers 4
    54 16x16x1 4 16 2,048 cmp, lds - lowers 4
    55 16x16x1 4 40 1,536 cmp, cmpx, lds - lowers 4

    AI-assisted.

  3. Not-Saii commented on Nov 28, 2026

    @Not-Saii
    ContributorAuthor

    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:

    • masks, v_cmpx, lane reads, v_readfirstlane, LDS, DPP and v_permlanex16;
    • a measurement of the early-exit-before-barrier shape, which the proposal doesn't cover yet.

    None of the 55 captured programs is expected to compile after stage 2. That is stage 3.

    Scope of the prototype emitter

    • When it applies: only to wave64 requests with more than 64 threads that the "converged group control flow" gate refuses today. Converged programs keep exchange_halves.
    • Refusals: any vector instruction the prototype doesn't lower in lane-pair form is refused with its own reason ("lane-pair layout: unsupported <name>"). Programs it can't handle stay refused rather than translated wrongly, and a census rerun shows coverage directly.
    • Layout:
      • Host numthreads is guest threads / 2.
      • Each guest VGPR becomes two allocas, the low set (guest lane j) and the high set (lane j + 32). SGPRs stay single, since one host wave is one guest wave.
      • s126/s127 (EXEC) and s106/s107 (VCC) map directly onto the two sets: set h is active when bit lane of word 126 + h is set.
    • Instruction mapping:
      • VOPC / carry-out: word h = WaveActiveBallot(active(h) && cond(h)).x, written to dst + h. No groupshared memory and no barrier.
      • v_cmpx: writes EXEC the same way.
      • v_readlane with constant lane k: WaveReadLaneAt(set[k >= 32], k & 31).
      • v_readfirstlane: read the low set at firstbitlow(exec_lo) when exec_lo != 0, otherwise the high set at firstbitlow(exec_hi).
      • DPP (quad_perm, row shifts, mirrors) and v_permlanex16: the existing wave32 lowering, once per set. Every census shape stays inside one 32-lane set.
      • LDS: each instruction issues the low-set access, then the high-set access, under each set's own predicate, with no barrier between the halves.
      • s_barrier: GroupMemoryBarrierWithGroupSync, as today.
    • Thread IDs: guest v0..v2 come from logical = wave * 64 + 32 * h + lane. The guest wave index comes from the same rank as initialize's @waveStarts. A rank that doesn't use LDS (needed by the census program at 32 KB) is left for later.

    Fixtures. Source-built .c67 requests encoded as instruction words, like tests/native_slot67_wave_size_check.py.

    • Each uses wave64 (.sa wave32 bit clear), 128 threads, two guest waves, and the tg_size entry SGPR.
    • Each is written by write_request and compiled with compile_dxil ... gfx1013-direct-cs@0 --requests.
    • Each is dispatched with native_store_replay ... --direct (hardware) and --direct-warp (WARP), two groups.
    • Expected words come from a small Python model of each program. Every output buffer has guard words and a sentinel fill.
    Fixture Shape What the output checks
    F1 mask_readlane SCC branch on the tg_size wave field: only guest wave 1 runs a v_cmp on v0 writing an SGPR pair, then v_readlane of lane 40 Both mask words and the lane-40 value in every lane of wave 1; wave 0's output keeps the sentinel
    F2 readfirstlane_high EXECZ region where wave 1's exec_lo is 0 (lanes 32–63 only), then v_readfirstlane The value from guest lane 32 of wave 1; wave 0 skips
    F3 lds_divergent Inside a branch only wave 1 takes: ds_write_b32 / ds_read_b32 across lanes j and j + 32; then a group-uniform s_barrier and a cross-wave LDS read In-branch exchange between the two sets, then wave 0 reads wave 1's words after the barrier
    F4 dpp_permlane_divergent Inside the wave-1 branch: row_shr:1, row_mirror and v_permlanex16 on a lane-ID value The CPU model's per-lane results for both sets
    F5 exit_before_barrier (measurement) Wave 0 reaches s_endpgm through an EXECZ skip; waves 1 and later write LDS, s_barrier, then read a neighbour's word Not a pass/fail fixture at first. It records what hardware and WARP do when one host wave returns before a group barrier

    F5 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_endpgm as return, so the result can be measured.

    Negative controls

    • On main: F1–F5 are refused with "multi-wave64 exchange requires converged group control flow". This runs in a _controls test with no GPU.
    • Lane-set swap: the model's expected output with the two sets swapped must mismatch the readback, for F1, F2 and F4. This is an expectation mutant, so the emitter needs no test hook.
    • Program mutants: F1 with the v_readlane lane changed from 40 to 8, and F2 with exec_lo non-zero, must both mismatch their unmodified expectations. That shows the high set is really read.
    • Outside the prototype: a converged wave64 fixture (the existing split-wave64 / two-wave64 cases) still compiles through exchange_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 with OFFSCREEN_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.
    • F5 is reported separately and stays out of the pass criteria until a design for it is agreed.

    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

    1. Is the scope right, with the layout only for programs the gate refuses today and exchange_halves kept for converged ones?
    2. The early-exit shape covers 10 of the 55 and 70% of their dispatches. Options:
      • (a) a host return followed by GroupMemoryBarrierWithGroupSync in the remaining waves. This depends on driver behaviour that D3D12 doesn't, as far as I know, specify, so F5 would only measure it.
      • (b) a groupshared count of running waves with a counted barrier, which has no forward-progress guarantee.
      • (c) keeping these refused.
        Which is acceptable, if any?
    3. Should stage 2 land as a PR (fixture plus prototype mode behind a refusal), or stay a branch with posted results until the design is agreed?

    AI-assisted.

  4. tedin7 commented on Nov 28, 2026

    @tedin7
    Collaborator

    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:

    1. Thread-to-lane mapping is not guaranteed. D3D12 doesn't promise that host wave w holds SV_GroupIndex 32w .. 32w+31, or that WaveGetLaneIndex() == SV_GroupIndex % 32. The whole scheme (guest lane numbering, v0/v1/v2, ballot bit order) depends on it. I'd derive the guest lane from WaveGetLaneIndex() and the guest wave from something wave-uniform, and add a cheap check (WaveActiveAllTrue that 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/3D numthreads such as 4×64×1 and 8×8×8 from the census).

    2. 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.

    3. Keep host lanes converged around every wave op. WaveActiveBallot, WaveReadLaneAt and WaveReadLaneFirst must 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 HLSL if around 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.

    4. Early exit before a barrier (your 10 programs, 70% of the dispatches). A guest wave that hits s_endpgm must not leave the host group while others still call GroupMemoryBarrierWithGroupSync. The usual fix is a per-wave exited flag: 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.

    5. v_readfirstlane with EXEC == 0 returns lane 0 on RDNA. The plan's "low set at firstbitlow(exec_lo), else high set" needs that third case.

    6. 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).

    7. VOPC/v_cmpx write the whole mask. Bits of inactive lanes become 0, not "unchanged"; the ballot of active(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.

  5. Not-Saii commented on Nov 28, 2026

    @Not-Saii
    ContributorAuthor

    @tedin7 thanks for the review. I built the stage 2 prototype and ran it. Results first, then your seven points.

    Build under test. main fdb6faaa plus 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. Host numthreads is (guest threads / 2, 1, 1), and the module declares WaveSize(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 reaches s_endpgm without passing an s_barrier, the program gets one barrier site in a loop. A wave runs to its next s_barrier or to s_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 a return. Programs whose barriers no wave can skip keep the plain barrier. An s_barrier inside a guest loop is refused for now.

    Fixture. tests/native_wave64_lane_pairs_check.py, registered as native_wave64_lane_pairs_controls (no GPU) and native_wave64_lane_pairs_hardware. Both pass. Each program is compared with a small CPU model over all 2,064 output words, guards included.

    Program Group What it checks
    mask_readlane 128×1×1 only the last guest wave runs a compare into an SGPR pair, then v_readlane of lane 40
    readfirstlane_high 128×1×1 v_cmpx leaves lanes 32–63 of the last wave, EXECZ skip, v_readfirstlane; a compare that is true for every lane then gives low word 0
    lds_divergent 128×1×1 in-branch ds_write and ds_read across lanes j and 63−j, then an unconditional s_barrier and a cross-wave read
    dpp_permlane_divergent 128×1×1 row_shr:1, row_mirror and v_permlanex16 inside the branch
    group_shape_2d, group_shape_3d 8×16×1, 4×4×8 v0, v1, v2, stored at an address computed from those ids
    readfirstlane_empty 128×1×1 v_readfirstlane with EXEC set to 0 returns lane 0
    lds_same_address 128×1×1 lanes j and j+32 write one LDS word in one instruction
    exit_before_barrier 256×1×1 wave 0 leaves through an EXECZ skip; waves 1–3 write LDS, meet and read wave 3's words
    • The first eight also run with 64 threads under both layouts (8×8×1 and 4×4×4 for the two shape programs). Both layouts match the model there, except for the two cases under points 5 and 6.
    • With the layout forced to split halves, all nine multi-wave programs are refused with "multi-wave64 exchange requires converged group control flow". An unmodified compiler built at 2d6dad19 refuses the same requests.
    • 14 negative controls each report a mismatch. Three of them: the model with the two 32-lane sets exchanged (mask_readlane: word 264, got 0xffffffff, expected 0x00001fff), v_readlane of lane 8 checked against the lane-40 expectation, and the model in which wave 0 had not left (exit_before_barrier: word 8, got the 0x69696969 fill).
    • Requests that do not take the new layout compile to the same bytes as before: 30 of 30 modules (wave32 and converged wave64, 64 to 256 threads) are identical to the unmodified compiler's output (compared at 2d6dad19).
    ctest --preset dev --no-tests=error -R '^native_wave64_lane_pairs_' -V

    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 2d6dad19 were within 7% of these numbers. Outputs are identical between the layouts in every row.

    Program Guest threads per group Split halves (ms) Lane pairs (ms) Pairs ÷ split
    compare into VCC, v_cndmask, LDS write and read, v_readfirstlane every round (441 instructions) 64 7.88 3.27 0.42
    128 12.07 3.72 0.31
    256 26.36 8.77 0.33
    ALU only (296 instructions) 64 0.87 1.62 1.87
    128 2.57 1.62 0.63
    256 7.05 4.06 0.58
    62 live VGPRs (625 instructions) 64 2.86 3.02 1.06
    128 4.43 4.05 0.91
    256 10.94 8.52 0.78
    • This matrix comes from a local script that is not in the branch. The fixture's timing mode 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).
    • Pipeline creation on modules the driver had not seen, median of 5: 92.8 → 119.6 ms, 34.3 → 57.1 ms and 84.7 → 189.0 ms for the three programs. Modules are 1.5 to 2 times larger.
    • The 62-VGPR program holds 124 vector registers per host thread under lane pairs. That cost at most 6%.
    • The ALU-only loss at 64 threads is a group-size effect on this GPU, not the paired code. The same wave32 program with the same thread total takes 1.48 ms in 32-thread groups and 0.43 ms in 64-thread groups. I have not found out why.
    • The ALU-only gains at 128 and 256 threads are not cleanly the layout either: split's cost per thread rises with group size there (0.013, 0.019 and 0.026 ns).

    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.

    1. Mapping. The emitter already takes the guest lane from WaveGetLaneIndex() and the guest wave from a wave-uniform rank (WaveActiveMin of the flat thread id), not from SV_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.
    2. WaveSize(32) is declared. I checked it in the module dump.
    3. Host branches depend only on wave-uniform values, and per-lane predication is select(active, new, old). The only per-lane host branches wrap memory side effects, and the wave operations sit outside them.
    4. This is the barrier loop above and exit_before_barrier.
    5. Implemented with the third case, and readfirstlane_empty passes. It also showed that split halves on main return lane 32 here (64 threads: got 0x2005, expected 0x5), so that one assertion is skipped under split. It is a separate bug and is not fixed in this change.
    6. lds_same_address locks 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.
    7. Folded into readfirstlane_high, with a negative control that expects the low word unchanged.

    Not done.

    • WARP 1.0.22: the fixture has no --direct-warp mode yet. No other adapter, no debug layer, no dispatch through the stand-in.
    • The census rerun over the 55 programs.
    • Lane pairs with buffer loads, atomics or image operations, and a barrier loop with more than one barrier.
    • exit_before_barrier shows that the loop works on this driver. It does not show that a plain return would 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.

  6. Leyukaka commented on Nov 28, 2026

    @Leyukaka
    Collaborator

    Review of the lane-pair design and the stage 2 results, from the code on main 052abe6f and the HLSL docs.

    Early exit before a barrier. Microsoft's GroupMemoryBarrierWithGroupSync page: "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.inl 1163). "Low set, then high set" orders lanes j and j + 32 of one thread only. Lane j of one thread against lane k + 32 of another, or against another thread's low set, is a groupshared race with no barrier between them. lds_same_address checks only the same-thread case.

    DPP and permlane on WARP. These lowerings pass a per-lane index to WaveReadLaneAt (inl 4080 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 of dpp_permlane_divergent needs 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_cmpx and carry-out: 5, 44, 48 and 50.

    A first PR that would be provable now:

    • lane pairs for VOPC, v_cmpx, carry-out, v_readlane with a constant lane, and v_readfirstlane;
    • LDS, s_barrier, DPP/permlane, ds_append and atomics refused with their own reason;
    • scalar results written after both lane sets have read their operands.

    Existing bug on main. With guest EXEC 0, the split v_readfirstlane (inl 3196-3200) selects candidates[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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions