Skip to content

tests: GPU readback for the binary64 roundings, v_trunc_f64, v_ceil_f64, v_rndne_f64 and v_floor_f64 (GPU-ROUND-F64) - #1034

Merged
aslan2142 merged 4 commits into
ProjectLeonida:mainfrom
milk4sale:gpu-test/round-f64
Nov 24, 2026
Merged

aslan2142 merged 4 commits into
ProjectLeonida:mainfrom
milk4sale:gpu-test/round-f64

Conversation

@milk4sale

@milk4sale milk4sale commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: GPU-ROUND-F64 (#14 (comment))

Depends on: #1012 (this branch is one commit on top of it. Both add a memory-fed fixture next to cs_w32_shift64 and touch the same lines of check.py, run_gpu_tests.py and tests/test_shader_checks.py; the last commit is the one to review.)

What and why

v_trunc_f64, v_ceil_f64, v_rndne_f64 and v_floor_f64 are translated to the driver's double-precision Trunc, Ceil, RoundEven and Floor (shaderFloat64). The row in docs/design.md is CPU-checked and hardware-confirmed on gfx1036, but no fixture in runtime/test/shaders ran the four ops, 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.

This adds cs_w32_round_f64, memory-fed like cs_w32_shift64 (#590) and cs_w32_cmp_f64 (#1012):

  • check.py seeds 64 binary64 inputs through VKC_HEAP_INIT; each thread loads one at run time, so nothing folds.
  • A thread 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 (round_f64: exact IEEE-754, the result keeping its source's sign). tests/test_gpu_round_f64.py checks that oracle against exact rational rounding and against the values the row names, and checks the judge, the assembly, the readback and the runner verdicts without a GPU.
  • dump_test gets an optional judge for a readback that is not compared word for word.

What it found

Two differences between the row and what the translated module does on a driver, posted as a finding (#14 (comment)):

  1. A signalling NaN comes back quiet, with sign and payload kept (0x7ff0000000000001 gives 0x7ff8000000000001), on the RTX 4070 Ti and on llvmpipe. The hardware returns it unchanged.
  2. llvmpipe reads the two smallest subnormals as zero: v_ceil_f64 of the positive one gives +0 where the hardware gives 1. The 4070 Ti keeps them. The module declares no DenormPreserve for 64 bits, and neither device reports shaderDenormPreserveFloat64.

Vulkan allows a driver both, so the fixture judges those two kinds of input by that (a NaN may come back as any NaN; a subnormal may be read as a zero of its sign) and every other word exactly. The row now records both as an approximation. The fix is claimed separately as SHADER-ROUND-F64-SPECIALS and will make the judge exact; it is not in this pull request.

Added with 60c2ed910: a third difference, and the cause of the red linux-gpu-tools here. The job failed this fixture with word 164 (thread 10): rndne of 0x3fe0000000000001 gave 0x0000000000000000, on some runners and not on others. It is llvmpipe, not the translation: llvmpipe's 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. On a CPU without AVX-512 the two ops go through the code it has for a float: a magnitude above 2^24 comes back unchanged (v_trunc_f64 of 123456789.0625 is 123456789.0625), and RoundEven of a smaller one can give the other neighbouring integer (1 for 1.5, 0 for the value just above 0.5). That is 48 of the 512 results. Floor and Ceil are exact on that path. My llvmpipe run passed because this machine has AVX-512; GALLIUM_OVERRIDE_CPU_CAPS=avx (or sse4.1, sse2) on the same machine gives the runner's failure word for word, with Mesa 26.2.6 as with the runner's 25.2.8.

So on llvmpipe, and on no other device, the judge 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 (ROUND_F64_FLOAT_PATH in check.py, keyed by device name like UNJUDGED_WORDS). v_floor_f64, v_ceil_f64, the kept pair and the inputs stay exact there. dump_test passes the test program's output to a judge, for its device line.

No translator or runtime change here.

Tested

At this head (355c8c9c2; main 82a2aabcc plus #1012), 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 on the RTX 4070 Ti: PASS natively and with LEONIDA_W64_EMULATE=1; on llvmpipe: PASS. --filter cs_w32_ on the 4070 Ti: 22/22.
  • Read exactly, without the judge's two allowances: on the 4070 Ti 497 of the 512 results are the hardware's and the other 15 are those of the two signalling NaNs; on llvmpipe the same 15 and five from the two subnormals.
  • Rules broken one at a time, fixture rebuilt, on both devices; each failed: rndne lowered as floor(x + 0.5) (word 20, the sign of -0), trunc lowered as Floor, ceil lowered as Floor, the neg source modifier ignored (word 8), the abs one ignored (word 26), the low result word taken from the high one (word 8), and the fixture without its v_cmpx (word 30). One control did not fail and is not counted: RoundEven replaced by GLSL Round gives the same words on both devices, because both send a tie to the even integer.
  • python -I tests/test_gpu_round_f64.py (14 tests), tests/test_shader_checks.py (87), tests/test_run_gpu_tests.py (64), tests/test_gpu_cmp_f64.py, tests/test_gpu_shift64.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, tests/test_regen_fixtures.py: OK. python -m compileall -q make_game.py tools tests and scripts/check_no_game_data.py on the changed files: OK.
  • git merge-tree of this branch against main fce586c6d: clean.
  • At 60c2ed910: the fixture passes on llvmpipe (Mesa 26.2.6) natively, under GALLIUM_OVERRIDE_CPU_CAPS=avx, sse4.1 and sse2, and at LP_NATIVE_VECTOR_WIDTH=128, and on the RTX 4070 Ti natively and with LEONIDA_W64_EMULATE=1. The judge of 355c8c9c2 fails under each of the three overrides at word 164, as the runner did; a scratch judge that lists every wrong result gave the same 48 under each. tests/test_gpu_round_f64.py (18 tests now) rebuilds those 48 and checks that nothing wider passes: not a non-neighbour, a lost sign, an unchanged value below 2^24, anything for ceil or floor, or anything on another device. On the CI image itself (ubuntu-24.04, Mesa 25.2.8, LLVM 20.1.2; the Runtime workflow run on my fork from a scratch branch that sets the avx override and counts): the fixture passes and 48 results take the allowance; three runs without the override landed on runners where none did. The whole GPU suite on llvmpipe gives the same verdict for every fixture natively and under the avx override (172 of 254 passed, 80 skipped; the two that fail are cs_imgload_tfe and cs_imgload_d16_tfe, which this branch's base predates the fix of, tests: correct resident TFE status expectations (SHADER-1266) #892), so no other fixture depends on that path. On the tree merged with main 4a50caf every standalone test file under tests/ passes except tests/test_ctest_registration.py, which fails on main alone (test_ctest_registration: read a named skip code (kSkip) by its value (red on main since #927) #1252).

Not run: the whole GPU suite and the whole standard-library test set at this head (both ran for #1012, one commit below, with the results given there); llvm-mc 19, which the linux-gpu-tools job assembles with (not installed here); the translator suite (nothing under tools/ or tests/semantic/ changes); Windows; AMD hardware.

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 (Ryzen 9 7900X, also with GALLIUM_OVERRIDE_CPU_CAPS=avx, sse4.1 and sse2); Mesa llvmpipe 25.2.8 (LLVM 20.1.2) on a GitHub ubuntu-24.04 runner

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No new rule; the existing row now names the fixture and what it measured.)

🤖 Generated with Claude Code

…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>
@iFeyz

iFeyz commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

AMD run: RX 9070 XT (RDNA4, GFX1201), AMD proprietary Windows driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11. Head 355c8c9c2, scripts/run_gpu_tests.py --filter _f64 with the test programs of a current main build.

…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>
milk4sale added a commit to milk4sale/leonida that referenced this pull request Nov 24, 2026
…s llvmpipe 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. That fixture is in this stack and was this branch's red linux-gpu-tools (`word 164 (thread 10):
rndne of 0x3fe0000000000001 gave 0x0000000000000000`); cs_w32_frexp_ldexp passed in that run. No conflict.

Tested on this merge: `--filter cs_w32_` on llvmpipe (Mesa 26.2.6) natively and under
GALLIUM_OVERRIDE_CPU_CAPS=avx, 15 of 23 passed and 8 skipped in both, and 23 of 23 on the RTX 4070 Ti
(NVIDIA 620.70.06).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
milk4sale added a commit to milk4sale/leonida that referenced this pull request Nov 24, 2026
…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>
milk4sale and others added 2 commits November 24, 2026 16:31
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>
milk4sale added a commit to milk4sale/leonida that referenced this pull request Nov 24, 2026
… 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>
milk4sale added a commit to milk4sale/leonida that referenced this pull request Nov 24, 2026
…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>
@aslan2142
aslan2142 merged commit 3a73ce1 into ProjectLeonida:main Nov 24, 2026
4 of 5 checks passed
@aslan2142

Copy link
Copy Markdown
Collaborator

Merged, after #1012. Checked locally on main 16ff59721 + 69935f84e:

  • Claim: valid. GPU-ROUND-F64 was posted at 16:54 UTC, before this PR, and is unedited.
  • It passes on its own: with main's translator, cs_w32_round_f64 passes on llvmpipe (Mesa 26.3.1, also with GALLIUM_OVERRIDE_CPU_CAPS=avx and sse4.1) and on an RDNA2 iGPU (RADV); --filter f64 gives 7 of 7 on both.
  • The expected words agree with an exact rational rounding model for all 512 results: ties, ±0, the 2^52 boundary, −0 results, ±infinity and NaN.
  • On the merge: the semantic suite passes (475 files, 6,212 tests, 0 files failed); test_gpu_round_f64, test_run_gpu_tests, test_shader_checks pass; the 13 docs and writer tests pass; check_no_game_data.py is clean on the 7 changed files.
  • CI had not finished on this head.

A note for later, not blocking: on llvmpipe the float-path allowance lets trunc and rndne return either neighbouring integer, so the strict check of those two rests on the other devices. It is worth narrowing once #1047 is in, if the CI runners allow it.

AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants