Repository navigation
fix(shader): give f16 fma invalid operations the default NaN - #7074
Conversation
|
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.
|
|
Linux NVIDIA data point: Ubuntu 24.04.4, RTX 4000 SFF Ada Generation, driver 595.99.02, GCC 13.3.0, Release. This PR at
With this PR |
|
Thanks for the RTX 4000 Ada / Linux run, and for checking against the strict tests from before #7093. Since #7093 made those checks accept any NaN, nothing in the suite would catch a regression here, so I've added Writing it turned up one case the first commit got wrong. Without this PR, AMD's driver on the RDNA 2 iGPU returns src2 for |
|
Re-ran |
jotitadev
left a comment
There was a problem hiding this comment.
Apple GPU data point for agc_driver_f16_fma_invalid_nan: Apple's driver gives a third NaN encoding here, so the test is red on Apple without the fix, not only on NVIDIA.
Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta. Head be20464. Method: macos-port @ b7eb6b6 + ImportWatched + PR diff, not main. One context conflict in FloatInstructions.cpp: the port predates the f16 input/tiny-result flush around fmaF16RoundedToOdd, so I kept the port's line and added this PR's invalidOperationF32(...) argument to its writeF16 call. The other four files applied cleanly.
| Tree | MoltenVK 1.4.2 (SDK) | MoltenVK main + SPIRV-Cross #2704 |
|---|---|---|
| new test only, recompiler unchanged | Failed: v_fma_f16 without a known float mode of 0x00007c00, 0x00000000, 0x00000000 is 0x00007e00, expected 0x0000fe00 |
Failed, same message |
| full PR | Passed | Passed |
So for inf * 0 in v_fma_f16, Apple returns the positive quiet NaN 0x7e00, while NVIDIA returns 0x7fff and AMD returns 0xfe00. The PR selects 0xfe00 on the bits, so the result no longer depends on the vendor. The test stops at the first row that fails, so this is the only raw Apple value I have.
Also with the PR: agc_driver_f16_min_max_nan passes on both drivers. agc_driver_float16_fma_rounding fails on the SDK driver and passes with #2704, the same as the port baseline (signed-zero issue, not this PR).
Full ^agc suite with the PR (SDK driver, -j1 --timeout 30, flip/display/lds_atomics64 excluded): 13 failures out of 434, the same 13 as the port baseline. No new failures.
GPUs tested: Apple M2 Max (MoltenVK 1.4.2 and MoltenVK main + SPIRV-Cross #2704)
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
|
Native hardware data for the case the debt line leaves open ("the native
So on this GPU the f16 fma forms follow the f32 rule in the debt entry: an invalid product gives the default NaN even when src2 is a NaN. The This is desktop RDNA 2, not the PS5's gfx1013. I have not run the PR's test through the Vulkan driver on this GPU. |
|
Thanks, that settles it. Since the iGPU's
|
|
The updated test on the AMD Windows driver whose
|
v_fma_f16, v_fmac_f16, v_fmamk_f16, v_fmaak_f16 and v_fma_mix_f32 with f16 sources left the NaN of an invalid operation to the driver, so inf * 0 gave 0x7fff and 0x7fffffff on NVIDIA where the hardware gives the default NaN 0xfe00 and 0xffc00000. An inf * 0 product, or a NaN from sources that are not NaN, now gives the default NaN; NaN sources are still left to the driver.
3b9c285 to
bd03daa
Compare
|
Checked the diff against the description, the new |
…2 mode With exact f32 arithmetic, nanResultF32 already gives an invalid operation of v_fma_mix_f32 with f16 sources the default NaN, so the select from boykopovar#7074 before it was redundant there. It now runs only with APS5_FAST_F32 set, where nanResultF32 returns early and that select is still the only thing giving inf * 0 the default NaN. In that mode the widened mix NaN sources are no longer built either, since nothing reads them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…2 mode With exact f32 arithmetic, nanResultF32 already gives an invalid operation of v_fma_mix_f32 with f16 sources the default NaN, so the select from boykopovar#7074 before it was redundant there. It now runs only with APS5_FAST_F32 set, where nanResultF32 returns early and that select is still the only thing giving inf * 0 the default NaN. In that mode the widened mix NaN sources are no longer built either, since nothing reads them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
On NVIDIA, an invalid operation in
v_fma_f16and its family, or inv_fma_mix_f32with f16 sources, returns NVIDIA's own NaN (0x7fff/0x7fffffff), not the default NaN. AMD's driver returns the default NaN (0xfe00/0xffc00000), and so does lavapipe on x86.agc_driver_f16_fma_denormal_modes(#7034) andagc_driver_fma_mix_f16_denormal_modes(#7040) originally failed on NVIDIA because of it:#7093 has since made both tests accept any NaN, so this PR adds its own test,
agc_driver_f16_fma_invalid_nan, which requires the exact bits.v_fma_f16,v_fmac_f16,v_fmamk_f16,v_fmaak_f16andv_fma_mix_f32with f16 sources left all of their NaN bits to the driver (docs/dev/debt/shader.md, "Signaling NaN inputs"). The f32-source forms already pick their NaN on the bits throughnanResultF32, where an invalid product gives0xffc00000. The f16-source forms can't reuse it, because NVIDIA's f16 to f32 conversion loses the payload of an f16 NaN source. An invalid operation has no payload to keep, so this PR handles only that case:inf * 0, orinf - infin the add) becomes the default NaN.v_fma_f16family:0xfe00, selected on the f16 bits after the conversion and clamp. A DX10 clamp still turns it into 0.v_fma_mix_f32with an f16 source:0xffc00000.inf * 0product with a NaN src2 also gives the default NaN, as in the f32 forms:0xfe00in the f16 fma forms and0xffc00000inv_fma_mix_f32. @thuanquang measured this natively on gfx1031 through HIP in all four modes (comment). The RDNA 2 iGPU's Vulkan driver instead returns src2 quieted in the f16 fma forms, so the test requires the default NaN there too.invalidOperationF32holds the condition.writeF16takes it as an optional argument, and only the f16 FMA family passes it.Follow-up, not in this PR: scalar f16 add, sub and mul have the same gap for
inf - infandinf * 0. Their tests accept any NaN, and their hardware bits are not measured here.Tested
Windows 11 (26100), Ryzen 5 7600, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, this branch at3b9c285ea(based on673f7406c; the earlier runs below were onmain47a266cf9merged withbe204648d).agc_driver_f16_fma_invalid_nancoversv_fma_f16,v_fmac_f16and bothv_fma_mix_f32forms. It runs 10 rows each, in 5 float modes (no known mode, denormals flushed or kept, IEEE off and on):core/shader/recompilerreverted to main0x7fff,0x7fffffff)inf * 0+ NaN src2 row (0x7e00)5bb403d84's src2 carve-out0x7fff)0x7e00)*_nantests, this PR,--repeat until-fail:5,ANYPS5_NO_SHADER_CACHE=1ctest -R '^agc_' -j8(645 tests),3b9c285eaagc_driver_multisample_fill_host_onlyfailure under-j8(passes 10/10 alone)ctest -j 8(1399 tests),be204648dguest_sce_net(host DNS timeout, also on main) anddynamic_segment/windows_icon(antivirus in TEMP; both pass with TEMP on an excluded folder)agc_driver_lds_mixed_width_atomics(#6666, fixed by #6976) andagc_driver_layered_volume_vertex_no_gpl(#5804), both failing on mainctest -R '^agc_'passes 662/662 (comment).python tools/check_conventions.py --base upstream/mainpasses.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)