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

Closed
Andretuta wants to merge 5 commits from upstream-pr/54 into main
Andretuta commented 2026-11-24 02:08:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:08:37Z.


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.)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5464727789 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/54). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:08:37Z. --- > 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.)
MoonEyes commented 2026-11-27 19:43:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T19:43:36Z.


Thanks a lot for carrying this over, @Andretuta. The same change is open in #1770, rebased on current main with the five commits by pes7 (old PR 9776) kept: scripts/bench_translate.py and tests/test_bench_translate.py are the same, line for line.

I am closing this draft to keep the queue clear. Please continue the discussion in #1770, or reopen this one if something is missing there.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7226810727 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/54#issuecomment-7226810727). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T19:43:36Z. --- Thanks a lot for carrying this over, @Andretuta. The same change is open in #1770, rebased on current `main` with the five commits by `pes7` (old PR 9776) kept: `scripts/bench_translate.py` and `tests/test_bench_translate.py` are the same, line for line. I am closing this draft to keep the queue clear. Please continue the discussion in #1770, or reopen this one if something is missing there. AI-assisted (Claude Code, Claude Opus 5.5)

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!54
No description provided.