Add CPU-only execution-equivalence tests for Wave32 shader SSA and structured EXEC #2090

Open
github-bot wants to merge 3 commits from github-bot/gh-2090 into main AGit
Owner

@⁠chaseb64 on GitHub · 2026-11-25 04:35 UTC · original
chaseb64:shader/wave32-execution-equivalence → main · +1837 −0 · 6 files · 3 commits · open

Summary

Add a CPU-only differential checker for synthetic Wave32 integer programs with uniform branches, EXEC narrowing and restoration, and bounded loops. Each executor observes the final 32 dwords in v2.

source instructions ── register interpreter ────────────── expected v2
         └─ GFX10 bytes ── ir::build ── SSA executor ───── compare v2
                                └─ structure::structure ── compare v2 per lane

The default suite includes a fixed generated corpus of 128 seeds (10,000–10,127). Every case must complete and agree at both transformed stages, with the seed and outcome reported on failure. The larger campaign runs on demand. Test and replay commands are in crates/victory-shader/tests/equivalence/README.md.

Test design

Grammar and observation. The program concatenates per-lane arithmetic, uniform two-arm branches, masked regions and counted loops with one to six trips. A loop body can contain branches and masked regions. Narrowed EXEC permits only per-lane arithmetic, under a guard or after a forward EXECZ skip, and each region restores its saved EXEC. Vector operations set or add a constant, add v1, or XOR with v1. Constants are 0–64 and addition wraps at 32 bits. A mask can come from the input scalar, an unsigned threshold < v0 comparison, or a uniform join between them. The initial v0, v1 and v2 values are distinct. The scalar roles are the input mask (s0), branch selector (s1), loop counter (s2), saved EXEC (s3) and joined mask (s4). EXEC starts full, with scratch scalar registers, VCC and SCC starting at zero. The final v_mov_b32 v2,v0 observes all 32 lanes exactly once after full EXEC returns. Intermediate flag and register state, branch traces, and instruction counts are outside that observation. A source wave may visit a block that an individual structured lane skips.

Independent comparison. The reference interprets typed instructions with absolute branch targets, its own scalar registers and full lane arrays. It updates active lanes only. The encoder separately writes little-endian GFX10 words with signed relative branch displacements. The SSA evaluator consumes the decoded fields, actual operand bindings, phis, predecessors and exits from ir::build(bytes, false, 3). The structured evaluator walks individual lanes through the exits and guards returned by structure::structure, using its boolean-node and mask-phi mappings. Both transformed evaluators operate on compiler output and the input fixture. They never inspect the source instruction stream. All three share the input fixture, the final observation and Rust integer arithmetic. Hand-written cases check the meaning of the generated instruction stream.

Campaign and reducer. A decimal SplitMix64 seed reconstructs the program and inputs. The opt-in campaign begins at zero by default and caps the search at 10,000 cases or 30 minutes, checking the deadline between bounded cases. Each execution allows 1,024 source instructions or block visits, per lane in structured execution. The summary counts agreement and each inconclusive or failing outcome separately. An SSA agreement still counts if a later stage fails. A semantic difference reports its seed, stage, first differing lane and both dwords. The reducer uses the original inputs, rebuilds branch targets after each edit, and removes regions or masked operations or shortens loop bounds. It keeps an edit only if the same stage, lane and values still disagree. This gives a local minimum under those edits. An injected guard fault exercises reduction, while other mutations exercise loop backedges, inactive-lane writes and structured branch destinations.

