Repository navigation
rdna2spirv: v_dot2_f32_f16, v_dot2c_f32_f16 and v_trig_preop_f64 (SHADER-449) - #2537
IAmNotSiob wants to merge 8 commits into
Conversation
|
Independent GPU coverage of the two dot instructions at GLSL Fma and All 11 differences in each mode came from FP32 subnormal accumulators. For example, with both packed inputs zero and the FP32 accumulator word |
|
ty for the 5070 run, 512 triples incl. D aliasing is way more than i covered :D |
|
Tested 1f8e711 on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass. The PR's diff applied cleanly to
|
|
Tested |
|
ty for testing ^^ |
|
Native RDNA2 run of Setup: AMD Radeon RDNA2 iGPU (Ryzen 7 7800X3D,
A wider sweep had a second model write and run a probe on the same GPU: 26,305 words, with seeded random inputs, half selection, (AI-assisted: the wider sweep by a second model on this machine; the table re-measured by me. Hand-written kernels, no game files.) |
|
Tested on Windows 11 with two GPUs on one machine (MSVC 14.51, llvm-mc 23.1.6). |
|
Tested 1f8e711 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). |
|
Tested Runtime and test programs built from this head (MSVC 14.51, Ninja, RelWithDebInfo), native Windows
What I found by editing the translated module (
So on this driver, GLSL.std.450 A possible fix that doesn't depend on the driver's AI-assisted (Claude Code); I checked the results. |
… Ldexp (AMD Windows flushes a denormal Ldexp result; found by @zneel)
|
thx @zneel, great digging :D pushed 3f1784f: the last scale step is now two exact f64 multiplies by 2^k built from bits (first by 2^max(k,-300) so the value stays normal and exact, then by 2^max(rest,-1022), anything below that underflows to 0 anyway), so there's still a single rounding and no dependence on the driver's Ldexp. cs_w32_trig_preop passes on RTX 6000 Ada (linux) with word 4 = 0x07DE294A, semantic tests ok. a rerun on your 9070 XT would close it out ^^ AI-assisted (Claude Code). |
|
Tested 3c20f6d on NVIDIA RTX 4080, driver 610.88, Windows 11: pass This head merges
AI-assisted. |
|
Tested
No game files. AI-assisted (Claude Code). |
|
Tested
AI-assisted (Claude Code). Synthetic shaders only, no game files. |
|
nice thx @amarovndres, that closes the AMD windows denormal case \o/ |
…, so this PR keeps only v_trig_preop_f64
|
merged main: main now has its own v_dot2_f32_f16 / v_dot2c_f32_f16 (68804c6), so this pr is down to v_trig_preop_f64 only. heads up for whoever owns that: my old dot2 test expected one rounding of the full f32 sum and main's gives 1 ulp different on some inputs (e.g. a=0xc7cac6f4 b=0xc3b34566 c=0xc2548905 -> main 0xc2730168 vs 0xc2730169). not measured which one rdna2 does, just flagging :) |
|
Independent Apple Silicon / MoltenVK check of head
Actionable harness gap found: that capability failure is counted as a FAIL, not a SKIP. No game data; synthetic fixtures and counts only. AI-assisted. |
|
thx @bobcatchris, good catch :) judge_cs_dump now treats exit 77 + 'no shaderFloat64' as a skip for any compute dump (pushed here and to #1976, which has cs_w32_f64_ops with the same issue), plus a unit test. AI-assisted (Claude Code). |
|
Tested 959f00c (merge base 7b7d73f) on NVIDIA GeForce RTX 5080, Linux 580.65.06: pass Tested the PR head merged with current main
Line-by-line against my main run (results that differ from main):
Not run: the full AI-assisted (Claude Code). |
|
Tested
New in this PR:
Every other test has the same result as on |
|
Tested 959f00c merged with main 98fa503 on Linux (Python 3.12.16) and Windows (RTX 4080 SUPER, UHD 770): pass. test_dot2_trig_preop and test_run_gpu_tests 2/2 ok. run_gpu_tests.py cs_w32_trig_preop 1/1 on RTX 4080 SUPER; skipped on UHD 770. Negative control with main's tools/rdna2spirv.py: test_dot2_trig_preop errors (2 errors) and the GPU case fails with a translation failure (no .spv). |
|
Tested
Not run: AI-assisted (Claude Code). |
SHADER-449 (claim in #2300). three RDNA2 ops the translator refused:
v_dot2_f32_f16,v_dot2c_f32_f16,v_trig_preop_f64. isa_coverage exact 498 -> 501.what it does
v_dot2_f32_f16(VOP3P) /v_dot2c_f32_f16(VOP2, accumulates into D): each f16·f16 product is exact in f32, so it's two f32Fmas, low half first:fma(S0.hi, S1.hi, fma(S0.lo, S1.lo, S2)).op_sel/op_sel_hi/neg_lo/neg_hion S0/S1,neg_lo[2]on S2,clamp. refused:abs, DPP/SDWA, VOP3neg, and S2 half-selects (S2 is f32).v_trig_preop_f64: the 53-bit segment of 2/π starting at fraction bitshift = (S1&31)*53 + max(exp-1077, 0), scaled by 2^(-53-shift) (+128 when exp >= 1968). NaN -> quieted NaN, a segment past the 37-word table -> +0. this matches LLVM'samdgcn_trig_preopconstant fold ("return 0 for outbound segment (hardware behavior)"). SPIR-V side:Privatetable array, 64-bit funnel shift on 32-bit words (no Int64 needed), and the scale split into twoLdexps so no step goes below the double range.testing
tests/semantic/test_dot2_trig_preop.py: dot2/dot2c value tests in the mini interp against a python model (random, modifiers, clamp, inf/NaN, a single-rounding case), table == 2/π computed from Machin, the reference model vs LLVM's fold values, spirv-val of all three ops, refusals. (the mini interp has no f64, so trig_preop values are checked on the GPU)opt -passes=instcombinefold: 891 swept (exponent, segment) pairs incl. the exponent 1077/1968 edges and the table end: 0 mismatches.cs_w32_trig_preop(seg 0, exp >= 1968, a denormal result, a funnel shift): PASS bit-exact on RTX 6000 Ada (Linux, NVIDIA), native andLEONIDA_W64_EMULATE=1. plus 480 random inputs through the same fixture vs the model: 480/480 bit-exact.test_fma_khrspirv-tools check deselected, old SPIRV-Tools on that box; fails on main too).test_docs_design_rows.pyfails the same 3 ways as on main (PROC-97/106), nothing new.unverified on AMD: dot2's add order (two roundings vs one, last bit only) and f16 denormals; trig_preop on real RDNA2 (follows LLVM). a device that flushes f64 denormals would fail the denormal word of the fixture.
overlaps: none in code.
check.py/run_gpu_tests.pylists touch the same lines as #1976 (mine), trivial rebase whichever lands second.AI-assisted (Claude Code).
TL;DR: adds 3 missing ops (two f16 dot products into f32 + the f64 2/π lookup used by big-argument sin/cos). CPU value tests, matches LLVM's reference on 891 cases, bit-exact on an NVIDIA GPU on 484 inputs.