Repository navigation
rdna2spirv: the binary64 roundings keep a NaN's bits and round a subnormal without the driver (SHADER-ROUND-F64-SPECIALS) - #1047
Conversation
…64, v_rndne_f64 and v_floor_f64 (GPU-ROUND-F64) The translator gives the four ops to the driver's double-precision Trunc, Ceil, RoundEven and Floor, and no fixture in runtime/test/shaders ran them, so what a driver does with ties, the largest value below 0.5, values at and above 2^52, signed zeros, subnormals, infinities and NaNs had never gone through the GPU suite. cs_w32_round_f64 is memory-fed, like cs_w32_shift64 and cs_w32_cmp_f64: check.py seeds 64 inputs and each thread loads one at run time and stores eight results: the four roundings, v_trunc_f64 with a neg source, v_ceil_f64 with an abs source, a v_floor_f64 whose destination pair overlaps its source pair, and a v_rndne_f64 run with the odd threads turned off, whose destination must keep the pair it held. The expected words come from Python floats (exact IEEE-754, the result keeping its source's sign) and are checked against exact rational rounding in tests/test_gpu_round_f64.py. Two kinds of input are judged by what Vulkan lets a driver do, not by RDNA2: a NaN may come back as another NaN, and a subnormal may be read as a zero of its sign, since the module declares no DenormPreserve for 64 bits. That is what the fixture measured: on an RTX 4070 Ti a signalling NaN comes back quiet, and on llvmpipe the smallest subnormals are also read as zero. The row in docs/design.md records both as an approximation. dump_test takes an optional judge for such a readback. No translator or runtime change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ormal without the driver (SHADER-ROUND-F64-SPECIALS) v_trunc_f64, v_ceil_f64, v_rndne_f64 and v_floor_f64 hand their source to the driver's double-precision Trunc, Ceil, RoundEven and Floor. Vulkan lets a driver return any NaN for a NaN operand and, with no DenormPreserve for 64 bits, read a subnormal as zero, and cs_w32_round_f64 measured both: a signalling NaN came back quiet on an RTX 4070 Ti (NVIDIA 620.70.06) and on llvmpipe, and llvmpipe read the smallest subnormals as zero, so v_ceil_f64 of the positive one gave +0. RDNA2 returns a NaN unchanged and keeps subnormals: that ceil is 1. The two kinds of source are now selected with integer ops on the words, after the source modifiers and before the output ones. A NaN's words pass through. A subnormal gives a zero of its sign, or 1 with its sign where the op rounds that sign away from zero (ceil of a positive one, floor of a negative one). Every other source still takes the driver's result. cs_w32_round_f64 now compares all 1152 words exactly, on both devices. tests/semantic/test_f64_round.py runs the four ops under a model of a driver that quiets a NaN and reads a subnormal as zero; without the change that class fails for the signalling NaNs and for ceil and floor of a subnormal. The row in docs/design.md describes the rule and how it was confirmed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Independent hardware verification from a second Windows box (Ryzen 5 7600 RDNA2 iGPU, gfx1035, AMD proprietary driver 24.10.24, Vulkan 1.3.280, 128-byte push constants, LEONIDA_VK_VALIDATION=1, LEONIDA_PC_TAIL_UBO=1; plus NVIDIA RTX 4070 SUPER, driver 610.88):
So the finding is a driver-conformance gap (NVIDIA quiets sNaNs; llvmpipe also flushes f64 subnormals), not an RDNA2 hardware bug, and this PR removes the driver dependence. AMD RDNA2 + NVIDIA both verified clean. AI-assisted verification. |
|
AMD run (the "Windows; AMD hardware" gap): RX 9070 XT (RDNA4, GFX1201), AMD proprietary Windows driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11,
|
…undEven (GPU-ROUND-F64) linux-gpu-tools failed this fixture with `word 164 (thread 10): rndne of 0x3fe0000000000001 gave 0x0000000000000000`, on some runners and not on others. The cause is llvmpipe, not the translation: its double vectors are twice its native width (512 bits at the usual 256), and it has the exact Trunc and RoundEven only for a width the CPU has a vector extension for. Without AVX-512 the two ops go through the code it has for a float, where a magnitude above 2^24 comes back unchanged and RoundEven of a smaller one can give the other neighbouring integer. That is 48 of the 512 results, the same 48 with Mesa 25.2.8 (LLVM 20.1.2) on a runner and with Mesa 26.2.6 (LLVM 23.1.4) under GALLIUM_OVERRIDE_CPU_CAPS=avx, sse4.1 or sse2 on a Ryzen 9 7900X; Floor and Ceil are exact on that path, and with AVX-512 (or AVX at LP_NATIVE_VECTOR_WIDTH=128) so are all four. On llvmpipe the judge now lets v_trunc_f64 and v_rndne_f64 return what that path can give: the source itself above 2^24, either neighbouring integer with the source's sign from 0.5 up to it. Everything else stays exact there, and no other device gets the allowance (ROUND_F64_FLOAT_PATH, keyed like UNJUDGED_WORDS). dump_test hands the test program's output to a judge, for its device line. Tested: the fixture passes on llvmpipe natively and under each of the three overrides, at LP_NATIVE_VECTOR_WIDTH=128, and on the RTX 4070 Ti (NVIDIA 620.70.06) natively and with LEONIDA_W64_EMULATE=1; the previous judge fails under each override at word 164. tests/test_gpu_round_f64.py rebuilds the 48 measured results and checks that nothing wider passes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…dge keeps llvmpipe's float-path allowance ProjectLeonida#1034 gained a commit: on llvmpipe, v_trunc_f64 and v_rndne_f64 may return what its float code gives a double on a CPU without AVX-512 (the cause of this branch's red linux-gpu-tools, `word 164 (thread 10): rndne of 0x3fe0000000000001 gave 0x0000000000000000`). The judge here stays exact for every other word and device, a NaN and a subnormal included, and takes that one allowance; docs/testing.md says so next to "compared exactly". Tested on this merge: the fixture passes on llvmpipe (Mesa 26.2.6) natively and under GALLIUM_OVERRIDE_CPU_CAPS=avx and sse2, and on the RTX 4070 Ti (NVIDIA 620.70.06) natively and with LEONIDA_W64_EMULATE=1. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Brings the branch up to date with main 68d1331. No conflicts; the merged tree was tested before the push (every standalone test file under tests/ passes except tests/test_ci_registration.py, which fails on main alone since ProjectLeonida#930). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Brings the branch up to date with main 68d1331. No conflicts; the merged tree was tested before the push (every standalone test file under tests/ passes except tests/test_ci_registration.py, which fails on main alone since ProjectLeonida#930). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Brings the branch up to date with main 6558d53, which now holds ProjectLeonida#1012 (GPU-CMP-F64), the pull request this one was stacked on. Git merged it without conflicts (git merge-tree, exit 0). GitHub had reported a conflict since ProjectLeonida#1012 merged, with the branch and main on two merge bases (68d1331 and 5040782); main is an ancestor of this commit. The merged tree was tested before the push: every standalone test file under tests/ passes except tests/test_ci_registration.py, which fails on main 6558d53 alone (ProjectLeonida#1365 fixes it). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… with ProjectLeonida#1012 merged Takes the updated head of ProjectLeonida#1034's branch, which holds main 6558d53 (ProjectLeonida#1012, GPU-CMP-F64, is merged there). Git merged it without conflicts (git merge-tree, exit 0), and the tree is the one a direct merge of main gives. GitHub had reported a conflict since ProjectLeonida#1012 merged, with the branch and main on two merge bases (68d1331 and 5040782). Merging ProjectLeonida#1034's head instead of main leaves this branch with one merge base with main when ProjectLeonida#1034 merges. The merged tree was tested before the push: every standalone test file under tests/ passes except tests/test_ci_registration.py, which fails on main 6558d53 alone (ProjectLeonida#1365 fixes it). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Merged, after #1012 and #1034. Checked locally on
AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5). |
Claimed in the coordination issue as: SHADER-ROUND-F64-SPECIALS (#14 (comment))
Depends on: #1034, which depends on #1012 (this branch is one commit on top of them; the last commit is the one to review. #1034 adds the fixture that found this and that this makes exact.)
What and why
v_trunc_f64,v_ceil_f64,v_rndne_f64andv_floor_f64bitcast their source pair to%doubleand call the driver's GLSL.std.450Trunc,Ceil,RoundEvenorFloor. For two kinds of source the driver's answer is not RDNA2's (the finding linked above, measured withcs_w32_round_f64):0x7ff0000000000001gave0x7ff8000000000001), on an RTX 4070 Ti (NVIDIA 620.70.06) and on llvmpipe. The hardware returns a NaN unchanged (row indocs/design.md, gfx1036, IEEE=0).DenormPreservefor 64 bits, so a driver may read one as zero, and llvmpipe did:v_ceil_f64of0x0000000000000001gave +0 andv_floor_f64of its negative -0, where the hardware gives 1 and -1. Declaring the mode is not a way out: neither device reportsshaderDenormPreserveFloat64, and adding it by hand changed nothing on either.The translator now selects those two sources with integer ops on the words, after the source modifiers and before the output ones:
v_ceil_f64of a positive one,v_floor_f64of a negative one);With that,
cs_w32_round_f64drops the two allowances #1034 gave it and compares all 1152 heap words exactly.tests/semantic/test_f64_round.pygetsF64RoundSpecialSources, which runs the four ops in the interpreter under a model of a driver that quiets a NaN and reads a subnormal as zero. The row indocs/design.mddescribes the rule and how it was confirmed, and no longer lists the approximation #1034 recorded.Tested
At this head, llvm-mc 23.1.4, SPIRV-Tools v2026.4:
python -I scripts/run_gpu_tests.py --build runtime/build --filter cs_w32_round_f64 --require-pass: PASS ("1152 words exact") on the RTX 4070 Ti natively and withLEONIDA_W64_EMULATE=1, and on llvmpipe. One commit below, compared exactly, 15 of the 512 results differ on the 4070 Ti and 20 on llvmpipe.--filter f64on the 4070 Ti: 7/7 (cs_div_fmas_f64,cs_div_fmas_f64_rt,cs_f64_add,cs_w32_cmp_f64,cs_w32_round_f64,ps_f64_mods,ps_f64_round). The module passesspirv-val.v_ceil_f64lifting the negative subnormal (word 34),v_floor_f64lifting the positive one (word 38), a subnormal's result losing its sign (word 40), a NaN's low word dropped (word 784),rndnelowered asfloor(x + 0.5)(word 20),truncorceillowered asFloor, thenegor theabssource modifier ignored (words 8 and 26), the two result words swapped (word 8), the fixture without itsv_cmpx(word 30). Two are not caught everywhere and are not counted: a subnormal left to the driver fails on llvmpipe and passes on the 4070 Ti, which keeps binary64 denormals, andRoundEvenreplaced by GLSLRoundpasses on both, since both send a tie to the even integer.python -m unittest discover -s tests/semantic -p test_f64_round.py: 10 tests. Withtools/rdna2spirv.pyput back to the commit below,F64RoundSpecialSourcesfails in 18 subtests (the signalling NaNs for all four ops,ceilandfloorof a subnormal) and the other tests pass.python -I scripts/run_semantic_tests.py tests/semantic -j 8: 470 files, 6,169 tests, 0 files failed._f64op), so no game shader's translation changes.tests/test_gpu_round_f64.py(14 tests),tests/test_shader_checks.py(87),tests/test_run_gpu_tests.py(64),tests/test_semantic_translator_use.py,tests/test_docs_design_rows.py,tests/test_docs_links.py,tests/test_docs_repo_paths.py,tests/test_text_write_line_endings.py: OK.python -m compileall -q make_game.py tools testsandscripts/check_no_game_data.pyon the changed files: OK.Not run: the whole GPU suite at this head (the change is confined to the four ops, and every fixture that uses a binary64 op was run); llvm-mc 19; Windows; AMD hardware. The hardware's words are the row's gfx1036 measurement, which this does not repeat: the 4070 Ti and llvmpipe runs show that the translated module now gives those words on two drivers that used to differ.
Merge of #1034's
60c2ed910(88785d0f3). The redlinux-gpu-toolshere was #1034's fixture on a runner without AVX-512, where llvmpipe computesTruncandRoundEvenof a double with its float code (48 of the 512 results; details in #1034). #1034 now lets llvmpipe, and only llvmpipe, return what that path gives forv_trunc_f64andv_rndne_f64. This branch merges that commit; the one conflict was inround_f64_problem, where the judge stays exact for every other word and device, a NaN and a subnormal included, and takes that one allowance. The translator change is as reviewed at26d010b41. On the merge: the fixture passes on llvmpipe (Mesa 26.2.6) natively and underGALLIUM_OVERRIDE_CPU_CAPS=avxandsse2, and on the RTX 4070 Ti natively and withLEONIDA_W64_EMULATE=1;tests/test_gpu_round_f64.py,tests/test_shader_checks.py,tests/test_run_gpu_tests.pyandtests/semantic/test_f64_round.pypass, also on the tree merged withmain4a50caf.GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 620.70.06, Linux (CachyOS, kernel 7.3.3); Mesa llvmpipe 26.2.6 (LLVM 23.1.4), same machine
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.🤖 Generated with Claude Code