Evidence

  • On native Apple Silicon macOS with pinned Rust 1.98.1, the baseline had 144 library tests pass and two benchmarks ignored. With the checker, all 144 library tests and 12 new focused tests passed.

  • Replacing a loop-carried phi's backedge input changed lane 0 from 9 to 3. Removing a structured write guard changed lane 1 from 1 to 17. The reducer preserved that exact difference while shrinking eight instructions to five. Both unmodified transformations matched the reference.

  • Seeds 0 through 9,999 agreed at both stages. Counts for refusals, unsupported cases, exhausted limits, invalid executions, compiler errors, panics and mismatches were all zero. Seed 42 also replayed individually.

  • An independent Windows review of the initial checker ran 128 fresh seeds (10,000–10,127). All agreed at both stages. Those seeds now run in the default suite. Independent review

  • Clippy and the asset-policy check passed. Upstream Windows CI passed on 42bd6f5, including the fixed corpus. Windows CI

  • The README-only follow-up passed the native equivalence suite (13 passed, one opt-in campaign ignored) and cargo xtask policy (188 files checked).

Merge Danger

Reversibility. Reverting the PR removes the checker.

Scope. The six added files live under the shader crate's integration tests. The synthetic grammar covers the stated Wave32 integer and control-flow subset through structurization. Nested loops, Wave64, floating point, memory, textures, barriers, derivatives, discards, cross-lane operations, arbitrary scalar side effects under narrowed EXEC, and mask-as-data uses are outside the grammar. Emitted host code and GPU execution are outside the comparison.

AI-assisted using OpenAI Codex. GPT-6.2 Astra (High) implemented the checker. GPT-6.2 Sol (High) added the fixed corpus, and GPT-6.2 Sol prepared the documentation revision. Existing coordination claim.

**@⁠chaseb64** on GitHub · 2026-11-25 04:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2090) `chaseb64:shader/wave32-execution-equivalence` → `main` · +1837 −0 · 6 files · 3 commits · open ## Summary Add a CPU-only differential checker for synthetic Wave32 integer programs with uniform branches, EXEC narrowing and restoration, and bounded loops. Each executor observes the final 32 dwords in v2. ```text source instructions ── register interpreter ────────────── expected v2 └─ GFX10 bytes ── ir::build ── SSA executor ───── compare v2 └─ structure::structure ── compare v2 per lane ``` The default suite includes a fixed generated corpus of 128 seeds (10,000–10,127). Every case must complete and agree at both transformed stages, with the seed and outcome reported on failure. The larger campaign runs on demand. Test and replay commands are in `crates/victory-shader/tests/equivalence/README.md`. ## Test design **Grammar and observation.** The program concatenates per-lane arithmetic, uniform two-arm branches, masked regions and counted loops with one to six trips. A loop body can contain branches and masked regions. Narrowed EXEC permits only per-lane arithmetic, under a guard or after a forward EXECZ skip, and each region restores its saved EXEC. Vector operations set or add a constant, add v1, or XOR with v1. Constants are 0–64 and addition wraps at 32 bits. A mask can come from the input scalar, an unsigned `threshold < v0` comparison, or a uniform join between them. The initial v0, v1 and v2 values are distinct. The scalar roles are the input mask (s0), branch selector (s1), loop counter (s2), saved EXEC (s3) and joined mask (s4). EXEC starts full, with scratch scalar registers, VCC and SCC starting at zero. The final `v_mov_b32 v2,v0` observes all 32 lanes exactly once after full EXEC returns. Intermediate flag and register state, branch traces, and instruction counts are outside that observation. A source wave may visit a block that an individual structured lane skips. **Independent comparison.** The reference interprets typed instructions with absolute branch targets, its own scalar registers and full lane arrays. It updates active lanes only. The encoder separately writes little-endian GFX10 words with signed relative branch displacements. The SSA evaluator consumes the decoded fields, actual operand bindings, phis, predecessors and exits from `ir::build(bytes, false, 3)`. The structured evaluator walks individual lanes through the exits and guards returned by `structure::structure`, using its boolean-node and mask-phi mappings. Both transformed evaluators operate on compiler output and the input fixture. They never inspect the source instruction stream. All three share the input fixture, the final observation and Rust integer arithmetic. Hand-written cases check the meaning of the generated instruction stream. **Campaign and reducer.** A decimal SplitMix64 seed reconstructs the program and inputs. The opt-in campaign begins at zero by default and caps the search at 10,000 cases or 30 minutes, checking the deadline between bounded cases. Each execution allows 1,024 source instructions or block visits, per lane in structured execution. The summary counts agreement and each inconclusive or failing outcome separately. An SSA agreement still counts if a later stage fails. A semantic difference reports its seed, stage, first differing lane and both dwords. The reducer uses the original inputs, rebuilds branch targets after each edit, and removes regions or masked operations or shortens loop bounds. It keeps an edit only if the same stage, lane and values still disagree. This gives a local minimum under those edits. An injected guard fault exercises reduction, while other mutations exercise loop backedges, inactive-lane writes and structured branch destinations. ## Evidence - On native Apple Silicon macOS with pinned Rust 1.98.1, the baseline had 144 library tests pass and two benchmarks ignored. With the checker, all 144 library tests and 12 new focused tests passed. - Replacing a loop-carried phi's backedge input changed lane 0 from 9 to 3. Removing a structured write guard changed lane 1 from 1 to 17. The reducer preserved that exact difference while shrinking eight instructions to five. Both unmodified transformations matched the reference. - Seeds 0 through 9,999 agreed at both stages. Counts for refusals, unsupported cases, exhausted limits, invalid executions, compiler errors, panics and mismatches were all zero. Seed 42 also replayed individually. - An independent Windows review of the initial checker ran 128 fresh seeds (10,000–10,127). All agreed at both stages. Those seeds now run in the default suite. [Independent review](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2090) - Clippy and the asset-policy check passed. Upstream Windows CI passed on `42bd6f5`, including the fixed corpus. [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/45549033051/job/138985481862) - The README-only follow-up passed the native equivalence suite (13 passed, one opt-in campaign ignored) and `cargo xtask policy` (188 files checked). ## Merge Danger **Reversibility.** Reverting the PR removes the checker. **Scope.** The six added files live under the shader crate's integration tests. The synthetic grammar covers the stated Wave32 integer and control-flow subset through structurization. Nested loops, Wave64, floating point, memory, textures, barriers, derivatives, discards, cross-lane operations, arbitrary scalar side effects under narrowed EXEC, and mask-as-data uses are outside the grammar. Emitted host code and GPU execution are outside the comparison. AI-assisted using OpenAI Codex. GPT-6.2 Astra (High) implemented the checker. GPT-6.2 Sol (High) added the fixed corpus, and GPT-6.2 Sol prepared the documentation revision. [Existing coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633).
Move the test design, independent comparison and reduction rationale to the PR description.

