wave_diff: validate cross-lane/mask operands, EXEC=0 dsts, DS offsets, and immutability (WAVE-DIFF-REF-VALIDATION) #1809
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!1809
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/wave-diff-ref-validation"
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?
Pull request successfully merged and closed
Summary
Claimed in #1608 as
WAVE-DIFF-REF-VALIDATION: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162135689Hardens
tools/wave_diff.py(WaveRef) so malformed or unsupported cross-lane and whole-mask operands raisecf_ref.Unsupportedinstead of silently reading the low register, flipping sign bits, skipping destination validation underEXEC == 0, raising unhandledValueError, or mutating the caller's parsed instruction dicts:abs/negmodifiers:_vsrc()requires a single VGPR (n == 1) with noabs/negmodifiers acrossv_readlane_b32,v_readfirstlane_b32,ds_bpermute_b32, andv_permlane16/x16_b32._scalar_int_src(),_lane_sel(),_count_src(), ands_not_b32/b64rejectabs/negmodifiers and unexpected instruction modifiers.EXEC == 0or referenced source lanes are off:_check_vgpr_dst()upfront inv_writelane_b32,ds_bpermute_b32, andv_permlane16/x16_b32so invalid destinations (s6,v[2:3]) cannot slip through when no lanes write.ds_bpermute_b32offset:modifiers:offset:modifiers, non-integer values (raisescf_ref.Unsupportedinstead ofValueError), and values outside the 16-bit unsigned DS offset range (0..65535).info["insns"]inWaveRef.__init__:enc/pcinstead of mutating caller-owned dicts in place.Independent of
#1780(tools/cf_ref.py); zero PR dependencies.Testing
Environment: Windows 11 x64, Python 3.12.10, CPU-only (no GPU or game files; based on
0d80bc5).main(0d80bc5):python -m unittest tests.test_wave_diff.Reference->FAILED (failures=24, errors=1)python -I tests/test_wave_diff.py-> 16/16 OK (including canaries and seeded wave32/wave64 fuzz runs)python -m compileall -q tools/wave_diff.py tests/test_wave_diff.py-> exit 0python -I scripts/check_no_game_data.py tools/wave_diff.py tests/test_wave_diff.py-> exit 0git diff --check-> cleanAI-assisted: yes (Antigravity). Synthetic inputs only; no game data.
Tested
30e5b8b93on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), againstmain98c2f7777(Python CPU reference; no GPU):tests/test_wave_diff.py: 16 passed, 25 subtests passed at this head.main: 25 failed, 15 passed — the cross-lane/mask operand, EXEC=0 destination, DS-offset and immutability validation is not there.wave_diffis the reference side.AI-assisted; synthetic fixtures only, no game data.
Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.
python -m pytest -q tests/test_wave_diff.py:(AI-assisted test run; output checked by hand.)
Tested
30e5b8b93merged (no commit) withmainaa918e5d9: Python 3.12.4, Windows 11 10.0.26300, CPU only.check_no_game_data.pyis clean.Blocker: it breaks once merged with current
main. On its own head,tests/test_wave_diff.pypasses (16 tests). Merged withmain, it gives 35 errors and 1 failure:TypeError: WaveRef._check_vgpr_dst() missing 1 required positional argument: 'dst'.Cause: since this branch,
main's base classtools/cpu_ref.pydefines its own_check_vgpr_dst(self, dst)and calls it with one argument (cpu_ref.py:373,:387). This PR'sWaveRef._check_vgpr_dst(self, op, dst)overrides it with another signature. Git merges cleanly, so nothing flags it. A rebase that renames the helper or reusescpu_ref's should fix it. #1780 has the same clash incf_ref.py.AI-assisted (Claude Code).
Independent verification on Windows 11 (
10.0.26200, x64) of30e5b8b932alone and merged ontoorigin/main(53b77df14f,0git text conflicts), tested under bothPython 3.12.10andPython 3.14.5:30e5b8b932):python -I -B tests/test_wave_diff.py:Ran 16 tests,OK(2.23 s).origin/main(53b77df14f) — reproduces#7247564981blocker:python -I -B tests/test_wave_diff.py:Ran 16 tests,FAILED (failures=1, errors=35)on bothPython 3.12.10andPython 3.14.5(TypeError: WaveRef._check_vgpr_dst() missing 1 required positional argument: 'dst'when base classtools/cpu_ref.pyinvokesself._check_vgpr_dst(dst)).WaveRef._check_vgpr_dstto_check_wave_vgpr_dstintools/wave_diff.pymakespython -I -B tests/test_wave_diff.pypass16/16(2.59 s,OK) when merged withorigin/main53b77df14f.git diff --checkandpython -I scripts/check_no_game_data.py tools/wave_diff.py tests/test_wave_diff.pyexited0.AI-assisted.
@ShotTechOp proposed fix for the
_check_vgpr_dstclash withmainreported above.main'scpu_ref.Machine._check_vgpr_dst(self, dst)is called with one argument from_write_vgpr, soWaveRef._check_vgpr_dst(self, op, dst)overrides it with an incompatible signature. Renaming the PR's helper keeps its checks at its three call sites and leaves the base method alone. The name differs from the one proposed on #1780, so the two PRs do not override each other either:Checked on Windows 11, Python 3.12, CPU only, on
main54b2a81e9+ this PR (30e5b8b93, merged locally, not pushed):tests/test_wave_diff.pyFAILED (failures=1, errors=35)test_wave_diff.py16 OK,test_cf_ref.py26 OK,test_cf_gpu_run.py17 OK,test_cf_ref_edge_fixes.py5 OK,test_cpu_ref.py39 OK,test_wave_trace.py10 OK,test_cf_diff.py(pytest) 42 passed,semantic/test_loop_ballot_barrier.py15 OK,semantic/test_saveexec_variants.py9 OKrun_semantic_tests.py tests/semantic: 529 files, 6525 tests, the same 2 failing files as plainmain(test_interp_computed_ij_fallback,test_valu_cvt_f16_int16_mods)main+ this PR + #1780 with both renames: the same files pass too.— OreoFR's agent (AI-assisted)
Reviewed the diff against
main:tools/wave_diff.py:72-218cleanly stops mutating callerinfo["insns"], rejectsabs/negand multi-dword VGPR operands on cross-lane/mask ops, validates destinations even whenEXEC=0, and range-checks 16-bit DSoffset:modifiers, with tests intests/test_wave_diff.py. Clean-room verified. Approving; please merge/rebase currentmainso CI runs green before merge.(AI-assisted review.)