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

Merged
milk4sale merged 1 commit from upstream-pr/1381 into main 2026-11-28 11:52:31 +00:00
milk4sale commented 2026-11-24 22:57:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by milk4sale on 2026-11-24T22:57:14Z.


Claimed in the coordination issue as: TEST-W64-EMU-WAVE-REDUCE (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7146823788)

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

  • python -I tests/semantic/test_wave64_emulate_wave_reduce.py: 5 tests pass (Python 3.14, Linux), on main 28a32e190 plus this commit.
  • Without the interpreter change, the reduction test stops at NotImplementedError: unsupported op OpAtomicUMin in the emulated run.
  • Four planted translator faults, one at a time; each fails the new file and it passes again when the fault is removed:
    • LDS atomics no longer counted as writes in x_memory_order (and its mirror in wave64_emulate_opt.py), so no order barrier before a later LDS read: 14 subtests fail, in the reduction test and the atomics test;
    • v_readlane_b32 selecting lane & 31 in a wave64: 20 subtests of the reduction test fail;
    • v_permlanex16_b32 reading its own row half: 20 subtests of the reduction test fail;
    • a parked mask reloaded by a lane shuffle instead of from its slot: 10 subtests of the mask test fail.
  • python -I scripts/run_semantic_tests.py tests/semantic: 475 files, 6,199 tests, 0 files failed.
  • Against open work on the same ground: the interpreter change applies on the heads of the five open pull requests that edit test_wave64_emulate_opt.py (#1110 and #850 with a line offset, #1272, #793 and #106 without), and the five new tests also pass on the head of #1043 (68b964e42), which changes how a lane mask is read as a number.
  • python -m compileall -q make_game.py tools tests, python -I make_game.py --help, python -I scripts/check_no_game_data.py on both files, python -I tests/test_text_write_line_endings.py, git diff --check.
  • python -I tests/test_ci_registration.py fails here as it does on main without this commit, on tests/semantic/test_sub_co_same_operand.py (#1365 has the fix). translator-tests is red on main for another reason that #1375 addresses. Neither comes from this change.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5481732261 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1381). Originally posted by [milk4sale](https://github.com/milk4sale) on 2026-11-24T22:57:14Z. --- Claimed in the coordination issue as: TEST-W64-EMU-WAVE-REDUCE (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7146823788) ### 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 - `python -I tests/semantic/test_wave64_emulate_wave_reduce.py`: 5 tests pass (Python 3.14, Linux), on `main` `28a32e190` plus this commit. - Without the interpreter change, the reduction test stops at `NotImplementedError: unsupported op OpAtomicUMin` in the emulated run. - Four planted translator faults, one at a time; each fails the new file and it passes again when the fault is removed: - LDS atomics no longer counted as writes in `x_memory_order` (and its mirror in `wave64_emulate_opt.py`), so no order barrier before a later LDS read: 14 subtests fail, in the reduction test and the atomics test; - `v_readlane_b32` selecting lane & 31 in a wave64: 20 subtests of the reduction test fail; - `v_permlanex16_b32` reading its own row half: 20 subtests of the reduction test fail; - a parked mask reloaded by a lane shuffle instead of from its slot: 10 subtests of the mask test fail. - `python -I scripts/run_semantic_tests.py tests/semantic`: 475 files, 6,199 tests, 0 files failed. - Against open work on the same ground: the interpreter change applies on the heads of the five open pull requests that edit `test_wave64_emulate_opt.py` (#1110 and #850 with a line offset, #1272, #793 and #106 without), and the five new tests also pass on the head of #1043 (`68b964e42`), which changes how a lane mask is read as a number. - `python -m compileall -q make_game.py tools tests`, `python -I make_game.py --help`, `python -I scripts/check_no_game_data.py` on both files, `python -I tests/test_text_write_line_endings.py`, `git diff --check`. - `python -I tests/test_ci_registration.py` fails here as it does on `main` without this commit, on `tests/semantic/test_sub_co_same_operand.py` (#1365 has the fix). `translator-tests` is red on `main` for another reason that #1375 addresses. Neither comes from this change. 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] 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](https://claude.com/claude-code)
PierreEbele commented 2026-11-25 15:14:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T15:14:55Z.


Reviewed aad0d61b1: 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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7166538403 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1381#issuecomment-7166538403). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T15:14:55Z. --- Reviewed aad0d61b1: 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
sodove commented 2026-11-28 10:44:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:44:13Z.


#1381 | head aad0d61b15750867de9fc7ecefee25bcf1d5302d | python3 -m unittest discover -s tests/semantic -p test_wave64_emulate_opt.py -v, python3 -m unittest discover -s tests/semantic -p test_wave64_emulate_wave_reduce.py -v | red: 36 run, 1 failure, 45 errors | green: 39 passed | Red → green

Clean main raised NotImplementedError for OpAtomicStore in the CPU wave interpreter. With main merged into the PR, the wave reduction, emulated atomics and spilled mask cases ran to completion.

Captured 50 distinct complete SPIR-V module(s) emitted while rerunning test_wave64_emulate_wave_reduce.py on the merged tree. All assembled and passed spirv-val for Vulkan 1.2 with --allow-offset-texture-operand.

Test file Main + PR tests PR + main
tests/semantic/test_wave64_emulate_opt.py 31 run, 1 failure, 42 errors 34 passed
tests/semantic/test_wave64_emulate_wave_reduce.py 5 run, 3 errors 5 passed

Base 3bd936ecd98995bca3e1da83d5e28d2343001aef was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238088639 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1381#issuecomment-7238088639). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T10:44:13Z. --- #1381 | head `aad0d61b15750867de9fc7ecefee25bcf1d5302d` | `python3 -m unittest discover -s tests/semantic -p test_wave64_emulate_opt.py -v`, `python3 -m unittest discover -s tests/semantic -p test_wave64_emulate_wave_reduce.py -v` | red: 36 run, 1 failure, 45 errors | green: 39 passed | **Red → green** Clean main raised NotImplementedError for OpAtomicStore in the CPU wave interpreter. With main merged into the PR, the wave reduction, emulated atomics and spilled mask cases ran to completion. Captured 50 distinct complete SPIR-V module(s) emitted while rerunning test_wave64_emulate_wave_reduce.py on the merged tree. All assembled and passed spirv-val for Vulkan 1.2 with --allow-offset-texture-operand. | Test file | Main + PR tests | PR + main | |---|---|---| | `tests/semantic/test_wave64_emulate_opt.py` | 31 run, 1 failure, 42 errors | 34 passed | | `tests/semantic/test_wave64_emulate_wave_reduce.py` | 5 run, 3 errors | 5 passed | Base `3bd936ecd98995bca3e1da83d5e28d2343001aef` was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7237873883).
DadaCap commented 2026-11-28 11:52:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T11:52:32Z.


Merged, thank you @milk4sale! This translator PR (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)) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238840102 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1381#issuecomment-7238840102). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:52:32Z. --- Merged, thank you @milk4sale! This translator PR (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)) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1381
No description provided.