rdna2spirv, docs: NVIDIA splits a binary64 Fma only when folding an all-constant one; add cs_div_fmas_f64_rt (FMA64-RT) #572

Manually merged
github merged 2 commits from gh-pr/572/head into gh-pr/572/base 2026-11-26 09:09:18 +00:00
Owner

@⁠DeSunShine on GitHub · 2026-11-24 08:43 UTC · original
DeSunShine:fma64-rt → main · +33 −7 · 6 files · 2 commits · merged 2026-11-24 15:50 UTC

Claim: FMA64-RT (issue #14). Carries on old upstream #8750, which was closed unmerged shortly before the original repository went private.

What changes

The binary64 Fma note added with the f64 FMA fix said NVIDIA's driver rounds GLSL Fma on doubles twice. That is too broad. Turing, Ampere and Ada split only an all-constant Fma that the driver folds while compiling the pipeline. The same operands read at run time are fused. Blackwell fuses both.

  • Wording in tools/rdna2spirv.py, docs/design.md, runtime/test/shaders/cs_div_fmas_f64.asm, scripts/run_gpu_tests.py and tests/semantic/test_fma_khr_f64.py now says this.
  • New fixture runtime/test/shaders/cs_div_fmas_f64_rt.asm: the same fma(a, a, c) cancellation probe (a = 1 + 2^-30, c = -(1 + 2^-29)) with its operands in s4..s7, seeded through VKC_SGPRS. The runner handles both fixtures in one branch.

Tested

RTX 4090, driver 621.24, Windows 11, default --fma glsl:

PASS  cs_div_fmas_f64       0x0 0x0 (split: ... when folding the constants; --fma khr fixes it)
PASS  cs_div_fmas_f64_rt    0x0 0x3c300000

The second result is fused (2^-60). The run-time result was also measured fused on an RTX 3070 (621.01) and an RTX 5060 Laptop, and on an RTX 4070 by the author of old #4536. tests/semantic/test_fma_khr_f64.py passes 5/5.

Synthetic fixtures only. No game files.

🤖 Generated with Claude Code

**@⁠DeSunShine** on GitHub · 2026-11-24 08:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/572) `DeSunShine:fma64-rt` → `main` · +33 −7 · 6 files · 2 commits · merged 2026-11-24 15:50 UTC Claim: FMA64-RT (issue #14). Carries on old upstream #8750, which was closed unmerged shortly before the original repository went private. ## What changes The binary64 `Fma` note added with the f64 FMA fix said NVIDIA's driver rounds GLSL `Fma` on doubles twice. That is too broad. Turing, Ampere and Ada split only an **all-constant** `Fma` that the driver folds while compiling the pipeline. The same operands read at run time are fused. Blackwell fuses both. - Wording in `tools/rdna2spirv.py`, `docs/design.md`, `runtime/test/shaders/cs_div_fmas_f64.asm`, `scripts/run_gpu_tests.py` and `tests/semantic/test_fma_khr_f64.py` now says this. - New fixture `runtime/test/shaders/cs_div_fmas_f64_rt.asm`: the same `fma(a, a, c)` cancellation probe (a = 1 + 2^-30, c = -(1 + 2^-29)) with its operands in s4..s7, seeded through `VKC_SGPRS`. The runner handles both fixtures in one branch. ## Tested RTX 4090, driver 621.24, Windows 11, default `--fma glsl`: ``` PASS cs_div_fmas_f64 0x0 0x0 (split: ... when folding the constants; --fma khr fixes it) PASS cs_div_fmas_f64_rt 0x0 0x3c300000 ``` The second result is fused (2^-60). The run-time result was also measured fused on an RTX 3070 (621.01) and an RTX 5060 Laptop, and on an RTX 4070 by the author of old #4536. `tests/semantic/test_fma_khr_f64.py` passes 5/5. Synthetic fixtures only. No game files. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Correcting #6635's wording. On an RTX 4090 (621.24) the split 0 of the
fma(a, a, c) probe comes from the driver folding an all-constant GLSL Fma
while compiling the pipeline: cs_div_fmas_f64's operands are literals.
The same values read at run time from user SGPRs (VKC_SGPRS) give the
fused 2^-60, as #4536 saw on an RTX 4070. --fma khr is still what makes
both single-rounded. Wording only in design.md's floating-point row,
cs_div_fmas_f64.asm's header, Gen.emit_fma64's docstring, the runner's
split note and test_fma_khr_f64's docstring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of #8750: the fused half of the claim had no fixture. The new
cs_div_fmas_f64_rt reads the same a and c from s4..s7 (VKC_SGPRS), so the
driver cannot fold the Fma; it is fused under the default GLSL Fma on the
RTX 4090 here. design.md now names the measured GPUs: the all-constant
Fma is split on the RTX 4090, RTX 3070 and Quadro RTX 4000 (Turing,
Linux) and fused on an RTX 5060 Laptop (Blackwell).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:09:16 +00:00
github manually merged commit 10b0052e57 into gh-pr/572/base 2026-11-26 09:09:18 +00:00
Author
Owner

@⁠qhukz13 on GitHub · 2026-11-24 11:25 UTC · original · reviewed

Reviewed on head 10b0052e5 (Linux, no GPU: CPU interpreter and the unit tests only).

Checked:

  • cs_div_fmas_f64_rt.asm: rsrc2 0x8090 gives 8 user SGPRs, so s4..s7 are seeded by VKC_SGPRS (low word first, matching DIV_FMAS_F64_SGPRS); the runner keeps VKC_SUBGROUP_SIZE from cs_env when it adds VKC_SGPRS.
  • tests/test_shader_checks.py 87/87, tests/test_run_gpu_tests.py 64/64, test_fma_khr_f64.py 5/5 (1 skipped, no spirv-val here), test_alu_div_fmas.py 9/9, compileall clean.
  • spirv_mini_interp on the same probe (v_div_fmas_f64, VCC = 0, a = 0x3ff00000_00400000, c = 0xbff00000_00800000) gives 0x3c300000_00000000, the fused 2^-60.
  • The red jobs are not from this diff: linux-gpu-tools fails cs_imgload_tfe / cs_imgload_d16_tfe, macos fails cs_fma_fused word 7 (f16); macOS skips both div_fmas fixtures (no shaderFloat64).

One data point this PR's CI already measured: on llvmpipe (LLVM 20.1.2, linux-gpu-tools job 138322550054) the run-time twin splits too:

PASS  cs_div_fmas_f64       0x0 0x0 (split ... when folding the constants ...)
PASS  cs_div_fmas_f64_rt    0x0 0x0 (split: the driver rounded GLSL Fma on doubles twice ...)

So "split only when folding an all-constant Fma" holds for the NVIDIA GPUs measured, not for every driver. The design.md row is already worded per GPU, but the emit_fma64 docstring and the test_fma_khr_f64.py docstring read as general; adding llvmpipe as a driver that splits both would keep anyone from reading the run-time result as safe. The runner's message for _rt on llvmpipe is already right.

Nits:

  • The PR description says Turing splits only the all-constant form, but the run-time twin was measured on Ada, Ampere and Blackwell; the Quadro RTX 4000 (Turing) row only has the constant result.
  • test_fma_khr_f64.py: "(run-time operands are fused) (RTX 4090, ..." has two parentheticals in a row.

Looks good to me otherwise.

**@⁠qhukz13** on GitHub · 2026-11-24 11:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/572#pullrequestreview-6038344190) · **reviewed** Reviewed on head 10b0052e5 (Linux, no GPU: CPU interpreter and the unit tests only). Checked: - `cs_div_fmas_f64_rt.asm`: rsrc2 0x8090 gives 8 user SGPRs, so s4..s7 are seeded by `VKC_SGPRS` (low word first, matching `DIV_FMAS_F64_SGPRS`); the runner keeps `VKC_SUBGROUP_SIZE` from `cs_env` when it adds `VKC_SGPRS`. - `tests/test_shader_checks.py` 87/87, `tests/test_run_gpu_tests.py` 64/64, `test_fma_khr_f64.py` 5/5 (1 skipped, no spirv-val here), `test_alu_div_fmas.py` 9/9, compileall clean. - `spirv_mini_interp` on the same probe (`v_div_fmas_f64`, VCC = 0, a = 0x3ff00000_00400000, c = 0xbff00000_00800000) gives 0x3c300000_00000000, the fused 2^-60. - The red jobs are not from this diff: linux-gpu-tools fails `cs_imgload_tfe` / `cs_imgload_d16_tfe`, macos fails `cs_fma_fused` word 7 (f16); macOS skips both div_fmas fixtures (no shaderFloat64). One data point this PR's CI already measured: on llvmpipe (LLVM 20.1.2, linux-gpu-tools job 138322550054) the run-time twin splits too: PASS cs_div_fmas_f64 0x0 0x0 (split ... when folding the constants ...) PASS cs_div_fmas_f64_rt 0x0 0x0 (split: the driver rounded GLSL Fma on doubles twice ...) So "split only when folding an all-constant Fma" holds for the NVIDIA GPUs measured, not for every driver. The design.md row is already worded per GPU, but the `emit_fma64` docstring and the `test_fma_khr_f64.py` docstring read as general; adding llvmpipe as a driver that splits both would keep anyone from reading the run-time result as safe. The runner's message for `_rt` on llvmpipe is already right. Nits: - The PR description says Turing splits only the all-constant form, but the run-time twin was measured on Ada, Ampere and Blackwell; the Quadro RTX 4000 (Turing) row only has the constant result. - `test_fma_khr_f64.py`: "(run-time operands are fused) (RTX 4090, ..." has two parentheticals in a row. Looks good to me otherwise.
Author
Owner

@⁠Timon360SB on GitHub · 2026-11-24 12:15 UTC · original

Independent verification — Turing and Blackwell

Tested exact PR head:
10b0052e570cc6786681bbcf36b61d85b20fc5a8

This addresses the missing Turing runtime-operand
measurement noted in the review.

Test environment

Configuration RTX 2060 SUPER RTX 5070
Architecture Turing Blackwell
NVIDIA driver 621.14 621.14
Windows 11 build 28000 26200
Vulkan API 1.4.357 1.4.357
Vulkan SDK 1.4.363.0 1.4.363.0
LLVM 21.1.8 21.1.8
MSVC 19.44.35230 19.44.35230
Build RelWithDebInfo RelWithDebInfo
Generator Ninja Multi-Config Ninja Multi-Config

Results

GPU Mode Constant FMA Runtime FMA
RTX 2060 SUPER Native Split Fused
RTX 2060 SUPER Wave64 emulation Split Fused
RTX 5070 Native Fused Fused
RTX 5070 Wave64 emulation Fused Fused

Exact output words:

RTX 2060 SUPER (both modes):

PASS cs_div_fmas_f64       0x0 0x0
PASS cs_div_fmas_f64_rt    0x0 0x3c300000

RTX 5070 (both modes):

PASS cs_div_fmas_f64       0x0 0x3c300000
PASS cs_div_fmas_f64_rt    0x0 0x3c300000

All 8 fixture executions passed. Shader translation
and spirv-val passed for both fixtures in every run.

The generated SPIR-V and index.json were also checked:

  • FMA mode: glsl.
  • Wave64 emulation enabled in the emulated runs.
  • No OpFmaKHR instructions.

Conclusion

The RTX 2060 SUPER confirms the previously missing
Turing data point: the constant-operand probe splits,
while the runtime-operand probe produces the fused
result (2^-60).

The RTX 5070 produces the fused result for both probes.

Results are identical between native and emulated
Wave64 on each tested GPU.

These measurements support the PR's description for
the tested NVIDIA GPUs and driver version. They do
not establish identical behavior across all drivers.

Synthetic fixtures only. No game files used.
AI-assisted test automation and result analysis.

**@⁠Timon360SB** on GitHub · 2026-11-24 12:15 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/572#issuecomment-7131196791) ## Independent verification — Turing and Blackwell Tested exact PR head: `10b0052e570cc6786681bbcf36b61d85b20fc5a8` This addresses the missing Turing runtime-operand measurement noted in the review. ### Test environment | Configuration | RTX 2060 SUPER | RTX 5070 | | --- | --- | --- | | Architecture | Turing | Blackwell | | NVIDIA driver | 621.14 | 621.14 | | Windows 11 build | 28000 | 26200 | | Vulkan API | 1.4.357 | 1.4.357 | | Vulkan SDK | 1.4.363.0 | 1.4.363.0 | | LLVM | 21.1.8 | 21.1.8 | | MSVC | 19.44.35230 | 19.44.35230 | | Build | RelWithDebInfo | RelWithDebInfo | | Generator | Ninja Multi-Config | Ninja Multi-Config | ### Results | GPU | Mode | Constant FMA | Runtime FMA | | --- | --- | --- | --- | | RTX 2060 SUPER | Native | Split | Fused | | RTX 2060 SUPER | Wave64 emulation | Split | Fused | | RTX 5070 | Native | Fused | Fused | | RTX 5070 | Wave64 emulation | Fused | Fused | Exact output words: RTX 2060 SUPER (both modes): PASS cs_div_fmas_f64 0x0 0x0 PASS cs_div_fmas_f64_rt 0x0 0x3c300000 RTX 5070 (both modes): PASS cs_div_fmas_f64 0x0 0x3c300000 PASS cs_div_fmas_f64_rt 0x0 0x3c300000 All 8 fixture executions passed. Shader translation and spirv-val passed for both fixtures in every run. The generated SPIR-V and index.json were also checked: - FMA mode: glsl. - Wave64 emulation enabled in the emulated runs. - No OpFmaKHR instructions. ### Conclusion The RTX 2060 SUPER confirms the previously missing Turing data point: the constant-operand probe splits, while the runtime-operand probe produces the fused result (2^-60). The RTX 5070 produces the fused result for both probes. Results are identical between native and emulated Wave64 on each tested GPU. These measurements support the PR's description for the tested NVIDIA GPUs and driver version. They do not establish identical behavior across all drivers. Synthetic fixtures only. No game files used. AI-assisted test automation and result analysis.
This discussion has been locked. Commenting is limited to contributors.
No description provided.