Repository navigation
Translator: cheaper f16 rounding and a single MODE pass, same bits (SHADER-594) - #3200
tibzejoker wants to merge 3 commits into
Conversation
|
Tested Independent Linux Vulkan check of All 18 synthetic compute words matched exact expectations in both runs, across nearest-even, toward zero and a switch back to nearest-even in one dispatch. The cases covered the tie at half of the smallest subnormal, the signed result just above it, the subnormal-to-normal boundary, overflow, and an ordinary rounding case. All 46 fill words stayed intact. The stock AI-assisted verification. |
|
Tested 9acdaa1 on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass. Semantic tests:
Full GPU suite:
Note: tested PR head as submitted (PR description lists dependency on #2731). AI-assisted (OpenCode). |
|
Tested 9acdaa1 merged onto main 1628210 on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:
AI-assisted (Claude Code). |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9acdaa1 to
d07396a
Compare
|
I took a closer look at the The restriction looks right: a sum/sub of two f16 values is a multiple of 2^-24, so below 2^-14 it is already an f16 subnormal and the rounding bias can be skipped. I also modelled the old and new integer sequences directly: 2,000,000 random f32 bit patterns plus edge values, and 300,000 f16 operand pairs with their exact f32 sums, comparing nearest-even and toward-zero in both. All matched. The full semantic suite on Two non-blocking follow-ups:
Thanks - the single-pass narrowing is a nice reduction. |
# Conflicts: # docs/design.md
Claimed in the coordination issue as: SHADER-594 (claim)
Follow-up to #2731, which is merged (
6e3426d6). Rebased onf847748c: only these three commits are left (onlydocs/design.mdconflicted).What and why
Makes the integer f16 narrowing (
Gen.f16_bits, SHADER-56) cheaper for every f16 result, with the same bits.Gen.f16_resemitted two full conversions and selected one. It now emits one, where the mode selects the bias and the overflow limit and value.SPIR-V instructions added per RDNA instruction after
spirv-opt -O(hand-written compute probes, inputs from a buffer, 40 copies minus 8):mainv_add_f16v_add_f16div:2v_pk_add_f16v_mul_f16v_fma_f16v_add_f16, run-time MODEv_add_f16div:2, run-time MODEv_pk_add_f16, run-time MODEv_mul_f16, run-time MODEv_fma_f16, run-time MODEFor the MODE rows the stored mode was replaced by a user-data word, so the optimizer can't fold it.
Tested
Windows 11, rerun on
f847748c+ these commits.Exhaustive equivalence with
main: the emitted integer sequences, before and after, were turned into C and run on all 2^32 f32 inputs and all 2^32 f16 operand pairs, through bothf16_bitsandf16_reswith a run-time mode (both roundings, sums with and without clamp): 0 differences. Nearest even also equals x86 F16C. The negative control (sum shortcut underdiv:2) gives 4,196,352 mismatches.python -m unittest discover -s tests/semantic: 7,322 pass, 1 expected failure (same asmain).The f16, MODE, d16, FMA, translate, format, buffer, decode and docs test files under pytest: 417 passed, 577 skipped (including tests that need an amdgcn
llvm-mc), 0 failed (same asmain).The probe modules pass
spirv-val.RTX 4090 (621.01), 4.19M threads x 800 f16 add/mul in a hand-written compute shader, timed in VRAM: 5.83 ms on
16282101, 4.35 ms with Translator: smaller f16 narrowing, same bits (SHADER-489) #2731 and this PR (0.075 ms without the ops).Not run by me: the GPU test suite and the game's shader corpus (so no before/after translated and valid counts). Independent RTX 5090 and Steam Deck runs on the pre-rebase head are in the comments.
AI-assisted (Claude Code).
Checklist
docs/design.md, with how it was confirmed.