Skip to content

tests: wave reductions and lane-spilled masks under --wave64-emulate, and the emulated CPU model runs the LDS min/max/sub atomics (TEST-W64-EMU-WAVE-REDUCE) - #1381

Open
milk4sale wants to merge 1 commit into
ProjectLeonida:mainfrom
milk4sale:test/w64-emulate-wave-reduce
Open

milk4sale wants to merge 1 commit into
ProjectLeonida:mainfrom
milk4sale:test/w64-emulate-wave-reduce

Conversation

@milk4sale

@milk4sale milk4sale commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: TEST-W64-EMU-WAVE-REDUCE (#14 (comment))

What and why

run_emulated_workgroup in tests/semantic/test_wave64_emulate_opt.py is the CPU model that runs --wave64-emulate output on all 64 lanes of a workgroup. It executed only the OR, add, AND, XOR and exchange atomics. A wave64 program with ds_min_u32 stopped at NotImplementedError: unsupported op OpAtomicUMin, so nothing that uses the LDS min, max or subtract instructions could be checked under emulation on the CPU. It now also runs OpAtomicUMin, UMax, SMin, SMax and ISub. The new branch sits below the existing one, so it does not touch the lines that the open pull requests on this function change (#1110 and #850).

tests/semantic/test_wave64_emulate_wave_reduce.py (new, hand-written, made-up values) uses it for two sequences a compiler emits for a wave64, which under emulation only come out right when the two 32-lane halves agree on every scalar:

  • A reduction over the wave that one lane commits to LDS. EXEC is widened with s_or_saveexec_b64 ..., -1, lanes that were off get the identity through v_cndmask_b32, four DPP steps reduce each 16-lane row (quad_perm [1,0,3,2] and [2,3,0,1], row_half_mirror, row_mirror), v_permlanex16_b32 joins the two rows of each half, v_readlane_b32 of lane 0 is folded into every lane and v_readlane_b32 of lane 63 is then the wave's result. EXEC is narrowed to the first lane that was on (s_ff1_i32_b64, s_lshl_b64 ..., 1, sN, s_and_b64 exec or s_and_saveexec_b64) and that lane does ds_or_b32 for an OR and ds_min_u32 for an unsigned MIN. A counter raised by ds_add_u32 beside each commit shows that exactly one lane ran it, which an idempotent OR or MIN would hide. Seven EXEC ranges: both halves, the whole wave, each half alone, one lane in the high half, lane 0 alone, and the two lanes either side of the half boundary.
  • A 64-bit lane mask kept in two lanes of a VGPR (an SGPR spill): v_writelane_b32 of each half of the pair, the SGPRs reused for another mask and for numbers, v_readlane_b32 back, then s_mov_b64 exec and v_cndmask_b32 on the reloaded pair. Six cases.
  • The five LDS atomics behind the new opcodes, ds_min_u32, ds_max_u32, ds_min_i32, ds_max_i32 and ds_sub_u32, from all 64 lanes of one wave, with lane values that tell signed from unsigned.

Each program is translated twice, without and with --wave64-emulate, and run on 64 lanes: natively by spirv_mini_interp.run_workgroup as one 64-wide subgroup, emulated by run_emulated_workgroup. Both must give every lane the words of a plain-Python reference.

The translator turns out to be right for both sequences and for the five atomics, natively and emulated: this pull request is coverage, not a fix.

Tested

Not run: Python 3.12 (the version CI installs), Windows and macOS. No GPU run: the programs run in the two CPU interpreters only, and no GPU fixture is added.

GPUs tested: n/a (two Python test files; no shader, fixture or runtime code)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

🤖 Generated with Claude Code

…(TEST-W64-EMU-WAVE-REDUCE)

run_emulated_workgroup, the CPU model that runs --wave64-emulate output on
all 64 lanes, executed only the OR, add, AND, XOR and exchange atomics: a
program with ds_min_u32 stopped at "unsupported op OpAtomicUMin". It now
runs OpAtomicUMin, UMax, SMin, SMax and ISub, in a branch of its own below
the existing one.

tests/semantic/test_wave64_emulate_wave_reduce.py uses it for two sequences
a compiler emits for a wave64 and that need both 32-lane halves to agree:

- a reduction over the wave (EXEC widened, the identity for lanes that were
  off, four DPP steps per 16-lane row, v_permlanex16_b32, v_readlane_b32 of
  lanes 0 and 63) that the first active lane alone commits with ds_or_b32 or
  ds_min_u32; a ds_add_u32 counter shows exactly one lane ran each commit
- a 64-bit lane mask kept in two lanes of a VGPR with v_writelane_b32 and
  read back with v_readlane_b32 after its SGPRs were reused
- ds_min_u32, ds_max_u32, ds_min_i32, ds_max_i32 and ds_sub_u32 from all 64
  lanes of one wave

Each program is translated without and with --wave64-emulate and run on 64
lanes, natively and emulated; both must match a plain-Python reference in
every lane. The translator is right for all of it: this is coverage.

Four planted translator faults each fail the new file and pass again when
removed: LDS atomics not ordered before a later LDS read, v_readlane_b32
selecting lane & 31 in a wave64, v_permlanex16_b32 reading its own row
half, a parked mask reloaded by a lane shuffle. Without the interpreter
change the reduction test stops at the NotImplementedError above.
scripts/run_semantic_tests.py tests/semantic: 475 files, 6199 tests, 0
files failed.

AI-assisted. No game files.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@PierreEbele

Copy link
Copy Markdown
Contributor

Reviewed aad0d61: coverage-only change (emulated interpreter + new wave64-emulate semantic test). Ran the new file, test_wave64_emulate_opt.py, and the full semantic suite on the PR tree (475 files, 6199 tests, 0 failed), and a probe of the paths the new test leaves out (buffer_atomic_* from a raw buffer, returning glc/_rtn_ forms): native, emulated and a plain-Python reference agree in every lane on the PR, and every emulated run stops at NotImplementedError: OpAtomicUMin on main, so the test exercises the fix. A planted fault in the new interpreter branch fails the new test. No findings; a rebase over current main would be tidy (clean auto-merge, verified).

AI-assisted review.

Recommendation: Merge

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.

2 participants