vk_model_fuzz: judge pk16_diff, vint_diff and sdwa_diff on any Vulkan GPU against their reference model (VK-MODEL-ORACLE) #1938

Open
github-bot wants to merge 1 commit from github-bot/gh-1938 into main AGit
Owner

@⁠levi2m on GitHub · 2026-11-25 16:15 UTC · original
levi2m:feat/vk-model-oracle → main · +306 −0 · 3 files · 1 commits · open

Claimed in the coordination issue as: VK-MODEL-ORACLE (claim, in #1608, the continuation of #14)
Depends on: none (does not edit pk16_diff.py, vint_diff.py, sdwa_diff.py or vk_fuzz_run.py, so it is independent of #1653, #1654, #1656 and #1519)
Fixes: none

What and why

pk16_diff.py, vint_diff.py and sdwa_diff.py can run their translated programs on a Vulkan GPU, but only as --oracle hw,vk: the expected words come from a native AMD GPU. Without one, the GPU half of these fuzzers is out of reach, so an NVIDIA or Intel card never gets judged against them.

tools/vk_model_fuzz.py runs the same programs (same generator, same seed) through the translator and vk_compute_test and judges the result against each fuzzer's reference model instead. That model is written from the ISA pseudocode and already decides the CPU-interpreter run. A mismatch means the GPU, the translator or the model disagrees; the docs say to re-read the program with the fuzzer itself first. A program the model declines is a skip. Exit codes follow the other tools: 0 match, 1 mismatch, 2 no vk_compute_test, 77 nothing judged.

Nothing existing is edited. The tool reuses vk_fuzz_run.judge and each fuzzer's generate, reference and verdict, plus the same uniform setting each fuzzer's own run_suite passes. docs/testing.md gets a short section next to the AMD hardware oracle one.

Tested

  • python -I tests/test_vk_model_fuzz.py: 10 tests OK. A stand-in judge replaces the GPU, so they need no Vulkan device or llvm-mc: the programs are the ones the fuzzer generates for the seed, the model words are what the GPU is judged against, sdwa is not assumed uniform, a declined program is a skip, and exit codes 0, 1, 2, 77 and the usage error.
  • On the GPU, native Windows 11, NVIDIA RTX 4050 Laptop (driver 621.01), vk_compute_test built with llvm-mingw, llvm-mc 21.1.8: pk16_diff 120 programs seed 11: 120 match, exit 0 (and 6,000 pk16_diff and 6,000 vint_diff programs over four seeds with the same harness: all match). With a folder that has no vk_compute_test: one ERROR: line, exit 2. vint_diff 120 programs seed 21: 120 match. sdwa_diff 120 programs seed 21: 116 match, 4 declined by the model (f16 NaN operands). First real use (an earlier script version of this same logic, before it was split into this tool), sdwa_diff seeds 12, 13 and 14 with 1,500 programs each: 1,457, 1,444 and 1,455 match, and 5 programs mismatch (4 of them v_cvt_f32_u32_sdwa with a sext() source; see the follow-up pull request for SHADER-SDWA-SEXT-SHIFTS). The CPU interpreter run of the same seeds has 0 mismatches, so those are the GPU differing from the SPIR-V's meaning.
  • python -m compileall -q tools tests, tests/test_text_write_line_endings.py, tests/test_docs_cli_flags.py, tests/test_docs_links.py, tests/test_ci_registration.py, tests/test_docs_design_rows.py: OK. scripts/check_no_game_data.py on the new files: clean. tests/test_tool_stdout_encoding.py fails on main for three other tools (compute_heap_layout_census.py, game_run_summary.py, stage_timeline.py) and passes for this one.
  • No game files.

GPUs tested: NVIDIA GeForce RTX 4050 Laptop GPU, driver 621.01, Windows 11 build 26200
AI-assisted: yes

**@⁠levi2m** on GitHub · 2026-11-25 16:15 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1938) `levi2m:feat/vk-model-oracle` → `main` · +306 −0 · 3 files · 1 commits · open Claimed in the coordination issue as: VK-MODEL-ORACLE ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608), in #1608, the continuation of #14) Depends on: none (does not edit `pk16_diff.py`, `vint_diff.py`, `sdwa_diff.py` or `vk_fuzz_run.py`, so it is independent of #1653, #1654, #1656 and #1519) Fixes: none ### What and why `pk16_diff.py`, `vint_diff.py` and `sdwa_diff.py` can run their translated programs on a Vulkan GPU, but only as `--oracle hw,vk`: the expected words come from a native AMD GPU. Without one, the GPU half of these fuzzers is out of reach, so an NVIDIA or Intel card never gets judged against them. `tools/vk_model_fuzz.py` runs the same programs (same generator, same seed) through the translator and `vk_compute_test` and judges the result against each fuzzer's reference model instead. That model is written from the ISA pseudocode and already decides the CPU-interpreter run. A mismatch means the GPU, the translator or the model disagrees; the docs say to re-read the program with the fuzzer itself first. A program the model declines is a skip. Exit codes follow the other tools: 0 match, 1 mismatch, 2 no `vk_compute_test`, 77 nothing judged. Nothing existing is edited. The tool reuses `vk_fuzz_run.judge` and each fuzzer's `generate`, `reference` and verdict, plus the same `uniform` setting each fuzzer's own `run_suite` passes. `docs/testing.md` gets a short section next to the AMD hardware oracle one. ### Tested - `python -I tests/test_vk_model_fuzz.py`: 10 tests OK. A stand-in judge replaces the GPU, so they need no Vulkan device or `llvm-mc`: the programs are the ones the fuzzer generates for the seed, the model words are what the GPU is judged against, sdwa is not assumed uniform, a declined program is a skip, and exit codes 0, 1, 2, 77 and the usage error. - On the GPU, native Windows 11, NVIDIA RTX 4050 Laptop (driver 621.01), `vk_compute_test` built with llvm-mingw, `llvm-mc` 21.1.8: `pk16_diff` 120 programs seed 11: 120 match, exit 0 (and 6,000 `pk16_diff` and 6,000 `vint_diff` programs over four seeds with the same harness: all match). With a folder that has no `vk_compute_test`: one `ERROR:` line, exit 2. `vint_diff` 120 programs seed 21: 120 match. `sdwa_diff` 120 programs seed 21: 116 match, 4 declined by the model (f16 NaN operands). First real use (an earlier script version of this same logic, before it was split into this tool), `sdwa_diff` seeds 12, 13 and 14 with 1,500 programs each: 1,457, 1,444 and 1,455 match, and 5 programs mismatch (4 of them `v_cvt_f32_u32_sdwa` with a `sext()` source; see the follow-up pull request for SHADER-SDWA-SEXT-SHIFTS). The CPU interpreter run of the same seeds has 0 mismatches, so those are the GPU differing from the SPIR-V's meaning. - `python -m compileall -q tools tests`, `tests/test_text_write_line_endings.py`, `tests/test_docs_cli_flags.py`, `tests/test_docs_links.py`, `tests/test_ci_registration.py`, `tests/test_docs_design_rows.py`: OK. `scripts/check_no_game_data.py` on the new files: clean. `tests/test_tool_stdout_encoding.py` fails on `main` for three other tools (`compute_heap_layout_census.py`, `game_run_summary.py`, `stage_timeline.py`) and passes for this one. - No game files. GPUs tested: NVIDIA GeForce RTX 4050 Laptop GPU, driver 621.01, Windows 11 build 26200 AI-assisted: yes
The Vulkan run of these fuzzers (--oracle hw,vk) takes its expected words
from a native AMD GPU, so a contributor with an NVIDIA or Intel card cannot
use it. tools/vk_model_fuzz.py runs the programs the fuzzer generates for
the same seed through the translator and vk_compute_test and judges them
against the fuzzer's reference model instead. A program the model declines
is a skip and never reaches the GPU. No existing fuzzer is edited.

