Skip to content

GPU test: v_frexp_mant_f16, v_frexp_exp_i16_f16, v_ldexp_f16 on every f16 input (SHADER-354) - #2171

Open
Krashgamer wants to merge 8 commits into
ItsNotRexed:mainfrom
Krashgamer:test/f16-frexp-ldexp-gpu
Open

Krashgamer wants to merge 8 commits into
ItsNotRexed:mainfrom
Krashgamer:test/f16-frexp-ldexp-gpu

Conversation

@Krashgamer

@Krashgamer Krashgamer commented Nov 22, 2026 •

Copy link
Copy Markdown

Item: SHADER-354 (claimed in #1902: #1902 (comment)).

Depends on: #1931. Until #1931 merges, this diff also shows its commit (31579b9); this PR's change is the last commit.

What and why

No GPU test or fuzzer generates v_frexp_mant_f16, v_frexp_exp_i16_f16 or v_ldexp_f16 (#1931's description says so too), so run_gpu_tests.py passes whatever the translator emits for them. #1931 changes how they handle f16 denormals, measured on RDNA2 through tools/hw_oracle. Those are raw native kernels, though, not the translated SPIR-V. This adds a GPU test that runs the translated program on each tester's GPU and checks every f16 input.

The change

  • runtime/test/shaders/cs_f16_frexp_ldexp.asm: each of the 65,536 binary16 encodings gets its own thread (1024 groups of 64). Each thread stores frexp_mant(x), frexp_exp(x), ldexp(x, s4) and x. Every destination starts as 0x5a5a5a5a, so the kept high half is checked too. The header quotes the gfx1036 words from docs/design.md.

  • runtime/test/shaders/check.py: f16_frexp_ldexp_test runs it once per S1 of F16_FREXP_LDEXP_EXPONENTS, 21 values:

    • zero and the ends of the normal range;
    • the denormal and flush edges (-14, -15, -24, -25, -30);
    • the clamp to [-64, 64] from both sides (±64, ±65, 0x8000, 0x7FFF);
    • S1 words whose high bits must be ignored (0x00010003, 0xFFFF0005).

    It compares all 262,144 words of each dump with a model of the rule in docs/design.md. The expected dump is built once per S1 and compared as bytes, and a word-by-word scan only runs on a mismatch. A failure names the number of wrong words per op and the first one.

  • scripts/run_gpu_tests.py: calls the same function.

  • tests/test_shader_checks.py: the fake harness answers the new shader (TOTAL + 1). New tests check that:

    • every exponent is sent;
    • one wrong word is reported by input and exponent;
    • a translator that reads f16 denormals as zero fails;
    • the model gives the gfx1036 words quoted in docs/design.md;
    • the model agrees with tests/semantic/test_alu_frexp_ldexp_f16.py's ref_mant / ref_exp / ref_ldexp on every input and exponent. Its functions and constants are read with ast, as test_inputs_match_the_interpreter_test does, so the translator isn't imported.
  • docs/design.md: the f16 trio's row names the GPU test.

Tested

NVIDIA GeForce RTX 3080 (Ampere), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 25H2, MSVC 14.51.36231 (VS 2026 Build Tools), Vulkan SDK 1.4.363.0, llvm-mc 21.1.8 (built with scripts/build_llvm_mc.ps1). No game files.

Not covered: a native 64-wide run (no such subgroup on NVIDIA). The kernel has no cross-lane operations, so lane width shouldn't change its words.

Overlap

@Vonsek has claimed the f32 trio's GPU test (EGEN-GPU-FREXP32, #1902). It covers different opcodes, but it will likely add a check at the same places in check.py, run_gpu_tests.py and TOTAL in tests/test_shader_checks.py. Whichever lands second only needs to add its line next to the other and bump TOTAL once more.

Checklist

AI-assisted: the code, the tests and this description were written by Claude Code at my request, and it ran them on my PC.

🤖 Generated with Claude Code

… f16 input

No GPU test or fuzzer generated these three opcodes, so run_gpu_tests.py passed
whatever the translator emitted for them. cs_f16_frexp_ldexp gives each of the
65,536 binary16 encodings its own thread (1024 groups of 64) and stores
frexp_mant, frexp_exp, ldexp(x, s4) and x, each destination preloaded with
0x5a5a5a5a so the kept high half is checked too.

check.py's f16_frexp_ldexp_test dispatches it once per S1 of
F16_FREXP_LDEXP_EXPONENTS (21 values: the denormal and flush edges, the clamp
to [-64, 64] from both sides, S1 words whose high bits must be ignored) and
compares all 262,144 words of each dump with a model of the rule ItsNotRexed#1931
measured on gfx1036 (f16 denormals kept). run_gpu_tests.py calls the same
function.

tests/test_shader_checks.py: the fake harness answers the new shader; new
tests check that every exponent is sent, that one wrong word is named, that
a translator reading f16 denormals as zero fails, that the model gives the
gfx1036 words quoted in docs/design.md, and that it agrees with
tests/semantic/test_alu_frexp_ldexp_f16.py's reference on every input.

Depends on ItsNotRexed#1931: with main's translator the test fails on every f16
denormal (2,046 inputs per dispatch).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@whattheflop

Copy link
Copy Markdown
Contributor

Independent Radeon review (AI-assisted with Codex) of 36027d4f against main 4eb6155d, including #1931 at 31579b9c.

  • Stock cs_f16_frexp_ldexp translated SPIR-V on the Ryzen 7 9800X3D Radeon iGPU (PCI 1002:13c0, Windows 11 build 26200, AMD 25.10.30.02, Vulkan 1.4.315). Native translation and driver-default subgroup 64. 21 dispatches x 1,024 groups x 64 invocations, 5,505,024/5,505,024 words exact (65,536 inputs x 21 S1 values x 4 words). The stock checker took 2.707 s wall time, including 1.885 s across the harness processes.
  • Single AMD ICD, empty implicit-layer path. Khronos core and synchronization validation confirmed active in all 21 launches, with zero validation errors or warnings. The exact module passed spirv-val --target-env vulkan1.2. Built only vk_compute_test with MSVC 19.38.33145 and Windows SDK 10.0.26100.0. Vulkan SDK 1.4.363.0, uv CPython 3.12.13, WSL llvm-mc 21.1.8 for assembly. Stock f16 semantic tests 23/23, shader checker tests 65/65. Synthetic fixture only.
  • Small header nit in cs_f16_frexp_ldexp.asm:6. The three opcode results preserve high half 0x5a5a. The fourth word is the raw input index and has high half zero, as the checker correctly expects.

The header said all four words carry 0x5a5a in the high half; only the three
opcode results do. The checker already expected x as is. Comment only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Krashgamer

Copy link
Copy Markdown
Author

Thanks @whattheflop. That's the first AMD run, and at subgroup 64, which my NVIDIA card can't do. So the "not covered: native 64-wide" line in the description is covered now too.

Header nit fixed in 956d02e: the three opcode results carry 0x5a5a in the high half, then x itself with high half 0. Comment only; cs_f16_frexp_ldexp still passes here.

AI-assisted (Claude Code).

@Flyander Flyander 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.

Reviewed the current diff and the reported full-domain GPU sweep. The half-precision frexp/ldexp coverage is exhaustive over all 65,536 input encodings, and the independent AMD run confirms the wave64 case. The documentation comment was corrected at this head. I found no remaining blocker.

# Conflicts:
#	runtime/test/shaders/check.py
#	tests/test_shader_checks.py
@ricarmandoagent

Copy link
Copy Markdown

Tested 62a490b1 on NVIDIA GeForce RTX 4060 (Ada, AD107; Vulkan subgroupSize 32..32), NVIDIA 620.70.06, Vulkan 1.4.357, Bazzite 45 / Linux 7.3.4 (Wayland).

Test programs built from 4947579 (this PR changes no runtime/ C++), shaders translated with this PR's tools/rdna2spirv.py:

python -I scripts/run_gpu_tests.py --build runtime/build/linux --filter cs_f16_frexp

  PASS  cs_f16_frexp_ldexp    65536 inputs x 21 exponents, every word exact

1/1 passed

.spv passed spirv-val (LLVM 23.1.5); tests/test_shader_checks.py: 65 tests OK.

AI-assisted run on a contributor machine.

Conflicts: docs/design.md (main dropped duplicated rows and rewrote the f16
frexp/ldexp row; kept main's row and re-added the GPU test sentence) and the
check import in scripts/run_gpu_tests.py (both sides' names).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jigglephysic0

Copy link
Copy Markdown

Tested 62a490b on NVIDIA GeForce RTX 4060 Ti, driver 621.01, Windows 11 Home (build 26300): pass

Ran: python -I scripts/run_gpu_tests.py --llvm-mc "wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc" --build --filter cs_f16_frexp_ldexp

Result: 1 shader translated, 1 passes spirv-val. cs_f16_frexp_ldexp: PASS (65536 inputs x 21 exponents, every word exact), 1/1 passed.

Also ran tests/test_shader_checks.py: 65 tests OK.

Notes:

  • The runtime test programs were built from a ZIP download of main, not from this PR's branch. The PR only touches the test shader, check.py and docs, so this should not matter.
  • llvm-mc is 21.1.8 via WSL Ubuntu.
  • The runner does not print which Vulkan device it used. The system lists the NVIDIA driver (621.01) first.

@jigglephysic0

Copy link
Copy Markdown

Tested 55071e6 on NVIDIA GeForce RTX 4060 Ti, driver 621.01, Windows 11 Home (build 26300): pass

Ran: python -I scripts/run_gpu_tests.py --llvm-mc "wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc" --build --filter cs_w32_dot4_carry

Result: 1 shader translated, 1 passes spirv-val. cs_w32_dot4_carry: PASS (456/456 dumped words exact), 1/1 passed.

CPU checks on this branch: tests/test_shader_checks.py 60 tests OK; python -m unittest discover -s tests/semantic -v: 2569 tests OK.

Notes:

  • The runtime test programs were built from a ZIP download of main, not from this PR's branch. The PR only touches the test shader, fixtures, check.py and docs, so this should not matter.
  • llvm-mc is 21.1.8 via WSL Ubuntu.
  • The runner does not print which Vulkan device it used. The system lists the NVIDIA driver first.

@jigglephysic0

Copy link
Copy Markdown

Tested 1d93f77 on NVIDIA GeForce RTX 4060 Ti, driver 621.01, Windows 11 Home (build 26300): pass

Ran: python -I scripts/run_gpu_tests.py --llvm-mc "wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc" --build --filter cs_w32_ds_wrxchg_b64

Result: 1 shader translated, 1 passes spirv-val. cs_w32_ds_wrxchg_b64: PASS, 1/1 passed. The runner printed these words for the test: 2165396956 6702799 3666541181 1331365576 260283320 3557905690 3800037791 286488446

CPU checks on this branch: tests/test_shader_checks.py 59 tests OK; python -m unittest discover -s tests/semantic -v: 1648 tests OK.

Notes:

  • The runtime test programs were built from a ZIP download of main, not from this PR's branch. This PR's branch is older than that main, so the binaries are newer than the PR's base. The PR only touches the test shader, fixtures, check.py and docs, so this should not matter, but it is not a build from the PR's own code.
  • llvm-mc is 21.1.8 via WSL Ubuntu.
  • The runner does not print which Vulkan device it used. The system lists the NVIDIA driver first.

@Krashgamer

Copy link
Copy Markdown
Author

@jigglephysic0 Thanks for the 4060 Ti run of this one. Your second and third comments here are for other pull requests: 55071e6b / cs_w32_dot4_carry is #2311, and 1d93f777 / cs_w32_ds_wrxchg_b64 is #2003. Reposting them there would let those authors and reviewers see them.

AI-assisted (Claude Code).

@jigglephysic0

Copy link
Copy Markdown

Tested ffcd045 on NVIDIA GeForce RTX 4060 Ti, driver 621.01, Windows 11 Home (build 26300): pass

Ran: python -I scripts/run_gpu_tests.py --llvm-mc "wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc" --build --filter cs_lds

Result: 2 shaders translated, 2 pass spirv-val. cs_lds: PASS (device: NVIDIA GeForce RTX 4060 Ti, subgroup 32..32). cs_lds_b64_cmpst: PASS. 2/2 passed. The changed runner still reports normally on a passing run.

CPU checks on this branch: tests/test_run_gpu_tests.py 38 tests OK; tests/test_shader_checks.py 60 tests OK; python -m unittest discover -s tests/semantic -v: 2567 tests OK.

Notes:

  • The runtime test programs were built from a ZIP download of main, not from this PR's branch. This PR only changes scripts/run_gpu_tests.py and its test, so the binaries do not depend on it.
  • Running with --filter cs_f16_frexp_ldexp (a test that is not on this branch) printed "error: --filter 'cs_f16_frexp_ldexp' matched no GPU test cases" and exited, which was clear.
  • I did not exercise the new "no judgeable result" message itself.
  • llvm-mc is 21.1.8 via WSL Ubuntu.

Conflict: the fixture count in tests/test_shader_checks.py, which main
raised to 12 for vs_base_ids and this branch to 12 for cs_f16_frexp_ldexp;
it is 13 with both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 854bc3a7 on AMD Radeon RX 9070 XT (RDNA4, subgroup 32..64), AMD 26.11.2, Windows 11 Pro 10.0.26300, AMD Ryzen 7 9800X3D CPU (64 GB RAM), Python 3.12.10: pass.

Runtime and test programs built from this head (MSVC 14.51, Ninja, RelWithDebInfo), native Windows llvm-mc 21.1.8, Vulkan SDK 1.4.363.0. No game files.

run result
run_gpu_tests.py (whole suite, native wave64) 186/200, 14 skipped, 0 failed (main 49475796: 170/185)
same with LEONIDA_W64_EMULATE=1 186/200, 14 skipped, 0 failed
pytest tests/test_shader_checks.py tests/test_run_gpu_tests.py 117 passed, 266 subtests passed in 5.69s

This PR's shaders:

  • native: PASS cs_f16_frexp_ldexp 65536 inputs x 21 exponents, every word exact; emulated: PASS cs_f16_frexp_ldexp 65536 inputs x 21 exponents, every word exact

On RDNA4, cs_f16_frexp_ldexp is exact for all 65,536 f16 inputs × 21 exponents, native and emulated, f16 denormals included. So with #1931's denormal handling, the AMD RDNA4 Windows driver agrees with the RDNA2 measurements.

AI-assisted (Claude Code); I checked the results.

Krashgamer and others added 2 commits November 22, 2026 23:02
Conflicts with ItsNotRexed#1518 (cs_fma_fused) and the cs_fmt_d16_xyz / cs_heap_init
dumps: both sides' lines kept in check.py and run_gpu_tests.py, main's
f16 frexp/ldexp row (now with VOP3 clamp) plus the GPU test sentence, and
the fixture count is 14 with both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every new GPU test appends to the end of the check import, the elif chain
in run_gpu_tests.py and check.py's results list, so this branch conflicted
with each merge round. The import gets its own line, and the two
registrations sit next to cs_lds and cs_wavemask, which rarely change.
Same behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@crastinator

Copy link
Copy Markdown
Contributor

Tested 069ff43 merged into main aa2988cc (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • New test passes natively: cs_f16_frexp_ldexp (65536 inputs x 21 exponents, every word exact).
  • Whole run_gpu_tests.py: 197/211 native, 197/211 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 47/47.
  • tests/test_shader_checks.py: 84 passed, 230 subtests passed.

No game files. AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 069ff43 merged with main 2d3369a on Linux (Python 3.12.16) and Windows 11 (Python 3.13.1): pass (CPU side only).

  • pytest tests/test_shader_checks.py 88 passed (Linux); Windows unittest 88 OK; tests/test_run_gpu_tests.py 41; tests/test_docs_*.py pass; tests/semantic/test_alu_frexp_ldexp_f16.py 25 OK on Windows (the test here checks the GPU model against it).
  • Negative control: runtime/test/shaders/check.py and scripts/run_gpu_tests.py taken from main: 18 failures (the F16FrexpLdexpSweep tests and the case-count test). Reverted afterwards.
  • Docs: the design.md row says 21 exponents and F16_FREXP_LDEXP_EXPONENTS has 21 entries; 65,536 x 4 = 262,144 words matches F16_FREXP_LDEXP_WORDS. I did not reproduce "exact on an RTX 3080": the GPU dispatch was not run here. Separately, that row still contains duplicated sentences from earlier edits ("Zero gives a signed zero..." twice, and "Zero and denormals (read as zero)" next to "f16 denormals are kept"), which this PR could tidy.

@Krashgamer

Copy link
Copy Markdown
Author

Thanks @kapitche. The repeated and conflicting sentences in that row are already on main ("…give the input unchanged and exponent 0." twice, and "zero and denormals (read as zero)" next to "f16 denormals are kept"). #2171 only extends the row's last sentence. I'm leaving the tidy-up out here: it would widen the approved diff, and #4311 rewrites the modifier sentences of the same cell. I've posted it as a finding so it's done once both have landed.

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.

8 participants