From 4776b052d53ec208b7dc10e88643b1342a9d6a7b Mon Sep 17 00:00:00 2001 From: Luiz Neves Date: Sat, 21 Nov 2026 18:33:55 -0300 Subject: [PATCH] check.py: run cs_w64x_partial at subgroup 32 under wave64 emulation (TEST-20) partial_wave_test always set VKC_SUBGROUP_SIZE=64. With LEONIDA_W64_EMULATE=1 the shader is translated for any subgroup width, and on AMD, where 64 is available, the emulated path was never run at 32 (#166, RX 6700 XT entry). Under emulation it now asks for 32; without emulation it still asks for 64. --- runtime/test/shaders/check.py | 5 +-- tests/test_partial_wave_subgroup.py | 50 +++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 tests/test_partial_wave_subgroup.py diff --git a/runtime/test/shaders/check.py b/runtime/test/shaders/check.py index 75f9a2d50..2dafa26d5 100644 --- a/runtime/test/shaders/check.py +++ b/runtime/test/shaders/check.py @@ -83,12 +83,13 @@ class Skip(str): def partial_wave_test(tools, spirv, name, expected_words): """A group smaller than a wave: run with subgroup size 64 requested (no full subgroups); None if the device - has no 64-wide subgroup (unless LEONIDA_W64_EMULATE=1).""" + has no 64-wide subgroup. With LEONIDA_W64_EMULATE=1 it asks for 32 instead, the width the emulation is for, so + a device that defaults to 64 (AMD) runs the emulated path at 32 too (#166).""" shader = os.path.join(spirv, name + ".spv") if not os.path.isfile(shader): return f"missing {name}.spv" old = os.environ.get("VKC_SUBGROUP_SIZE") - os.environ["VKC_SUBGROUP_SIZE"] = "64" + os.environ["VKC_SUBGROUP_SIZE"] = "32" if W64_EMULATED else "64" try: code, out = run(os.path.join(tools, "vk_compute_test" + EXE), shader, "1", "dump") finally: diff --git a/tests/test_partial_wave_subgroup.py b/tests/test_partial_wave_subgroup.py new file mode 100644 index 000000000..10dab70a3 --- /dev/null +++ b/tests/test_partial_wave_subgroup.py @@ -0,0 +1,50 @@ +"""TEST-20: check.py's partial-wave test asks vk_compute_test for subgroup size 64 natively and for 32 under +LEONIDA_W64_EMULATE=1, so a device that defaults to 64 (AMD) also runs the emulated path at 32.""" +import os +from pathlib import Path +import sys +import tempfile +import unittest +from unittest.mock import patch + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "runtime" / "test" / "shaders")) +import check + +NAME, WANT = check.W64X_PARTIAL[0] + + +class PartialWaveSubgroupSize(unittest.TestCase): + def run_partial(self, emulated, max_subgroup=64): + asked = [] + + def harness(_tool, _shader, *_args): + asked.append(os.environ.get("VKC_SUBGROUP_SIZE")) + return 0, f"device: gpu (subgroup 32..{max_subgroup})\nout[0..7] = " + " ".join(map(str, WANT)) + "\n" + + with tempfile.TemporaryDirectory() as tmp: + (Path(tmp) / f"{NAME}.spv").touch() + with (patch.object(check, "run", side_effect=harness), patch.object(check, "W64_EMULATED", emulated), + patch.dict(os.environ, {"VKC_SUBGROUP_SIZE": "16"})): + result = check.partial_wave_test(tmp, tmp, NAME, WANT) + restored = os.environ.get("VKC_SUBGROUP_SIZE") + return result, asked, restored + + def test_native_asks_for_64(self): + result, asked, restored = self.run_partial(emulated=False) + self.assertEqual((result, asked, restored), ("", ["64"], "16")) + + def test_emulated_asks_for_32(self): + result, asked, restored = self.run_partial(emulated=True) + self.assertEqual((result, asked, restored), ("", ["32"], "16")) + + def test_emulated_runs_on_a_32_wide_device(self): + result, asked, _ = self.run_partial(emulated=True, max_subgroup=32) + self.assertEqual((result, asked), ("", ["32"])) + + def test_native_skips_without_64_wide_subgroups(self): + result, _, _ = self.run_partial(emulated=False, max_subgroup=32) + self.assertIsNone(result) + + +if __name__ == "__main__": + unittest.main()