From 346117c243ff42d9db567ad0875c46747d2f6f30 Mon Sep 17 00:00:00 2001 From: syfyra <258908070+syfyra@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:33:44 +0100 Subject: [PATCH] tools: gpu_results.py reads the GPU test records into one overview (GPU-RESULTS-OVERVIEW) gpu-test-results/ holds 46 records and 35 open pull requests add more, but nothing reads them: which fixtures fail on which GPUs and drivers is only in their prose, and the hand-written table in docs/gpu_test_results.md lists 11 runs. tools/gpu_results.py parses the `Key: value` fields the records share and prints a row per record (GPU, driver, how far its commit is behind main, the native and the wave64-emulated run as passed/total with skips and failures, the failed fixtures), then each failing fixture with the records and vendors it fails on, where it was last seen failing and how many records at newer commits no longer list it. --markdown prints the record table for a document, --json everything, and --check names a record that lacks GPU, Driver, OS or Commit. gpu-test-results/README.md states the format the records use. The test file also reads the repository's own records, so one that lacks a required field fails there. Co-Authored-By: Claude Fable 5.2 --- gpu-test-results/README.md | 37 ++++ tests/test_gpu_results.py | 354 ++++++++++++++++++++++++++++++++++++ tools/gpu_results.py | 355 +++++++++++++++++++++++++++++++++++++ 3 files changed, 746 insertions(+) create mode 100644 gpu-test-results/README.md create mode 100644 tests/test_gpu_results.py create mode 100644 tools/gpu_results.py diff --git a/gpu-test-results/README.md b/gpu-test-results/README.md new file mode 100644 index 0000000000..a9baac40a0 --- /dev/null +++ b/gpu-test-results/README.md @@ -0,0 +1,37 @@ +# GPU test records + +One text file per GPU, driver and run of the GPU tests. [docs/testing.md](../docs/testing.md) has how to run them and +what to post; a record is a pull request that adds a file here. + +## Format + +A record is a list of fields. A field starts in the first column as `Key:` and continues on indented lines. The +files here are the examples; these are the fields `tools/gpu_results.py` reads: + +| Field | What goes in it | +|---|---| +| `GPU:` | Vendor and model, then the family in parentheses: `NVIDIA GeForce RTX 4070 (Ada / AD104, PCI 10de:2786)` | +| `Driver:` | Driver and version first, the rest after a comma: `RADV (Mesa 26.3.1), Vulkan 1.4.363` | +| `Subgroup:` | The device's subgroup range: `32..64` | +| `OS:` | System and version | +| `Commit:` | The commit that was built, as a hash | +| `Tools:` | llvm-mc, SPIRV-Tools, compiler, CMake and Python versions | +| `run_gpu_tests.py:` | One line per run with what it printed: `native: 197/248 passed, 49 skipped, 2 failed` and `LEONIDA_W64_EMULATE=1: 229/248 passed, 17 skipped, 2 failed` | +| `Failed:` | `none`, or the failed fixtures first and then what was read: `cs_a, cs_b (both runs): got 2071, want 71`. A further fixture starts a line of its own: `ps_c: ...` | +| `Skipped:` | Why the skipped ones were skipped | +| `Notes:` | Anything else, as `- ` lines; say here if it was AI-assisted | + +Other fields (`build.py:`, `check.py:`, `ctest:`, `CPU:`, `RAM:` and so on) are kept as written. A run of a few +selected tests says so, as docs/testing.md asks. + +## Overview of all records + +```sh +python -I tools/gpu_results.py # every record, each failing fixture and where it fails +python -I tools/gpu_results.py --check gpu-test-results/MyGPU.txt # does a new record have the fields? +python -I tools/gpu_results.py --markdown # the record table for a document +``` + +The overview lists each record's native and wave64-emulated counts, each failing fixture with the records and +vendors it fails on, and how many records taken at newer commits no longer list it: many records name failures +that `main` has fixed since. diff --git a/tests/test_gpu_results.py b/tests/test_gpu_results.py new file mode 100644 index 0000000000..b9f2952380 --- /dev/null +++ b/tests/test_gpu_results.py @@ -0,0 +1,354 @@ +"""tools/gpu_results.py on synthetic GPU test records, and on the repository's own (no GPU, no game data). + + python -I tests/test_gpu_results.py + +The synthetic records use the layouts the files in gpu-test-results/ use, with invented devices and numbers. +""" +import contextlib +import io +import json +import os +import subprocess +import sys +import tempfile +import unittest +from unittest import mock + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, os.path.join(ROOT, "tools")) + +import gpu_results # noqa: E402 + +FULL = """\ +GPU: NVIDIA GeForce RTX 9990 (Zeta / ZT104, PCI 10de:ffff), subgroup 32..32 +Driver: NVIDIA 700.10 (proprietary, Windows), Vulkan SDK 1.4.400.0 (loader and tools) +Subgroup: 32..32 (the run_gpu_tests.py device line shows subgroup 32..32) +OS: Windows 11 Pro 10.0.30000 (en-GB) +Commit: 0123456789abcdef0123456789abcdef01234567 (main, 2026-11-24) +Tools: llvm-mc 23.1.6 (conda llvm-tools with the AMDGPU target), SPIRV-Tools v2026.4, + CMake 3.31.6 + Ninja, Python 3.13.6 +run_gpu_tests.py: 257 shaders: 257 translated, 257 pass spirv-val + native: 197/248 passed, 49 skipped, 2 failed + LEONIDA_W64_EMULATE=1: 229/248 passed, 17 skipped, 2 failed +Failed: cs_alpha, cs_beta_d16 (exit 1, native and emulated alike). These are the same + two that fail on another card, where the cause is known; + cs_gamma and cs_delta pass with the fix applied. +Skipped: native: 31 "no 64-wide compute subgroup on this device" and 16 delegated cases. +Notes: +- Built with scripts\\build_runtime.ps1 at the commit above. +- AI-assisted. No game files, nothing online. +""" + + +def record(gpu="AMD Radeon RX 1 (RDNA9 / GFX9999, Navi 99)", driver="RADV (Mesa 30.1.2-arch1), Vulkan 1.5.1", + commit="aaaaaaa (main)", runs="native: 10/12 passed, 2 skipped, 0 failed", failed="none", extra=""): + return (f"GPU: {gpu}\nDriver: {driver}\nOS: Arch Linux, kernel 9.9\n" + f"Commit: {commit}\nrun_gpu_tests.py: 20 shaders: 20 translated\n {runs}\n" + f"Failed: {failed}\n{extra}") + + +class RecordsCase(unittest.TestCase): + def setUp(self): + td = tempfile.TemporaryDirectory(prefix="leonida gpu_results ") + self.addCleanup(td.cleanup) + self.dir = td.name + + def write(self, name, text, folder=None): + path = os.path.join(folder or self.dir, name) + with open(path, "w", encoding="utf-8", newline="\n") as f: + f.write(text) + return path + + def parse(self, text, name="R.txt"): + return gpu_results.parse_record(self.write(name, text)) + + def run_tool(self, *args): + out, err = io.StringIO(), io.StringIO() + with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err): + code = gpu_results.main(list(args)) + return code, out.getvalue(), err.getvalue() + + +class ParseTest(RecordsCase): + def test_a_full_record(self): + r = self.parse(FULL, "RTX9990.txt") + self.assertEqual((r["file"], r["gpu"], r["family"], r["vendor"]), + ("RTX9990.txt", "NVIDIA GeForce RTX 9990", "Zeta", "NVIDIA")) + self.assertEqual((r["driver"], r["os"]), ("NVIDIA 700.10", "Windows 11 Pro 10.0.30000")) + self.assertEqual((r["commit"], r["subgroup"]), ("0123456789abcdef0123456789abcdef01234567", [32, 32])) + self.assertEqual(r["runs"], [ + {"mode": "native", "label": "native", "passed": 197, "total": 248, "skipped": 49, "failed": 2}, + {"mode": "emulated", "label": "LEONIDA_W64_EMULATE=1", "passed": 229, "total": 248, "skipped": 17, + "failed": 2}]) + # The wrapped sentence that starts with cs_gamma names fixtures that pass. + self.assertEqual(r["failed"], ["cs_alpha", "cs_beta_d16"]) + self.assertEqual((r["problems"], r["notes"]), ([], [])) + self.assertNotIn("path", r, "a report must not carry the folder it was read from") + + def test_fields_start_in_the_first_column_and_continue_until_the_next(self): + fields = gpu_results.parse_fields( + "GPU: one\n two\n\n three\nNot a field, just prose with a colon later: here\n" + "Driver:\n indented: not a field\nrun_gpu_tests.py (native): 1/1 passed\n- bullet: no\nOS: last\n") + self.assertEqual(fields, [ + ("GPU", "one\ntwo\n\nthree\nNot a field, just prose with a colon later: here"), + ("Driver", "indented: not a field"), ("run_gpu_tests.py (native)", "1/1 passed\n- bullet: no"), + ("OS", "last")]) + self.assertEqual(gpu_results.parse_fields("prose before any field\n"), []) + + def test_names_are_shortened_without_losing_the_version(self): + for driver, want in (("RADV (Mesa 30.1.2-arch1), Vulkan 1.5.1", "RADV (Mesa 30.1.2-arch1)"), + ("AMD proprietary 26.11.2 (LLPC, driverVersion 2.0.416),\n Vulkan 1.4", "AMD proprietary 26.11.2"), + ("MoltenVK 1.4.2 (Homebrew bottle), Vulkan 1.4.357", "MoltenVK 1.4.2"), + # A comma inside the parenthesis does not end the name. + ("ANV (Mesa 30.2.7, LLVM 30), Vulkan 1.5", "ANV (Mesa 30.2.7, LLVM 30)"), + ("llvmpipe", "llvmpipe")): + self.assertEqual(self.parse(record(driver=driver))["driver"], want) + # Only the first line of a field is its name. + r = self.parse("GPU: AMD W\n second line of the GPU field\nDriver: d 1\nOS: Linux Mint 30\n" + " kernel 9.1 and more\nCommit: abcdef0\n") + self.assertEqual((r["gpu"], r["os"]), ("AMD W", "Linux Mint 30")) + for gpu, name, family, vendor in ( + ("AMD Radeon Graphics, Ryzen 5 0000X iGPU (RDNA9, gfx9999), subgroup 32..64", + "AMD Radeon Graphics, Ryzen 5 0000X iGPU", "RDNA9", "AMD"), + ("Intel Graphics (Meteor Lake-P, Xe-LPG, integrated)", "Intel Graphics", "Meteor Lake-P", "Intel"), + ("Apple M9 (Apple GPU, 12 cores)", "Apple M9", "Apple GPU", "Apple"), + ("GeForce GTX 1, subgroup 32", "GeForce GTX 1", "", "NVIDIA"), + ("none - Mesa llvmpipe (LLVM 19.1.7)", "none - Mesa llvmpipe", "LLVM 19.1.7", "software"), + ("Imagination BXM-8-256", "Imagination BXM-8-256", "", "other")): + r = self.parse(record(gpu=gpu)) + self.assertEqual((r["gpu"], r["family"], r["vendor"]), (name, family, vendor)) + self.assertEqual(self.parse(record(gpu="AMD X (RDNA9), subgroup 32..64"))["subgroup"], [32, 64]) + self.assertIsNone(self.parse(record())["subgroup"]) + + def test_runs_are_labelled_by_what_stands_before_or_after_the_counts(self): + def runs(text): + return [(run["mode"], run["passed"], run["total"], run["skipped"], run["failed"]) + for run in self.parse(record(runs=text))["runs"]] + + self.assertEqual(runs("228/248 passed, 16 skipped, 4 failed"), [("native", 228, 248, 16, 4)]) + self.assertEqual(runs("183/248 passed, 61 skipped, 4 failed\n 214/248 passed, 30 skipped, 4 failed " + "(LEONIDA_W64_EMULATE=1)"), + [("native", 183, 248, 61, 4), ("emulated", 214, 248, 30, 4)]) + self.assertEqual(runs("218/235 passed, 16 skipped, 1 failed (native and LEONIDA_W64_EMULATE=1 alike)"), + [("native", 218, 235, 16, 1), ("emulated", 218, 235, 16, 1)]) + self.assertEqual(runs("Native: 198/249 passed, 49 skipped, 2 failed (exit 1).\n" + " LEONIDA_W64_EMULATE=1: 97/97 passed"), + [("native", 198, 249, 49, 2), ("emulated", 97, 97, None, None)]) + self.assertEqual(runs("81/97 passed, 16 skipped, 0 failed (exit 0)"), [("native", 81, 97, 16, 0)]) + # A run of another kind keeps its own label and is neither the native nor the emulated run. + self.assertEqual(runs("Native + validation: 202/263 passed, 53 skipped, 8 failed\n" + " LEONIDA_W64_EMULATE=1 --filter cs_ (as CI): 93/121 passed, 28 skipped, 0 failed"), + [("Native + validation", 202, 263, 53, 8), + ("LEONIDA_W64_EMULATE=1 --filter cs_ (as CI)", 93, 121, 28, 0)]) + self.assertEqual(runs("257 shaders: 257 translated, 257 pass spirv-val"), []) + + def test_a_run_can_be_named_in_the_field_itself(self): + r = self.parse("GPU: AMD Y\nDriver: d 1\nOS: o\nCommit: abcdef0\n" + "run_gpu_tests.py (native): 258/258 translated and pass spirv-val; " + "231/249 passed, 16 skipped, 2 failed\n" + "run_gpu_tests.py (LEONIDA_W64_EMULATE=1): 258/258 translated; 230/249 passed, 16 skipped, 3 failed\n") + self.assertEqual([(run["mode"], run["passed"], run["failed"]) for run in r["runs"]], + [("native", 231, 2), ("emulated", 230, 3)]) + + def test_failed_fixtures_are_the_ones_the_field_opens_with_or_gives_a_line_of_their_own(self): + def failed(text): + return self.parse(record(failed=text))["failed"] + + for nothing in ("none", "None.", "none, in either run. cs_alpha and cs_beta pass on this commit.", "", + "none. What the earlier record listed:\n cs_alpha: passes since the fix"): + self.assertEqual(failed(nothing), []) + self.assertEqual(failed("cs_alpha and cs_beta, in every run: \"64 bad\", the expected 71 plus 2000."), ["cs_alpha", "cs_beta"]) + self.assertEqual(failed("ms_clip, ms_wave_s3: the harness exits without a result. The other four\n" + " (ms_tri, ms_pack) pass.\n" + " ms_v5 and ms_ballot) pass, and the extension is enabled."), ["ms_clip", "ms_wave_s3"]) + self.assertEqual(failed("cs_one: got 8192, want 7682\n cs_two: got 8224\n" + " The fixtures of another fix, not on main yet.\n" + " cs_three (both modes): exit 1.\n ps_four and vs_five: flake\n" + " cs_one: listed twice"), + ["cs_one", "cs_two", "cs_three", "ps_four", "vs_five"]) + self.assertEqual(failed("cs_ext in all four profiles:\n 6 of 64 words differ"), ["cs_ext"]) + self.assertEqual(failed("- gs_tri: wrong winding"), ["gs_tri"]) + # Not a fixture name: no stage prefix, or prose first. + self.assertEqual(failed("two fixtures, cs_alpha and cs_beta"), []) + self.assertEqual(failed("d3d12_execute_indirect_validation: 5 cases"), []) + + def test_what_a_record_lacks_is_a_problem_and_what_could_not_be_read_a_note(self): + r = self.parse("GPU: AMD Z\nOS: o\nCommit: the tip of main\nNotes:\n- nothing else\n") + self.assertEqual(r["problems"], ["no Driver field", "the Commit field has no commit hash"]) + self.assertEqual(r["notes"], ["no run_gpu_tests.py line with `N/M passed`"]) + self.assertEqual((r["commit"], r["runs"], r["failed"]), (None, [], [])) + r = self.parse(record(runs="native: 1/9 passed, 0 skipped, 8 failed", failed="cs_only: bad")) + self.assertEqual((r["problems"], r["notes"]), ([], ["8 failed in a run, 1 fixture name(s) read from Failed"])) + self.assertEqual(self.parse("")["problems"], [f"no {key} field" for key in ("GPU", "Driver", "OS", "Commit")]) + # A field that is there but empty is as good as missing. + self.assertEqual(self.parse("GPU: AMD Z\nDriver:\nOS: o\nCommit: abcdef0\n")["problems"], ["no Driver field"]) + + def test_the_first_field_of_a_name_is_the_records(self): + # A record can quote another one further down; the header block comes first. + r = self.parse(record(gpu="AMD First (RDNA9)", commit="abcdef0") + + "Notes:\n- compared with\nGPU: NVIDIA Second (Zeta)\nCommit: 1234567\n") + self.assertEqual((r["gpu"], r["vendor"], r["commit"]), ("AMD First", "AMD", "abcdef0")) + + +class OverviewTest(RecordsCase): + def three(self): + self.write("A.txt", record(gpu="NVIDIA A (Zeta)", commit="1111111", failed="cs_x, cs_a: bad", + runs="native: 8/12 passed, 2 skipped, 2 failed")) + self.write("B.txt", record(gpu="AMD B (RDNA9)", commit="2222222", failed="cs_x: bad", + runs="native: 9/12 passed, 2 skipped, 1 failed")) + self.write("C.txt", record(gpu="NVIDIA C (Zeta)", commit="3333333")) + self.write("README.md", "# not a record\n") + return [gpu_results.parse_record(p) for p in gpu_results.find_records([self.dir])] + + def test_fixtures_are_listed_with_the_records_and_vendors_they_fail_on(self): + report = gpu_results.overview(self.three(), None) + self.assertEqual([r["file"] for r in report["records"]], ["A.txt", "B.txt", "C.txt"]) + self.assertEqual(report["vendors"], {"NVIDIA": 2, "AMD": 1}) + # The fixture that fails most often comes first, not the first of the alphabet. + self.assertEqual(report["fixtures"], [ + {"fixture": "cs_x", "records": ["A.txt", "B.txt"], "vendors": {"NVIDIA": 1, "AMD": 1}, + "last_behind": None, "last_record": None, "newer_without": None}, + {"fixture": "cs_a", "records": ["A.txt"], "vendors": {"NVIDIA": 1}, + "last_behind": None, "last_record": None, "newer_without": None}]) + + def test_newer_records_that_no_longer_list_a_fixture_are_counted(self): + records = self.three() + for r, behind in zip(records, (40, 12, 3)): + r["behind"] = behind + records.append({**records[2], "file": "D.txt", "behind": 0, "runs": []}) # no run: says nothing + records.append({**records[2], "file": "E.txt", "behind": None}) # commit unknown here + records.append({**records[2], "file": "F.txt", "behind": 12}) # as old as B: not newer + by = {e["fixture"]: e for e in gpu_results.fixtures(records)} + self.assertEqual((by["cs_x"]["last_record"], by["cs_x"]["last_behind"], by["cs_x"]["newer_without"]), + ("B.txt", 12, 1)) + self.assertEqual((by["cs_a"]["last_record"], by["cs_a"]["last_behind"], by["cs_a"]["newer_without"]), + ("A.txt", 40, 3)) + + def test_commit_distances_come_from_git(self): + repo = os.path.join(self.dir, "repo") + os.mkdir(repo) + env = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")} + env.update({"GIT_CONFIG_GLOBAL": os.devnull, "GIT_CONFIG_NOSYSTEM": "1"}) + + def git(*args): + r = subprocess.run(["git", "-c", "user.name=Test", "-c", "user.email=test@example.invalid", + "-c", "commit.gpgsign=false", "-C", repo, *args], capture_output=True, encoding="utf-8", + env=env) + self.assertEqual(r.returncode, 0, r.stderr) + return r.stdout.strip() + + git("init", "-q", "-b", "main") + shas = [] + for n in range(4): + git("commit", "-q", "--allow-empty", "-m", f"commit {n}") + shas.append(git("rev-parse", "HEAD")) + records = [{"commit": shas[0], "behind": None}, {"commit": shas[2][:9], "behind": None}, + {"commit": shas[3], "behind": None}, {"commit": "fffffff", "behind": None}, + {"commit": None, "behind": None}] + with mock.patch.dict(os.environ, env, clear=True): + self.assertTrue(gpu_results.commits_behind(records, "main", repo=repo)) + self.assertEqual([r["behind"] for r in records], [3, 1, 0, None, None]) + self.assertFalse(gpu_results.commits_behind(records, "no-such-branch", repo=repo)) + self.assertFalse(gpu_results.commits_behind(records, "main", repo=self.dir)) + + +class CommandLineTest(RecordsCase): + def setUp(self): + super().setUp() + self.write("RTX9990.txt", FULL) + self.write("Vega.txt", record(failed="cs_alpha: bad", runs="native: 11/12 passed, 0 skipped, 1 failed")) + self.write("notes.md", "GPU: not a record\n") + + def test_text_report(self): + code, out, err = self.run_tool(self.dir, "--no-git") + self.assertEqual((code, err), (0, "")) + self.assertIn("2 record(s): NVIDIA 1, AMD 1\n", out) + self.assertNotIn("behind:", out) + lines = out.splitlines() + header = next(i for i, line in enumerate(lines) if line.startswith("record")) + self.assertEqual(lines[header].split(), ["record", "GPU", "driver", "behind", "native", "emulated", "failed"]) + # Rows go by vendor, then GPU: AMD before NVIDIA, whatever the files are called. Columns line up. + self.assertRegex(lines[header + 1], r"^Vega\.txt +AMD Radeon RX 1 \(RDNA9\) +RADV \(Mesa 30\.1\.2-arch1\) +\? +" + r"11/12 0s 1f +- +cs_alpha$") + self.assertRegex(lines[header + 2], r"^RTX9990\.txt +NVIDIA GeForce RTX 9990 \(Zeta\) +NVIDIA 700\.10 +\? +" + r"197/248 49s 2f +229/248 17s 2f +cs_alpha, cs_beta_d16$") + self.assertEqual(lines[header + 1].index("11/12"), lines[header].index("native")) + self.assertIn("\nFixtures that fail\n cs_alpha: 2 record(s), NVIDIA 1, AMD 1\n RTX9990.txt, Vega.txt\n" + " cs_beta_d16: 1 record(s), NVIDIA 1\n RTX9990.txt\n", out) + self.assertNotIn("Other runs", out) + self.assertNotIn("Not read in full", out) + self.assertNotIn(self.dir, out) + + def test_other_runs_and_unread_records_are_named(self): + self.write("C.txt", record(runs="Native + validation: 5/9 passed, 1 skipped, 3 failed", failed="cs_q: bad")) + self.write("D.txt", "GPU: Intel D\nDriver: ANV 1\nOS: o\nCommit: abcdef1\n") + out = self.run_tool(self.dir, "--no-git")[1] + self.assertIn("\nOther runs\n C.txt: Native + validation: 5/9 1s 3f\n", out) + self.assertIn("\nNot read in full\n C.txt: 3 failed in a run, 1 fixture name(s) read from Failed\n" + " D.txt: no run_gpu_tests.py line with `N/M passed`\n", out) + + def test_markdown_table(self): + self.write("P.txt", record(gpu="AMD P|Q (RDNA9)", failed="none")) + code, out, _ = self.run_tool(self.dir, "--markdown", "--no-git", "--folder-url", "records/") + self.assertEqual(code, 0) + lines = out.splitlines() + self.assertEqual(lines[:2], ["| Record | GPU | Driver | OS | Commit | Native | Emulated | Failed |", + "|---|---|---|---|---|---|---|---|"]) + self.assertIn("| [P.txt](records/P.txt) | AMD P\\|Q (RDNA9) | RADV (Mesa 30.1.2-arch1) | Arch Linux | `aaaaaaa` | " + "10/12 2s 0f | - | none |", lines) + self.assertIn("| [RTX9990.txt](records/RTX9990.txt) | NVIDIA GeForce RTX 9990 (Zeta) | NVIDIA 700.10 | " + "Windows 11 Pro 10.0.30000 | `012345678` | 197/248 49s 2f | 229/248 17s 2f | `cs_alpha`, `cs_beta_d16` |", lines) + self.assertEqual(len(lines), 5) + self.assertIn("](../gpu-test-results/P.txt)", self.run_tool(self.dir, "--markdown", "--no-git")[1]) + + def test_json_is_the_whole_report_without_local_paths(self): + code, out, _ = self.run_tool(self.dir, "--json", "--no-git") + report = json.loads(out) + self.assertEqual((code, sorted(report), report["main"]), (0, ["fixtures", "main", "records", "vendors"], None)) + self.assertEqual([r["file"] for r in report["records"]], ["RTX9990.txt", "Vega.txt"]) + self.assertEqual(report["fixtures"][0]["fixture"], "cs_alpha") + self.assertNotIn(os.path.basename(self.dir), out) + + def test_check_names_the_records_to_fix_and_exits_1(self): + code, out, _ = self.run_tool(self.dir, "--check") + self.assertEqual((code, out), (0, "2 record(s) checked, 0 to fix\n")) + bad = self.write("Bad.txt", "GPU: AMD Bad\nDriver: d\nCommit: soon\nrun_gpu_tests.py: 1/1 passed\n") + self.write("Thin.txt", "GPU: AMD Thin\nDriver: d\nOS: o\nCommit: abcdef1\n") + code, out, _ = self.run_tool(self.dir, "--check") + self.assertEqual(code, 1) + self.assertEqual(out, "Bad.txt: no OS field\nBad.txt: the Commit field has no commit hash\n" + "Thin.txt: note: no run_gpu_tests.py line with `N/M passed`\n4 record(s) checked, 1 to fix\n") + # One file can be checked alone, as for a pull request that adds it. + self.assertEqual(self.run_tool(bad, "--check")[0], 1) + self.assertEqual(self.run_tool(os.path.join(self.dir, "Vega.txt"), "--check"), (0, "1 record(s) checked, 0 to fix\n", "")) + + def test_a_missing_target_is_a_usage_error(self): + code, out, err = self.run_tool(os.path.join(self.dir, "nowhere")) + self.assertEqual((code, out), (2, "")) + self.assertIn("gpu_results: ", err) + self.assertIn("no such record or folder", err) + with self.assertRaises(SystemExit) as stop, contextlib.redirect_stderr(io.StringIO()): + gpu_results.main([self.dir, "--json", "--check"]) + self.assertEqual(stop.exception.code, 2) + + +class RepositoryRecordsTest(unittest.TestCase): + def test_every_record_in_the_repository_has_the_required_fields(self): + paths = gpu_results.find_records([gpu_results.DEFAULT_FOLDER]) + self.assertGreater(len(paths), 40) + for path in paths: + record_ = gpu_results.parse_record(path) + with self.subTest(record=record_["file"]): + self.assertEqual(record_["problems"], [], "gpu-test-results/README.md has the fields a record needs") + self.assertTrue(record_["gpu"] and record_["driver"] and record_["os"] and record_["commit"]) + + def test_the_default_folder_is_the_repositorys(self): + out, err = io.StringIO(), io.StringIO() + with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err): + code = gpu_results.main(["--check"]) + self.assertEqual((code, err.getvalue()), (0, "")) + self.assertRegex(out.getvalue(), r"\d+ record\(s\) checked, 0 to fix\n$") + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/gpu_results.py b/tools/gpu_results.py new file mode 100644 index 0000000000..7d73ee5dfa --- /dev/null +++ b/tools/gpu_results.py @@ -0,0 +1,355 @@ +"""One overview of the GPU test records in gpu-test-results/: what ran where, and which fixtures fail on what. + + python -I tools/gpu_results.py [RECORD_OR_FOLDER ...] [--markdown | --json | --check] [--main REF | --no-git] + +A record is a text file of `Key: value` fields, each starting in the first column and continued by indented +lines (gpu-test-results/README.md has the fields). Nothing else reads them, so which fixtures fail on which GPUs +and drivers is only in their prose. This reads every record (the repository's folder when none is named) and +prints: + +- a row per record: GPU, driver, how far its commit is behind `--main`, the native and the wave64-emulated run of + `run_gpu_tests.py` as passed/total with skips and failures, and the fixtures it lists as failed; +- each failing fixture with the records and vendors it fails on. A fixture that fails across vendors points at + the fixture or the translator, one that fails on a single driver at that driver. With git at hand it also says + where it was last seen failing and how many records taken at newer commits do not list it, since many records + name failures that `main` has fixed since; +- the records it could not count, and why. + +`--markdown` prints the record table for a document, `--json` everything as one object. `--check` only verifies +the records: it names each one that lacks GPU, Driver, OS or Commit, or whose Commit has no hash, and exits 1 when +there is one, which is the check for a pull request that adds a record. + +What is read from the prose is a convention, not a grammar: a run is a line with `N/M passed`, labelled by what +stands before it (`native:`, `LEONIDA_W64_EMULATE=1:`) or after it in parentheses; a failed fixture is a fixture +name (`cs_`, `ps_`, `vs_`, `ms_`, `gs_`...) that a line of the `Failed:` field starts with, alone or as a list. +A record that words these differently is still shown, with what could be read. + +Exit 0, or 1 when `--check` finds a record to fix, 2 on a usage error. Reads the records and asks git for commit +distances; writes nothing. Standard library only; no game files. +""" +import argparse +import json +import os +import re +import subprocess +import sys +import textwrap +from collections import Counter + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +DEFAULT_FOLDER = os.path.join(ROOT, "gpu-test-results") +REQUIRED = ("GPU", "Driver", "OS", "Commit") +# A key has no comma: a sentence that happens to hold a colon is not a field. +FIELD = re.compile(r"^([A-Za-z][^:,\n]{0,60}?):(?:[ \t]+|$)") +COUNTS = re.compile(r"(\d+)\s*/\s*(\d+)\s+passed(?:\s*,\s*(\d+)\s+skipped)?(?:\s*,\s*(\d+)\s+failed)?") +FIXTURE = r"(?:cs|ps|vs|ms|gs|hs|ds)_[a-z0-9_]+" +FAILED_LEAD = re.compile(rf"^(?:[-*]\s+)?({FIXTURE}(?:\s*(?:,|/|&|and|,\s*and)\s*{FIXTURE})*)") +ENTRY_END = re.compile(r"\s*(?:\([^)]*\))?\s*:") +HASH = re.compile(r"\b[0-9a-f]{7,40}\b") +VENDORS = (("NVIDIA", ("nvidia", "geforce", "quadro", "tesla")), ("AMD", ("amd", "radeon")), + ("Intel", ("intel",)), ("Apple", ("apple",)), ("software", ("llvmpipe", "lavapipe", "swiftshader"))) + + +def parse_fields(text): + """[(key, value)] in file order. A field starts in the first column; indented lines, blank lines and lines + that are no field continue the one before.""" + fields = [] + for line in text.splitlines(): + m = FIELD.match(line) + if m: + fields.append([m.group(1).strip(), line[m.end():].strip()]) + elif fields: + fields[-1][1] += "\n" + line.strip() + return [(key, value.strip()) for key, value in fields] + + +def outside_parentheses(text, stop=","): + """`text` up to the first `stop` that is not inside parentheses.""" + depth = 0 + for i, ch in enumerate(text): + if ch == "(": + depth += 1 + elif ch == ")": + depth = max(0, depth - 1) + elif ch == stop and depth == 0: + return text[:i] + return text + + +def short(text, keep_parenthesis_without_digit=False): + """The first line of a field without its trailing detail: `NVIDIA 617.42 (proprietary), Vulkan ...` -> + `NVIDIA 617.42`. A driver named without a version keeps its parenthesis: `RADV (Mesa 26.3.1)`.""" + head = outside_parentheses(text.split("\n", 1)[0]).strip() + name, paren, rest = head.partition(" (") + if paren and keep_parenthesis_without_digit and not any(ch.isdigit() for ch in name): + return f"{name} ({rest.split(')', 1)[0]})" + return name.strip() + + +def gpu_name(text): + """`NVIDIA GeForce RTX 4070 (Ada / AD104, PCI ...), subgroup 32..32` -> (`NVIDIA GeForce RTX 4070`, `Ada`).""" + head = text.split("\n", 1)[0] + name, paren, rest = head.partition(" (") + family = re.split(r"[,/)]", rest, maxsplit=1)[0].strip() if paren else "" + return outside_parentheses(name).strip() if not paren else name.strip(), family + + +def vendor_of(gpu): + low = gpu.lower() + for vendor, words in VENDORS: + if any(word in low for word in words): + return vendor + return "other" + + +def mode_of(label): + """native, emulated, both (one line for the two runs) or the label itself for any other run.""" + low = label.lower() + emulated = "w64_emulate" in low or "emulated" in low + native = re.search(r"\bnative\b", low) is not None + if emulated and native: + return "both" + if emulated: + return "emulated" if re.fullmatch(r"\W*(leonida_w64_emulate=1|emulated)\W*", low) else label + if native: + return "native" if re.fullmatch(r"\W*native\W*", low) else label + return "native" if not label else label + + +def parse_runs(fields): + """The run_gpu_tests.py runs of a record: [{mode, label, passed, total, skipped, failed}].""" + runs = [] + for key, value in fields: + if not key.startswith("run_gpu_tests.py"): + continue + key_label = key[len("run_gpu_tests.py"):].strip(" ()") + for line in value.splitlines(): + m = COUNTS.search(line) + if not m: + continue + before = line[:m.start()].split(";")[-1].strip().rstrip(":").strip() + after = re.match(r"\s*[.;]?\s*\(([^)]*)\)", line[m.end():]) + label = before or key_label or (after.group(1).strip() if after else "") + if after and not before and not key_label and mode_of(label) not in ("native", "emulated", "both"): + label = "" # a remark in parentheses, such as "(exit 1)", is not the name of a run + run = {"label": label, "passed": int(m.group(1)), "total": int(m.group(2)), + "skipped": None if m.group(3) is None else int(m.group(3)), + "failed": None if m.group(4) is None else int(m.group(4))} + mode = mode_of(label) + for one in (("native", "emulated") if mode == "both" else (mode,)): + runs.append({"mode": one, **run}) + return runs + + +def parse_failed(fields): + """The fixtures the Failed field names. The field opens with them (`cs_a, cs_b (both modes): ...`); a later + line adds more only as an entry of its own, `ps_c: ...` or `ps_c (native): ...`, because a wrapped sentence + can start with a fixture that passes (`cs_d and cs_e pass with #N applied`).""" + names = [] + for key, value in fields: + if key != "Failed" or value.lower().startswith("none"): + continue + for number, line in enumerate(value.splitlines()): + line = line.strip() + m = FAILED_LEAD.match(line) + if not m or (number and not ENTRY_END.match(line[m.end():])): + continue + for name in re.findall(FIXTURE, m.group(1)): + if name not in names: + names.append(name) + return names + + +def parse_record(path): + with open(path, encoding="utf-8", errors="replace") as f: + fields = parse_fields(f.read()) + first = {} + for key, value in fields: + first.setdefault(key, value) + gpu, family = gpu_name(first.get("GPU", "")) + commit = HASH.search(first.get("Commit", "")) + subgroup = re.search(r"(\d+)\s*\.\.\s*(\d+)", first.get("Subgroup", "") + "\n" + first.get("GPU", "")) + runs = parse_runs(fields) + record = { + "file": os.path.basename(path), + "gpu": gpu, "family": family, "vendor": vendor_of(first.get("GPU", "")), + "driver": short(first.get("Driver", ""), keep_parenthesis_without_digit=True), + "os": short(first.get("OS", "")), + "commit": commit.group(0) if commit else None, "behind": None, + "subgroup": [int(subgroup.group(1)), int(subgroup.group(2))] if subgroup else None, + "runs": runs, "failed": parse_failed(fields), + "problems": [f"no {key} field" for key in REQUIRED if not first.get(key)], + "notes": [], + } + if first.get("Commit") and not commit: + record["problems"].append("the Commit field has no commit hash") + if not runs: + record["notes"].append("no run_gpu_tests.py line with `N/M passed`") + most = max((run["failed"] or 0 for run in runs), default=0) + if most and len(record["failed"]) < most: + record["notes"].append(f"{most} failed in a run, {len(record['failed'])} fixture name(s) read from Failed") + return record + + +def find_records(targets): + paths = [] + for target in targets: + if os.path.isdir(target): + paths += [os.path.join(target, name) for name in sorted(os.listdir(target)) + if name.lower().endswith(".txt")] + elif os.path.isfile(target): + paths.append(target) + else: + raise OSError(f"{target}: no such record or folder") + return paths + + +def commits_behind(records, main, repo=ROOT): + """Fill `behind`: how many commits on `main` a record's commit lacks. Left None where git cannot tell.""" + def git(*args): + try: + r = subprocess.run(["git", "-C", repo, *args], capture_output=True, text=True, encoding="utf-8", + errors="replace") + except OSError: + return None + return r.stdout.strip() if r.returncode == 0 else None + + if git("rev-parse", "--verify", "--quiet", f"{main}^{{commit}}") is None: + return False + for record in records: + if record["commit"]: # a hash this repository does not have leaves it None: rev-list fails + count = git("rev-list", "--count", f"{record['commit']}..{main}") + record["behind"] = int(count) if count and count.isdigit() else None + return True + + +def run_of(record, mode): + return next((run for run in record["runs"] if run["mode"] == mode), None) + + +def fixtures(records): + """Each failing fixture: the records that list it, by vendor, and what newer records say.""" + counted = [r for r in records if r["runs"]] + table = [] + for name in sorted({name for r in records for name in r["failed"]}): + on = [r for r in records if name in r["failed"]] + aged = [r["behind"] for r in on if r["behind"] is not None] + entry = {"fixture": name, "records": [r["file"] for r in on], + "vendors": dict(Counter(r["vendor"] for r in on).most_common()), + "last_behind": min(aged) if aged else None, "last_record": None, "newer_without": None} + if aged: + entry["last_record"] = next(r["file"] for r in on if r["behind"] == entry["last_behind"]) + # Strictly newer than the newest record that lists it, so none of these lists it. + entry["newer_without"] = sum(1 for r in counted if r["behind"] is not None + and r["behind"] < entry["last_behind"]) + table.append(entry) + return sorted(table, key=lambda e: (-len(e["records"]), e["fixture"])) + + +def overview(records, main): + return {"records": records, "main": main, + "vendors": dict(Counter(r["vendor"] for r in records).most_common()), + "fixtures": fixtures(records)} + + +def show_run(run): + if not run: + return "-" + return (f"{run['passed']}/{run['total']}" + ("" if run["skipped"] is None else f" {run['skipped']}s") + + ("" if run["failed"] is None else f" {run['failed']}f")) + + +def print_text(report): + records = report["records"] + print(f"{len(records)} record(s): " + ", ".join(f"{v} {n}" for v, n in report["vendors"].items())) + if report["main"]: + print(f"behind: commits of {report['main']} that the record's commit does not have; ? when git cannot tell") + print("runs: passed/total, s skipped, f failed\n") + rows = [("record", "GPU", "driver", "behind", "native", "emulated", "failed")] + for r in sorted(records, key=lambda r: (r["vendor"], r["gpu"], r["file"])): + rows.append((r["file"], r["gpu"] + (f" ({r['family']})" if r["family"] else ""), r["driver"], + "?" if r["behind"] is None else str(r["behind"]), show_run(run_of(r, "native")), + show_run(run_of(r, "emulated")), ", ".join(r["failed"]) or "-")) + widths = [max(len(row[i]) for row in rows) for i in range(len(rows[0]) - 1)] + for row in rows: + print(" ".join(cell.ljust(width) for cell, width in zip(row, widths)) + " " + row[-1]) + if report["fixtures"]: + print("\nFixtures that fail") + for e in report["fixtures"]: + line = (f" {e['fixture']}: {len(e['records'])} record(s), " + + ", ".join(f"{vendor} {n}" for vendor, n in e["vendors"].items())) + if e["last_behind"] is not None: + line += (f"; last in {e['last_record']} ({e['last_behind']} behind), " + f"{e['newer_without']} newer record(s) do not list it") + print(line) + print(textwrap.fill(", ".join(e["records"]), width=110, initial_indent=" ", subsequent_indent=" ", + break_long_words=False, break_on_hyphens=False)) + other = [(r["file"], run) for r in records for run in r["runs"] if run["mode"] not in ("native", "emulated")] + if other: + print("\nOther runs") + for name, run in other: + print(f" {name}: {run['label']}: {show_run(run)}") + noted = [(r["file"], text) for r in records for text in r["problems"] + r["notes"]] + if noted: + print("\nNot read in full") + for name, text in noted: + print(f" {name}: {text}") + + +def print_markdown(report, folder_url): + print("| Record | GPU | Driver | OS | Commit | Native | Emulated | Failed |") + print("|---|---|---|---|---|---|---|---|") + cell = lambda text: text.replace("|", "\\|") # noqa: E731 + for r in sorted(report["records"], key=lambda r: (r["vendor"], r["gpu"], r["file"])): + print("| " + " | ".join(( + f"[{cell(r['file'])}]({folder_url}/{r['file']})", + cell(r["gpu"] + (f" ({r['family']})" if r["family"] else "")), cell(r["driver"]), cell(r["os"]), + f"`{r['commit'][:9]}`" if r["commit"] else "?", show_run(run_of(r, "native")), + show_run(run_of(r, "emulated")), ", ".join(f"`{name}`" for name in r["failed"]) or "none")) + " |") + + +def main(argv=None): + ap = argparse.ArgumentParser(description=__doc__.strip().splitlines()[0]) + ap.add_argument("targets", nargs="*", metavar="RECORD_OR_FOLDER", + help="records or folders of *.txt records (default: the repository's gpu-test-results)") + form = ap.add_mutually_exclusive_group() + form.add_argument("--markdown", action="store_true", help="the record table as Markdown") + form.add_argument("--json", action="store_true", help="everything as one JSON object") + form.add_argument("--check", action="store_true", + help="only verify the records; exit 1 when one lacks a required field") + ap.add_argument("--main", default="origin/main", help="the branch commit distances are measured to (origin/main)") + ap.add_argument("--no-git", action="store_true", help="do not ask git how far behind each record's commit is") + ap.add_argument("--folder-url", default="../gpu-test-results", + help="link prefix of the records in --markdown (default ../gpu-test-results, as seen from docs/)") + args = ap.parse_args(argv) + try: + records = [parse_record(path) for path in find_records(args.targets or [DEFAULT_FOLDER])] + except OSError as e: + print(f"gpu_results: {e}", file=sys.stderr) + return 2 + if args.check: + bad = [(r["file"], text) for r in records for text in r["problems"]] + for name, text in bad: + print(f"{name}: {text}") + for r in records: + for text in r["notes"]: + print(f"{r['file']}: note: {text}") + print(f"{len(records)} record(s) checked, {len({name for name, _ in bad})} to fix") + return 1 if bad else 0 + measured = not args.no_git and commits_behind(records, args.main) + report = overview(records, args.main if measured else None) + if args.json: + print(json.dumps(report, indent=2)) + elif args.markdown: + print_markdown(report, args.folder_url.rstrip("/")) + else: + print_text(report) + return 0 + + +if __name__ == "__main__": + try: + sys.stdout.reconfigure(errors="replace") + except (AttributeError, ValueError, OSError): + pass + sys.exit(main())