tests: cs_fma_fused takes its f16 operands at run time, like its f32 ones (TEST-FMA-FUSED-F16-RUNTIME) #1724
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1724"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by hugo0024 on 2026-11-25T09:46:50Z.
Claimed in the coordination issue as: TEST-FMA-FUSED-F16-RUNTIME (claim)
What and why
cs_fma_fusedfails on a Mac with MoltenVK 1.4.2 in word 7, thev_fma_f16:docs/testing.mdhas a Known problems row for it and the macOS job lists it inEXPECTED_FAILURES. On an Apple M5 the word reads0x0000, want0x7351.The translation is not what is wrong. The fixture reads the operands of its f32 multiply-adds from
s4..s7"so a driver cannot fold the multiply-adds at compile time", but the three operands of the f16 one were literals, so that whole multiply-add was a compile-time constant, and MoltenVK 1.4.2 gets that constant wrong. Measured on the M5 with the fixture otherwise unchanged:main)0x00000x73510x73510x7351runtime/test/shaders/cs_fma_fused.asm: the f16 triple is thes4word XOR a literal each (0x3f800800 ^ 0x3f8064e1 = 0x6ce1, and so on), so it is the same triple at run time, and the header says why.tests/semantic/test_fma_fused_fixture.py: the translated fixture gives the eight words of its header in the interpreter, and every register one of its multiply-adds reads comes froms4..s7, so a literal operand cannot come back unnoticed.docs/testing.md: the Known problems row now says what is left, an f16 multiply-add whose three operands are all constants, and that the fixture no longer has one. A second row records what the review measured on KosmicKrisp (Mesa 26.3.1, Apple M3): with the operands taken at run time word 7 reads0x7352there, where the folded constant was exact. That row says the test is expected to fail there and why the f16 word gets no allowance.tests/semantic/README.mdlists the new test..github/workflows/runtime.yml:cs_fma_fusedis out of the macOS job'sEXPECTED_FAILURES. That job's run on the first version of this pull request, with the entry still listed, printedcs_fma_fused passed: drop it from the expected failures, so the runner's MoltenVK 1.4.2 (Apple Paravirtual device) agrees with the M5.The translator,
check.pyandrun_gpu_tests.pyare not changed: the expected words are the same.Tested
Apple M5, MoltenVK 1.4.2, llvm-mc 23.1.6, SPIRV-Tools v2026.4. Before is
main626d1281a, after is this branch on3de22a190(the fixture, the translator and the two runners are the same at both), with the test programs built from626d1281a.run_gpu_tests.py --filter cs_fma_fused, 5 runsword 7 (f16): got 0x00000000, want 0x000073518/8 fused exact (GLSL Fma)LEONIDA_FMA=exact, 5 runsLEONIDA_W64_EMULATE=1build.py <out> cs_fma_fused, thencheck.pyword 7 (f16): got 0x00000000, want 0x00007351okrun_gpu_tests.py, all testscs_fma_fused,cs_imgatomic_extcs_imgatomic_ext,ps_imgatomiccs_fma_fused(fail to pass) andps_imgatomic(pass to fail). The second is the intermittent #543, not this change: its module is byte-identical in both runs, and run alone six times it passes five and fails one in each tree.cs_imgatomic_extis red onmainand claimed by someone else (GPU-IMG-ATOMIC-EXT-VOLUME-TAG).273 shaders: 272 translated, 272 pass spirv-valin both, and 1 of the 275 modules in the work folder changes:cs_fma_fused.LEONIDA_FMA=exactpassed before is the same effect, not a fix: it changes only how the f32 multiply-adds around the f16 one are translated; the f16 one does not useFmain either mode (Gen.fma_f16_odd).tests/semantic/test_fma_fused_fixture.py: 3 tests pass; againstmain's fixture the run-time check fails (['v15', 'v16', 'v17'] != []). With one operand word changed by one bit the eight-word check fails, so it does compare.python3 -I scripts/run_semantic_tests.py tests/semantic: 487 files, 6,279 tests, 0 failed before; 488 files, 6,282 tests, 0 failed after.tests/test_translate.pyoncs_dpp_cmp.asm, #1375's subject;cs_fma_fused.asmassembles and validates there as before).main; none is touched here (#1412 and #1561 have fixed them onmainsince).tests/test_docs_*.pypass;python3 -I scripts/check_no_game_data.pyis clean on the new test and the fixture.Run again on 28 November after a rebase onto
mainef8fbf09f(the same M5, test programs built from thatmain):main'scs_fma_fusedstill fails withword 7 (f16): got 0x00000000, want 0x00007351, and this branch passes 5 of 5 by default and 5 of 5 withLEONIDA_FMA=exact.run_gpu_tests.py, all tests:main197/271 passed, 72 skipped, failedcs_fma_fusedandcs_imgatomic_ext; this branch 198/271 passed, 72 skipped, failedcs_imgatomic_ext, and no other test differs. Translator suite: 505 files, 6,397 tests, 0 failed onmain; 506 files, 6,400 tests, 0 failed here.Not tested here: any GPU other than the M5. The KosmicKrisp numbers are the reviewers', measured on an Apple M3; I have no KosmicKrisp. On a driver that evaluated the constant correctly the only change is that the f16 word is computed at run time.
GPUs tested: Apple M5 (8-core GPU), MoltenVK 1.4.2, macOS 27.2.1 (26B131)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-25T10:16:31Z.
Tested on an Apple M3 (macOS 26.5.1), this branch at
aebef89d1, test programs built frommain626d1281a:main0x00000000(20/20)0x00007352, want0x00007351So the fix works for MoltenVK, but on KosmicKrisp the f16 multiply-add was only exact while it was a compile-time constant: computed at run time it reads one ulp off, which looks like KosmicKrisp splitting the f16
Fmaas it splits six of the seven f32 ones (those the check accepts as split). The macOS job runs MoltenVK only, so CI would not show it. AI-assisted (Claude Code).Imported from ubiquitarianism/leonida. Originally posted by potatoe0100 on 2026-11-25T10:29:26Z.
Tested
aebef89d1merged ontomain57ba40bd6(clean), native Windows 11 Pro 26H2 (build 26300), NVIDIA GeForce RTX 4060, driver 621.14, VS 2022 RelWithDebInfo + Ninja, llvm-mc 21.1.8.run_gpu_tests.py --filter cs_fma_fused:main8/8 fused exact (GLSL Fma)LEONIDA_FMA=exact8/8 fused exact (single-rounded FMA: OpFmaKHR or --fma exact)LEONIDA_W64_EMULATE=1LEONIDA_VK_VALIDATION=1+ GPU-AVSo NVIDIA never hit the word 7 zero that MoltenVK did, and the run-time f16 operands don't change anything here.
python -I tests/semantic/test_fma_fused_fixture.py: 3 tests OK.AI-assisted testing (non-developer tester).
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-25T10:34:36Z.
Review: COMMENTED
Independent CPU check at
aebef89d: the three fixture tests passed. With the same test file copied to the merge base3de22a19, only the runtime-operand check failed, on the original three literal-fed registers.The f16 operands also let us quantify the one-ULP result Tauwni reported on KosmicKrisp. The exact product is 14988, halfway between binary16 values 14984 (
0x7351) and 14992 (0x7352). The addend is -2^-22. A single rounding gives0x7351; rounding the product first to nearest-even gives0x7352, and rounding the following sum keeps it there. That matches the reported value under separate rounding.AI-assisted, CPU-only verification. No independent driver trace or Mac run.
Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-25T10:54:25Z.
Review: APPROVED
### Clean-Room & Technical Verification
main(bcaa13dad) is 100% clean with zero merge conflicts.check_no_game_data.pyclean).runtime/test/shaders/cs_fma_fused.asm, replaces hardcoded literals for thev_fma_f16test case with dynamic run-time registers derived froms4XOR literals.0x0000/0x3c00instead of the expected0x7351round-to-odd result.tests/semantic/test_fma_fused_fixture.pyvalidating that every multiply-add in the fixture consumes run-time registers rather than folding literals, while verifying correct word generation inspirv_mini_interp.docs/testing.md.LGTM! Approved.
Imported from ubiquitarianism/leonida. Originally posted by hugo0024 on 2026-11-25T11:25:09Z.
@Tauwni thank you for the three-driver run. I have no KosmicKrisp here, so yours is the only measurement of it, and @lixonik's arithmetic matches the fixture's header, which gives
0x7352as the f32-then-f16 value. So on KosmicKrisp the round-to-odd result is lost when the multiply-add is computed on the GPU, and the literal form passed there because the constant was folded exactly.I kept the run-time operands. With literals the word checks a compiler's constant folder on either driver, and the one-step difference on KosmicKrisp holds for any run-time
v_fma_f16, which the fixture did not show before.0003d3de7adds a Known problems row for it with your numbers (Apple M3, Mesa 26.3.1, 20 of 20) and a line in the fixture's header; no instruction changes.Thanks also to @potatoe0100 for the RTX 4060 run. AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by adrianmjim on 2026-11-25T12:00:46Z.
Tested this PR's diff at
0003d3de7, applied ontomain42537e7b6, on AMD: Radeon RX 7900 XT (RDNA3), driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, Vulkan SDK 1.4.363.0, llvm-mc 23.1.5, test programs from amain42537e7b6build. This is the first AMD run of this branch. With the f16 operands at run time, the driver can no longer fold them at compile time, so word 7 now checks thefma_f16_oddsequence as the GPU runs it, not a value the compiler may have folded. No game files.--filter cs_fma_fusedFma), 5 runs8/8 fused exact (GLSL Fma)LEONIDA_FMA=exact, 5 runs8/8 fused exact (single-rounded FMA: OpFmaKHR or --fma exact)LEONIDA_FMA=khr, 5 runsLEONIDA_W64_EMULATE=18/8 fused exact (GLSL Fma)main's fixture, for comparison8/8 fused exact (GLSL Fma)So on AMD the run-time round-to-odd sequence gives
0x7351(KosmicKrisp gave0x7352), and the seven f32 words come out fused in all three modes. Word 7 is the same SPIR-V in every mode, so the repeat runs only confirm the same result.Imported from ubiquitarianism/leonida. Originally posted by EvgHaze on 2026-11-25T12:48:54Z.
Apple check — and this one changes a result on KosmicKrisp, so it may need a decision.
2x2: fixture × driver
mainfixtureword 7 (f16): got 0x00000000, want 0x000073518/8 fused exact (GLSL Fma)f16 exactword 7 (f16): got 0x00007352, want 0x00007351So on this machine the change does exactly what it says for MoltenVK — the old fixture's constant-folded operand gave
0x00000000there, and with runtime operands MoltenVK is exact. But the same runtime operand makes KosmicKrisp return0x7352where the fixture now wants0x7351, one ULP off, while the old constant-folded fixture passed on KosmicKrisp.Two readings, and I cannot tell them apart from a Mac:
docs/testing.mdKnown-problems row for KosmicKrisp (like the other rows), not a weaker expectation;What is certain: merging this as-is turns a passing KosmicKrisp run red on an Apple M3, so it should not land without either a known-problems row or a word verified on hardware.
I can run the same 2x2 on a second Mac configuration if that helps narrow it (another M-series machine, or KosmicKrisp built from a newer Mesa).
AI-assisted. No game data: the fixture is hand-written and every number above is test output.
Imported from ubiquitarianism/leonida. Originally posted by EvgHaze on 2026-11-25T13:19:07Z.
Correction to my comment above: the head
0003d3dealready carries the KosmicKrisp row indocs/testing.md("cs_fma_fusedfails on a Mac with KosmicKrisp: word 7 reads0x7352, want0x7351"), and its arithmetic matches what I measured exactly —0x7352on an Apple M3 with Mesa 26.3.1, and the rule is that the f16 form does not go throughFma, so--fma glsldoes not cover it. So the "needs a known-problems row" half of my earlier comment is answered.The part that is still open is the runner, not the docs:
scripts/run_gpu_tests.py --filter cs_fma_fusedwith this diff on KosmicKrisp reportsand there is no per-driver allowance in the diff (the four changed files are
docs/testing.md, the fixture, the semantic README and the semantic test). Onmainthat test passes on KosmicKrisp because the literals fold exactly, so after this lands an Apple contributor running the GPU suite on KosmicKrisp sees one red test that the docs say is expected.Is that intended (KK red, documented, no allowance), or should the runner accept the measured KK word the way
ps_nan_payloadaccepts the canonical NaN only for KosmicKrisp? Either way works for me; I only want the expectation stated so the next Apple run is not read as a regression. I can make the runner change and test it on both drivers if you want it.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-26T06:22:36Z.
Following up on the KosmicKrisp word 7 (
0x7352, want0x7351): I narrowed it down, and the cause is in the driver's optimiser, not infma_f16_odd.Apple M3, macOS 26.5.1. KosmicKrisp and llvmpipe are Mesa 26.3.1 through the loader, MoltenVK is 1.4.2. Scratch fixtures took their operands from
s4 = 0x3f800800through XOR, as #1724 does. They were translated bymaina73a57e13and run withvk_compute_test.v_cvt_f32_f16of0x8004gives0xb4800000on all three drivers, and so doesv_add_f16of it with itself (0x8008). So this is not a denormal flush.fma_f16_oddfrom plain VALU ops (v_mul_f32p = x·y,v_add_f32s = p+z, then the fourv_sub_f32and the finalv_add_f32), each one aNoContractionop in the SPIR-V. I stored every intermediate. All three drivers give the same words: p = s =0x466a3000, bb = 0, sb = s, da = 0, db = err =0xb4800000.errstored, KosmicKrisp returns0x00000000. It is the same seven ops, still all decoratedNoContraction. MoltenVK and llvmpipe return0xb4800000.So once the intermediates are dead, KosmicKrisp folds the TwoSum algebraically:
(p + z) - p→z, thenerr→ 0. TheNoContractiondecoration should forbid that, like NIR'sexact. Witherr= 0,fma_f16_oddnever makes the f32 sum odd, and the f16 rounding becomes the f32-then-f16 value0x7352, which is the word measured. Words 0 to 6 are not affected, because they useFmaand not this sequence.So this supports reading 1 in @EvgHaze's comment: the fixture's
0x7351is right (AMD gives it too, from @adrianmjim's run), and the KosmicKrisp known-problems row describes a driver bug. That bug probably also affects every otherNoContractionerror-term sequence on KosmicKrisp (fma_mix_odd,--fma exact), but I have only measured this one.The
err-only probe, for anyone who wants to report it to Mesa:No change to this PR from me. This is only meant to settle which word is the reference.
AI-assisted (Claude Code). No game data.
Imported from ubiquitarianism/leonida. Originally posted by hugo0024 on 2026-11-26T07:37:21Z.
@EvgHaze thanks for the 2x2 on both drivers and for the correction, and @Tauwni for narrowing it down.
Intended: red on KosmicKrisp, documented, no allowance. That is how the
cs_bvh/cs_bvh32row for KosmicKrisp just above the new one is handled, and it says not to weaken the expected words.0x7352is the word the fixture's header gives for rounding to f32 and then to f16, the result word 7 exists to tell apart from the single rounding, andjudge_fma_fusedsays the f16 word "must always be exact". A checker that accepted0x7352on KosmicKrisp would stop testing the f16 form there.ps_nan_payload's allowance covers which NaN payload reads back; here the two words are different numbers.Tauwni's probe puts the cause in the driver: stored step by step the
NoContractionTwoSum is exact, and with onlyerrstored KosmicKrisp returns 0. So what would turn the test green is a fix in Mesa, and that probe is ready to go into a report there. I have no KosmicKrisp here and have measured none of this.Rebased onto
maina73a57e13; the conflict was the neighbouring Known problems row #860 added, and both rows are kept. The macOS job of the previous run printedcs_fma_fused passed: drop it from the expected failures, so the runner's MoltenVK agrees with the M5, and51439f9dbtakes it out of the macOS job'sEXPECTED_FAILURES.@adrianmjim thanks for the RX 7900 XT run. AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-26T07:44:47Z.
A correction to my comment above about where the fold happens. It is not in NIR.
MESA_KK_DEBUG=mslshows that all seven TwoSum ops reach the Metal source, each one wrapped in#pragma METAL fp math_mode(safe). KosmicKrisp then compiles the library withMTL_MATH_MODE_FAST.I rebuilt the same kernel in a standalone Metal program (macOS 26.5.1, M3), and Apple's compiler ignores that pragma in a
fastorrelaxedlibrary: the error term comes out 0, whether the pragma is at block, function or file scope. In asafelibrary it gives0xb4800000. The other way round does work: afastpragma inside asafelibrary folds it. So this is a KosmicKrisp issue for Mesa (compilesafeand relax per op), and the reading above stands:0x7351is the reference word.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T09:48:20Z.
Red/green: tests/semantic/test_fma_fused_fixture.py fails on main (1 failed) and passes with this PR (3 passed).
Runtime batch of 20 PRs tested by OreoFR (full build, ctest without the game, Python suite, translator): same results as main
09c153948, RTX 4070 Laptop / Windows 11.AI-assisted (Claude Code, Claude Opus 5.5)
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:53:39Z.
Verified by OreoFR
09c153948+ PR headb327d6970; integration package 1 of 6 (20 PRs, merged without conflict)AI-assisted (Claude Code, Claude Opus 5.5).