AI-assisted using OpenAI Codex (GPT-6.2 Sol).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:54:33 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-25 04:40 UTC · original

Triage verdict — Keep the CPU differential suite (82291ac)

Evidence

  • @⁠chaseb64’s reference interpreter compares observable register results against both the compiler’s actual SSA bindings and structured lane execution. It complements the existing phi and exit-shape tests by checking whether the same values reach the output. Suite · Campaign

Checks and limits

  • Exact-head Windows CPU run: 12 passed, with the generated campaign ignored by default. I then ran 128 fresh seeds starting at 10,000, outside the author’s reported range. All 128 agreed in both transformed executors, with zero refusals, unsupported cases, budget limits, or differences. The run took about 0.12 seconds in debug.
  • This checks the selected Wave32 integer and EXEC subset through SSA and structuring. It does not exercise DXIL emission or GPU execution.

Next step

  • Keep the broad opt-in campaign. Consider a small fixed generated corpus in the default suite whose selected cases are all required to complete and agree. The opt-in scan reports refusals and checker limits, but allows them, so it would not fail if those outcomes grew while a few programs still completed.

This verification was AI-assisted.

**@⁠jeremygold02** on GitHub · 2026-11-25 04:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2090#issuecomment-7153063250) **Triage verdict — Keep the CPU differential suite** (`82291ac`) **Evidence** - @⁠chaseb64’s reference interpreter compares observable register results against both the compiler’s actual SSA bindings and structured lane execution. It complements the existing phi and exit-shape tests by checking whether the same values reach the output. [Suite](https://github.com/Marvisak/VIctory/blob/82291ac43f3e4db748f5023b3b8aaa7e30246f1c/crates/victory-shader/tests/equivalence.rs) · [Campaign](https://github.com/Marvisak/VIctory/blob/82291ac43f3e4db748f5023b3b8aaa7e30246f1c/crates/victory-shader/tests/equivalence/search.rs#L253-L299) **Checks and limits** - Exact-head Windows CPU run: 12 passed, with the generated campaign ignored by default. I then ran 128 fresh seeds starting at 10,000, outside the author’s reported range. All 128 agreed in both transformed executors, with zero refusals, unsupported cases, budget limits, or differences. The run took about 0.12 seconds in debug. - This checks the selected Wave32 integer and EXEC subset through SSA and structuring. It does not exercise DXIL emission or GPU execution. **Next step** - Keep the broad opt-in campaign. Consider a small fixed generated corpus in the default suite whose selected cases are all required to complete and agree. The opt-in scan reports refusals and checker limits, but allows them, so it would not fail if those outcomes grew while a few programs still completed. This verification was AI-assisted.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:18 UTC · original · edited 2026-11-26 04:21 UTC

