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

Closed
opened 2026-11-26 20:19:59 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1034
Author: @milk4sale
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: gpu-test/round-f64


📝 Commits (4)

  • 355c8c9 tests: GPU readback for the binary64 roundings, v_trunc_f64, v_ceil_f64, v_rndne_f64 and v_floor_f64 (GPU-ROUND-F64)
  • 60c2ed9 tests: cs_w32_round_f64 allows llvmpipe's float path for Trunc and RoundEven (GPU-ROUND-F64)
  • e040dce Merge main into gpu-test/round-f64
  • 69935f8 Merge main into gpu-test/round-f64

📊 Changes

7 files changed (+581 additions, -5 deletions)

View changed files

📝 docs/design.md (+1 -1)
📝 docs/testing.md (+37 -0)
📝 runtime/test/shaders/check.py (+153 -2)
➕ runtime/test/shaders/cs_w32_round_f64.asm (+56 -0)
📝 scripts/run_gpu_tests.py (+5 -0)
➕ tests/test_gpu_round_f64.py (+319 -0)
📝 tests/test_shader_checks.py (+10 -2)

📄 Description

Claimed in the coordination issue as: GPU-ROUND-F64 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7138391743)

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 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7138652249):

  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, #892), so no other fixture depends on that path. On the tree merged with main 4a50cafc7 every standalone test file under tests/ passes except tests/test_ctest_registration.py, which fails on main alone (#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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1034 **Author:** [@milk4sale](https://github.com/milk4sale) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `gpu-test/round-f64` --- ### 📝 Commits (4) - [`355c8c9`](https://github.com/ubiquitarianism/leonida/commit/355c8c9c2da01a9898df5061d266ca1f5567cdc9) tests: GPU readback for the binary64 roundings, v_trunc_f64, v_ceil_f64, v_rndne_f64 and v_floor_f64 (GPU-ROUND-F64) - [`60c2ed9`](https://github.com/ubiquitarianism/leonida/commit/60c2ed910b90aef3cf5af1df2366a28a25afbe64) tests: cs_w32_round_f64 allows llvmpipe's float path for Trunc and RoundEven (GPU-ROUND-F64) - [`e040dce`](https://github.com/ubiquitarianism/leonida/commit/e040dce1f09d42f21a8fed75668c53c0d49fb57a) Merge main into gpu-test/round-f64 - [`69935f8`](https://github.com/ubiquitarianism/leonida/commit/69935f84ee8d670626594c3c5e4a171b2e20fcf0) Merge main into gpu-test/round-f64 ### 📊 Changes **7 files changed** (+581 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) 📝 `docs/testing.md` (+37 -0) 📝 `runtime/test/shaders/check.py` (+153 -2) ➕ `runtime/test/shaders/cs_w32_round_f64.asm` (+56 -0) 📝 `scripts/run_gpu_tests.py` (+5 -0) ➕ `tests/test_gpu_round_f64.py` (+319 -0) 📝 `tests/test_shader_checks.py` (+10 -2) </details> ### 📄 Description Claimed in the coordination issue as: GPU-ROUND-F64 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7138391743) 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 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7138652249): 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, #892), so no other fixture depends on that path. On the tree merged with `main` 4a50cafc7 every standalone test file under `tests/` passes except `tests/test_ctest_registration.py`, which fails on `main` alone (#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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:59 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1072
No description provided.