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
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1381"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_workgroupintests/semantic/test_wave64_emulate_opt.pyis the CPU model that runs--wave64-emulateoutput on all 64 lanes of a workgroup. It executed only the OR, add, AND, XOR and exchange atomics. A wave64 program withds_min_u32stopped atNotImplementedError: 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 runsOpAtomicUMin,UMax,SMin,SMaxandISub. 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:s_or_saveexec_b64 ..., -1, lanes that were off get the identity throughv_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_b32joins the two rows of each half,v_readlane_b32of lane 0 is folded into every lane andv_readlane_b32of 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 execors_and_saveexec_b64) and that lane doesds_or_b32for an OR andds_min_u32for an unsigned MIN. A counter raised byds_add_u32beside 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.v_writelane_b32of each half of the pair, the SGPRs reused for another mask and for numbers,v_readlane_b32back, thens_mov_b64 execandv_cndmask_b32on the reloaded pair. Six cases.ds_min_u32,ds_max_u32,ds_min_i32,ds_max_i32andds_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 byspirv_mini_interp.run_workgroupas one 64-wide subgroup, emulated byrun_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), onmain28a32e190plus this commit.NotImplementedError: unsupported op OpAtomicUMinin the emulated run.x_memory_order(and its mirror inwave64_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_b32selecting lane & 31 in a wave64: 20 subtests of the reduction test fail;v_permlanex16_b32reading its own row half: 20 subtests of the reduction test fail;python -I scripts/run_semantic_tests.py tests/semantic: 475 files, 6,199 tests, 0 files failed.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.pyon both files,python -I tests/test_text_write_line_endings.py,git diff --check.python -I tests/test_ci_registration.pyfails here as it does onmainwithout this commit, ontests/semantic/test_sub_co_same_operand.py(#1365 has the fix).translator-testsis red onmainfor 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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (No translator change.)🤖 Generated with Claude Code
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, returningglc/_rtn_forms): native, emulated and a plain-Python reference agree in every lane on the PR, and every emulated run stops atNotImplementedError: OpAtomicUMinon 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
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 → greenClean 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.
tests/semantic/test_wave64_emulate_opt.pytests/semantic/test_wave64_emulate_wave_reduce.pyBase
3bd936ecd98995bca3e1da83d5e28d2343001aefwas 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.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.