Skip to content

bench_wave64: isolate driver selection from single-GPU filters - #8801

Open
THEMANnt wants to merge 2 commits into
ItsNotRexed:mainfrom
THEMANnt:fix/bench-wave64-device-filter
Open

THEMANnt wants to merge 2 commits into
ItsNotRexed:mainfrom
THEMANnt:fix/bench-wave64-device-filter

Conversation

@THEMANnt

@THEMANnt THEMANnt commented Nov 23, 2026 •

Copy link
Copy Markdown

What changed

The wave64 benchmark runs separate AMD and NVIDIA driver configurations. An inherited LEONIDA_VK_DEVICE remains useful when one driver exposes more than one GPU. Keep a matching filter. If the first process says no physical device matches it, print a notice and retry that configuration with the driver's default device. A configuration keeps that choice for subsequent processes. The benchmark fails if no configuration completes using the filter, and the caller's environment is preserved.

Claim: #8683 (comment)

Verification

  • All 13 focused tests passed on Windows with Python 3.14.8. The new tests reproduced the same-vendor selection regression before the follow-up and cover retry scope, invalid device names, and an unrelated device failure.
  • Ran all three driver configurations on AMD Radeon Graphics (32.0.21030.2001) and an RTX 5070 Ti (32.0.16.1692), using a prebuilt synthetic cs_w32_permute module. Each valid filter gave matching hashes and the expected opposite-vendor fallback. A nonexistent filter exited 1. The dual-AMD selection case was tested with a simulated GPU pair.
  • Changed-file no-game-data, Python compilation and whitespace checks passed.

AI-assisted. Synthetic inputs only.

@shyro29 shyro29 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 651759141 on Linux x86_64, CPython 3.14 (no game files, synthetic): pass.

  • python -I tests/test_bench_wave64.py at the head: OK; the same test file against main's script: FAILED (failures=3) — red/green confirmed.
  • The one-line fix is the right scope: a user running the benchmark on a multi-GPU box with LEONIDA_VK_DEVICE exported would have had every benchmark subprocess pinned to that device, so the amd/nv configurations would measure the wrong GPU (or nothing). Popping it from the child environment keeps the operator's shell filter for other work.
  • python -I scripts/check_no_game_data.py on the two changed files: clean. AI-assisted (Claude Code).

@slint6614-dev

Copy link
Copy Markdown
Contributor

AMD Windows check of 651759141 (AI-assisted), on a machine with two AMD GPUs and no NVIDIA: Radeon RX 9070 (RDNA4) + Ryzen 9600X iGPU "AMD Radeon(TM) Graphics" (gfx1036), Adrenalin 26.11.2, Windows 11 26300, Python 3.12; vk_compute_test from a RelWithDebInfo build of main 867d922.

tests/test_bench_wave64.py: OK. But dropping LEONIDA_VK_DEVICE changes which GPU is benchmarked here, because VK_LOADER_DRIVERS_SELECT='*amd*,*radeon*' lets both AMD devices through. bench_wave64.py --reps 20 --procs 1 with LEONIDA_VK_DEVICE="Radeon(TM) Graphics":

AMD native AMD --wave64-emulate
main 867d922 AMD Radeon(TM) Graphics, 1.776 ms AMD Radeon(TM) Graphics, 2.826 ms
this PR AMD Radeon RX 9070, 0.666 ms AMD Radeon RX 9070, 0.754 ms

So on a dual-AMD machine the PR always takes the driver's first AMD device and the user can no longer choose the iGPU (with LEONIDA_VK_DEVICE="RX 9070" both versions use the RX 9070). Perhaps drop the variable only for the NVIDIA configuration, or only when it doesn't name a device the driver filter keeps. (NVIDIA row: vkCreateInstance -> -9 on both, expected with no NVIDIA driver.)

@altLov3r

Copy link
Copy Markdown

Tested 651759141 on Windows 11 with Python 3.14.4: PASS.

  • python -I tests/test_bench_wave64.py -v: 11/11 OK (0.055 s), including the new test_configured_driver_does_not_inherit_the_single_device_filter regression confirming LEONIDA_VK_DEVICE is cleared in the benchmark subprocess while keeping the driver selector and caller env.

No game files. AI-assisted (Antigravity / Gemini 4 Neon).

@wavehs

wavehs commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

macOS arm64 verification (Apple M3 Pro, three Vulkan ICDs on one host)

Tested PR head 65175914 merged onto main 867d922f0 (merge 651759141), no conflicts.

Host: macOS 27.2.1, Apple M3 Pro (arm64), CPython 3.15.2. Vulkan ICDs present: MoltenVK 1.4.0, Mesa KosmicKrisp 26.3.0, lavapipe (Mesa 26.3.0).

