Repository navigation
Recompiler: direct f32 compares test for NaN explicitly again - #3539
ArtuArtaza wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Skip the predicate regression test when DXC is unavailable
The new predicate regression test fails on hosts without DXC before it can check the predicates. Check dxc::location() up front and use skip_test("no DXC") if the compiler is unavailable. Keep validation and disassembly failures visible when DXC is installed.
Local verification on Windows 11, DXC 1.9.2602.17. I applied the PR diff to 9dfbe3e, verified that the changed source file matches e921d6a, and ran the original and guarded variants separately with cargo test --offline --locked -p xcl --lib <test> -- --exact --nocapture.
- With DXC available, both variants passed (
1 passedeach). - With compiler discovery disabled by a test-only hook, the original failed during translation with
dxcompiler.dll not found. The guarded variant reportedSKIPPED: no DXCand exited successfully.
Codex assisted with the review, patch, and targeted test runs.
|
@ArtuArtaza I ran your predicate test unchanged on parent I also ran the three existing numerical tests on my RTX 3080 (driver 616.92, DXC The regression test catches the old instruction on the parent. The numerical results showed no regression on this NVIDIA adapter. I didn’t test the reported AMD driver behavior. I used Codex GPT-6.2 Sol to run the comparison. A separate GPT-6.2 Sol agent reviewed the source and test evidence. Codex GPT-6.2 Astra drafted this comment. I reviewed and approved this comment before posting. |
a899ec9 (xcl-dev#3269) lowered the direct translator's f32 compares (f16 ones go through f32) to one `fcmp` each, without the explicit NaN tests of xcl-dev#46. Three GPU tests fail on an RX 6700 XT (32.0.21045.29003) since then: gpu_f32_compares_with_nan, gpu_float_compares_random and f32_programs_on_the_gpu. They pass on its parent 5b0d5fa. The DXIL is right, the driver is not. It takes `fcmp one` (v_cmp_lg) for `une`, so a NaN operand gives true, and it gives the second of two compares of the same operands that differ only in ordered / unordered (`olt` and `ult`) the first one's result, in either order. Two plain fcmps in a kernel without any wave operation show it: 36 of the 182 ordered pairs of predicates are wrong on that card and 0 on WARP, the same with XCL_DXIL_NO_OPT=all, so no optimizer pass takes part. xcl-dev#46 had found the second form on RDNA3 and an RDNA2 iGPU. Splitting only `lg` into `olt | ogt` leaves 16 pairs wrong and the three tests failing. The explicit tests do not depend on what the driver makes of an fcmp of a NaN. They cost 1.65 % more DXIL over 567 sampled programs of a retail title. The new test reads the predicates from the disassembly, so it fails without an AMD card too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
e921d6a to
261483f
Compare
|
Review (head 261483f, diff read, not a merge-check: the
Fine: removing the f32 branch brings back exactly the explicit NaN form ( AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
No other open PR restores the explicit NaN tests for f32 compares. #2258 goes the other way: one AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
Since
a899ec90(#3269) three GPU tests fail on my RX 6700 XT (driver 32.0.21045.29003):gpu_f32_compares_with_nan,gpu_float_compares_randomandf32_programs_on_the_gpu. That commit lowered the direct translator's f32 compares (f16 ones go through f32) to onefcmpeach and dropped the explicit NaN tests, which the translators have because of an AMD driver bug (#46). This PR puts the explicit form back for f32. Related: #46, #3269, #2258, #3023, #42.The DXIL of
a899ec90is right; the driver does two wrong things with it:fcmp one(whatv_cmp_lgbecame) forune: a NaN operand gives true instead of false;oltandult,oeqandueq, ...) the first one's result, in either order, also when one of them is written with its operands swapped (olt a, bandugt b, a).v_cmp_lt_f32thenv_cmp_nge_f32is such a pair.How it was narrowed (local probes, not in this PR):
5b0d5fa3(the parent) passes the three tests,a899ec90fails them (2 runs), main9dfbe3eawith only this change passes them.fcmps of the same two loaded floats in a compute kernel with no wave operation, all 182 ordered pairs of the 14 predicates, results against IEEE: RX 6700 XT 36 pairs wrong (26 of them containone, 10 are the merged ones), WARP 0 wrong, from the same DXIL. The translator's own kernels give the same 36 in wave32 and wave64, also withXCL_DXIL_NO_OPT=all: no optimizer pass takes part.!(a >= b)intofcmp ult. Recompiler: lower direct DXIL float_compare to ordered/unordered fcmp #2258 (the same change as ina899ec90, open) was reported failing on an RX 9070 XT and an RX 6800M. Recompiler: direct DXIL optimizer runs to a fixed point with new passes #3269 lists AMD GPUs under "Not tested".GetCachedBlobholds only a key), so "merges" is read from the results.Other forms tried on this card:
fcmp)lgasoltorogt, the rest onefcmp(amd-dev's form)nX=xor (oX), true,lg=oltorogtThe third form is much smaller, but it relies on the driver not folding the
xorback into an unordered compare, and I can only measure one driver. The explicit form does not depend on what the driver makes of anfcmpof a NaN, and it is what main emitted untila899ec90. If the third form also passes on RDNA3 / RDNA4 drivers, it could replace this one.What is in it
crates/xcl/src/gpu/dxil/lower_valu.rs:float_compareloses its f32 branch, so f32 takes the explicit form that f64 already takes; the comment gives the reason.f32_compares_use_no_predicate_that_amd_merges: the 14 f32 compares, wave32 and wave64, must not disassemble toone,ueq,ugt,uge,ultorule. It needs no GPU: Recompiler: direct DXIL optimizer runs to a fixed point with new passes #3269's NVIDIA runs of the GPU tests passed, so they did not show this.TRANSLATOR_VERSIONbump: agpu/dxiledit changes the direct translations' cache identity by itself.Tested
CARGO_PROFILE_DEV_DEBUG=0,CARGO_PROFILE_RELEASE_DEBUG=0).cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4one921d6a9(on main9dfbe3ea): 2884 passed, 4 failed, 51 ignored (44 test binaries). The 4 are 3 tests, and all 3 fail with the same values on unmodified main9dfbe3eaon this card (ran them there alone):gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form(what Recompiler: compact literal indices are read from one table word on AMD #3473 fixes),gpu_direct_image_get_resinfo_d16(see Tests: name the trailing VGPRs in the D16 resinfo kernel test #3513) andtwo_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs(parent and child run). 4SKIPPED(2 no heap windows, 1 no GPU_UPLOAD heaps, 1 cannot disable the driver cache).cargo test -p xcl --lib -- gpu_f32_compares_with_nan gpu_float_compares_random f32_programs_on_the_gpu --test-threads=1): pass oncfb9753aand5b0d5fa3, fail ona899ec90, pass here. The new test fails with main'sfloat_compare(fcmp one) and passes with this one.xcl shaders <archive> --direct --sample 600 --seed 3 --max-bytes 40000 --split 0 --timeout 120, summed DXIL, both forms from one local build of9dfbe3eawith a switch): 24,387,884 B on main, 24,789,936 B here (+1.65 %).--sample 4000 --seed 11 --max-bytes 60000 --split 0): 1,925 programs hold anfcmp one(15,852 of 929,962 f32fcmps), 5 hold a pair the driver would merge. It only matters in lanes where an operand is NaN; whether the picture changes was not measured.Regression run
60 s (menus),
scripts/smoke.ps1,XCL_DEVICE_TYPE=lockhart XCL_PREPARE=0, A pressed every 15 s from 30 s: main9dfbe3ea, then this PR's head (which ran first).Not tested
a899ec90).AI use
🤖 Generated with Claude Code