bvh_tri_probe: fix skipped-kernel compare/exit, check_kernel stores, and atomic I/O (BVH-TRI-PROBE-COMPARE-CHECK-AND-IO) #1546

Open
github-bot wants to merge 1 commit from github-bot/gh-1546 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 04:07 UTC · original
IlyassRS3:fix/bvh-tri-probe-compare-and-io → main · +206 −25 · 2 files · 1 commits · open

What

Fix comparison, safety-check, architecture-skip, and file-output bugs in tools/bvh_tri_probe.py without changing any kernel assembly lines (PINNED hashes are unchanged):

  1. Skipped hardware kernels vacuously reported as "OK" (compare, main):
    • When run_hw() skips a kernel (e.g., 8192-word lane kernels under Linux DRM's 4096-word limit) and the translator backend is not enabled, vals in compare() is empty, so all(v == want for v in vals) vacuously evaluated to True, marking 448–896 skipped rows "OK" and counting them as matches.
    • Mark rows with no backend results as "SKIP", report skipped counts separately in main()'s summary ({matched} match, {bad} mismatch, {skipped} skipped), and exit 77 when every selected row was skipped.
  2. Safety-checker gaps in check_kernel():
    • Raise ValueError (instead of raw StopIteration) on an empty k.cases list and guard guard < 2 before slicing lines[guard - 2:guard].
    • Validate every global_store* instruction (including implicit offset:0 stores without an offset: suffix), use the instruction's actual byte width (previously s[24:25] hardcoded + 4, missing global_store_dwordx4 overflows past ctl + 16), reject negative offsets (off < 0), and reject unknown store ops/bases with ValueError instead of raw KeyError.
  3. Unsupported GPU architecture skip (main):
    • Catch ValueError from asm.family(oracle.arch) (e.g. gfx900) so --oracle hw prints SKIP: <arch> is not GFX10 (RDNA1/RDNA2) and returns 77 as documented instead of crashing with an uncaught traceback.
  4. CLI validation & atomic LF-only output (write_kernels, main):
    • Validate --write-kernels against empty/whitespace strings and existing non-directory paths with error: ... and exit 2 (previously --write-kernels "" was silently ignored and an existing file raised FileExistsError), and catch (OSError, ValueError) cleanly.
    • Write .s, .json, and --json outputs atomically via a sibling temp file (newline="\n", file_mode.published_mode, replace_retry.replace, allow_nan=False) and terminate per-kernel .json files with "\n".

Claimed in the coordination issue as

BVH-TRI-PROBE-COMPARE-CHECK-AND-IO — verified 0 open PRs and 0 prior claims; unable to post a comment on #14 because GitHub disabled commenting once #14 reached its 2,500-comment cap (and no successor "Coordinating who works on what" issue is open yet).

Testing

  • python3 -I -W error tests/test_bvh_tri_probe.py -v: 22/22 OK (including all 5 PINNED kernel SHA-256 checks and 5 new/extended regression tests).

  • python3 -I tools/bvh_tri_probe.py --self-test: OK (22 kernels, 564 single-lane cases, 2 x 7 lane cases).

  • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.

  • python3 -I scripts/check_no_game_data.py tools/bvh_tri_probe.py tests/test_bvh_tri_probe.py: clean.

  • python3 -m compileall -q tools/bvh_tri_probe.py tests/test_bvh_tri_probe.py: clean.

  • Mutation check against unpatched main:tools/bvh_tri_probe.py: all 6 new/extended tests fail on main (FAILED (failures=3, errors=3)).

  • AI-assisted: yes

  • GPUs tested: none (CPU-only tests with stand-in oracle on macOS; no GPU or game files needed)

**@⁠IlyassRS3** on GitHub · 2026-11-25 04:07 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1546) `IlyassRS3:fix/bvh-tri-probe-compare-and-io` → `main` · +206 −25 · 2 files · 1 commits · open ## What Fix comparison, safety-check, architecture-skip, and file-output bugs in `tools/bvh_tri_probe.py` without changing any kernel assembly lines (`PINNED` hashes are unchanged): 1. **Skipped hardware kernels vacuously reported as `"OK"` (`compare`, `main`)**: - When `run_hw()` skips a kernel (e.g., 8192-word lane kernels under Linux DRM's 4096-word limit) and the translator backend is not enabled, `vals` in `compare()` is empty, so `all(v == want for v in vals)` vacuously evaluated to `True`, marking 448–896 skipped rows `"OK"` and counting them as matches. - Mark rows with no backend results as `"SKIP"`, report skipped counts separately in `main()`'s summary (`{matched} match, {bad} mismatch, {skipped} skipped`), and exit `77` when every selected row was skipped. 2. **Safety-checker gaps in `check_kernel()`**: - Raise `ValueError` (instead of raw `StopIteration`) on an empty `k.cases` list and guard `guard < 2` before slicing `lines[guard - 2:guard]`. - Validate **every** `global_store*` instruction (including implicit `offset:0` stores without an `offset:` suffix), use the instruction's actual byte width (previously `s[24:25]` hardcoded `+ 4`, missing `global_store_dwordx4` overflows past `ctl + 16`), reject negative offsets (`off < 0`), and reject unknown store ops/bases with `ValueError` instead of raw `KeyError`. 3. **Unsupported GPU architecture skip (`main`)**: - Catch `ValueError` from `asm.family(oracle.arch)` (e.g. `gfx900`) so `--oracle hw` prints `SKIP: <arch> is not GFX10 (RDNA1/RDNA2)` and returns `77` as documented instead of crashing with an uncaught traceback. 4. **CLI validation & atomic LF-only output (`write_kernels`, `main`)**: - Validate `--write-kernels` against empty/whitespace strings and existing non-directory paths with `error: ...` and exit `2` (previously `--write-kernels ""` was silently ignored and an existing file raised `FileExistsError`), and catch `(OSError, ValueError)` cleanly. - Write `.s`, `.json`, and `--json` outputs atomically via a sibling temp file (`newline="\n"`, `file_mode.published_mode`, `replace_retry.replace`, `allow_nan=False`) and terminate per-kernel `.json` files with `"\n"`. ## Claimed in the coordination issue as `BVH-TRI-PROBE-COMPARE-CHECK-AND-IO` — verified 0 open PRs and 0 prior claims; unable to post a comment on `#14` because GitHub disabled commenting once `#14` reached its 2,500-comment cap (and no successor `"Coordinating who works on what"` issue is open yet). ## Testing - `python3 -I -W error tests/test_bvh_tri_probe.py -v`: **22/22 OK** (including all 5 `PINNED` kernel SHA-256 checks and 5 new/extended regression tests). - `python3 -I tools/bvh_tri_probe.py --self-test`: OK (`22 kernels, 564 single-lane cases, 2 x 7 lane cases`). - `python3 -I tests/test_text_write_line_endings.py`: **3/3 OK**. - `python3 -I scripts/check_no_game_data.py tools/bvh_tri_probe.py tests/test_bvh_tri_probe.py`: clean. - `python3 -m compileall -q tools/bvh_tri_probe.py tests/test_bvh_tri_probe.py`: clean. - Mutation check against unpatched `main:tools/bvh_tri_probe.py`: all 6 new/extended tests fail on `main` (`FAILED (failures=3, errors=3)`). - AI-assisted: yes - GPUs tested: none (CPU-only tests with stand-in oracle on macOS; no GPU or game files needed)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:56:07 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 04:07 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 04:07 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1546#pullrequestreview-6051722908) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 04:20 UTC · original