Check Result
python3 -I tests/test_bench_wave64.py 11/11 pass
compileall, git diff --check clean

The conflict this prevents is worse than "the wrong GPU is picked" — I reproduced it

With two selectable devices on this host:

# A: the benchmark's own selector only
VK_LOADER_DRIVERS_SELECT='*lvp*' vk_compute_test cs_bvh.spv 1 bvh
device: llvmpipe (LLVM 23.1.5, 128 bits) (subgroup 4..4)          <- lavapipe, as asked

# B: same, plus an inherited single-device filter
VK_LOADER_DRIVERS_SELECT='*lvp*' LEONIDA_VK_DEVICE='Apple M3 Pro' vk_compute_test …
LEONIDA_VK_DEVICE=apple m3 pro: no Vulkan physical device matches  <- the run dies

So the inherited filter does not merely override VK_LOADER_DRIVERS_SELECT: because the loader has already hidden the named device, the device pick finds nothing and the process exits before benchmarking. env.pop("LEONIDA_VK_DEVICE", None) turns a hard "no Vulkan physical device matches" into the configuration that was actually requested, which is exactly right. Good that the PR is worded as "ignore the inherited filter" rather than "prefer the selector" — the observed failure is a rejection, not a preference.

Scope check, and the one place to keep an eye on

build() (scripts/bench_wave64.py:30) still inherits LEONIDA_VK_DEVICE. That is safe today because it always sets LEONIDA_W64_EMULATE explicitly, and wave64_settings returns immediately for "on"/"off" without calling runtime_gpu_info() — so no device probing happens during translation. If build() ever gains an auto-detect path (e.g. dropping the explicit flag), it will need the same env.pop, and the symptom would be a different shader being translated rather than a visible failure. A one-line comment at build() saying why it is deliberately not popped would keep that from biting later.

The test's assertion that os.environ still holds LEONIDA_VK_DEVICE after run() is the right second half: it pins that only the subprocess copy is modified, so the filter is not silently unset for the rest of the benchmark run.

Unrelated to this diff, for anyone running it on a Mac: all three CONFIGS are AMD/NVIDIA selectors, so on this host each one correctly reports no matching device. The change is exercised by the unit test, not by the benchmark here.

No functional issues found.

No game files. AI-assisted.

@garuspl

garuspl commented Nov 23, 2026

Copy link
Copy Markdown

Tested 6517591 on Windows 11 (CPU only, no GPU needed): pass

Windows 11 Pro, Python 3.14.7, no GPU or game files involved; pytest/numpy/Pillow pinned from tests/requirements.txt in a fresh venv. Method: PR head merged onto main 867d922, the PR's test files run with python -m pytest before and after the merge, plus python -m compileall -q on the changed files (clean).

  • tests/test_bench_wave64.py: main 10 passed, 6 subtests passed; with the PR 11 passed, 9 subtests passed.

AI-assisted (Claude Code, Claude Opus 5.5).

@comtek21516

Copy link
Copy Markdown

Tested 651759141 merged onto main at 867d922f0 on Quadro RTX 4000 (Turing, subgroup 32..32), NVIDIA 615.71.09, Ubuntu 22.04.5 (kernel 5.15), g++ 13.4, llvm-mc 21.1.8, Vulkan SDK 1.4.363.1, Python 3.12.16: pass for what one NVIDIA GPU can show.

Not run: scripts/bench_wave64.py itself. Its AMD configurations need an AMD device, and with one driver the inherited filter and VK_LOADER_DRIVERS_SELECT cannot disagree, so this machine cannot reproduce the case the change is for. No game files. AI-assisted (Claude Code).

@lordra9-svg

Copy link
Copy Markdown

Independent check of 65175914175e86836dc9ab459490d3931c56d6c4 (PR head), Linux (Bazzite 45), Python 3.15.2, RADV Mesa 26.3.1, Vulkan 1.4.363, llvm-mc 23.1.6. Three Vulkan devices: AMD Radeon RX 7800 XT (RADV NAVI32, gfx1101), Ryzen 7 7700 iGPU (RADV RAPHAEL_MENDOCINO) and llvmpipe (CPU). So the single-device filter is a real filter here, and this is the Linux loader path the Windows report did not cover.

Unit tests — python3 -I tests/test_bench_wave64.py: 11 tests, OK (including the new test_configured_driver_does_not_inherit_the_single_device_filter).

Live run — inherited LEONIDA_VK_DEVICE="5070 Ti" (a device that does not exist here, so it can only exclude everything), --groups 4096 --reps 3 --procs 1:

PR head:

