Repository navigation
fix(shader): flush v_fma_f16 family denormals by the f16 denormal field - #7034
Conversation
v_fma_f16, v_fmac_f16, v_fmamk_f16 and v_fmaak_f16 ignored the FLOAT_MODE f16 denormal field. On RDNA2 (gfx1031) at f16 round to nearest even, bit 6 clear flushes every denormal input to a zero of its sign, and bit 7 clear flushes the result when the exact product-sum rounded to 11 significant bits with an unbounded exponent is below 2^-14, the rule v_mul_f16 already follows. The f16 FMA path now flushes its inputs and its round-to-odd result in those modes; the magnitude test is shared with float16Binary as flushTinyF16Value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Another AMD driver, since the description lists other AMD drivers as untested. Windows 11 (26300), Radeon 860M (RDNA 3.5,
AI-assisted: yes (Claude Code). |
|
Confirmed a cross-vendor test failure on unchanged main
Built |
|
Second NVIDIA data point, with the bit pattern explained: RTX 4070 (driver 596.21, Windows 11 Pro 26220, WinLibs GCC 15.2) on plain Written with Claude Code assistance (validation by a subagent, reviewed in this session). |
What
v_fma_f16,v_fmac_f16,v_fmamk_f16andv_fmaak_f16ignored theFLOAT_MODEf16 denormal field; the technical debt entry for the scalar f16 ops listed "ternary arithmetic" as keeping the previous lowering. On the GPU, at f16 round to nearest even:FLOAT_MODEclear (f16 denormal modes 0 and 2) every denormal input is flushed to a zero of its sign, sov_fma_f16 0, 0, 0x8001is0x0000wheremainwrites0x8001;v_mul_f16already follows. Sov_fma_f16 0, 0, 0x0001is0x0000wheremainwrites0x0001, while0x0400 * 0x0400 + 0x8400(exactly -2^-14 + 2^-28) rounds to0x8400and is kept. Detecting tininess before rounding instead flushes it to0x8000and disagrees with the GPU on 10 (mode 0) and 103 (mode 1) of the 4580 rows without NaN operands.float16Ternarynow flushes the inputs of the f16 FMA path withflushF16InputValueand its round-to-odd f32 result against 2^-14 - 2^-26 (0x387ff000) in the modes that flush them, gated likefloat16Binaryon f16 round to nearest even. The magnitude test moves from a lambda infloat16BinarytoflushTinyF16Value, which both paths andflushF16InputValueuse. Comparing the round-to-odd value is the same as comparing the exact one, since0x387ff000has an even significand.v_fma_mixlo/mixhi_f16, directed rounding and shaders without a known float mode are translated as before.Measured
The same instructions were run directly on the GPU with the
tools/hw-oracletemplate, launched through the driver's HIP runtime, and through the recompiler on Vulkan, at IEEE 0 and 1, over 5075 operand triples: the 4000 from 20 halves around the denormal range (±0, ±0x0001, ±0x03ff, 0x0200, ±0x0400, 0x0401, ±0.5, ±1, 0x7bff, inf, 0x3bff, 0x3c01, 0x1fff, 0x2001), 75 whose product-sum lies just below 2^-14, and 1000 random ones:mainvs GPU (v_fma_f16andv_fmac_f16each)With this change every mode also matches, at IEEE 0 and 1 and
FP16_OVFL0 and 1, over the first 4075 triples forv_fmamk_f16with literals0x8400and0x3bff,v_fmaak_f16with0x8400,v_fma_f16 -v4, |v5|, -v6,op_sel:[1,1,1,0]high-half sources,op_sel:[0,0,0,1]into a register holding another value,clamp, and VOP3v_fmac_f16_e64(0 mismatches each). VOP3v_fmac_f16_e64with a source modifier orclampthrows "VOP3 source modifiers are not implemented" in the recompiler; this PR does not touch that path.Tested
Windows 11 26200, AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON,ANYPS5_REQUIRE_VULKAN=1:agc_driver_f16_fma_denormal_modes:v_fma_f16and VOP2v_fmac_f16over 64 of those triples (inputs and results at the denormal boundary, the triples just below 2^-14, infinities and invalid products), in f16 denormal modes 0 to 3 at IEEE 0 and 1 and without a known float mode, against the GPU's results for each mode. Onmainit fails:v_fma_f16 f16 denormal mode 0, IEEE mode on of 0x3bff, 0x0400, 0x0000 is 0x0400, expected 0x0000. With this change it passes.ctest --parallel 4 --timeout 120onmain6a32550fdwith this change: 1368 tests, 2 fail, both failing onmainon this GPU too:agc_driver_lds_mixed_width_atomics(agc_* tests: 3 of 483 fail on AMD Radeon RX 6400, pass on NVIDIA RTX 4080 SUPER #5271) andagc_driver_layered_volume_vertex_no_gpl(AMD Windows: GPL-mode cache failures (alpha/wave32 pass after local driver update) #4768).agc_driver_float16_fma_rounding,agc_driver_f16_denormal_flushand the other f16 tests pass.python tools/check_conventions.py --base origin/mainwith this title and body passes.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code