Repository navigation
rdna2spirv: align v_div_fixup_f16/f64 with native RDNA2 gfx1036 measurements - #2477
Conversation
|
Independent review of 21a1ecf on Windows 11 build 26300, RTX 5070 driver 621.24. All five PR tests and Vulkan 1.2 validation passed. I found two places where the translated output differs from the published RDNA2 pseudocode, §12.12, VOP3 opcodes 863 and 352.
These are synthetic standalone inputs, useful for distinguishing instruction branches. I verified the translated outputs on NVIDIA. Native AMD confirmation of the NaN payload and underflow word would help settle the contract. AI-assisted review. |
|
Tested translator commit
|
|
Thanks @duudiis for the thorough GPU review and exact reproducers! Fixed both issues: (1) removed NaN(S0) from the infinity branch so NaN(S0) falls through to copysign(S0, sign_out) (0x7e35 -> 0xfe35 in f16, 0xfff8123456789abc -> 0x7ff8123456789abc in f64); (2) added exponent underflow/overflow checks (exp(S2)-exp(S1) <= -25 / >= 16 for f16, <= -1075 / >= 1024 for f64, so 2^-1022 / 2^100 -> +0.0). Updated docs/design.md and tests/semantic/test_alu_div_fixup.py (5/5 pass with spirv-val). |
|
Measured
(AI-assisted hardware verification.) |
2c43266 to
d6a74bd
Compare
|
Thanks @timelery for measuring both ops on native RDNA2 gfx1036 silicon! Updated tools/rdna2spirv.py, docs/design.md, and tests/semantic/test_alu_div_fixup.py (5/5 pass with spirv-val) to match every measured gfx1036 rule under IEEE=0: NaN(S0) -> +-inf, no exponent-diff cutoff on f16, f64 underflow cutoff at e2 - e1 <= -1076 (no overflow cutoff), and sNaN preserved unchanged under IEEE=0. |
1e1aae8 to
48a1a98
Compare
|
Independent check of Native gfx1036 (Ryzen 9 9950X3D iGPU, AMD driver 32.0.21030.2001, raw
Translated (compute
So this head's f64 exponent rules match the hardware on every case here. Not covered by this PR or by my runs above: the same grid with f64 denormals flushed (MODE Windows 11, llvm-mc AMD LLVM 23.0.0git, Vulkan SDK 1.4.363. Synthetic programs only, no game files. The scripts are local. AI-assisted (Claude Code). |
|
Tested Runtime and test programs built from this head (MSVC 14.51, Ninja, RelWithDebInfo), native Windows
No suite shader uses AI-assisted (Claude Code); I checked the results. |
…Rexed#2477 is on main ItsNotRexed#2477 (48a1a98) makes the translator return signed infinity for v_div_fixup_f64 with NaN(S0), as measured on RDNA2 gfx1036, which is what the reference already modelled. The case is no longer a known divergence (as TreXito's review of ItsNotRexed#4536 observed: two tests fail on main because they expect the old divergence). - Remove the div-fixup-nan-s0 entry, its reference skip and its dedicated --known program; NaN(S0) programs are compared like any other. - Add a positive test that the reference and the translator give +-inf for qNaN, -qNaN and sNaN with both output signs. - Rework the two --known tests so they no longer depend on div_fixup: the three remaining forms are excluded with a reason by default, run with --known, and a planted clamp-only translator error exits 1 and prints the shrunk program. - docs/shader_validation.md no longer lists the div_fixup case. Same change as 41525870 (prepared for ItsNotRexed#4586, which ItsNotRexed#2477 made redundant). AI-assisted (OpenBot team). Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
…nts on main (ItsNotRexed#2477) TreXito's review of ItsNotRexed#4536 found 40 mismatches in 24000 programs (seeds 776401 and 776402, exp(S2) - exp(S1) >= 1024): the reference predates ItsNotRexed#2477 (48a1a98), whose measured RDNA2 gfx1036 rules are in the docs/design.md v_div_fixup row. The translator is the side that is right. Checked against that row and against the v_div_fixup_f64 lowering in tools/rdna2spirv.py on main, not only against the proposed patch: - NaN in S2 or S1 passes through unchanged (a signalling NaN is not quieted with IEEE=0); the priority NaN(S2) over NaN(S1) is unchanged. - The underflow cutoff is exp(S2) - exp(S1) <= -1076 (was < -1074). - There is no overflow check (was >= 1024). - NaN(S0) gives signed infinity, still below the underflow case. test_div_fixup_table is updated row by row (gap 1074/1075 pass S0, 1076 gives a signed zero, no overflow rows, unquieted sNaN) and docs/shader_validation.md records the rule. AI-assisted (OpenBot team). Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
Found while validating the ItsNotRexed#2477 follow-up on the RTX 4070: with the current translator, `v_cmp_eq_i32_e32 vcc_lo, 0, 0; v_div_fmas_f64 v[8:9], s[4:5], -1.0, 1` mismatched. The reference scaled by a fixed 2^64 when VCC is set; main now follows the hardware-verified (gfx1036, 153/153 f64 stress cases) rule in the docs/design.md v_div_fmas row: 2^+128 when exp(S2) > 1023 (|S2| >= 2.0), 2^-128 otherwise. Same class of stale reference as the v_div_fixup_f64 one fixed in the previous commit (TreXito's review of ItsNotRexed#4536). A table test pins both sides of the |S2| = 2.0 threshold and the VCC-clear case; reverting to the fixed 2^64 fails it. AI-assisted (OpenBot team). Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
…k oracle (TEST-545) tests/semantic/test_valu_div_fixup.py compared a hand-written Python model of the fixup against itself and never imported tools/rdna2spirv.py, so it passed whatever the translator did, and its rules had drifted from native RDNA2 (gfx1036) on six points (NaN priority, the sign of 0/0 and inf/inf, inf(S2), the copysign of the pass-through, NaN(S0), and the exponent-difference cutoff). It now translates hand-written listings and asserts what the translator emits: the pure-integer lowering's op order and classification constants, NaN(S2) above NaN(S1) read off the dataflow, one word per measured rule through spirv_mini_interp, and the EXEC-masked and null-destination cases. The f16 model is gone rather than ported: the translator has no v_div_fixup_f16 lowering yet (ItsNotRexed#2477 adds it with its own translator tests). Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Implements RDNA2 VOP3 division special-case fixup instructions
v_div_fixup_f16andv_div_fixup_f64intools/rdna2spirv.py(+2 RDNA2 ISA coverage):S0quotient,S1denominator,S2numerator; RDNA2 ISAV_DIV_FIXUP_F16/V_DIV_FIXUP_F64):sign_out = sign(S1) ^ sign(S2)NaN(S2)-> quietedS2;NaN(S1)-> quietedS1(0/0)or(inf/inf)-> canonical negative qNaN (0xFE00/0xFFF80000_00000000)(x/inf)or(0/y)->copysign(0, sign_out)(x/0)or(inf/y)orNaN(S0)->copysign(inf, sign_out)copysign(S0, sign_out)v_div_fixup_f16: supportsop_sel:[s0,s1,s2,dst],abs/neg, output modifiers (mul:2/mul:4/div:2/clamp), and preserves the unwritten 16-bit half of the destination.v_div_fixup_f64: supports VGPR/SGPR pairs, inline constants,abs/neg, needs noOpCapability Float64in plain form, enablesFloat64+clamp_mods_f64()when output modifiers are present, and rejects non-pair destinations.docs/design.mdand CPU semantic +spirv-valtests intests/semantic/test_alu_div_fixup.py.Verification
python -B -I tests/semantic/test_alu_div_fixup.pyon unpatchedtools/rdna2spirv.pyfailed with 24Unsupportederrors (v_div_fixup_f16andv_div_fixup_f64).python -m compileall -q make_game.py tools testspython -B -I tests/semantic/test_alu_div_fixup.py -v(5/5 pass: all 11 special/normal cases bit-exact inspirv_mini_interpfor both f16 and f64,op_sel,abs/neg, SGPR/inline, output modifiers, non-pair rejection,spirv-as+spirv-val --target-env vulkan1.2)