Repository navigation
Translator: opt-in native f16 arithmetic, about 20x faster f16 ops (--native-f16, SHADER-673) - #4012
tibzejoker wants to merge 2 commits into
Conversation
f16 add/sub/mul, scalar and packed, become 16-bit float ops (fma too with --fma khr). Same results as the integer narrowing, NaN payloads aside, on every operand pair on an RTX 4090; about 20x faster on an f16 add/mul chain. Off by default; the runtime enables shaderFloat16 and vk_pipeline_check skips a shader the device can't run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated test:
Same machine and setup as my earlier manual reports. AI-assisted (Claude Code). |
|
Tested 392c83b on Windows, CPython 3.14.7, CPU only (no GPU, no game files). This computer has no SPIRV-Tools.
I found one defect in the feature list. The list requires FMA support for two float widths when the shader uses FMA at only one width. Run this script from the repository root: import sys, re
sys.path.insert(0, "tests/semantic")
import test_native_f16 as t
for ops in (["v_fma_f16 v1, v2, v3, v4"], ["v_add_f16_e32 v1, v2, v3", "v_fma_f32 v5, v2, v3, v4"]):
asm, meta = t.translate(ops, fma_khr=True)
print(re.findall(r"= OpFmaKHR (%\w+)", asm), [x for x in meta["features"] if "Fma" in x])Actual result: Expected result: the first shader requires Possible correction: record the width of each FMA instruction during translation, and put only those widths in the list. I did not run a GPU. AI-assisted. |
whattheflop
left a comment
There was a problem hiding this comment.
Independent Radeon iGPU check at 392c83b1: this driver reports shaderFloat16 and all three required f16 float controls. Native and integer translations both matched 3/3 expected packed/scalar words with zero validation warnings or errors, including two rounding ties, a preserved subnormal and negative zero. Full GPU report and scope.
Two harness details affect repeatability on other devices:
vk_pipeline_checkcreates the module before the new float16 feature/control checks. For a device withoutshaderFloat16, that is already too late for a module declaringFloat16. #3045 has a similar pre-module gate.vk_compute_testcurrently creates its device without enablingshaderFloat16. The scratch runner checked the required properties, enabled the feature for the native variant, and then dispatched both modules. This keeps the ordinary harness from being mistaken for a native-f16 validation path. Vulkan float-control properties
AI-assisted (Codex).
|
Tested Runtime and test programs built from each commit with GPU suite (
Run | main | this PR
-- | -- | --
default | 164/210, 0 failed, 46 skipped | 164/210, 0 failed, 46 skipped
LEONIDA_W64_EMULATE=1 | 195/210, 0 failed, 15 skipped | 195/210, 0 failed, 15 skipped
Python tests (CPython 3.13.17, tests/requirements.txt):
Result: 4 modules ok, 4 compute pipelines ok, 0 skipped. The driver reports This only shows that the driver accepts the modules. I did not repeat your 2^32-input comparison, so the results themselves are checked only on your RTX 4090 (same Ada architecture).
AI-assisted (Claude Code). |
|
Tested
AI-assisted (Claude). No game files. |
|
Tested 392c83b (base
No game files used. AI-assisted (Claude Code). |
|
Tested
So every fixture that takes the native half path gives the same words and pixels as the integer-narrowing path on this GPU, and validation is clean.
I didn't measure the speed-up; these are correctness runs. AI-assisted (Claude Code). No game files. |
|
Tested 392c83b on AMD Radeon RX 6800 (RDNA2), AMD 26.8.1 (Windows 32.0.21045.5002), Windows 11 Pro 25H2 (build 26200): pass for the default translation (flag off).
Built with AI-assisted (Claude Code): it built both commits and ran the tests. |
|
Tested 1. Wrong packed result in a wave64 shader (AMD only)
The low half takes 2. Signalling NaN inputs come back unquieted (AMD only)This is an exhaustive comparison (my own harness, not in the PR). One wave32 kernel runs 65,536 threads with
There's no fma, because this iGPU has no
3. Two NaN operands (AMD only)With every NaN input quieted first (the same integer instructions in both modules), 13 of 15 forms match over 2^32 pairs on AMD. The two that differ are Other results
So, to the description's question of whether it could become a default on AMD: not on this driver as it stands. (1) is a wrong value, which design.md's contract table should record if the flag stays. (2) and (3) only matter if NaN bits matter, which depends on the console's IEEE mode (SHADER-190). Local test changes, not in the PR:
Tools: Vulkan SDK 1.4.363.0, llvm-mc 21.1.8, MSVC from VS 2026 (18.11), Ninja RelWithDebInfo, AI-assisted: the harness, setup and runs were done with Claude Code. |
…6, AMD limits - Merge origin/main (561b65a): keep main's SignedZeroInfNanPreserve 64 for Float64 modules, add the 16-bit modes after it. - shader_meta: list shaderFmaFloat16 / shaderFmaFloat32 for the widths an OpFmaKHR actually uses, not both whenever FMAKHR is declared (review on ItsNotRexed#4012). New test test_fma_features_follow_the_widths_used. - vk_compute_test enables shaderFloat16 when the module declares Float16, and exits 77 on a device without it. - runtime/test/shaders/build.py: LEONIDA_NATIVE_F16=1 passes --native-f16. - docs/design.md: the AMD iGPU results from ItsNotRexed#4012 (unquieted sNaN, NaN operand choice, a wave64 driver miscompile); the flag stays off by default. - test_native_f16.py puts its own folder on sys.path (runs under python -I). tests/semantic: 6157 OK (main 561b65a: 6150 OK, same skips). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks all for the runs, especially the AMD ones. Pushed
AI-assisted (Claude Code). |
Claimed in the coordination issue as: SHADER-673 (claim, with the correction on why
OpFConvertnarrowing doesn't work)What and why
--native-f16(off by default) translates f16 arithmetic to 16-bit float ops instead of f32 math plus integer narrowing:v_add_f16,v_sub_f16,v_subrev_f16,v_mul_f16,v_pk_add_f16,v_pk_mul_f16become one%half/%v2halfop on operands bitcast from the packed word.--fma khr,v_fma_f16,v_fmac_f16andv_pk_fma_f16becomeOpFmaKHRon%half(correctly rounded, so one rounding as on RDNA2).op_sel, SDWA), neg and abs are applied to the bits.RoundingModeRTE 16,DenormPreserve 16andSignedZeroInfNanPreserve 16. The index listsshaderFloat16(plusshaderFmaFloat16for the fma) and the three 16-bit float-controls properties.vk_pipeline_checkchecks them, the runtime enablesshaderFloat16where the GPU has it, andmake_game.pyforwards the flag.Why not narrow the f32 result with
OpFConvert: NVIDIA folds the f32 -> f16 -> f32 round trip between two ops (as in #513). On an RTX 4090 single ops matched, but two-op chains were wrong in 8 to 23% of cases, andNoContraction,OpQuantizeToF16and a volatile variable don't stop it. The design.md row says so.Tested
Windows 11, RTX 4090 (621.01), on
aa2988cc.v_cvt_f32_f16: 4.15 ms with the integer path, 0.21 ms with--native-f16(0.13 ms for the same chain in f32, 0.07 ms without the ops).vk_pipeline_checkcreates the pipeline of a--native-f16 --fma khrmodule, and the runtime object with theshaderFloat16change builds.aa2988ccon all 81 semantic fixtures.python -m unittest discover -s tests/semantic: same result asaa2988cc(its 9 failures intest_loop_ballot_barrier,test_cmp_class_f64andtest_mutationsfail the same way there), plus 6 new tests. pytest on the translate, f16, MODE, d16, FMA, make_game and docs test files: 772 passed, 598 skipped, 0 failed.spirv-val: all modules, native and default.Not run: AMD and Intel GPUs (an AMD run of the same comparison would decide whether it can become a default there), the GPU test suite, and the game's shader corpus.
AI-assisted (Claude Code).
Checklist
docs/design.md, with how it was confirmed.