tools/rdna2spirv: balance --shard by file size and fail fast on stat error (OLD-9779) #1261

Open
github-bot wants to merge 2 commits from github-bot/gh-1261 into main AGit
Owner

@⁠ambroseautomation on GitHub · 2026-11-24 21:01 UTC · original
ambroseautomation:carry/old-9779-shard-size-balance → main · +115 −3 · 2 files · 2 commits · open

Claimed in the coordination issue as: OLD-9779 (#14)

What and why

Carries forward old-pr/9779 (draft #57, original commit author pes7 preserved across both commits; indexed in #17), rebased cleanly onto current main (0b45fdc21).

Replaces round-robin files[index::count] sharding in tools/rdna2spirv.py with deterministic size-balanced greedy bucketing (shard_bucket()):

  • Sorts input .asm files largest-first by os.path.getsize and assigns each to the lightest bucket so far, then returns the requested shard's bucket in name order — reducing parallel shader-stage makespan on skewed shader corpora while producing byte-identical output and requiring no inter-process coordination.
  • Fails fast with the failing file path if os.path.getsize raises OSError instead of silently substituting weight 0 (which could cause two shards to disagree on the partition and produce duplicates/holes on merge).
  • Adds tests/test_rdna2spirv_shard.py covering partition completeness/disjointness, cross-process determinism, single-shard passthrough, skewed-corpus balance vs. round-robin, and fail-fast behavior on unreadable file sizes.

Tested

  • python -I tests/test_rdna2spirv_shard.py -v: 5 tests, OK.
  • python -m compileall -q make_game.py tools tests: exit 0.
  • python -I tools/rdna2spirv.py --help: exit 0.
  • python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/test_rdna2spirv_shard.py: exit 0 (no game data).

GPUs tested: n/a (CLI sharding logic + stdlib unit tests on Windows 11 Pro 64-bit, Python 3.12.10)

AI-assisted: yes

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 — CLI sharding only, no codegen changes)
**@⁠ambroseautomation** on GitHub · 2026-11-24 21:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1261) `ambroseautomation:carry/old-9779-shard-size-balance` → `main` · +115 −3 · 2 files · 2 commits · open Claimed in the coordination issue as: OLD-9779 (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why Carries forward `old-pr/9779` (draft #57, original commit author `pes7` preserved across both commits; indexed in #17), rebased cleanly onto current `main` (`0b45fdc21`). Replaces round-robin `files[index::count]` sharding in `tools/rdna2spirv.py` with deterministic size-balanced greedy bucketing (`shard_bucket()`): - Sorts input `.asm` files largest-first by `os.path.getsize` and assigns each to the lightest bucket so far, then returns the requested shard's bucket in name order — reducing parallel shader-stage makespan on skewed shader corpora while producing byte-identical output and requiring no inter-process coordination. - Fails fast with the failing file path if `os.path.getsize` raises `OSError` instead of silently substituting weight 0 (which could cause two shards to disagree on the partition and produce duplicates/holes on merge). - Adds `tests/test_rdna2spirv_shard.py` covering partition completeness/disjointness, cross-process determinism, single-shard passthrough, skewed-corpus balance vs. round-robin, and fail-fast behavior on unreadable file sizes. ### Tested - `python -I tests/test_rdna2spirv_shard.py -v`: 5 tests, OK. - `python -m compileall -q make_game.py tools tests`: exit 0. - `python -I tools/rdna2spirv.py --help`: exit 0. - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/test_rdna2spirv_shard.py`: exit 0 (no game data). GPUs tested: n/a (CLI sharding logic + stdlib unit tests on Windows 11 Pro 64-bit, Python 3.12.10) AI-assisted: yes ### 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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — CLI sharding only, no codegen changes)
files[index::count] balanced nothing. Shaders differ in size by two orders of magnitude, so a round-robin split can
hand one shard most of the work while every other process waits for it, and the stage is as slow as its heaviest
shard.

shard_bucket() sorts by file size (largest first) and gives each file to the lightest bucket so far, then a shard
takes its own bucket. Every shard computes the same partition from the same directory listing, so the processes still
do not talk to each other, and each bucket is handed out in name order.

Measured on a synthetic corpus shaped like the real one (96 shaders of 200 instructions, 16 of 2,000, 6 of 12,000;
largest 10% of the total; per-file time measured, then makespan over the buckets):

    shards   round-robin   shard_bucket   gain
         2         2.15s          2.15s   1.00x
         4         1.28s          1.09s   1.17x
         8         0.65s          0.55s   1.18x
        16         0.53s          0.42s   1.26x

The corpus is synthetic: what the real skew is has to be measured with game data, which is why the change keeps the
interface (--shard i/n) and the fallback (a file whose size cannot be read is scheduled, with weight 0) intact.

tests/test_rdna2spirv_shard.py checks the partition (disjoint, complete, deterministic, name order within a bucket),
that a skewed listing beats round-robin at every shard count, and that an unreadable file is not dropped.
Reported by @Zhenyettta on #7479: with a weight of 0 for an unreadable file, two shards can take the same shader while
another one falls out of every bucket, and the merge then publishes a set with a duplicate and a hole.

Every shard derives the partition alone from the same listing, so the one thing that must not happen is a shard
placing a file by a number the others do not have. The size lookup now raises with the path and the advice to run the
shard again; a transient failure becomes a retry instead of a silently wrong set.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:44:54 +00:00
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 06:27 UTC · original · approved these changes

Approving. Merged into current main (42537e7) with no conflicts. tests/test_rdna2spirv_shard.py passes (5 passed), and the full translator suite gives 487 files / 6,279 tests with only test_int32_to_f64 failing, as on main here (Linux, Python 3.13).

The partition is deterministic: largest first, ties broken by path, each file to the lightest bucket with ties broken by index. So every shard derives the same buckets and together they cover each file exactly once. Refusing on an unreadable size, rather than weighting it 0, is the right call for the reason the comment gives.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-25 06:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1261#pullrequestreview-6052823944) · **approved these changes** Approving. Merged into current main (42537e7) with no conflicts. `tests/test_rdna2spirv_shard.py` passes (5 passed), and the full translator suite gives 487 files / 6,279 tests with only `test_int32_to_f64` failing, as on main here (Linux, Python 3.13). The partition is deterministic: largest first, ties broken by path, each file to the lightest bucket with ties broken by index. So every shard derives the same buckets and together they cover each file exactly once. Refusing on an unreadable size, rather than weighting it 0, is the right call for the reason the comment gives. AI-assisted (Claude).
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 14:39 UTC · original

Reviewed daf7362: ran tests/test_rdna2spirv_shard.py (5/5; errors on main without shard_bucket),
tests/test_rdna2spirv_cli.py (36, 2 skipped: no SPIRV-Tools here) and tests/test_rdna2spirv_merge.py
(30) on both trees, plus probes: the buckets partition exactly, agree across listing orders and
balance where files[i::n] did not (60 KB alone vs 60 KB plus tail at n=4); a 4-shard CLI run with
--merge publishes the full set on both trees; an unreadable size stops every shard before anything
is published, and the first commit's weight-0 guess, reproduced, would have published 6 duplicated

  • 1 missing. No finding. Nits if you want them: the OSError reaches the user as a traceback rather
    than the file's ERROR + exit-2 convention, and one unreadable file now stops all shards. AI-assisted
    review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 14:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1261#issuecomment-7165621895) Reviewed daf7362: ran tests/test_rdna2spirv_shard.py (5/5; errors on main without shard_bucket), tests/test_rdna2spirv_cli.py (36, 2 skipped: no SPIRV-Tools here) and tests/test_rdna2spirv_merge.py (30) on both trees, plus probes: the buckets partition exactly, agree across listing orders and balance where files[i::n] did not (60 KB alone vs 60 KB plus tail at n=4); a 4-shard CLI run with --merge publishes the full set on both trees; an unreadable size stops every shard before anything is published, and the first commit's weight-0 guess, reproduced, would have published 6 duplicated + 1 missing. No finding. Nits if you want them: the OSError reaches the user as a traceback rather than the file's ERROR + exit-2 convention, and one unreadable file now stops all shards. AI-assisted review. **Recommendation:** Merge
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/1261/head:github-bot/gh-1261'
git switch 'github-bot/gh-1261'

Merge

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