OLD-9776: scripts: measure the translator (us per instruction) and compare two tools/ trees #1770

Open
github-bot wants to merge 5 commits from github-bot/gh-1770 into main AGit
Owner

@⁠potatoe0100 on GitHub · 2026-11-25 11:47 UTC · original
potatoe0100:carry/old-9776 → main · +436 −0 · 2 files · 5 commits · open

Claimed in the coordination issue as: OLD-9776 (#1608)

What and why

Carries on old PR 9776 by @⁠pes7 (draft #54, branch old-pr/9776, listed in #17), rebased on current main with the author's five commits kept.

The tests check what tools/rdna2spirv.py emits but nothing about how long it takes, so a change to the parser or the instruction table can slow a full shader build a lot and still pass. scripts/bench_translate.py times translate() on the hand-written semantic fixtures and on two generated straight-line programs (ALU work and s_nop dispatch), reports best-of-N microseconds per instruction, can compare two tools/ trees with interleaved timing (--compare A B), prints JSON, and can fail on --max-slowdown. Standard library only; no game data, LLVM or SPIRV-Tools. tests/test_bench_translate.py covers the options and error cases. Its baseline numbers are from one machine, so --baseline/--write-baseline let a run use its own.

Tested

  • python -I tests/test_bench_translate.py: 10 tests OK (Linux, Python 3.13; also OK on Windows 11, Python 3.14).
  • python -I scripts/bench_translate.py --runs 1 on current main's translator: runs, 52 fixtures timed, 54 compute/mesh listings skipped as designed (they need an FSSM header). Python 3.13, Linux.
  • python -m compileall -q scripts tests: clean.

GPUs tested: n/a (no GPU code)

AI-assisted: yes (Claude rebased and tested; the change is pes7's)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

**@⁠potatoe0100** on GitHub · 2026-11-25 11:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1770) `potatoe0100:carry/old-9776` → `main` · +436 −0 · 2 files · 5 commits · open Claimed in the coordination issue as: OLD-9776 (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why Carries on old PR 9776 by @⁠pes7 (draft #54, branch `old-pr/9776`, listed in #17), rebased on current `main` with the author's five commits kept. The tests check what `tools/rdna2spirv.py` emits but nothing about how long it takes, so a change to the parser or the instruction table can slow a full shader build a lot and still pass. `scripts/bench_translate.py` times `translate()` on the hand-written semantic fixtures and on two generated straight-line programs (ALU work and `s_nop` dispatch), reports best-of-N microseconds per instruction, can compare two `tools/` trees with interleaved timing (`--compare A B`), prints JSON, and can fail on `--max-slowdown`. Standard library only; no game data, LLVM or SPIRV-Tools. `tests/test_bench_translate.py` covers the options and error cases. Its baseline numbers are from one machine, so `--baseline`/`--write-baseline` let a run use its own. ### Tested - `python -I tests/test_bench_translate.py`: 10 tests OK (Linux, Python 3.13; also OK on Windows 11, Python 3.14). - `python -I scripts/bench_translate.py --runs 1` on current `main`'s translator: runs, 52 fixtures timed, 54 compute/mesh listings skipped as designed (they need an FSSM header). Python 3.13, Linux. - `python -m compileall -q scripts tests`: clean. GPUs tested: n/a (no GPU code) AI-assisted: yes (Claude rebased and tested; the change is pes7's) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The repository tests what rdna2spirv.py emits and nothing about how long it takes, so a change to the parser or
the instruction table can cost a large share of a build (26,503 shaders) and still pass every test.

The script times translate() on the hand-written semantic fixtures and on two generated straight-line programs
(ALU work, s_nop dispatch), reports best-of-N us per instruction against a recorded baseline, prints JSON for
tooling, and can fail a --max-slowdown check. No game data, no LLVM, no SPIRV-Tools.
A single-tree measurement cannot separate a real speedup from the machine drifting between runs: the same code
measured minutes apart moved by 40% here. --compare loads each tree in its own subprocess (LEONIDA_TOOLS_DIR, as
tests/semantic/support.py does), alternates the order every round so whoever runs first does not pay the cold file
cache, discards a warm-up round, and keeps the best per side.

Control: --compare tools tools --rounds 3 --runs 2 gives 1.01x / 1.00x / 0.99x on the three measurements.
Reported on #7056: --json returned before the limit was evaluated, so a job that collects JSON read a success code for
a run whose numbers were all over the limit. The limit is now evaluated once, before either format prints, and the
JSON carries over_limit; both formats return 1.

The committed BASELINE is one machine's numbers, so --max-slowdown against it fails on any other machine with no
regression in it. --write-baseline FILE records this run, --baseline FILE compares against it (JSON reports
baseline_source), and the text output names which baseline it used.

Tests: the limit is checked in both formats (exit 1, over_limit non-empty), and a written baseline round-trips
(exit 0 at 5x, baseline keys equal to measured keys).
Both reported by @YordiLorenzo on #7056. --compare returned 0 whatever the limit said, although the help promises it in
every output format: the ratios are candidate/reference, so the limit now applies to them directly and a measurement
over it exits 1 with the factor printed. A baseline holding only some of the measurements raised KeyError in the text
output: the per-program line reads the baseline with .get() and says so when a measurement has none.

Two regression tests: --compare with --max-slowdown 0.01 over identical trees exits 1, and a corpus-only baseline
still prints every row. 7 tests, OK.
Reported by @SamuelReeder on #7056. --compare ignored --json, --write-baseline and --baseline; a --baseline path that
does not exist was accepted and produced empty numbers; and naming one file for both baseline flags let a run that
failed the limit replace the reference it failed against, so the same workload passed on the retry. All three are now
parser errors, with the reason in the message.

--compare also refuses to compare two trees whose measurements do not cover the same programs (a skipped program read
as a ratio that looks like a win) and reports an empty corpus instead of dividing by nothing.

Tests: the three refusals, an aliased baseline, a missing baseline file.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:04:20 +00:00
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/1770/head:github-bot/gh-1770'
git switch 'github-bot/gh-1770'

Merge

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