AMD native                 AMD Radeon RX 7800 XT (RADV NAVI32) median    0.112 ms   best 0.109
AMD --wave64-emulate       AMD Radeon RX 7800 XT (RADV NAVI32) median    0.113 ms   best 0.113
reference output hash: a8a855ac (AMD native)

Both AMD configurations run, the emulated output hash equals the native one, and the parent's LEONIDA_VK_DEVICE is irrelevant to them.

Same command with main 867d922f0's scripts/bench_wave64.py:

AMD native: failed or unsupported: exit 1: LEONIDA_VK_DEVICE=5070 ti: no Vulkan physical device matches
AMD --wave64-emulate: failed or unsupported: exit 1: LEONIDA_VK_DEVICE=5070 ti: no Vulkan physical device matches
no reference output from AMD native: cannot compare

So the new environment handling is what makes the AMD comparison survive an inherited filter, and the change is a no-op when no filter is set.

NVIDIA --wave64-emulate fails in both trees with vkCreateInstance -> -9 because this machine has no NVIDIA ICD; that is the expected result, not a regression.

Synthetic cs_bench_mix only; no game files. AI-assisted (OpenCode).

@Pablo-Barros

Copy link
Copy Markdown

Tested 651759141 (base 867d922f0) on a two-GPU machine, Windows 11 build 26300, Python 3.12.10: pass.

GPUs: NVIDIA GeForce RTX 3070 (driver 32.0.16.1088, Vulkan 1.4.341, subgroups 32..32) and AMD Radeon(TM) Graphics, the Ryzen 7 7800X3D's iGPU (driver 32.0.21042.62, Vulkan 1.4.315, subgroups 32..64). MSVC 19.44, Vulkan SDK 1.4.363, vk_compute_test built from this head.

  • python -I tests/test_bench_wave64.py: 11 tests OK.
  • This head, with LEONIDA_VK_DEVICE=3070 set in the caller's environment: python -I scripts/bench_wave64.py --groups 1 --reps 2 --procs 1 takes AMD Radeon(TM) Graphics for AMD native and for AMD --wave64-emulate, the RTX 3070 for NVIDIA --wave64-emulate, and prints emulated output equals the reference.
  • main 867d922f0, same programs and same environment: both AMD configurations fail with LEONIDA_VK_DEVICE=3070: no Vulkan physical device matches, and it prints no reference output from AMD native: cannot compare (exit 1). Without the variable it runs and gives the same reference hash as this head, ade6bdc3.

The timings are not worth reading: another job was using the RTX 3070 during the runs. Synthetic shaders only, no game data.

AI-assisted (ZCode).

@THEMANnt

Copy link
Copy Markdown
Author

The update at d5633bb1 addresses the dual-AMD regression. A driver configuration keeps a matching LEONIDA_VK_DEVICE. If its first attempt reports the exact no-match error, that configuration prints a fallback notice and uses the driver default for the remaining processes. Other errors still fail, and the overall comparison fails if no configuration completes with the requested filter.

All 13 benchmark tests passed, including a simulated discrete/integrated AMD pair. A Windows Vulkan test ran all three configurations with a prebuilt synthetic cs_w32_permute module on AMD Radeon Graphics (32.0.21030.2001) and an RTX 5070 Ti (32.0.16.1692). Both valid device filters gave matching output hashes and fallback only on the opposite vendor. The nonexistent device filter exited 1. AI-assisted.

@OlaiFG7

OlaiFG7 commented Nov 23, 2026

Copy link
Copy Markdown

Reviewed 6517591, code read (CPU), AI-assisted: the new test fails on main and passes here, so it tests the claim. Ran python -I tests/test_bench_wave64.py: pass (11); with only scripts/bench_wave64.py reverted to main the new test fails (3). I agree with slint6614-dev's dual-AMD finding: popping LEONIDA_VK_DEVICE unconditionally at bench_wave64.py:59 removes the user's ability to choose between two AMD GPUs, because the benchmark then always takes the loader's first AMD device. Please drop the variable only when it names a device that VK_LOADER_DRIVERS_SELECT excludes (or at least not when the user set it explicitly), and add a test for the kept case.

@OlaiFG7

OlaiFG7 commented Nov 23, 2026

Copy link
Copy Markdown

Correction to my review above: it was written against the earlier head 6517591. The current head d5633bb ("Preserve matching Vulkan device filters in the benchmark") already addresses the dual-AMD concern: LEONIDA_VK_DEVICE is kept, a configuration whose driver cannot see that GPU falls back to the default device and says so, and the run fails if no configuration completed using the filter. Please disregard my request to keep the variable. I have not re-run the tests on the new head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants