AMD: f16 math rounds toward zero, WARP lost on fcmp false/true (cross-device fuzz of this fork) #136
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork#136
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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:legacyF32ToF16, which AMD's driver rounds toward zero (WARP and the console round to nearest even). E.g.v_add_f16(0xf8b6, 0x0001)gives0xf8b5on both AMD GPUs;0xf8b6is correct. Affectsv_add/sub/subrev/fma/fmac_f16,v_pk_add/fma_f16andv_fma_mixlo/hi_f16.f16_nearest). With it, all three devices agree on every one of thesefcmp false/fcmp trueremove the WARP device (v_cmp_f/tru_f{16,32}). Every later GPU test in the process then fails.dxil.dll1.7, the Windows SDK's (emit::recttests)These also differ, but are known or not this fork's doing:
v_min/max/med3_f32,v_cube*), tracked upstream as FIND-4 in Marvisak/VIctory#1633;v_fma_f32is fused on AMD and not on WARP (theFMadshortcut);v_cvt_f32_u32andv_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.
@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.
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.
@alexdeliu on GitHub · 2026-11-24 21:56 UTC · original
@GeaorgeAyvazov thank you, that corrects my wording.
legacyF32ToF16truncates 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
0xf8b6on every device, as your first row shows. Yet both AMD GPUs return0xf8b5for the translatedv_add_f16. So AMD's compiler doesn't evaluatef16tof32 → fadd → f32tof16in 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.@Peppacodes on GitHub · 2026-11-24 22:59 UTC · original
For the
fcmp false/fcmp truerow: #160 here applies the same lowering as Marvisak/VIctory#1326 to this fork, forv_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).
@alexdeliu on GitHub · 2026-11-24 23:58 UTC · original
@Peppacodes thanks. One change with the 64-bit
v_cmp_f/tpart, 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-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.