tests/test_vk_model_fuzz.py stands in for the GPU, so it needs no Vulkan
device; docs/testing.md has a short section next to the AMD hardware oracle.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:11:56 +00:00
Author
Owner

@⁠Mby159 on GitHub · 2026-11-25 18:41 UTC · original

Independent verification on a second vendor's GPU (AMD Radeon 780M), with the reference model as the oracle.

Machine. AMD Radeon 780M Graphics (RDNA3 iGPU, gfx1103), AMD proprietary 26.10.2 (32.0.32015.12012, LLPC), Vulkan 1.4.359, subgroup 32..64, Windows 11 10.0.29712. Python 3.13.17, LLVM 23.1.6 (conda-forge llvm-tools, AMDGPU target), CMake 4.5.1 + Ninja, llvm-mingw clang++ 23.1.6. vk_compute_test built from this pull request's tree (base b0f3d3998) with -DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF. The programs are assembled for gfx1013 as the tool does; the device that runs them is RDNA3.

Your reviewer check passes here: python -I tests/test_vk_model_fuzz.py -> 10 tests OK.

The 120-program numbers match what the pull request reports for the RTX 4050 Laptop.

fuzzer seed programs here (Radeon 780M)
pk16_diff 11 120 120 match, exit 0
vint_diff 21 120 120 match, exit 0
sdwa_diff 21 120 116 match, 4 declined by the model (f16 NaN operands), exit 0

At 1,500 programs, for the two seeds below, the model and the GPU agree on every program the model judges.

python -I tools/vk_model_fuzz.py sdwa_diff --programs 1500 --seed 12 --build runtime/build
fuzzer seed programs GPU CPU interpreter, same programs
sdwa_diff 12 1,500 1,459 match, 41 declined by the model (40 f16 NaN operand + 1 f16 NaN result payload), 0 mismatch 1,459 pass, 41 skipped, 0 mismatch
sdwa_diff 13 1,500 1,446 match, 54 declined by the model (f16 NaN operand), 0 mismatch 1,446 pass, 54 skipped, 0 mismatch

