Skip to content

GPU fixture: f16 denormal operands of v_cvt_f32_f16, v_pk_fma_f16, v_pk_fmac_f16 - #4488

Open
fromthemoonx wants to merge 1 commit into
ItsNotRexed:mainfrom
fromthemoonx:test-f16-denorm-widen
Open

fromthemoonx wants to merge 1 commit into
ItsNotRexed:mainfrom
fromthemoonx:test-f16-denorm-widen

Conversation

@fromthemoonx

Copy link
Copy Markdown

Claimed in #4421 as a new TEST item (my claiming: comment there, no ID assigned yet).

What and why

9d71037 (#3220) made Gen.f16_in widen f16 operands exactly, because NVIDIA (RTX 5060 Ti, 610.88) read an SDWA-selected f16 denormal as 0. Three ops still widen with UnpackHalf2x16 directly, outside f16_in: v_cvt_f32_f16 (tools/rdna2spirv.py:8338), v_pk_fma_f16 (the VOP3P f16 path, :7015) and v_pk_fmac_f16 (:6987). No GPU fixture fed them a denormal: ps_f32_mods, ps_ops and ps_f16_const use normal values only.

runtime/test/shaders/cs_w32_f16_denorm_widen.asm does. One wave32 group stores eight words:

The expected words follow from RDNA2's f16 MODE keeping denormals (value m × 2^-24). They're computed from the IEEE half format in the CPU test.

No translator change. On a CPU run with every UnpackHalf2x16 denormal flushed (the mock from #3220's test), all seven denormal words read 0. So these ops do depend on the driver keeping denormals. But an RTX 3060 keeps them in every shape here, including the SDWA conversion (results below), so routing them through exact widening would only add instructions; see #4345 for why module size matters. The fixture makes any GPU or driver that does flush fail loudly. Related: #4296 keeps DenormPreserve 16 for modules with half conversions, which this one has.

Files:

  • runtime/test/shaders/cs_w32_f16_denorm_widen.asm: the fixture, with derivations in its header
  • runtime/test/shaders/check.py, scripts/run_gpu_tests.py: registered as a wave32 dump with the expected words
  • tests/semantic/regen_fixtures.py and fixtures/disasm/cs_w32_f16_denorm_widen.s: the generated translator input
  • tests/semantic/test_f16_denorm_widen_fixture.py: runs the fixture through spirv_mini_interp, checks the words against the IEEE values, and checks that both GPU runners expect the same words

Tested

  • GPU: NVIDIA GeForce RTX 3060 12 GB (Ampere), driver 610.88, Windows 11 Pro 26300, llvm-mc 23.1.6 (conda-forge), SPIRV-Tools 2026.4, vk_compute_test built by scripts\build_runtime.ps1 (MSVC, VS 2022 Build Tools). py -3.12 -I scripts\run_gpu_tests.py --filter cs_w32_f16_denorm_widen: PASS natively (32-wide subgroup) and with LEONIDA_W64_EMULATE=1, all 8 words exact.
  • CPU (Linux, CPython 3.13.18): pytest tests/semantic/test_f16_denorm_widen_fixture.py tests/semantic/test_misc_ext_fixture.py tests/test_run_gpu_tests.py tests/test_shader_checks.py: all pass. tests/test_translate.py::test_gpu_samples_translate_and_validate[cs_w32_f16_denorm_widen.asm] passes with llvm-mc 20 and spirv-val 2025.1. regen_fixtures.py --check, compileall and git diff --check are clean.
  • Not run on AMD. A result there would confirm the words natively.

AI-assisted (Claude). No game files.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FXR27ZYP9qtZtN8SG7QPWW

…pk_fmac_f16

9d71037 (ItsNotRexed#3220) widened f16 operands exactly in Gen.f16_in because NVIDIA read
an SDWA-selected denormal as 0. v_cvt_f32_f16, v_pk_fma_f16 and v_pk_fmac_f16
still widen with UnpackHalf2x16 directly, and no GPU fixture fed them a
denormal. cs_w32_f16_denorm_widen does: denormals from a VGPR, a literal and an
SDWA WORD_1 select, as multiplicands, addends and the fmac accumulator, plus a
normal control word. Expected words follow from RDNA2 keeping f16 denormals.

Registered in check.py and run_gpu_tests.py (wave32 dump), in
regen_fixtures.py, and run on the CPU by test_f16_denorm_widen_fixture.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FXR27ZYP9qtZtN8SG7QPWW
@SweatierKey

Copy link
Copy Markdown
Contributor

Tested 0c71f17e on Linux CPU (Python 3.13.5, LLVM 18.1.8, SPIRV-Tools, clean worktree): pass (CPU/offline validation).

  • PYTHONPATH=tests/semantic python3 -m unittest tests/semantic/test_f16_denorm_widen_fixture.py -v: 3/3 OK (all 8 expected words match IEEE binary16 oracle, spirv_mini_interp, check.py, and scripts/run_gpu_tests.py).
  • python3 -I tests/test_shader_checks.py: 75/75 OK; python3 -I tests/test_semantic_translator_use.py: 3/3 OK.
  • llvm-mc -arch=amdgcn -mcpu=gfx1013 -show-encoding runtime/test/shaders/cs_w32_f16_denorm_widen.asm: exit 0; translated fixture passes spirv-as + spirv-val --target-env vulkan1.2 (29,084 B). git diff --check clean. (GPU readback still needs a physical Vulkan GPU.) No game files. AI-assisted.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 0c71f17e on Windows 11: python tests/semantic/test_f16_denorm_widen_fixture.py -> 3 tests, OK; git diff --check clean.

The new cs_w32_f16_denorm_widen fixture covers f16 denormal operands through v_cvt_f32_f16, v_pk_fma_f16 and v_pk_fmac_f16, with the semantic fixture check. I did not build/run the GPU case here; the fixture and its expected words are generated and checked on the CPU. No blocking issue.

@bobcatchris

Copy link
Copy Markdown
Contributor

Apple M2 data point at head 0c71f17 (macOS 26.4, MoltenVK 1.4.2 direct, subgroup 4..32, llvm-mc 23.1.6, clean full build on AppleClang 17).

  • python -I scripts/run_gpu_tests.py --filter cs_w32_f16_denorm_widen --build runtime/build/linux: 1 shader translated, 1 pass spirv-val; 1/1 passed — words 864026624 3095379968 939524096 914358272 2147549248 33554433 262147 1065353216, 0 mismatches.
  • A/B relevant to the separate f16-compare finding on the live board: --filter ps_vcmp_f16 still gives 0/2 with the same words as unpatched main, so this change does not fix the MoltenVK NaN-compare failures.

Adds an Apple/MoltenVK result to the NVIDIA run in the PR body. Head fetched read-only, no rebase/edit/push. Synthetic shaders and counts only; no game files.

AI-assisted.

@CaravelaLabs

Copy link
Copy Markdown
Contributor

Automated test: 0c71f17e merged onto main 03b09a08 on AMD Radeon 8060S (RADV GFX1151, RDNA 3.5), Mesa 25.2.8, Ubuntu 24.04, runtime rebuilt from this branch in a clean sandbox. Result: pass.

  • scripts/run_gpu_tests.py: 193/210 passed, 15 skipped (plain main: 192/209 passed, 15 skipped).
    • new test cs_w32_f16_denorm_widen: pass (864026624 3095379968 939524096 914358272 2147549248 33554433 262147 1065353216)
  • Python tests this PR touches: 3 passed, 10 subtests passed.

Same machine and setup as my earlier manual reports. AI-assisted (Claude Code).

@mrbean56

Copy link
Copy Markdown

Tested 0c71f17e on AMD Radeon RX 7800 XT (RADV NAVI32, Mesa 26.x, Vulkan 1.4.309), Linux, LLVM 19 llvm-mc: GPU pass.

  • python3 -I scripts/run_gpu_tests.py --llvm-mc /usr/lib/llvm-19/bin/llvm-mc --build <ninja Release> --filter f16_denorm --require-pass:
    • 1 shaders: 1 translated, 1 pass spirv-val
    • PASS cs_w32_f16_denorm_widen 864026624 3095379968 939524096 914358272 2147549248 33554433 262147 1065353216
    • 1/1 passed
      So the hand-derived words in check.py reproduce on RDNA3/RADV, not just on the GPU they were measured on — the denormal operand handling of v_cvt_f32_f16, v_pk_fma_f16 and v_pk_fmac_f16 agrees across the two AMD families.
  • pytest tests/semantic/test_f16_denorm_widen_fixture.py -q: 3 passed, 10 subtests. The corpus fixture and the GPU kernel are the same program, so the CPU model and the GPU agree on this one.
  • LLVM 19 assembles it; only the gfx11/gfx12 true16 tests need 21+ (llvm-mc-19 is what this box has).

No game data. AI-assisted.

@smowlyy

smowlyy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

A data point on the driver that had #3220's bug. I tested 0c71f17e (base 03b09a08) on the RTX 5060 Ti with NVIDIA 610.88, the driver that read the SDWA BYTE_1 denormal of ps_sdwa_f16_const as 0. cs_w32_f16_denorm_widen passes there: it gives the expected words natively and with LEONIDA_W64_EMULATE=1, so the SDWA WORD_1 conversion keeps its denormal too. So 610.88's flush doesn't reach these three ops in these shapes, which fits the decision not to change the translator here. AI-assisted (Claude Code), no game files.

Hardware: AMD Ryzen 5 7600X, Windows 11 Home 26300. GPUs: NVIDIA GeForce RTX 5060 Ti, driver 610.88 (Vulkan 1.4.341, subgroup 32..32); AMD Radeon(TM) Graphics iGPU (RDNA2 gfx1036, subgroup 32..64), AMD Windows driver 24.10.24 (Vulkan driver 2.0.302). MSVC 14.44, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8, Python 3.12.10. Test programs built at the PR head with scripts\build_runtime.ps1. Implicit layers off.

python -I scripts/run_gpu_tests.py, whole suite:

device mode result cs_w32_f16_denorm_widen
RTX 5060 Ti, 610.88 native 165/211 passed, 46 skipped (wave64), 0 failed PASS
RTX 5060 Ti, 610.88 LEONIDA_W64_EMULATE=1 196/211 passed, 15 skipped, 0 failed PASS
Radeon iGPU, 24.10.24 native 101/211 passed, 110 skipped, 0 failed PASS
Radeon iGPU, 24.10.24 LEONIDA_W64_EMULATE=1 101/211 passed, 110 skipped, 0 failed PASS

All four give 864026624 3095379968 939524096 914358272 2147549248 33554433 262147 1065353216. The Radeon row is the AMD Windows driver (PAL), not RADV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants