tests: GPU-free repro of the FMA denormal-product divergence (TEST-FMA-DENORM-PRODUCT) #1692

Open
github-bot wants to merge 1 commit from github-bot/gh-1692 into main AGit
Owner

@⁠GTAVIB4GTAVI on GitHub · 2026-11-25 08:23 UTC · original
GTAVIB4GTAVI:test/fma-nvidia-repro → main · +261 −0 · 2 files · 1 commits · open

Claimed as: TEST-FMA-DENORM-PRODUCT (standalone claim issue #1594: #14 is at GitHub's 2,500-comment cap and rejects new comments)

What and why

whoalin1 reported on #14 (7150696174 (a), 7152027316 (c)) that on an RTX 4070 SUPER v_fmamk_f32 with an exact product of -2^-127 and addend 0x00ffffff returns the addend instead of RDNA2's 0x00bfffff: the driver flushes the denormal intermediate product. Nothing in the tree pinned that mix (cs_fma_fused probes rounding on normal products). This adds a repro that needs no GPU.

  • tests/semantic/fixtures/ps_fma_denorm_product.asm: hand-written, v_fmamk_f32, v_fmaak_f32, v_fma_f32, v_fmac_f32 on push-constant operands.
  • tests/semantic/test_fma_denorm_product.py, 12 tests, per --fma mode:
    • what is emitted: glsl one GLSL.std.450 Fma per op; khr one OpFmaKHR per op with FMAKHR and SPV_KHR_fma; exact no OpFmaKHR, every OpFMul/OpFAdd/OpFSub NoContraction, and its 4 GLSL Fma feed only OpSelect;
    • the mrt0 words under three models of the driver's fused op: fused (the hardware word in every mode); product-flushing (glsl and khr give the addend, the reported NVIDIA word; exact keeps the hardware word, also with every f32 denormal result flushed); NaN for every finite operand triple (exact unchanged).
    • the expected words are checked against exact rationals, not against the interpreter.

Test only: no translator change, no docs change. Whether NVIDIA's OpFmaKHR keeps the product has not been measured by anyone; the file only pins that khr leaves it to that one op. The sNaN item of 7152027316 is #1554's and is not part of this.

Tested

Windows 10 22H2, Python 3.12, SPIRV-Tools from Vulkan SDK 1.4.363.0.

  • python -m unittest discover -s tests/semantic -p test_fma_denorm_product.py: 12 tests OK, on main 3f81d46ac (after rebase) and on c7e82e26e.
  • python -I scripts/run_semantic_tests.py tests/semantic -j 8, same base c7e82e26e: without the commit 487 files / 6,279 tests / 0 files failed; with it 488 / 6,291 / 0 files failed. Not re-run after the rebase onto 3f81d46ac.
  • python -I scripts/check_no_game_data.py on both files: clean.

GPUs tested: n/a (CPU interpreter only; the divergence itself was not measured on this box's RTX 2080 Ti)

AI-assisted: yes

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. (n/a: test only)

🤖 Generated with Claude Code

**@⁠GTAVIB4GTAVI** on GitHub · 2026-11-25 08:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1692) `GTAVIB4GTAVI:test/fma-nvidia-repro` → `main` · +261 −0 · 2 files · 1 commits · open Claimed as: TEST-FMA-DENORM-PRODUCT (standalone claim issue #1594: #14 is at GitHub's 2,500-comment cap and rejects new comments) ### What and why whoalin1 reported on #14 (7150696174 (a), 7152027316 (c)) that on an RTX 4070 SUPER `v_fmamk_f32` with an exact product of `-2^-127` and addend `0x00ffffff` returns the addend instead of RDNA2's `0x00bfffff`: the driver flushes the denormal intermediate product. Nothing in the tree pinned that mix (`cs_fma_fused` probes rounding on normal products). This adds a repro that needs no GPU. - `tests/semantic/fixtures/ps_fma_denorm_product.asm`: hand-written, `v_fmamk_f32`, `v_fmaak_f32`, `v_fma_f32`, `v_fmac_f32` on push-constant operands. - `tests/semantic/test_fma_denorm_product.py`, 12 tests, per `--fma` mode: - what is emitted: `glsl` one GLSL.std.450 `Fma` per op; `khr` one `OpFmaKHR` per op with `FMAKHR` and `SPV_KHR_fma`; `exact` no `OpFmaKHR`, every `OpFMul`/`OpFAdd`/`OpFSub` `NoContraction`, and its 4 GLSL `Fma` feed only `OpSelect`; - the mrt0 words under three models of the driver's fused op: fused (the hardware word in every mode); product-flushing (`glsl` and `khr` give the addend, the reported NVIDIA word; `exact` keeps the hardware word, also with every f32 denormal result flushed); NaN for every finite operand triple (`exact` unchanged). - the expected words are checked against exact rationals, not against the interpreter. Test only: no translator change, no docs change. Whether NVIDIA's `OpFmaKHR` keeps the product has not been measured by anyone; the file only pins that `khr` leaves it to that one op. The sNaN item of 7152027316 is #1554's and is not part of this. ### Tested Windows 10 22H2, Python 3.12, SPIRV-Tools from Vulkan SDK 1.4.363.0. - `python -m unittest discover -s tests/semantic -p test_fma_denorm_product.py`: 12 tests OK, on `main` 3f81d46ac (after rebase) and on c7e82e26e. - `python -I scripts/run_semantic_tests.py tests/semantic -j 8`, same base c7e82e26e: without the commit 487 files / 6,279 tests / 0 files failed; with it 488 / 6,291 / 0 files failed. Not re-run after the rebase onto 3f81d46ac. - `python -I scripts/check_no_game_data.py` on both files: clean. GPUs tested: n/a (CPU interpreter only; the divergence itself was not measured on this box's RTX 2080 Ti) AI-assisted: yes ### 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. (n/a: test only) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
v_fmamk_f32 with an exact product of -2^-127 and addend 0x00ffffff is 0x00bfffff on RDNA2; an RTX 4070 SUPER
returned the addend (whoalin1, #14 comments 7150696174 (a) and 7152027316 (c)). Nothing pinned that mix:
cs_fma_fused probes rounding on normal products.

tests/semantic/fixtures/ps_fma_denorm_product.asm runs v_fmamk/fmaak/fma/fmac_f32 on push-constant operands.
tests/semantic/test_fma_denorm_product.py (12 tests) pins, per --fma mode:
- glsl: one GLSL.std.450 Fma per op. khr: one OpFmaKHR per op, with FMAKHR and SPV_KHR_fma. exact: no OpFmaKHR,
  every FMul/FAdd/FSub NoContraction (124 for the 4 ops), and its 4 GLSL Fma feed only OpSelect.
- the words under three models of the driver's fused op: fused (0x00bfffff in every mode); flushing a denormal
  product (glsl and khr give the addend, NVIDIA's word; exact keeps 0x00bfffff, also with every f32 denormal
  result flushed); NaN for every finite operand triple (exact unchanged).
Expected words are checked against exact rationals, not against the interpreter. With exact's tiny-product
2^96 scaling disabled in a copy of tools/, 4 subtests fail. spirv-val accepts all three modes.

Semantic suite, same base c7e82e26e, -j 6: A 487 files / 6,279 tests / 0 failed; B 488 / 6,291 / 0 failed.

Test only, no translator change, no game data. The sNaN item of 7152027316 is #1554's. Claim: #1594.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: GTAVIB4GTAVI <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:01:03 +00:00
Author
Owner

@⁠mcpeacebir-lang on GitHub · 2026-11-25 11:22 UTC · original

Verified on native Windows: head 12f177867 merged onto current main bcaa13dad (merges cleanly, test-only diff of 2 files). Windows 11 Pro 26200, CPython 3.14.4, 16 cores. No GPU, no game files.

  • python -m unittest discover -s tests/semantic -p test_fma_denorm_product.py: 12 tests OK. test_spirv_tools_accept_every_mode was skipped: SPIRV-Tools is not on PATH on this machine.
  • python -I scripts/run_semantic_tests.py tests/semantic (16 jobs), main + this PR: 489 files / 6,299 tests / 0 files failed. On main alone the same machine gave 488 / 6,287 / 0 failed, so this also covers the rebase the PR body says was not re-run.
  • Mutation check: with emit_fma in a copy of tools/rdna2spirv.py changed so that --fma exact falls back to GLSL Fma (elif FMA_EXACT: -> elif False:), run through LEONIDA_TOOLS_DIR, 4 of the 12 tests fail (15 subtest failures): both EmittedOps exact checks plus test_exact_keeps_the_product_under_a_flushing_driver and test_exact_takes_no_finite_word_from_the_driver_fma. The file guards the exact path, not only the current output.
  • The pinned words recomputed by hand: -2^-64 * 2^-63 + 0x00ffffff = (2^24 - 1 - 2^22) * 2^-149 = 0x00bfffff; 2^-130 + 2^-126 = 0x00880000; 2^-130 + 0x00ffffff is the tie (2^24 - 1 + 2^19) * 2^-149, which rounds to the even 0x01040000. All match CASES.
  • scripts/check_no_game_data.py on both files: clean. git diff --check: clean. tests/test_text_write_line_endings.py: OK.

No changes requested from me.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠mcpeacebir-lang** on GitHub · 2026-11-25 11:22 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1692#issuecomment-7160956928) Verified on native Windows: head `12f177867` merged onto current `main` `bcaa13dad` (merges cleanly, test-only diff of 2 files). Windows 11 Pro 26200, CPython 3.14.4, 16 cores. No GPU, no game files. - `python -m unittest discover -s tests/semantic -p test_fma_denorm_product.py`: 12 tests OK. `test_spirv_tools_accept_every_mode` was skipped: SPIRV-Tools is not on PATH on this machine. - `python -I scripts/run_semantic_tests.py tests/semantic` (16 jobs), main + this PR: 489 files / 6,299 tests / 0 files failed. On main alone the same machine gave 488 / 6,287 / 0 failed, so this also covers the rebase the PR body says was not re-run. - Mutation check: with `emit_fma` in a copy of `tools/rdna2spirv.py` changed so that `--fma exact` falls back to GLSL `Fma` (`elif FMA_EXACT:` -> `elif False:`), run through `LEONIDA_TOOLS_DIR`, 4 of the 12 tests fail (15 subtest failures): both `EmittedOps` exact checks plus `test_exact_keeps_the_product_under_a_flushing_driver` and `test_exact_takes_no_finite_word_from_the_driver_fma`. The file guards the exact path, not only the current output. - The pinned words recomputed by hand: `-2^-64 * 2^-63 + 0x00ffffff` = (2^24 - 1 - 2^22) * 2^-149 = `0x00bfffff`; `2^-130 + 2^-126` = `0x00880000`; `2^-130 + 0x00ffffff` is the tie (2^24 - 1 + 2^19) * 2^-149, which rounds to the even `0x01040000`. All match `CASES`. - `scripts/check_no_game_data.py` on both files: clean. `git diff --check`: clean. `tests/test_text_write_line_endings.py`: OK. No changes requested from me. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 17:36 UTC · original

Reviewed 12f1778: the new semantic test passes (12 tests; the spirv-as/val subtest skips here, so its spirv-val claim is not verified by me), and the same two files copied onto main pass too, as expected for a test-only change; test_fma_exact and test_fma_khr pass on both trees; check_no_game_data is clean. Checked the central claim: with exact's tiny-product 2^96 scaling disabled in a copy of tools/, exactly the 4 predicted exact-mode subtests fail, so the GPU-free repro really does pin the divergence. The full suite was not rerun.

AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 17:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1692#issuecomment-7169737487) Reviewed 12f1778: the new semantic test passes (12 tests; the spirv-as/val subtest skips here, so its spirv-val claim is not verified by me), and the same two files copied onto main pass too, as expected for a test-only change; test_fma_exact and test_fma_khr pass on both trees; check_no_game_data is clean. Checked the central claim: with exact's tiny-product 2^96 scaling disabled in a copy of tools/, exactly the 4 predicted exact-mode subtests fail, so the GPU-free repro really does pin the divergence. The full suite was not rerun. AI-assisted review. **Recommendation:** Merge
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1692/head:github-bot/gh-1692'
git switch 'github-bot/gh-1692'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1692'
git switch 'github-bot/gh-1692'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1692'
git switch 'github-bot/gh-1692'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1692'
git switch 'main'
git merge --squash 'github-bot/gh-1692'
git switch 'main'
git merge --ff-only 'github-bot/gh-1692'
git switch 'main'
git merge 'github-bot/gh-1692'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.