scripts: measure the translator (us per instruction) and compare two tools/ trees #54

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

@⁠Andretuta on GitHub · 2026-11-24 02:08 UTC · original
ubiquitarianism:old-pr/9776 → main · +436 −0 · 2 files · 5 commits · draft

Carried over from old PR 9776 by pes7 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9776, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
pes7: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Nothing in this repository measures how long the translator takes. This adds the number — and a way to compare two versions of tools/rdna2spirv.py on the same machine, which is what every performance claim needs.

A build translates 26,503 shaders. A change to the parser, the operand splitter or the instruction table can cost a large share of that build and still pass every test, spirv-val included. There is no test that would notice.

What it adds

file what
scripts/bench_translate.py µs per instruction on the repository's own hand-written fixtures and on two generated programs (ALU work vs s_nop dispatch, so a slower parser and a slower code generator can be told apart); --json; --max-slowdown F against a baseline; --write-baseline FILE / --baseline FILE so the comparison is against the machine in front of you, not against somebody else's CPU; --compare A B times two tools/ trees interleaved (alternating order, warm-up round dropped, best of N per side)
tests/test_bench_translate.py 10 tests: the report structure, the limit in both output formats, the baseline round-trip, --compare ratios, the refusals, the partial baseline

No game data, no LLVM, no SPIRV-Tools. Inputs are the repository's own fixtures plus generated listings.

What it already measured on main

input instructions µs/instruction
corpus, 52 semantic fixtures 4,475 55 (dominated by the ~1.7 ms fixed cost of a small program)
synthetic ALU 2,004 32
synthetic s_nop 2,004 14

So ~44% of the per-instruction cost is line parsing and dispatch, not code generation, and scaling is linear from 204 to 16,004 instructions. That is the kind of thing this repository could not answer before, in one run.

The calibration that makes --compare trustworthy: identical trees give 1.01x / 1.00x / 0.99x. A harness that cannot read "no change" cannot be used to claim a change.

Review already applied

Three independent reviewers ran it; all their findings are fixed and covered by tests: --json used to skip the slowdown check, --compare ignored --max-slowdown, a partial baseline raised KeyError, the flag combinations were silently ignored, a failing run could overwrite the baseline it failed against, and --compare would happily compare two trees whose measurements cover different programs.

cc @ItsNotRexed @KoertLichtendonk

Checklist

  • 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. (Not applicable: no translator change.)
**@⁠Andretuta** on GitHub · 2026-11-24 02:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/54) `ubiquitarianism:old-pr/9776` → `main` · +436 −0 · 2 files · 5 commits · draft > Carried over from **old PR 9776** by `pes7` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9776`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `pes7`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): **Nothing in this repository measures how long the translator takes.** This adds the number — and a way to compare two versions of `tools/rdna2spirv.py` on the same machine, which is what every performance claim needs. A build translates 26,503 shaders. A change to the parser, the operand splitter or the instruction table can cost a large share of that build and still pass every test, `spirv-val` included. There is no test that would notice. ### What it adds | file | what | |---|---| | `scripts/bench_translate.py` | µs per instruction on the repository's own hand-written fixtures and on two generated programs (ALU work vs `s_nop` dispatch, so a slower parser and a slower code generator can be told apart); `--json`; `--max-slowdown F` against a baseline; `--write-baseline FILE` / `--baseline FILE` so the comparison is against the machine in front of you, not against somebody else's CPU; `--compare A B` times two `tools/` trees **interleaved** (alternating order, warm-up round dropped, best of N per side) | | `tests/test_bench_translate.py` | 10 tests: the report structure, the limit in both output formats, the baseline round-trip, `--compare` ratios, the refusals, the partial baseline | No game data, no LLVM, no SPIRV-Tools. Inputs are the repository's own fixtures plus generated listings. ### What it already measured on `main` | input | instructions | µs/instruction | |---|---|---| | corpus, 52 semantic fixtures | 4,475 | 55 (dominated by the ~1.7 ms fixed cost of a small program) | | synthetic ALU | 2,004 | 32 | | synthetic `s_nop` | 2,004 | 14 | So ~44% of the per-instruction cost is line parsing and dispatch, not code generation, and scaling is linear from 204 to 16,004 instructions. That is the kind of thing this repository could not answer before, in one run. The calibration that makes `--compare` trustworthy: identical trees give **1.01x / 1.00x / 0.99x**. A harness that cannot read "no change" cannot be used to claim a change. ### Review already applied Three independent reviewers ran it; all their findings are fixed and covered by tests: `--json` used to skip the slowdown check, `--compare` ignored `--max-slowdown`, a partial baseline raised `KeyError`, the flag combinations were silently ignored, a failing run could overwrite the baseline it failed against, and `--compare` would happily compare two trees whose measurements cover different programs. cc `@ItsNotRexed` `@KoertLichtendonk` ### Checklist - [x] 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`. (Not applicable: no translator change.)
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 08:42:29 +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/54/head:github-bot/gh-54'
git switch 'github-bot/gh-54'

Merge

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