Skip to content

feat(shader): pass 16-bit wave64 sums between 32-lane halves - #425

Merged
pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
earpjonathan:shader/reduce-addh-wave64
Nov 27, 2026
Merged

pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
earpjonathan:shader/reduce-addh-wave64

Conversation

@earpjonathan

Copy link
Copy Markdown
Contributor

In halves (#180), a console wave64 runs as two host waves of 32 lanes. Its 16-bit float sums were still refused there with "a 16-bit wave reduction over both 32-lane halves". This PR passes them between the halves, as #360 did for the other reductions.

Changes

  • Shape::Half in halves, where every lane of the group runs the section together (across_here):
    • each host wave sums its own 32 lanes in f32, as before;
    • the two totals pass between the halves through reduce_across (Op::AddH is added there, with 0 for a missing upper half);
    • the sum is rounded to f16 once, as the single-wave lowering does.
  • The high 16 bits are kept from console lane hi. That lane's ballot bit and value are now read across the halves (ballot_across_halves, read_lane_across), because on the upper host wave lane hi belongs to the other half.
  • Elsewhere (a section not every lane runs together) it is refused as before, with the same reason as the other reductions.

Tests (halves_tests.rs)

  • half_reduction is a console wave64 f16 sum of the thread id, built the way the compiler emits it: DPP within rows, v_permlanex16_b32 across rows, then lanes 31 and 63 read and added.
  • reductions_and_prefixes_pass_between_halves checks three things:
    • the wave analysis recognizes the fixture as a whole-wave sum;
    • it translates in groups of 32, 64, 96 and 128;
    • halves declares 32-lane waves.
    • On main this test fails with the old refusal.
  • reductions_and_prefixes_across_halves_match_the_console_on_every_gpu runs the sum on every hardware adapter and compares each lane with the console's result, in groups of 32, 64, 96 (no upper half in the second console wave) and 128.
    • The inputs are f16 subnormals whose bit pattern is the lane number.
    • The partial sums are exact in f16, so per-step f16 rounding and the translator's f32 accumulation agree.
  • Under Wine (CrossOver 26.3's wine; Wine's d3d12 adapter has 32-lane waves, so halves ran), victory-shader: 374 passed, 0 failed, 5 ignored.
  • cargo test -p xtask natively, where the asset policy runs: 7 passed, "asset policy: 262 files ok".
  • cargo clippy --workspace --all-targets -- -D warnings, with and without --all-features, for x86_64-pc-windows-gnullvm.

None of this ran in the game.

🤖 Generated with Claude Code, with Codex

A console wave64's f16 sum (`v_add_f16` reduced in each 32-lane half,
then lanes 31 and 63 added) was refused on 32-lane hosts. In halves each
host wave now sums its own lanes in f32, the two totals pass between the
halves through `reduce_across`, and the result is rounded to f16 once, as
the single-wave lowering does. The high half kept from lane `hi` is read
across the halves too.

Prepared with Codex

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@evan-kolberg

Copy link
Copy Markdown
Contributor

Independent M4 Pro / D3DMetal 4.0 beta 3 check of high-half provenance and the #3342 composition. I extended earpjonathan’s exact #425 fixture by storing each thread index in the high half of its input, with the original FP16 bits in the low half.

  • Exact feat(shader): pass 16-bit wave64 sums between 32-lane halves #425: the copy after EXEC restore returned all 320/320 packed words across 32-, 64-, 96-, and 128-thread groups. The partial second Wave64 at 96 threads returned 0x005f08f8, including lane 95’s tag.
  • With draggygaggy-maker’s #3342 classifier: the copy before restore went from a translation refusal at all four sizes to 320/320 exact words. Both copy orders emitted byte-identical DXIL at every size. This extends the earlier Wave32 readback to console Wave64 split across physical Wave32 waves.

Prepared and tested with Codex.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants