[PR #1653] sdwa_diff: guard asm.family() oracle leak, validate oracle/CLI/reference inputs, and restore KNOWN #1666

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1653
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/sdwa-diff-oracle-cli-and-ref


📝 Commits (1)

  • 1d155fe sdwa_diff: handle unknown hw arch without oracle leak, validate oracle results/CLI/ref, and restore KNOWN

📊 Changes

2 files changed (+163 additions, -8 deletions)

View changed files

📝 tests/test_sdwa_diff.py (+107 -0)
📝 tools/sdwa_diff.py (+56 -8)

📄 Description

Item ID: SDWA-DIFF-ORACLE-CLI-AND-REF
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155622653

Summary

  • Oracle arch validation without leak (tools/sdwa_diff.py): catch ValueError from asm.family(oracle.arch) (e.g. gfx900 or unsupported arch strings), close oracle, print hardware oracle unavailable: ..., and return exit 77 instead of crashing and leaking the oracle handle.
  • Module state restoration: restore module-global KNOWN in main()'s finally block (and handle --list-ops/--self-test before mutating it) so in-process calls do not permanently leak KNOWN = True.
  • Hardware oracle & shrink guards: validate oracle is not None, exact result-list length in hw_prepare(), and 4-word tuples/lists in _diff() (turning short/malformed oracle or shrink responses into clean RuntimeError -> exit 2 instead of AttributeError/IndexError). Catch transient Skip during the final shrunk recheck and fall back to the original failure detail.
  • CLI validation: reject empty/whitespace --hw-arch, --build, and --work.
  • Reference validation: raise RefError on unknown SDWA selectors (src*_sel/dst_sel), unknown dst_unused modes (previously fell through silently to UNUSED_PAD), wrong operand counts, non-VGPR destinations, and unparseable operands.
  • Tests (tests/test_sdwa_diff.py): add 5 regression tests covering all of the above.

Verification

  • python3 -W error -I tests/test_sdwa_diff.py -v: 27 passed, 0 failed (2.469s).
  • Mutation check against unpatched main: ran=27, failures=4, errors=6.
  • python3 -m compileall -q tools/sdwa_diff.py tests/test_sdwa_diff.py, python3 -I tests/test_text_write_line_endings.py, python3 -I scripts/check_no_game_data.py: all pass.

AI-assisted: yes
GPUs tested: none (CPU unit tests with stubbed hardware oracle and spirv_mini_interp; no game data)


🔄 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/1653 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/sdwa-diff-oracle-cli-and-ref` --- ### 📝 Commits (1) - [`1d155fe`](https://github.com/ubiquitarianism/leonida/commit/1d155fe33807e97a7a5229db494ddb5e61630530) sdwa_diff: handle unknown hw arch without oracle leak, validate oracle results/CLI/ref, and restore KNOWN ### 📊 Changes **2 files changed** (+163 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_sdwa_diff.py` (+107 -0) 📝 `tools/sdwa_diff.py` (+56 -8) </details> ### 📄 Description Item ID: `SDWA-DIFF-ORACLE-CLI-AND-REF` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155622653 ## Summary - **Oracle arch validation without leak (`tools/sdwa_diff.py`)**: catch `ValueError` from `asm.family(oracle.arch)` (e.g. `gfx900` or unsupported arch strings), close `oracle`, print `hardware oracle unavailable: ...`, and return exit `77` instead of crashing and leaking the oracle handle. - **Module state restoration**: restore module-global `KNOWN` in `main()`'s `finally` block (and handle `--list-ops`/`--self-test` before mutating it) so in-process calls do not permanently leak `KNOWN = True`. - **Hardware oracle & shrink guards**: validate `oracle is not None`, exact result-list length in `hw_prepare()`, and 4-word tuples/lists in `_diff()` (turning short/malformed oracle or shrink responses into clean `RuntimeError` -> exit `2` instead of `AttributeError`/`IndexError`). Catch transient `Skip` during the final shrunk recheck and fall back to the original failure detail. - **CLI validation**: reject empty/whitespace `--hw-arch`, `--build`, and `--work`. - **Reference validation**: raise `RefError` on unknown SDWA selectors (`src*_sel`/`dst_sel`), unknown `dst_unused` modes (previously fell through silently to `UNUSED_PAD`), wrong operand counts, non-VGPR destinations, and unparseable operands. - **Tests (`tests/test_sdwa_diff.py`)**: add 5 regression tests covering all of the above. ## Verification - `python3 -W error -I tests/test_sdwa_diff.py -v`: **27 passed, 0 failed** (2.469s). - Mutation check against unpatched `main`: **ran=27, failures=4, errors=6**. - `python3 -m compileall -q tools/sdwa_diff.py tests/test_sdwa_diff.py`, `python3 -I tests/test_text_write_line_endings.py`, `python3 -I scripts/check_no_game_data.py`: all pass. AI-assisted: yes GPUs tested: none (CPU unit tests with stubbed hardware oracle and `spirv_mini_interp`; no game data) --- <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#1666
No description provided.