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

Merged
GTAVIB4GTAVI merged 1 commit from upstream-pr/1692 into main 2026-11-28 11:54:35 +00:00
GTAVIB4GTAVI commented 2026-11-25 08:23:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by GTAVIB4GTAVI on 2026-11-25T08:23:11Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5487747038 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1692). Originally posted by [GTAVIB4GTAVI](https://github.com/GTAVIB4GTAVI) on 2026-11-25T08:23:11Z. --- 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)
mcpeacebir-lang commented 2026-11-25 11:22:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by mcpeacebir-lang on 2026-11-25T11:22:18Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7160956928 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1692#issuecomment-7160956928). Originally posted by [mcpeacebir-lang](https://github.com/mcpeacebir-lang) on 2026-11-25T11:22:18Z. --- 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).
PierreEbele commented 2026-11-25 17:36:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T17:36:09Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7169737487 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1692#issuecomment-7169737487). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T17:36:09Z. --- 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
sodove commented 2026-11-28 10:44:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:44:49Z.


#1692 | head 12f177867863936c83dc49ac81f211ddb720e47d | python3 -m unittest discover -s tests/semantic -p test_fma_denorm_product.py -v | red: 12 passed | green: 12 passed | Passed on both trees. Fused results on both trees, AMD KHR skipped

Test-only PR. The CPU suite exercises the fused, flushing and poisoned driver models. All 12 tests passed in both phases.

Captured 3 distinct complete SPIR-V module(s) emitted while rerunning test_fma_denorm_product.py on the merged tree. All assembled and passed spirv-val for Vulkan 1.2 with --allow-offset-texture-operand.

Additional physical-device measurement using this PR’s fixture.translate(mode), CASES inputs and expected four words per pixel. I drew an 8×8 target for each mode/input pair with the unmodified Vulkan harness and vs_ids. On both trees RTX 5070 Ti returned the fused result in GLSL, KHR and exact modes. AMD did so in GLSL and exact, and returned skip 77 for KHR (shaderFmaFloat32 unavailable). All 64 pixels matched in every executed draw, including both subnormal products. The previously reported product flush on RTX 4070 SUPER did not reproduce on this RTX 5070 Ti and driver.

Windows Vulkan adapters: AMD Radeon(TM) Graphics (26.11.2) and NVIDIA GeForce RTX 5070 Ti (610.74).

Additional commands

  • vk_harness vs_ids.spv <mode>.spv <out.raw> 8 8 (VKH_SGPRS from each PR test vector)

Base 3bd936ecd98995bca3e1da83d5e28d2343001aef was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Native runs used Windows 11, Python 3.12.10. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238095304 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1692#issuecomment-7238095304). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T10:44:49Z. --- #1692 | head `12f177867863936c83dc49ac81f211ddb720e47d` | `python3 -m unittest discover -s tests/semantic -p test_fma_denorm_product.py -v` | red: 12 passed | green: 12 passed | **Passed on both trees. Fused results on both trees, AMD KHR skipped** Test-only PR. The CPU suite exercises the fused, flushing and poisoned driver models. All 12 tests passed in both phases. Captured 3 distinct complete SPIR-V module(s) emitted while rerunning test_fma_denorm_product.py on the merged tree. All assembled and passed spirv-val for Vulkan 1.2 with --allow-offset-texture-operand. Additional physical-device measurement using this PR’s fixture.translate(mode), CASES inputs and expected four words per pixel. I drew an 8×8 target for each mode/input pair with the unmodified Vulkan harness and vs_ids. On both trees RTX 5070 Ti returned the fused result in GLSL, KHR and exact modes. AMD did so in GLSL and exact, and returned skip 77 for KHR (shaderFmaFloat32 unavailable). All 64 pixels matched in every executed draw, including both subnormal products. The previously reported product flush on RTX 4070 SUPER did not reproduce on this RTX 5070 Ti and driver. Windows Vulkan adapters: AMD Radeon(TM) Graphics (26.11.2) and NVIDIA GeForce RTX 5070 Ti (610.74). Additional commands - `vk_harness vs_ids.spv <mode>.spv <out.raw> 8 8 (VKH_SGPRS from each PR test vector)` Base `3bd936ecd98995bca3e1da83d5e28d2343001aef` was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Native runs used Windows 11, Python 3.12.10. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7237873883).
DadaCap commented 2026-11-28 11:54:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T11:54:38Z.


Merged, thank you @GTAVIB4GTAVI! This translator PR (tests: GPU-free repro of the FMA denormal-product divergence (TEST-FMA-DENORM-PRODUCT)) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238863113 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1692#issuecomment-7238863113). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:54:38Z. --- Merged, thank you @GTAVIB4GTAVI! This translator PR (tests: GPU-free repro of the FMA denormal-product divergence (TEST-FMA-DENORM-PRODUCT)) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1692
No description provided.