The two runs see the same programs: the model declines exactly the same ones (the f16 NaN operand, and for seed 12 the f16 NaN result whose payload is not modelled), so the skip breakdown is identical. sdwa_diff.py's own defaults are --max-ops 4 and the family op set, while this tool uses --max-ops 6 and the fuzzer's whole OPS table, so the CPU runs above were given --max-ops 6 --ops <all 92 opcodes> to land on the same program set.

The exit 2 path behaves as documented: --build pointing at a folder without vk_compute_test prints one ERROR: line and exits 2.

One scope note. I ran wave 32 only (the tool's default), did not run the 6,000-program sweeps, did not run --wave 64, and a 1,500-program seed-14 run had not finished when I posted this.

Separately: the SDWA case #1939 describes, found with this tool on an NVIDIA driver, does not reproduce on this driver - the details are in #1939.

**@⁠Mby159** on GitHub · 2026-11-25 18:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1938#issuecomment-7171251888) Independent verification on a second vendor's GPU (AMD Radeon 780M), with the reference model as the oracle. **Machine.** AMD Radeon 780M Graphics (RDNA3 iGPU, gfx1103), AMD proprietary 26.10.2 (32.0.32015.12012, LLPC), Vulkan 1.4.359, subgroup 32..64, Windows 11 10.0.29712. Python 3.13.17, LLVM 23.1.6 (conda-forge llvm-tools, AMDGPU target), CMake 4.5.1 + Ninja, llvm-mingw clang++ 23.1.6. `vk_compute_test` built from this pull request's tree (base `b0f3d3998`) with `-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF`. The programs are assembled for `gfx1013` as the tool does; the device that runs them is RDNA3. **Your reviewer check passes here**: `python -I tests/test_vk_model_fuzz.py` -> 10 tests OK. **The 120-program numbers match what the pull request reports for the RTX 4050 Laptop.** | fuzzer | seed | programs | here (Radeon 780M) | |---|---|---|---| | `pk16_diff` | 11 | 120 | 120 match, exit 0 | | `vint_diff` | 21 | 120 | 120 match, exit 0 | | `sdwa_diff` | 21 | 120 | 116 match, 4 declined by the model (f16 NaN operands), exit 0 | **At 1,500 programs, for the two seeds below, the model and the GPU agree on every program the model judges.** ``` python -I tools/vk_model_fuzz.py sdwa_diff --programs 1500 --seed 12 --build runtime/build ``` | fuzzer | seed | programs | GPU | CPU interpreter, same programs | |---|---|---|---|---| | `sdwa_diff` | 12 | 1,500 | 1,459 match, 41 declined by the model (40 f16 NaN operand + 1 f16 NaN result payload), 0 mismatch | 1,459 pass, 41 skipped, 0 mismatch | | `sdwa_diff` | 13 | 1,500 | 1,446 match, 54 declined by the model (f16 NaN operand), 0 mismatch | 1,446 pass, 54 skipped, 0 mismatch | The two runs see the same programs: the model declines exactly the same ones (the f16 NaN operand, and for seed 12 the f16 NaN result whose payload is not modelled), so the skip breakdown is identical. `sdwa_diff.py`'s own defaults are `--max-ops 4` and the family op set, while this tool uses `--max-ops 6` and the fuzzer's whole `OPS` table, so the CPU runs above were given `--max-ops 6 --ops <all 92 opcodes>` to land on the same program set. **The `exit 2` path behaves as documented**: `--build` pointing at a folder without `vk_compute_test` prints one `ERROR:` line and exits 2. **One scope note.** I ran wave 32 only (the tool's default), did not run the 6,000-program sweeps, did not run `--wave 64`, and a 1,500-program seed-14 run had not finished when I posted this. Separately: the SDWA case #1939 describes, found with this tool on an NVIDIA driver, does not reproduce on this driver - the details are in #1939.
Author
Owner

@⁠levi2m on GitHub · 2026-11-26 14:37 UTC · original

Thanks @⁠Mby159 for running this on the 780M. It is good to see the tool agree on a second vendor's GPU, and your point that the 1,500-program CPU runs need --max-ops 6 and the full op list to land on the same programs is a useful one.

AI-assisted: yes

**@⁠levi2m** on GitHub · 2026-11-26 14:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1938#issuecomment-7195084761) Thanks @⁠Mby159 for running this on the 780M. It is good to see the tool agree on a second vendor's GPU, and your point that the 1,500-program CPU runs need `--max-ops 6` and the full op list to land on the same programs is a useful one. AI-assisted: yes
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/1938/head:github-bot/gh-1938'
git switch 'github-bot/gh-1938'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1938'
git switch 'github-bot/gh-1938'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1938'
git switch 'github-bot/gh-1938'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1938'
git switch 'main'
git merge --squash 'github-bot/gh-1938'
git switch 'main'
git merge --ff-only 'github-bot/gh-1938'
git switch 'main'
git merge 'github-bot/gh-1938'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.