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

Open
opened 2026-11-26 20:16:49 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/54
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9776


📝 Commits (5)

  • 7528472 scripts: a throughput benchmark for the translator (us per instruction)
  • 9022fe5 scripts: --compare A B, interleaved timing of two tools/ trees
  • 77c47dd bench_translate: honour --max-slowdown in --json too, and let a run save its own baseline
  • 908fe04 bench_translate: --compare honours --max-slowdown, and a partial baseline no longer aborts
  • 99fe480 bench_translate: refuse flag combinations that were silently ignored, and require a baseline that exists

📊 Changes

2 files changed (+436 additions, -0 deletions)

View changed files

➕ scripts/bench_translate.py (+309 -0)
➕ tests/test_bench_translate.py (+127 -0)

📄 Description

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.)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/54 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9776` --- ### 📝 Commits (5) - [`7528472`](https://github.com/ubiquitarianism/leonida/commit/75284723f330b073296e66fd7af30b18253d802b) scripts: a throughput benchmark for the translator (us per instruction) - [`9022fe5`](https://github.com/ubiquitarianism/leonida/commit/9022fe5e07ab9f34b88707969d58414662227894) scripts: --compare A B, interleaved timing of two tools/ trees - [`77c47dd`](https://github.com/ubiquitarianism/leonida/commit/77c47dda66b9ed4e4687397317813ad5abcabb5a) bench_translate: honour --max-slowdown in --json too, and let a run save its own baseline - [`908fe04`](https://github.com/ubiquitarianism/leonida/commit/908fe049fe060fe6b3447fb09a8a64f6e603cb87) bench_translate: --compare honours --max-slowdown, and a partial baseline no longer aborts - [`99fe480`](https://github.com/ubiquitarianism/leonida/commit/99fe4802a5105e2dd0a0beade9bfb5a162045b29) bench_translate: refuse flag combinations that were silently ignored, and require a baseline that exists ### 📊 Changes **2 files changed** (+436 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `scripts/bench_translate.py` (+309 -0) ➕ `tests/test_bench_translate.py` (+127 -0) </details> ### 📄 Description > 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.) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#107
No description provided.