bench_wave64: exercise partial ballots and check the stock shader output #1238

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

@⁠titoreinaldo on GitHub · 2026-11-24 20:41 UTC · original
titoreinaldo:contrib/r2-ballot → main · +66 −3 · 4 files · 1 commits · open

Claimed in the coordination issue as: SHADER-BENCH-MIX-BALLOT
Claim in #14

What and why

The stock benchmark used the bottom two bits of (index * 0x9e3779b1) ^ index for its ballot. Those bits always cancel, so no lane was selected. A broken prefix count in the upper half of the wave could still give identical output across runs and GPUs.

Using bits 8–9 selects 16,896 of the first 65,536 inputs. Each 32-lane half has 7–9 participants, and the halves have different counts in every one of those 1,024 workgroups. The harness now checks the stock shader’s output against a CPU implementation after timing, including its whole-wave prefix, neighbor reads and branches. Custom benchmark shaders retain the existing dump mode.

Tested

  • Built the original and revised synthetic shaders separately with LLVM and SPIR-V Tools. Both translated and validated. On the RTX 3070 the original shader failed the new check at all 65,536 words. A separate control that zeroed only the upper-half prefix mask failed at 29,440 words, starting at lane 34.
  • With the fix, both GPUs passed vk_compute_test cs_bench_mix.spv 65535 bench_mix: 4,194,240 words checked per GPU, zero mismatches, output hash 7d38f475 (with VKC_BENCH=1).
  • python -I scripts/bench_wave64.py --emulated-only --build <build> --groups 1024 --procs 2 --reps 2 returned the same hash c80c78fb on each GPU. python -I tests/test_bench_wave64.py passed all 15 tests.
  • The shared base 58be9cdf ran 6,168 translator tests in 470 files with zero failing files. Verified a clean merge with main at 705ea091 and with #1054.

GPUs tested: Windows 11 Pro 26H2 build 26300.9974. NVIDIA GeForce RTX 3070 eGPU, driver 610.88, reported subgroup 32..32. Intel(R) Arc(TM) Graphics, driver 32.0.101.8132, reported subgroup 8..32. Both runs used wave64 emulation, and each harness log identified its selected device. Native wave64 hardware coverage is still open.

AI-assisted: yes, OpenAI Codex. Synthetic shader and buffers.

**@⁠titoreinaldo** on GitHub · 2026-11-24 20:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1238) `titoreinaldo:contrib/r2-ballot` → `main` · +66 −3 · 4 files · 1 commits · open Claimed in the coordination issue as: SHADER-BENCH-MIX-BALLOT [Claim in #14](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why The stock benchmark used the bottom two bits of `(index * 0x9e3779b1) ^ index` for its ballot. Those bits always cancel, so no lane was selected. A broken prefix count in the upper half of the wave could still give identical output across runs and GPUs. Using bits 8–9 selects 16,896 of the first 65,536 inputs. Each 32-lane half has 7–9 participants, and the halves have different counts in every one of those 1,024 workgroups. The harness now checks the stock shader’s output against a CPU implementation after timing, including its whole-wave prefix, neighbor reads and branches. Custom benchmark shaders retain the existing dump mode. ### Tested - Built the original and revised synthetic shaders separately with LLVM and SPIR-V Tools. Both translated and validated. On the RTX 3070 the original shader failed the new check at all 65,536 words. A separate control that zeroed only the upper-half prefix mask failed at 29,440 words, starting at lane 34. - With the fix, both GPUs passed `vk_compute_test cs_bench_mix.spv 65535 bench_mix`: 4,194,240 words checked per GPU, zero mismatches, output hash `7d38f475` (with `VKC_BENCH=1`). - `python -I scripts/bench_wave64.py --emulated-only --build <build> --groups 1024 --procs 2 --reps 2` returned the same hash `c80c78fb` on each GPU. `python -I tests/test_bench_wave64.py` passed all 15 tests. - The shared base `58be9cdf` ran 6,168 translator tests in 470 files with zero failing files. Verified a clean merge with `main` at `705ea091` and with #1054. GPUs tested: Windows 11 Pro 26H2 build 26300.9974. NVIDIA GeForce RTX 3070 eGPU, driver 610.88, reported subgroup 32..32. Intel(R) Arc(TM) Graphics, driver 32.0.101.8132, reported subgroup 8..32. Both runs used wave64 emulation, and each harness log identified its selected device. Native wave64 hardware coverage is still open. AI-assisted: yes, OpenAI Codex. Synthetic shader and buffers.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:44:02 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 09:37 UTC · original

Reviewed 5a1e17f: switches the cs_bench_mix ballot mask to bits 8-9 (v_bfe_u32) — hash & 3 is identically zero for this hash, so the benchmark never exercised a partial ballot — and adds the bench_mix CPU readback check to vk_compute_test, which bench_wave64.py now requires for the stock shader and treats a mismatch line as a failure. I ran the Python tests in a sandbox (15/15 on the PR; the new test fails on main's script, proving the check is new), a repo no-game-data check, and a probe that translates each tree's asm with the repo translator and runs it on the CPU SPIR-V interpreter: the PR tree's output matches check_bench_mix on all 256 words of 4 workgroups, while main's old mask selects literally zero lanes per group; over all 16384 dispatches the new mask stays 7-9 lanes per half with no degenerate half. I also built vk_compute_test from this head on Linux arm64 and ran scripts/bench_wave64.py --emulated-only --groups 256 --reps 2 --procs 2 on Mesa llvmpipe: exit 0, so the bench_mix CPU check passed on every word, with a stable output hash across processes. No native wave64 device here, so the AMD-native and NVIDIA configurations are still unverified. Minor notes: the two Python files also changed on main since your branch point (the missing-.spv validation and its test), so the merge-tree today is clean but a rebase would keep the diff readable; and the ^5 xor never fires at these vote constants (pre-existing).
AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 09:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1238#issuecomment-7158585475) Reviewed 5a1e17f: switches the cs_bench_mix ballot mask to bits 8-9 (`v_bfe_u32`) — `hash & 3` is identically zero for this hash, so the benchmark never exercised a partial ballot — and adds the bench_mix CPU readback check to vk_compute_test, which bench_wave64.py now requires for the stock shader and treats a mismatch line as a failure. I ran the Python tests in a sandbox (15/15 on the PR; the new test fails on main's script, proving the check is new), a repo no-game-data check, and a probe that translates each tree's asm with the repo translator and runs it on the CPU SPIR-V interpreter: the PR tree's output matches check_bench_mix on all 256 words of 4 workgroups, while main's old mask selects literally zero lanes per group; over all 16384 dispatches the new mask stays 7-9 lanes per half with no degenerate half. I also built vk_compute_test from this head on Linux arm64 and ran `scripts/bench_wave64.py --emulated-only --groups 256 --reps 2 --procs 2` on Mesa llvmpipe: exit 0, so the bench_mix CPU check passed on every word, with a stable output hash across processes. No native wave64 device here, so the AMD-native and NVIDIA configurations are still unverified. Minor notes: the two Python files also changed on main since your branch point (the missing-.spv validation and its test), so the merge-tree today is clean but a rebase would keep the diff readable; and the ^5 xor never fires at these vote constants (pre-existing). AI-assisted review. **Recommendation:** Merge
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/1238/head:github-bot/gh-1238'
git switch 'github-bot/gh-1238'

Merge

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