Automated triage for the maintainers.

Merge candidate. Thanks for trimming the docs: tests/equivalence/README.md is now 17 lines with just the commands, and the test code and fixed corpus are unchanged since the last review. The suite only touches tests: a reference interpreter for a Wave32 integer/EXEC subset compared against SSA evaluation of ir::build and lane-by-lane evaluation of structure::structure, with the fixed corpus running by default and the larger campaign #[ignore]d.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2090#issuecomment-7159522527) · edited 2026-11-26 04:21 UTC <!-- victory-triage v1 head=7d85912fa58e09cbb2f7e4c6d52278701011172c verdict=merge-candidate at=2026-11-26T04:21:48Z --> Automated triage for the maintainers. **Merge candidate.** Thanks for trimming the docs: `tests/equivalence/README.md` is now 17 lines with just the commands, and the test code and fixed corpus are unchanged since the last review. The suite only touches tests: a reference interpreter for a Wave32 integer/EXEC subset compared against SSA evaluation of `ir::build` and lane-by-lane evaluation of `structure::structure`, with the fixed corpus running by default and the larger campaign `#[ignore]`d. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠chaseb64 on GitHub · 2026-11-26 03:18 UTC · original

Thanks for the feedback. In 7d85912, I cut the README from 74 lines to 17 and kept the test and replay commands. The grammar, independent comparison, and reducer rationale are now in the PR description. The fixed corpus and test code are unchanged.

git diff --check passed, the native equivalence suite passed 13 tests with the opt-in campaign ignored, and cargo xtask policy passed all 188 files.

AI-assisted using OpenAI Codex (GPT-6.2 Sol for the documentation revision).

**@⁠chaseb64** on GitHub · 2026-11-26 03:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2090#issuecomment-7181587677) Thanks for the [feedback](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2090). In `7d85912`, I cut the README from 74 lines to 17 and kept the test and replay commands. The grammar, independent comparison, and reducer rationale are now in the PR description. The fixed corpus and test code are unchanged. `git diff --check` passed, the native equivalence suite passed 13 tests with the opt-in campaign ignored, and `cargo xtask policy` passed all 188 files. AI-assisted using OpenAI Codex (GPT-6.2 Sol for the documentation revision).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2090/head:github-bot/gh-2090'
git switch 'github-bot/gh-2090'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2090'
git switch 'github-bot/gh-2090'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2090'
git switch 'github-bot/gh-2090'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2090'
git switch 'main'
git merge --squash 'github-bot/gh-2090'
git switch 'main'
git merge --ff-only 'github-bot/gh-2090'
git switch 'main'
git merge 'github-bot/gh-2090'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2090
No description provided.