rdna2-hwprobe: probe kernels for f16 FMA, s_bfe widths, NaN rules and norm conversions, with gfx1036 results (stacked on #41) #72

Closed
github-bot wants to merge 1 commit from gh-pr/72/head into gh-pr/72/base
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 23:16 UTC · original
QuentinDanblon:probe/valu-open-questions → main · +65 −25 · 2 files · 87 commits · closed without merging

Library / area: tools/rdna2-hwprobe (the hardware probe added by #41). No runtime or translator change.

Exports changed (exports.txt rows): none

Source of the behaviour: the kernels were run on RDNA2 hardware (gfx1036) by @⁠SchmashinPrunes, results below. Mnemonics and encodings are LLVM's AMDGPU GFX10 ones (Apache-2.0 WITH LLVM-exception); the harness (runner, kernel preamble, metadata) is @⁠SchmashinPrunes' from #41.

Stacked on #41. This branch is #41's head 2515839 plus one commit, so the diff shows #41's files too. Only tools/rdna2-hwprobe/valu_probe.py and a README section are new (commits efffbc0 and ae3a658). If #41 lands first I'll rebase and the diff shrinks to that commit.

Why

Four questions in open PRs and on main come down to "what does RDNA2 return", and #41 showed the only reliable way to answer that: run it. valu_probe.py reuses that harness for non-MTBUF instructions and generates 33 kernels:

Probe Question Where it matters
fma16 Are VOP2 0x36 / 0x37 / 0x38 fused (v_fmac/fmamk/fmaak_f16, LLVM's GFX10 names) or multiply-then-add (v_mac/madmk/madak_f16, what main implements)? Each kernel also runs v_fma_f16 and v_mul_f16 + v_add_f16 on the same inputs, so both references come from the hardware. About 28,000 of 65,536 inputs per kernel separate the two. #49 vs the ISA sweep on main
sbfe s_bfe_{u,i}{32,64} with a width field of 32 or more (64 or more for the 64-bit forms): 7-bit width with sign-fill past the top bit (main since 8491769), 7-bit width with the literal ISA formula (zero-fill), or width modulo the operand size. 152 cases, with junk in the unused bits of S1. #38, #70
nan Which NaN v_fma_f32, v_mul_f32, v_add_f32, v_sub_f32, v_fmac_f32, v_min_f32, v_max_f32 return, IEEE mode off and on, over every combination of quiet/signalling NaN, infinity, zero and denormal. tb_fma on main, #61
norm Rounding, NaN and range handling of v_cvt_pknorm_{i,u}16_{f32,f16} and v_cvt_norm_{i,u}16_f16 (the f16 forms are exhaustive over 16 bits). tb_nrm, #63

valu_probe.py show <dir> prints, per question, how many recorded outputs match each candidate rule.

Results (gfx1036, measured by @⁠SchmashinPrunes)

Run with the generator unmodified on the gfx1036 iGPU of a Ryzen 5 9600X (ROCm/HIP 5.7.1), all 33 kernels: #41. Recorded in the README by ae3a658.

Probe Answer
fma16 Fused: 254,891 discriminating inputs, all match hardware v_fma_f16, none match multiply-then-add. Supports #49.
sbfe 7-bit width with sign-fill, 152 / 152 (literal ISA formula 114, modulo 100). Main since 8491769 is right; supports #70.
norm Round to nearest, 0 mismatches on the six instructions, NaN gives 0.
nan The candidate printed by show does not fit. He fitted rules with 0 mismatches (default NaN 0xffc00000, no quieting in IEEE mode 0, 0 * inf + NaN gives the default NaN, v_sub_f32 negates src1 first). They are written in the README; show is not updated to check them.

This is RDNA2, not the console's gfx1013.

What was checked, and what was not

  • I have no AMD GPU: the hardware run is his, not mine.
  • The 33 kernels assemble and link with LLVM 18 (clang-18, ld.lld-18) and disassemble identically for gfx1036 and gfx1013.
  • show was run against simulated outputs for each possible answer (fused and unfused, each of the three s_bfe models, first-NaN and reversed, nearest and half-up) and reports the right one each time.
  • One thing the simulation taught me, noted in the code: for the normalized conversions the only exact tie a float can produce is ±0.5, where ties-to-even and ties-away agree, so the probe distinguishes nearest / half-up / truncate, not even vs away.

To run it (needs the ROCm setup described in the tool's README):

python3 tools/rdna2-hwprobe/valu_probe.py gen /tmp/valu
clang-18 -x assembler -target amdgcn-amd-amdhsa -mcpu=gfx1036 -c /tmp/valu/k.s -o /tmp/valu/k.o
ld.lld-18 -shared /tmp/valu/k.o -o /tmp/valu/k.co
<runner built by run.sh> /tmp/valu
python3 tools/rdna2-hwprobe/valu_probe.py show /tmp/valu
  • cargo test -p <crate>: not applicable, no crate is touched by the new commit (#41's own tests: --test exec exec_mem::mtbuf 8 / 8 on WARP and on an RTX 5090 with #41 merged onto 8491769)
  • No game or console files and no binaries included
  • No fake success; anything not possible is left missing with a note

🤖 Generated with Claude Code

**@⁠QuentinDanblon** on GitHub · 2026-11-21 23:16 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/72) `QuentinDanblon:probe/valu-open-questions` → `main` · +65 −25 · 2 files · 87 commits · closed without merging **Library / area:** `tools/rdna2-hwprobe` (the hardware probe added by #41). No runtime or translator change. **Exports changed (exports.txt rows):** none **Source of the behaviour:** the kernels were run on RDNA2 hardware (gfx1036) by @⁠SchmashinPrunes, results below. Mnemonics and encodings are LLVM's AMDGPU GFX10 ones (Apache-2.0 WITH LLVM-exception); the harness (runner, kernel preamble, metadata) is @⁠SchmashinPrunes' from #41. **Stacked on #41.** This branch is #41's head `2515839` plus one commit, so the diff shows #41's files too. Only `tools/rdna2-hwprobe/valu_probe.py` and a README section are new (commits `efffbc0` and `ae3a658`). If #41 lands first I'll rebase and the diff shrinks to that commit. ### Why Four questions in open PRs and on main come down to "what does RDNA2 return", and #41 showed the only reliable way to answer that: run it. `valu_probe.py` reuses that harness for non-MTBUF instructions and generates 33 kernels: | Probe | Question | Where it matters | |---|---|---| | `fma16` | Are VOP2 0x36 / 0x37 / 0x38 fused (`v_fmac/fmamk/fmaak_f16`, LLVM's GFX10 names) or multiply-then-add (`v_mac/madmk/madak_f16`, what main implements)? Each kernel also runs `v_fma_f16` and `v_mul_f16` + `v_add_f16` on the same inputs, so both references come from the hardware. About 28,000 of 65,536 inputs per kernel separate the two. | #49 vs the ISA sweep on main | | `sbfe` | `s_bfe_{u,i}{32,64}` with a width field of 32 or more (64 or more for the 64-bit forms): 7-bit width with sign-fill past the top bit (main since `8491769`), 7-bit width with the literal ISA formula (zero-fill), or width modulo the operand size. 152 cases, with junk in the unused bits of S1. | #38, #70 | | `nan` | Which NaN `v_fma_f32`, `v_mul_f32`, `v_add_f32`, `v_sub_f32`, `v_fmac_f32`, `v_min_f32`, `v_max_f32` return, IEEE mode off and on, over every combination of quiet/signalling NaN, infinity, zero and denormal. | `tb_fma` on main, #61 | | `norm` | Rounding, NaN and range handling of `v_cvt_pknorm_{i,u}16_{f32,f16}` and `v_cvt_norm_{i,u}16_f16` (the f16 forms are exhaustive over 16 bits). | `tb_nrm`, #63 | `valu_probe.py show <dir>` prints, per question, how many recorded outputs match each candidate rule. ### Results (gfx1036, measured by @⁠SchmashinPrunes) Run with the generator unmodified on the gfx1036 iGPU of a Ryzen 5 9600X (ROCm/HIP 5.7.1), all 33 kernels: https://git.gtahub.st/github/omonkeyz--xbox-emulator/pulls/41. Recorded in the README by `ae3a658`. | Probe | Answer | |---|---| | `fma16` | Fused: 254,891 discriminating inputs, all match hardware `v_fma_f16`, none match multiply-then-add. Supports #49. | | `sbfe` | 7-bit width with sign-fill, 152 / 152 (literal ISA formula 114, modulo 100). Main since `8491769` is right; supports #70. | | `norm` | Round to nearest, 0 mismatches on the six instructions, NaN gives 0. | | `nan` | The candidate printed by `show` does not fit. He fitted rules with 0 mismatches (default NaN `0xffc00000`, no quieting in IEEE mode 0, `0 * inf + NaN` gives the default NaN, `v_sub_f32` negates src1 first). They are written in the README; `show` is not updated to check them. | This is RDNA2, not the console's gfx1013. ### What was checked, and what was not - I have no AMD GPU: the hardware run is his, not mine. - The 33 kernels assemble and link with LLVM 18 (`clang-18`, `ld.lld-18`) and disassemble identically for `gfx1036` and `gfx1013`. - `show` was run against simulated outputs for each possible answer (fused and unfused, each of the three `s_bfe` models, first-NaN and reversed, nearest and half-up) and reports the right one each time. - One thing the simulation taught me, noted in the code: for the normalized conversions the only exact tie a float can produce is ±0.5, where ties-to-even and ties-away agree, so the probe distinguishes nearest / half-up / truncate, not even vs away. To run it (needs the ROCm setup described in the tool's README): ``` python3 tools/rdna2-hwprobe/valu_probe.py gen /tmp/valu clang-18 -x assembler -target amdgcn-amd-amdhsa -mcpu=gfx1036 -c /tmp/valu/k.s -o /tmp/valu/k.o ld.lld-18 -shared /tmp/valu/k.o -o /tmp/valu/k.co <runner built by run.sh> /tmp/valu python3 tools/rdna2-hwprobe/valu_probe.py show /tmp/valu ``` - [x] `cargo test -p <crate>`: not applicable, no crate is touched by the new commit (#41's own tests: `--test exec exec_mem::mtbuf` 8 / 8 on WARP and on an RTX 5090 with #41 merged onto `8491769`) - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Cherry-picked from SchmashinPrunes:valu-nan-rules (0acea8a) without the three
__pycache__/*.pyc files that commit carried (no binaries in the repository).

nan_arith() / nan_minmax() encode the rules fitted on gfx1036; show_nan counts
the NaN-related results that differ from them, per instruction and IEEE mode.
Author's result on the recorded gfx1036 outputs: 0 differing results.
Checked here on simulated outputs only: 0 differing results when the outputs
follow the rules, 104 / 88 / 22 flagged when the default NaN is changed to
0x7fc00000.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:09:24 +00:00
github-bot closed this pull request 2026-11-26 06:09:24 +00:00
Author
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-22 00:15 UTC · original

Thanks for recording the results! Following up on the fitting script: I put the fitted NaN rules into show, as one commit on top of ae3a658. If you want it in #72, cherry-pick:

0acea8a on SchmashinPrunes:valu-nan-rules

  • New nan_arith() / nan_minmax() encode the rules. show_nan checks every NaN-related output against them and prints how many differ per instruction and IEEE mode, with a few examples. That replaces the old candidate line and the raw min/max tables, and the README is updated to match.
  • On the recorded gfx1036 outputs every instruction reports 0 differing results in both modes. Six planted rule changes each make it report mismatches: default NaN, sub sign, mode-0 quieting, fma invalid priority, mode-1 sNaN priority, and two-NaN min/max.
  • The full show still runs end to end. The other sections are unchanged.
**@⁠SchmashinPrunes** on GitHub · 2026-11-22 00:15 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/72#issuecomment-7071428911) Thanks for recording the results! Following up on the fitting script: I put the fitted NaN rules into `show`, as one commit on top of `ae3a658`. If you want it in #72, cherry-pick: `0acea8a` on [SchmashinPrunes:valu-nan-rules](https://github.com/SchmashinPrunes/xbox-emulator/commit/0acea8a0303d3ba86c39a4d764f842c40fd4344a) - New `nan_arith()` / `nan_minmax()` encode the rules. `show_nan` checks every NaN-related output against them and prints how many differ per instruction and IEEE mode, with a few examples. That replaces the old candidate line and the raw min/max tables, and the README is updated to match. - On the recorded gfx1036 outputs every instruction reports 0 differing results in both modes. Six planted rule changes each make it report mismatches: default NaN, sub sign, mode-0 quieting, fma invalid priority, mode-1 sNaN priority, and two-NaN min/max. - The full `show` still runs end to end. The other sections are unchanged.
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-22 00:20 UTC · original

Taken, thank you: 0acea8a is on this PR as HEAD, with you as the author. One change: I left out the three __pycache__/*.pyc files the commit carried, since the repository takes no binaries (I made the same mistake on my first probe commit).

Checked on my side, on simulated outputs only (no AMD GPU here): show runs end to end, reports 0 differing results in both IEEE modes when the outputs follow nan_arith / nan_minmax (same case counts as yours: 65,265 fma, 43,824 mul, 43,886 add and sub, 43,736 min and max), and flags 104 / 88 / 22 results when I change the default NaN to 0x7fc00000.

**@⁠QuentinDanblon** on GitHub · 2026-11-22 00:20 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/72#issuecomment-7071479917) Taken, thank you: `0acea8a` is on this PR as `HEAD`, with you as the author. One change: I left out the three `__pycache__/*.pyc` files the commit carried, since the repository takes no binaries (I made the same mistake on my first probe commit). Checked on my side, on simulated outputs only (no AMD GPU here): `show` runs end to end, reports 0 differing results in both IEEE modes when the outputs follow `nan_arith` / `nan_minmax` (same case counts as yours: 65,265 fma, 43,824 mul, 43,886 add and sub, 43,736 min and max), and flags 104 / 88 / 22 results when I change the default NaN to `0x7fc00000`.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:12 UTC · original

Main's history was rewritten, which auto-closed this PR (sorry for the noise). This is stacked on #41. Resubmit it after #41, with only valu_probe.py and the probe notes. Put the notes in the PR description or a .txt, because .md files under tools/ are not published. Strip comment lines. To resubmit: git fetch this repo, branch from the current main, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

**@⁠omonkeyz** on GitHub · 2026-11-22 13:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/72#issuecomment-7079646463) Main's history was rewritten, which auto-closed this PR (sorry for the noise). This is stacked on #41. Resubmit it after #41, with only valu_probe.py and the probe notes. Put the notes in the PR description or a .txt, because .md files under tools/ are not published. Strip comment lines. To resubmit: `git fetch` this repo, branch from the current `main`, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.