tools: a native RDNA 2 reference for float arithmetic (T5) #420

Merged
JeffreyBytes merged 10 commits from upstream-pr/420 into main 2026-11-29 01:32:04 +00:00
JeffreyBytes commented 2026-11-28 22:03:20 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-11-28T22:03:20Z.


Summary

First piece of T5 (#412): a hardware reference for the float arithmetic family, recorded on an RX 6700 XT, plus a no-GPU test that holds the models to it.

It builds on @JohnVonWells's tools/native_rdna2/. Two routes, same inputs:

  • ROCm route (the primary one). float.hip + check_float.py, same structure as the f64/half/SAD checks. 20 hand-written instructions, each run under all 1,024 MODE[9:0] values: 329,728 comparisons against the model, 0 mismatches. On gfx1031/gfx1032 it sets HSA_OVERRIDE_GFX_VERSION=10.3.0 for its own runs and says so in the receipt.
  • Vulkan route (second witness). vulkan_float.py + vulkan.c. One GLSL compute shader per instruction through RADV, and it refuses to record unless the instruction shows up in RADV_DEBUG=shaders disassembly. 17 instructions under the five SPIR-V float modes.

The two agree on every bit they share: RADV's default is exactly MODE 0xc0 (what the translator starts from), DenormPreserve is 0xf0, DenormFlushToZero is 0x00.

Instructions: v_add_f32, v_sub_f32, v_mul_f32, v_fmac_f32, v_fma_f32, v_fma_mix_f32, v_fma_mixlo_f16, v_pk_fmac_f16, v_min_f32, v_max_f32, v_rndne_f32, v_trunc_f32, v_floor_f32, v_ceil_f32, v_cvt_f32_i32, v_cvt_i32_f32, v_cvt_u32_f32, and on the ROCm side also v_mul_legacy_f32, v_fmac_legacy_f32, v_fma_legacy_f32.

What it found

Which MODE bits matter (full table in docs/CONSOLE_REFERENCE.md): for add/sub/mul/fma it's 0x233, i.e. f32 rounding (1:0), f32 denormals kept for sources (4) and for results (5), and IEEE (9). IEEE quiets NaN results and makes min/max return a quieted signaling NaN source. DX10 clamp changed nothing here.

Under MODE 0xc0 the card:

  • flushes f32 denormal sources, not just results (ceil(0x00000001) is +0, not 1.0), and flushes on "tiny after rounding";
  • passes a signaling NaN through unquieted;
  • gives 0xffc00000 for invalid operations, and 0 × inf in an fma wins over a NaN addend;
  • flips the sign of a NaN subtrahend in v_sub_f32;
  • treats min/max as minimumNumber/maximumNumber, with -0 below +0.

tools/check_basic_alu_gpu.py's models disagree with the card in three places. I have not changed them in this PR, the test just pins the disagreements down:

  • They compute from denormal sources; the card flushes them. Float.matches only allows a flushed result. 250 of the card's results are rejected for this, and the check can't see it because FLOAT_EDGE has no f32 denormals and the random inputs stay between 2^-30 and 2^30.
  • Float.matches returns as soon as the expectation is a NaN and never looks at also, so with separate putting the twice-rounded result first it rejects the card's fused -inf for 2^127·2^127 - inf.
  • The legacy multiply-adds are modeled as rounding twice. On this card they round once.

I'll send the model fixes and denormal inputs as a follow-up, since that touches a translator check and needs a GPU run on both vendors.

Limits

  • This is a GFX10.3 card. The gfx1030 assembler refuses v_mac_f32, v_mad_f32, v_madak_f32, v_madmk_f32, v_mac_legacy_f32 and v_mad_legacy_f32, and recorded shaders do use v_mad_f32. So this can't be the reference for the GFX10.1 side. v_fmac_legacy_f32/v_fma_legacy_f32 have the same encodings as RDNA 1's mac_legacy/mad_legacy (VOP2 6, VOP3 0x140); they fuse here, and I don't know that they do on the console.
  • The Vulkan route only gets the forms ACO picks, and on this card the translated shaders go through the same driver.
  • Nothing here measures a console. MODE 0xc0 as the console's starting value comes from the title's stage descriptors (#333), not from hardware, and that only covers bits 7:0.
  • Tiny-after-rounding under directed rounding is only lightly covered by these inputs.

Layout

  • tools/native_rdna2/: float.hip, check_float.py, vulkan_float.py, vulkan.c, ieee_float.py (exact IEEE model), rdna2_float.py (the card as a function of MODE)
  • evidence/native-rdna2-float.json (234 KB, a hash per MODE combination plus raw words under 0xc0), evidence/native-rdna2-vulkan-float.json (430 KB, raw words for 5 modes)
  • tests/test_native_rdna2_float.py, tests/test_native_rdna2_vulkan.py: no GPU, about 12 s together
  • docs/CONSOLE_REFERENCE.md, the README, and the T5 row in the roadmap marked in progress

The Vulkan receipt is the big file. If 430 KB is too much for evidence/ I can cut it to hashes plus the default mode like the other one.

Tested

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them:

No Lanes scenario: this runs native instructions outside TuxBox's providers, so there's nothing for Lanes to exercise. No NVIDIA run: the recorders only run on an RDNA 2 card, and the PR changes no provider, translator or shared check code. The tests that hold the models to the receipts need no GPU and run in CI.

GPU, driver and backend: AMD Radeon RX 6700 XT (1002:73df, gfx1031), Mesa RADV 26.3.1, Linux 7.3.6, ROCm under /opt/rocm. No Proton involved.

Commands run and their results:

python tuxbox.py check --no-gpu
  passed   Build the shader compiler (13s)
  passed   Python tests (22s)
  passed   Shader compiler tests (13s)
  passed   DXBC tests (2s)
  passed   XG layout tests (10s)
  passed   Storage codec tests (1s)
  passed   D3D12 Windows typecheck (10s)

python -m unittest discover -s tests -q
  Ran 594 tests, OK (skipped=21)

python tools/native_rdna2/check_float.py --work build/native-rdna2-float --output build/native-rdna2-float.json
  PASS 329728 model comparisons, 0 mismatches     (3 runs, identical; output equals the checked-in receipt)

python tools/native_rdna2/vulkan_float.py verify
  PASS 17 instructions under 5 modes               (bit for bit against the receipt)

python tools/native_rdna2/check_sad.py ...  with HSA_OVERRIDE_GFX_VERSION=10.3.0
  PASS 81920 model comparisons, 0 mismatches       (equals the RX 6950 XT receipt except the device name)

I only have Python 3.14 here, so 3.10 is syntax-checked and CI will be the real test.

Checks

docs/RESULTS.md and docs/progress.svg regenerate to what's already there; the new receipts aren't a type those views count.

<!-- greyfinch-sync:brcly/TuxBox:issue:5545006242 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/420). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-11-28T22:03:20Z. --- ## Summary First piece of T5 (#412): a hardware reference for the float arithmetic family, recorded on an RX 6700 XT, plus a no-GPU test that holds the models to it. It builds on @JohnVonWells's `tools/native_rdna2/`. Two routes, same inputs: - **ROCm route (the primary one).** `float.hip` + `check_float.py`, same structure as the f64/half/SAD checks. 20 hand-written instructions, each run under all 1,024 `MODE[9:0]` values: 329,728 comparisons against the model, 0 mismatches. On gfx1031/gfx1032 it sets `HSA_OVERRIDE_GFX_VERSION=10.3.0` for its own runs and says so in the receipt. - **Vulkan route (second witness).** `vulkan_float.py` + `vulkan.c`. One GLSL compute shader per instruction through RADV, and it refuses to record unless the instruction shows up in `RADV_DEBUG=shaders` disassembly. 17 instructions under the five SPIR-V float modes. The two agree on every bit they share: RADV's default is exactly MODE `0xc0` (what the translator starts from), `DenormPreserve` is `0xf0`, `DenormFlushToZero` is `0x00`. Instructions: `v_add_f32`, `v_sub_f32`, `v_mul_f32`, `v_fmac_f32`, `v_fma_f32`, `v_fma_mix_f32`, `v_fma_mixlo_f16`, `v_pk_fmac_f16`, `v_min_f32`, `v_max_f32`, `v_rndne_f32`, `v_trunc_f32`, `v_floor_f32`, `v_ceil_f32`, `v_cvt_f32_i32`, `v_cvt_i32_f32`, `v_cvt_u32_f32`, and on the ROCm side also `v_mul_legacy_f32`, `v_fmac_legacy_f32`, `v_fma_legacy_f32`. ### What it found Which MODE bits matter (full table in `docs/CONSOLE_REFERENCE.md`): for add/sub/mul/fma it's `0x233`, i.e. f32 rounding (1:0), f32 denormals kept for sources (4) and for results (5), and IEEE (9). IEEE quiets NaN results and makes min/max return a quieted signaling NaN source. DX10 clamp changed nothing here. Under MODE `0xc0` the card: - flushes f32 denormal **sources**, not just results (`ceil(0x00000001)` is +0, not 1.0), and flushes on "tiny after rounding"; - passes a signaling NaN through unquieted; - gives `0xffc00000` for invalid operations, and `0 × inf` in an fma wins over a NaN addend; - flips the sign of a NaN subtrahend in `v_sub_f32`; - treats min/max as minimumNumber/maximumNumber, with -0 below +0. `tools/check_basic_alu_gpu.py`'s models disagree with the card in three places. I have **not** changed them in this PR, the test just pins the disagreements down: - They compute from denormal sources; the card flushes them. `Float.matches` only allows a flushed *result*. 250 of the card's results are rejected for this, and the check can't see it because `FLOAT_EDGE` has no f32 denormals and the random inputs stay between 2^-30 and 2^30. - `Float.matches` returns as soon as the expectation is a NaN and never looks at `also`, so with `separate` putting the twice-rounded result first it rejects the card's fused -inf for 2^127·2^127 - inf. - The legacy multiply-adds are modeled as rounding twice. On this card they round once. I'll send the model fixes and denormal inputs as a follow-up, since that touches a translator check and needs a GPU run on both vendors. ### Limits - This is a GFX10.3 card. The gfx1030 assembler refuses `v_mac_f32`, `v_mad_f32`, `v_madak_f32`, `v_madmk_f32`, `v_mac_legacy_f32` and `v_mad_legacy_f32`, and recorded shaders do use `v_mad_f32`. So this can't be the reference for the GFX10.1 side. `v_fmac_legacy_f32`/`v_fma_legacy_f32` have the same encodings as RDNA 1's `mac_legacy`/`mad_legacy` (VOP2 6, VOP3 0x140); they fuse here, and I don't know that they do on the console. - The Vulkan route only gets the forms ACO picks, and on this card the translated shaders go through the same driver. - Nothing here measures a console. MODE `0xc0` as the console's starting value comes from the title's stage descriptors (#333), not from hardware, and that only covers bits 7:0. - Tiny-after-rounding under directed rounding is only lightly covered by these inputs. ### Layout - `tools/native_rdna2/`: `float.hip`, `check_float.py`, `vulkan_float.py`, `vulkan.c`, `ieee_float.py` (exact IEEE model), `rdna2_float.py` (the card as a function of MODE) - `evidence/native-rdna2-float.json` (234 KB, a hash per MODE combination plus raw words under `0xc0`), `evidence/native-rdna2-vulkan-float.json` (430 KB, raw words for 5 modes) - `tests/test_native_rdna2_float.py`, `tests/test_native_rdna2_vulkan.py`: no GPU, about 12 s together - `docs/CONSOLE_REFERENCE.md`, the README, and the T5 row in the roadmap marked in progress The Vulkan receipt is the big file. If 430 KB is too much for `evidence/` I can cut it to hashes plus the default mode like the other one. ## Tested - [x] The checks relevant to this change passed - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below - [x] Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: No Lanes scenario: this runs native instructions outside TuxBox's providers, so there's nothing for Lanes to exercise. No NVIDIA run: the recorders only run on an RDNA 2 card, and the PR changes no provider, translator or shared check code. The tests that hold the models to the receipts need no GPU and run in CI. GPU, driver and backend: AMD Radeon RX 6700 XT (`1002:73df`, gfx1031), Mesa RADV 26.3.1, Linux 7.3.6, ROCm under `/opt/rocm`. No Proton involved. Commands run and their results: ```text python tuxbox.py check --no-gpu passed Build the shader compiler (13s) passed Python tests (22s) passed Shader compiler tests (13s) passed DXBC tests (2s) passed XG layout tests (10s) passed Storage codec tests (1s) passed D3D12 Windows typecheck (10s) python -m unittest discover -s tests -q Ran 594 tests, OK (skipped=21) python tools/native_rdna2/check_float.py --work build/native-rdna2-float --output build/native-rdna2-float.json PASS 329728 model comparisons, 0 mismatches (3 runs, identical; output equals the checked-in receipt) python tools/native_rdna2/vulkan_float.py verify PASS 17 instructions under 5 modes (bit for bit against the receipt) python tools/native_rdna2/check_sad.py ... with HSA_OVERRIDE_GFX_VERSION=10.3.0 PASS 81920 model comparisons, 0 mismatches (equals the RX 6950 XT receipt except the device name) ``` I only have Python 3.14 here, so 3.10 is syntax-checked and CI will be the real test. ## Checks `docs/RESULTS.md` and `docs/progress.svg` regenerate to what's already there; the new receipts aren't a type those views count.
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
brcly/TuxBox!420
No description provided.