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

Merged
leonida/mandy
quietfold merged 1 commit from fix/bvh-tri-probe-compare-and-io into main 2026-11-28 10:45:28 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 04:07:42 +00:00

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)

## 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)
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 04:07:57 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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.
GeorgiyDemo commented 2026-11-25 04:20:08 +00:00

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.

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.
MoonEyes commented 2026-11-28 10:45:24 +00:00

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.