[PR #1381] 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) #1410

Open
opened 2026-11-26 20:21:10 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1381
Author: @milk4sale
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: test/w64-emulate-wave-reduce


📝 Commits (1)

  • aad0d61 tests: wave reductions and lane-spilled masks under --wave64-emulate (TEST-W64-EMU-WAVE-REDUCE)

📊 Changes

2 files changed (+309 additions, -0 deletions)

View changed files

📝 tests/semantic/test_wave64_emulate_opt.py (+22 -0)
➕ tests/semantic/test_wave64_emulate_wave_reduce.py (+287 -0)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1381 **Author:** [@milk4sale](https://github.com/milk4sale) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `test/w64-emulate-wave-reduce` --- ### 📝 Commits (1) - [`aad0d61`](https://github.com/ubiquitarianism/leonida/commit/aad0d61b15750867de9fc7ecefee25bcf1d5302d) tests: wave reductions and lane-spilled masks under --wave64-emulate (TEST-W64-EMU-WAVE-REDUCE) ### 📊 Changes **2 files changed** (+309 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `tests/semantic/test_wave64_emulate_opt.py` (+22 -0) ➕ `tests/semantic/test_wave64_emulate_wave_reduce.py` (+287 -0) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1410
No description provided.