AMD: f16 math rounds toward zero, WARP lost on fcmp false/true (cross-device fuzz of this fork) #136

Open
opened 2026-11-26 03:36:46 +00:00 by github-bot · 5 comments
Owner

@⁠alexdeliu on GitHub · 2026-11-24 21:45 UTC · original

I ran the cross-device VALU fuzzer from Marvisak/VIctory#1614 on this fork's main (4e17478, with #135 applied). It runs each lowered VOP3/VOP3P opcode as a one-thread compute shader on every adapter, here an RX 9070 (RDNA4), a Ryzen 7700 iGPU (gfx1036, RDNA2) and WARP, on the same 200 edge and random inputs, and compares the results bit for bit. The fork's own changes added no new disagreements. Three bugs carried over from upstream matter on AMD and in CI, and each already has an upstream fix:

Finding Where it shows Upstream fix
f16 math on AMD is rounded toward zero. f16 results computed in f32 go through legacyF32ToF16, which AMD's driver rounds toward zero (WARP and the console round to nearest even). E.g. v_add_f16(0xf8b6, 0x0001) gives 0xf8b5 on both AMD GPUs; 0xf8b6 is correct. Affects v_add/sub/subrev/fma/fmac_f16, v_pk_add/fma_f16 and v_fma_mixlo/hi_f16. AMD hosts: slightly darker or biased f16 lighting and colour math Marvisak/VIctory#422 (f16_nearest). With it, all three devices agree on every one of these
fcmp false / fcmp true remove the WARP device (v_cmp_f/tru_f{16,32}). Every later GPU test in the process then fails. WARP, so the hosted runners Marvisak/VIctory#1326
PSV0 with repeated semantic names fails dxil.dll 1.7, the Windows SDK's (emit::rect tests) any host with the stock SDK validator #61 here (verified on the RX 9070)

These also differ, but are known or not this fork's doing:

  • fp32 denormals and the sign of a flushed zero (v_min/max/med3_f32, v_cube*), tracked upstream as FIND-4 in Marvisak/VIctory#1633;
  • v_fma_f32 is fused on AMD and not on WARP (the FMad shortcut);
  • WARP's own inexact v_cvt_f32_u32 and v_log_f32.

Full per-opcode tables with repro words: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87#file-4-valu-fuzz-md

The RX 9070 and gfx1036 are both in my box. Mention @⁠alexdeliu with a commit or a test, and I'll run it on both.

