Repository navigation
Recompiler: v_med3_f32 / _f16 with a NaN operand give the min of the others (#678) - #686
joeypercia wants to merge 3 commits into
Conversation
|
Independent test report on Tested
Not tested
AI use
|
|
Test report for Tested
16 test binaries: 692 passed, 1 failed, 41 ignored. Same machine, This PR's tests:
Failures:
16 test binaries instead of SKIPPED (no wave64 on this GPU): AI use: Claude Code (Claude Opus 5.5) ran the builds and tests and wrote this report from their output. |
|
Independent Release result at 3115aae. On NVIDIA RTX 5070 (driver 591.86), Rust 1.100.0 MSVC and DXC 1.8.2502.11, the unmodified gpu_med3_with_a_nan_operand_is_the_min_of_the_others test passed in an optimized build. Command: |
|
Native RDNA2 signaling-NaN check for #678 I measured
For example, This confirms the quiet-NaN behavior in the PR and gives separate signaling-NaN cases to use if IEEE-mode handling is extended. Not tested The PR's translated HLSL, other GPUs, and combinations with multiple signaling NaNs plus an exceptional third operand. AI use OpenAI Codex (GPT-6 family, exact model variant unavailable) wrote and ran the probe and drafted this report. |
|
Regression runs for this PR's head main: this PR: Tested
Not tested
Report written with Claude Code (Claude Opus 5.5) from runs on this machine. |
|
2| |
|
Tested on AMD Radeon RX 9070 XT (RDNA4) at AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32015.7029; Ryzen 7 5700X3D; 32 GB RAM; Windows 11 Pro build 26300.9974; Rust 1.100.0; DXC 1.9.2602.17; debug build. Tested:
Not tested: retail title / Report written by Claude Code (Claude Sonnet 5.5) from a real run on this machine. Correction (hidden skips): "0 SKIPPED" above means no |
|
Tested on NVIDIA (32-lane waves): passes
Not tested: AMD, any title (no smoke run). AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report. |
The three-source program check written for the direct backend computed med3 with Rust's min / max, which ignore a NaN, so with xcl-dev#686's rule (a NaN operand gives the smaller of the other two, on both paths now) lane 0's med3(|y|, NaN, 4.0) came out 4.0 against an expected 16.0. The expected value follows the hardware rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YPhfiWsdJcDBLYSS8edLyS
|
The direct DXIL backend counterpart of this fix, from @regiumlepidi's parity sweep on #1269:
How to take it: this PR predates the direct backend on patch (2 commits, for
|
…others (xcl-dev#678) With a quiet NaN operand the hardware's v_med3 returns v_min(v_min(s0, s1), s2), the smaller of the two other operands, as LLVM's amdgcn_fmed3 folding documents. med3f computed max(min(a, b), min(max(a, b), c)), which gives max(a, b) for a NaN in c and b / a for a NaN in a / b (med3(2, 1, NaN) = 2, want 1), on NVIDIA and AMD alike. The clamp form med3(NaN, lo, hi) was already right. Fixes xcl-dev#678 Assisted-by: Claude Code (Claude Opus 5.5)
… others med3f was max(min(a, b), min(max(a, b), c)) for every input, so a NaN operand did not give what the hardware does: v_min(v_min(a, b), c), the smaller of the other two. With a NaN in any operand it now selects min(min(a, b), c), as xcl-dev#686 does on the HLSL path; other inputs are unchanged. gpu_med3_with_a_nan_operand_is_the_min_of_the_others now passes with XCL_DIRECT_DXIL=1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YPhfiWsdJcDBLYSS8edLyS
3115aae to
8c60272
Compare
|
Tested Intel Arc A770 (driver 32.0.101.9175) on clean PR head I prebuilt outside the GPU lock in the unoptimized test profile with cargo test --locked -p xcl --lib -j 2 --no-run
& $testExe gpu::recomp::tests::gpu_med3_with_a_nan_operand_is_the_min_of_the_others --exact --nocapture --test-threads=11 passed, 0 failed, 0 ignored, 0 skipped. The wave32 HLSL/DXC dispatch matched all ten bit-exact results for each of Not tested Signaling NaNs, direct-DXIL parity, native or split wave64, other GPUs, the full workspace suite, and retail smoke runs. AI use Codex in T3 Code ( |
|
CI \Build and test\ passed on \8c60272, and the direct DXIL \med3f\ + \lower.rs\ expectation updates look clean.\n\nRemaining before merge:\n1. Fix/re-run the \PR description\ check (none reported yet on branch |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
With a quiet NaN operand the hardware's
v_med3_f32/v_med3_f16returnv_min(v_min(s0, s1), s2), the smaller of the two other operands, as LLVM'samdgcn_fmed3folding documents (AMDGPUInstCombineIntrinsic.cpp).med3fcomputedmax(min(a, b), min(max(a, b), c)), which givesmax(a, b)for a NaN incandb/afor a NaN ina/b. It now takes the min of the others when an operand is NaN; the median path is unchanged. Fixes #678.What is in it
crates/xcl/src/gpu/recomp/emit.rs:med3f(used byv_med3_f32andv_med3_f16) handles a NaN operandcrates/xcl/src/gpu/recomp/tests.rs:gpu_med3_with_a_nan_operand_is_the_min_of_the_others, f32 and f16: a NaN in each position with both operand orders, the clamp form, two NaNs, and a no-NaN controlcrates/xcl/src/gpu/dxil/prelude.rs(by @milesah3ad, from the parity sweep on [OFFICIAL] Looking for PRs with shaders optimization #1269): the direct DXIL backend'smed3fgets the same NaN rule, so the test passes withXCL_DIRECT_DXIL=1toocrates/xcl/src/gpu/recomp/lower.rs(by @milesah3ad):check_f32_three_sourceexpects the NaN rule; with this PR on currentmain,lower_dxil::tests::f32_programs_on_the_gpufailed on both paths without itmain(aa9ab8a), which now has the direct backendTested
cargo test --workspace --no-fail-fast -- --test-threads=2on8c60272: RTX 4070 Ti 1083 passed, 0 failed, 46 ignored; RDNA2 1082 passed, 1 failed, 46 ignored. The failure isgpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1(seed 540,res[833] = 0x7, CPU0x6, no med3 in the program); it fails the same way onmainaa9ab8a(2 runs of 2)XCL_DIRECT_DXIL=1on both GPUs:gpu_med3_with_a_nan_operand_is_the_min_of_the_othersandlower_dxil::tests::f32_programs_on_the_gpupassSKIPPED: RTX 4070 Ti the wave64 / per-lanelowerandlower_dxilGPU tests (no wave64); RDNA2 the mesh tests (no mesh shaders); both: thef16_programs_on_the_gpuper-lane forms refused by gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 (V_MUL_F16/V_PK_MUL_F16/V_CVT_F16_F32)emit.rsback tomain, the new test fails: 8 wrong (all four non-clamp NaN positions, f32 and f16) on the RTX 4070 Ti and on RDNA2gfx1031, rawv_med3_f32/v_med3_f16on the hardware): a quiet NaN in any position gives the min of the other two, as this PR does; signaling NaNs differ with the IEEE mode bit on (src0/src1sNaN givessrc2); sNaN cases are left out (see Not tested)Regression run
RTX 4070 Ti (driver 616.56), release builds, 60 s each,
scripts/smoke.ps1 -Title retail-titleon the newer retail title, mainaa9ab8aand this PR's head8c60272(no uncommitted changes). (@Anon64's earlier runs, on an RTX 3060 for the previous head3115aae, were equally clean.)main:
PR:
Not tested
v_med3with a NaN operand outside the clamp form. They use the instruction a lot: itsshaders.rpf(xcl shaders --json, 26 503 shaders) has 58 722v_med3_f32in 8 050 shaders (and 21v_med3_f16). The 60 s runs above show no regression but cannot tell whether such a NaN occurs.AI use