Tested 4cc96d172 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main c7e82e26e (Python tool; hardware path not run):

  • pytest 9.2.0 on tests/test_bvh_tri_probe.py: 22 passed, 678 subtests passed at this head (the PINNED kernel hashes are unchanged, as the PR says).
  • The same file on main: 6 failed, 16 passed, 675 subtests — the skipped-kernel compare/exit, write_kernels and atomic JSON-replace tests.
  • Not run: run_hw() on a real AMD GPU (none here), so the hardware-kernel skip path is only covered through the tests' mocks.

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 04:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1546#issuecomment-7152748656) Tested `4cc96d172` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `c7e82e26e` (Python tool; hardware path not run): - pytest 9.2.0 on `tests/test_bvh_tri_probe.py`: **22 passed, 678 subtests passed** at this head (the `PINNED` kernel hashes are unchanged, as the PR says). - The same file on `main`: **6 failed**, 16 passed, 675 subtests — the skipped-kernel compare/exit, `write_kernels` and atomic JSON-replace tests. - Not run: `run_hw()` on a real AMD GPU (none here), so the hardware-kernel skip path is only covered through the tests' mocks. AI-assisted; synthetic fixtures only, no game data.
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/1546/head:github-bot/gh-1546'
git switch 'github-bot/gh-1546'

Merge

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