**@⁠alexdeliu** on GitHub · 2026-11-24 21:45 UTC · [original](https://github.com/fxceless/victory-fork/issues/136) I ran the cross-device VALU fuzzer from Marvisak/VIctory#1614 on this fork's `main` (`4e17478`, with #135 applied). It runs each lowered VOP3/VOP3P opcode as a one-thread compute shader on every adapter, here an **RX 9070 (RDNA4)**, a **Ryzen 7700 iGPU (gfx1036, RDNA2)** and **WARP**, on the same 200 edge and random inputs, and compares the results bit for bit. The fork's own changes added no new disagreements. Three bugs carried over from upstream matter on AMD and in CI, and each already has an upstream fix: | Finding | Where it shows | Upstream fix | |---|---|---| | **f16 math on AMD is rounded toward zero.** f16 results computed in f32 go through `legacyF32ToF16`, which AMD's driver rounds toward zero (WARP and the console round to nearest even). E.g. `v_add_f16(0xf8b6, 0x0001)` gives `0xf8b5` on both AMD GPUs; `0xf8b6` is correct. Affects `v_add/sub/subrev/fma/fmac_f16`, `v_pk_add/fma_f16` and `v_fma_mixlo/hi_f16`. | AMD hosts: slightly darker or biased f16 lighting and colour math | Marvisak/VIctory#422 (`f16_nearest`). With it, all three devices agree on every one of these | | **`fcmp false` / `fcmp true` remove the WARP device** (`v_cmp_f/tru_f{16,32}`). Every later GPU test in the process then fails. | WARP, so the hosted runners | Marvisak/VIctory#1326 | | **PSV0 with repeated semantic names fails `dxil.dll` 1.7**, the Windows SDK's (`emit::rect` tests) | any host with the stock SDK validator | #61 here (verified on the RX 9070) | These also differ, but are known or not this fork's doing: - fp32 denormals and the sign of a flushed zero (`v_min/max/med3_f32`, `v_cube*`), tracked upstream as FIND-4 in Marvisak/VIctory#1633; - `v_fma_f32` is fused on AMD and not on WARP (the `FMad` shortcut); - WARP's own inexact `v_cvt_f32_u32` and `v_log_f32`. Full per-opcode tables with repro words: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87#file-4-valu-fuzz-md The RX 9070 and gfx1036 are both in my box. Mention @⁠alexdeliu with a commit or a test, and I'll run it on both.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:46 +00:00
Author
Owner

@⁠GeaorgeAyvazov on GitHub · 2026-11-24 21:55 UTC · original

Additional synthetic D3D12 measurements for the f16 conversion in this issue. I compiled the following expression with DXC 1.9.2609.5, cs_6_0, using two runtime uint inputs from a UAV. The disassembly contains two legacyF16ToF32 calls, fadd fast float, and legacyF32ToF16. This isolates the host operation; I did not run the VIctory frontend or its VALU fuzzer.

f32tof16(f16tof32(a) + f16tof32(b))

All three adapters returned identical bits: RTX 3070 Ti Laptop (32.0.15.9186), Intel Iris Xe (30.0.101.1029), and WARP (10.0.26100.9818). Each pair was dispatched separately. Inputs and outputs below are hex binary16 encodings.

a b observed on all three nearest-even reference
f8b6 0001 f8b6 f8b6
3c00 1000 3c00 3c00
3c01 1000 3c01 3c02
bc00 9000 bc00 bc00
bc01 9000 bc01 bc02
3c00 1001 3c00 3c01
bc00 9001 bc00 bc01
0400 83ff 0001 0001

The original pair alone does not distinguish conversion modes on this path: adding the smallest positive half to that large negative value already rounds back to the first operand in binary32. The odd-significand halfway pairs and the just-above-halfway pairs do distinguish them. Their sums are exactly representable in binary32. All three adapters returned the toward-zero result in these four cases, including WARP. The nearest-even reference was computed separately with Python struct.pack('<e', sum). These observations are specific to the DXIL sequence above.

Test prepared and run with OpenAI Codex using synthetic inputs.

**@⁠GeaorgeAyvazov** on GitHub · 2026-11-24 21:55 UTC · [original](https://github.com/fxceless/victory-fork/issues/136#issuecomment-7145562271) Additional synthetic D3D12 measurements for the f16 conversion in this issue. I compiled the following expression with DXC 1.9.2609.5, cs_6_0, using two runtime uint inputs from a UAV. The disassembly contains two legacyF16ToF32 calls, fadd fast float, and legacyF32ToF16. This isolates the host operation; I did not run the VIctory frontend or its VALU fuzzer. `f32tof16(f16tof32(a) + f16tof32(b))` All three adapters returned identical bits: RTX 3070 Ti Laptop (32.0.15.9186), Intel Iris Xe (30.0.101.1029), and WARP (10.0.26100.9818). Each pair was dispatched separately. Inputs and outputs below are hex binary16 encodings. | a | b | observed on all three | nearest-even reference | |---|---|---|---| | f8b6 | 0001 | f8b6 | f8b6 | | 3c00 | 1000 | 3c00 | 3c00 | | 3c01 | 1000 | 3c01 | 3c02 | | bc00 | 9000 | bc00 | bc00 | | bc01 | 9000 | bc01 | bc02 | | 3c00 | 1001 | 3c00 | 3c01 | | bc00 | 9001 | bc00 | bc01 | | 0400 | 83ff | 0001 | 0001 | The original pair alone does not distinguish conversion modes on this path: adding the smallest positive half to that large negative value already rounds back to the first operand in binary32. The odd-significand halfway pairs and the just-above-halfway pairs do distinguish them. Their sums are exactly representable in binary32. All three adapters returned the toward-zero result in these four cases, including WARP. The nearest-even reference was computed separately with Python struct.pack('<e', sum). These observations are specific to the DXIL sequence above. Test prepared and run with OpenAI Codex using synthetic inputs.
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 21:56 UTC · original

@⁠GeaorgeAyvazov thank you, that corrects my wording. legacyF32ToF16 truncates on your three devices too, WARP included, so "AMD rounds toward zero, WARP to nearest even" was wrong as a statement about the conversion.

Your measurements also pin down what is AMD-specific. In my example the binary32 sum is exact: -38592 + 2⁻²⁴ rounds back to -38592 in f32. A conversion of it alone gives 0xf8b6 on every device, as your first row shows. Yet both AMD GPUs return 0xf8b5 for the translated v_add_f16. So AMD's compiler doesn't evaluate f16tof32 → fadd → f32tof16 in f32. It appears to fold the chain into a native f16 add that rounds toward zero, which shows up even when the f32 result is exact.

Either way, rounding to nearest even in the shader fixes both effects: the truncating conversion on every device, and AMD's fold. That is #422 upstream, and it is now also in VIctory main (77053a0, "f16 results round to nearest even"). With it, the RX 9070, the gfx1036 iGPU and WARP agree on every f16 opcode in the fuzzer.

**@⁠alexdeliu** on GitHub · 2026-11-24 21:56 UTC · [original](https://github.com/fxceless/victory-fork/issues/136#issuecomment-7145594303) @⁠GeaorgeAyvazov thank you, that corrects my wording. `legacyF32ToF16` truncates on your three devices too, WARP included, so "AMD rounds toward zero, WARP to nearest even" was wrong as a statement about the conversion. Your measurements also pin down what is AMD-specific. In my example the binary32 sum is exact: -38592 + 2⁻²⁴ rounds back to -38592 in f32. A conversion of it alone gives `0xf8b6` on every device, as your first row shows. Yet both AMD GPUs return `0xf8b5` for the translated `v_add_f16`. So AMD's compiler doesn't evaluate `f16tof32 → fadd → f32tof16` in f32. It appears to fold the chain into a native f16 add that rounds toward zero, which shows up even when the f32 result is exact. Either way, rounding to nearest even in the shader fixes both effects: the truncating conversion on every device, and AMD's fold. That is #422 upstream, and it is now also in VIctory `main` (`77053a0`, "f16 results round to nearest even"). With it, the RX 9070, the gfx1036 iGPU and WARP agree on every f16 opcode in the fuzzer.
Author
Owner

@⁠Peppacodes on GitHub · 2026-11-24 22:59 UTC · original

For the fcmp false / fcmp true row: #160 here applies the same lowering as Marvisak/VIctory#1326 to this fork, for v_cmp_f/tru_{f32,f16}. They lower to constant lane booleans, so WARP keeps its device. It has a test on the hardware adapter and WARP, with ordinary and NaN operands.

Upstream #1326 also folds the 64-bit integer v_cmp_f/t. I can add that part to #160 too, credited to fuzeofficlal, if you'd rather have the whole of it in one change.

AI-assisted (Claude Code).

**@⁠Peppacodes** on GitHub · 2026-11-24 22:59 UTC · [original](https://github.com/fxceless/victory-fork/issues/136#issuecomment-7146874889) For the `fcmp false` / `fcmp true` row: #160 here applies the same lowering as Marvisak/VIctory#1326 to this fork, for `v_cmp_f/tru_{f32,f16}`. They lower to constant lane booleans, so WARP keeps its device. It has a test on the hardware adapter and WARP, with ordinary and NaN operands. Upstream #1326 also folds the 64-bit integer `v_cmp_f/t`. I can add that part to #160 too, credited to fuzeofficlal, if you'd rather have the whole of it in one change. AI-assisted (Claude Code).
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 23:58 UTC · original

@⁠Peppacodes thanks. One change with the 64-bit v_cmp_f/t part, credited to fuzeofficlal, sounds good to me. It closes the fcmp row of this issue in one place. The final call is the maintainer's.

**@⁠alexdeliu** on GitHub · 2026-11-24 23:58 UTC · [original](https://github.com/fxceless/victory-fork/issues/136#issuecomment-7148007539) @⁠Peppacodes thanks. One change with the 64-bit `v_cmp_f/t` part, credited to fuzeofficlal, sounds good to me. It closes the fcmp row of this issue in one place. The final call is the maintainer's.
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-25 06:22 UTC · original

Follow-up for this fork: the AMD driver findings are now a standalone kit, https://github.com/alexdeliu/rdna2-conformance. It runs HLSL probes and translator-emitted DXIL vectors on every D3D12 adapter. On an RX 9070 + gfx1036 the bugs reproduce only from the translators' own DXIL, not from the same operations in HLSL, so it is worth running before an AMD release. Reports from your NVIDIA cards would fill in the matrix.

**@⁠alexdeliu** on GitHub · 2026-11-25 06:22 UTC · [original](https://github.com/fxceless/victory-fork/issues/136#issuecomment-7154733390) Follow-up for this fork: the AMD driver findings are now a standalone kit, https://github.com/alexdeliu/rdna2-conformance. It runs HLSL probes and translator-emitted DXIL vectors on every D3D12 adapter. On an RX 9070 + gfx1036 the bugs reproduce only from the translators' own DXIL, not from the same operations in HLSL, so it is worth running before an AMD release. Reports from your NVIDIA cards would fill in the matrix.
This discussion has been locked. Commenting is limited to contributors.
No description provided.