feat(tools): add a hardware oracle for RDNA instruction semantics #871

Merged
adriadam10 merged 1 commit from upstream-pr/871 into main 2026-10-06 20:11:26 +00:00
adriadam10 commented 2026-10-06 11:54:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T11:54:43Z.


What

The hardware oracle proposed in #843: tools/hw-oracle/ runs a body of RDNA assembly on a local AMD GPU, one input row per lane, and prints the 16 output dwords of each lane. It is meant for measuring instruction semantics before implementing them and for pinning measured rows in tests/execution/. Usage, kernel ABI and limits are in docs/dev/HW_ORACLE.md.

  • oracle.c loads a code object through the ROCm HSA runtime and dispatches it on /dev/kfd. oracle --target prints the GPU's gfx name.
  • template.s is the kernel wrapper: v4-v7 hold the inputs and v10-v25 are stored. It works in wave32 and wave64, gives 4 KiB of LDS, and takes the FLOAT_MODE (IEEE, f32/f16 denormals) per run.
  • hw_oracle.py builds the oracle once, assembles the body for the detected target with clang + ld.lld, and runs it. It works from the command line or as run(body, rows, ...) from Python.

It isn't tied to a distribution. The runtime comes from ROCM_PATH, /opt/rocm or the system paths (libhsa-runtime-dev, rocm-runtime-devel, hsa-rocr), and the target is read from the GPU. Nothing is registered in CMake or CI: CI has no AMD GPU.

Draft until @boykopovar decides on #843. If he'd rather not have the tool in the repository, I'll close this.

Tested

Linux (CachyOS), Radeon 660M (RDNA2, gfx1035), HSA runtime from the Arch packages under ROCM_PATH. Checked wave32 and wave64, IEEE=0 (the f16 example in the doc keeps the NaN payload), coarse (LDS and float atomics kernel), extra (SGPR load past the rows), and 2500 rows split over 3 dispatches. Five of the kernels I measured with for the shader PRs (division, f16, relative moves, LDS atomics) give bit-identical results with this version and with the one I have used since 2026-10-03 (#264, #318, #320), on 1160 rows each (64 for the LDS one, which only addresses 64 lanes). Not tested on RDNA3 or on other distributions.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4758317394 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/871). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-06T11:54:43Z. --- ### What The hardware oracle proposed in #843: `tools/hw-oracle/` runs a body of RDNA assembly on a local AMD GPU, one input row per lane, and prints the 16 output dwords of each lane. It is meant for measuring instruction semantics before implementing them and for pinning measured rows in `tests/execution/`. Usage, kernel ABI and limits are in `docs/dev/HW_ORACLE.md`. - `oracle.c` loads a code object through the ROCm HSA runtime and dispatches it on `/dev/kfd`. `oracle --target` prints the GPU's gfx name. - `template.s` is the kernel wrapper: `v4`-`v7` hold the inputs and `v10`-`v25` are stored. It works in wave32 and wave64, gives 4 KiB of LDS, and takes the FLOAT_MODE (IEEE, f32/f16 denormals) per run. - `hw_oracle.py` builds the oracle once, assembles the body for the detected target with `clang` + `ld.lld`, and runs it. It works from the command line or as `run(body, rows, ...)` from Python. It isn't tied to a distribution. The runtime comes from `ROCM_PATH`, `/opt/rocm` or the system paths (`libhsa-runtime-dev`, `rocm-runtime-devel`, `hsa-rocr`), and the target is read from the GPU. Nothing is registered in CMake or CI: CI has no AMD GPU. Draft until @boykopovar decides on #843. If he'd rather not have the tool in the repository, I'll close this. ### Tested Linux (CachyOS), Radeon 660M (RDNA2, gfx1035), HSA runtime from the Arch packages under `ROCM_PATH`. Checked wave32 and wave64, IEEE=0 (the f16 example in the doc keeps the NaN payload), `coarse` (LDS and float atomics kernel), `extra` (SGPR load past the rows), and 2500 rows split over 3 dispatches. Five of the kernels I measured with for the shader PRs (division, f16, relative moves, LDS atomics) give bit-identical results with this version and with the one I have used since 2026-10-03 (#264, #318, #320), on 1160 rows each (64 for the LDS one, which only addresses 64 lanes). Not tested on RDNA3 or on other distributions. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
adriadam10 commented 2026-10-06 20:11:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T20:11:22Z.


boykopovar agreed on #843 (Discord): merging. Based on current main, CI green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6024566222 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/871#issuecomment-6024566222). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-06T20:11:22Z. --- boykopovar agreed on #843 (Discord): merging. Based on current main, CI green.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
boykopovar/AnyPS5!871
No description provided.