Repository navigation
Recompiler: use IEEE-754 equality for float compare-and-swap atomics - #2011
Merged
Merged
Conversation
RDNA2 float compare-and-swap atomics (`ds_cmpst[_rtn]_f32`,
`{buffer,flat,global}_atomic_fcmpswap[_x2]`, `image_atomic_fcmpswap`)
compare using IEEE-754 float equality where `-0.0 == +0.0` swaps
(returning the pre-swap sign bits) and `NaN == NaN` (both qNaN and sNaN)
does not swap, as verified on RDNA2 silicon (`XCL-BT-042`, xcl-dev#1489).
Previously both the HLSL emitter (`recomp/emit.rs`) and Direct DXIL
translator (`dxil/lower_mem.rs`, `dxil/lower_image.rs`) lowered all
float CAS atomics to raw bitwise compare-exchange. Replace those with
bounded 4096-iteration CAS loops starting from an atomic `Or 0` read
(preventing 64-bit load tearing or non-atomic early-exit reads on
mismatch) and checking bitwise IEEE-754 ordered equality
(`!is_nan(cur) && (cur == cmp || ((cur | cmp) & !SIGN) == 0)`) in pure
`u32` / `u64` integer ops so DXC fast-math cannot miscompile NaN/zero
checks, 64-bit `fcmpswap` needs no `DoubleExtensions`, and `PRELUDE_MEM`
stays untouched. Integer `cmpswap` / `cmpst_b32` ops remain single
bitwise compare-exchanges.
Update `atomic_fcmpswap_x2_uses_ieee_64_bit_cas` and
`gpu_atomic_fcmpswap_x2`, and add `gpu_float_cas_uses_ieee_equality`
covering all 32-bit/64-bit float CAS families plus integer controls on
both HLSL and Direct DXIL.
Part of xcl-dev#1489
Assisted-by: Google Antigravity (Gemini 4 Neon)
|
Full-suite run, since this PR has no test report yet. Tested exact head Tested
Not tested
AI use
|
Contributor
|
AMD RDNA3 (RX 7800 XT, native wave64) test report for #2011 at head Tested
Not tested
AI use
|
|
Independent Intel Arc A770 verification of clean PR head Tested
cargo test -p xcl --lib gpu::recomp::tests::atomic_fcmpswap_x2_uses_ieee_64_bit_cas -- --exact --nocapture
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
cargo test -p xcl --lib gpu::recomp::tests::gpu_float_cas_uses_ieee_equality -- --exact --nocapture
}
Not tested Full workspace suite, release build, retail-title smoke, heap-window GPU dispatch, or other GPU/driver combinations in this run. AI use Codex ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes RDNA2 float compare-and-swap atomics (
ds_cmpst[_rtn]_f32,{buffer,flat,global}_atomic_fcmpswap[_x2], andimage_atomic_fcmpswap) in both the HLSL emitter and Direct DXIL translator from raw bitwise compare-exchange to bounded CAS loops using IEEE-754 float equality (-0.0 == +0.0swaps and returns the pre-swap sign bits;qNaN == qNaNandsNaN == sNaNkeep without swapping). Part of #1489 (XCL-BT-042).Matches
AC-Storm-YT's RDNA2 (gfx1036) silicon verification on #1489 (#issuecomment-7142546620). Comparisons are expressed with pureuint/uint64_tbit operations (!is_nan(cur) && (cur == cmp || ((cur | cmp) & !SIGN) == 0)) so DXC fast-math cannot miscompile NaN or signed-zero checks, 64-bitfcmpswapneeds noDoubleExtensions, andPRELUDE_MEMstays untouched. Bitwise integercmpswap/cmpst_b32operations remain single compare-exchange instructions.What is in it
crates/xcl/src/gpu/recomp/emit.rs: split"fcmpswap"/"cmpst_f32"from bitwise"cmpswap"/"cmpst_b32"inrmw32and"fcmpswap"from"cmpswap"inrmw64, emitting bounded 4096-iteration IEEE-754 CAS loops starting from an atomicOr 0read (InterlockedOr/InterlockedOr64+InterlockedCompareExchange/InterlockedCompareExchange64, preventing 64-bit load tearing or non-atomic mismatch early-exits, compatible with multi-window accessors).crates/xcl/src/gpu/dxil/lower_mem.rs: addLw::feq_bits32,Lw::feq_bits64,Lw::fcas32, andLw::fcas64(initializinginitvia atomicOr 0), and use them for"fcmpswap"/"cmpst_f32"inrmw32and"fcmpswap"inatomic64.crates/xcl/src/gpu/dxil/lower_image.rs: addLw::texel_fcas(reusingLw::feq_bits32and atomicOr 0initial read) forimage_atomic_fcmpswapwhile keepingimage_atomic_cmpswapas a singleatomic_cmpxchg.crates/xcl/src/gpu/recomp/tests.rs:atomic_fcmpswap_x2_uses_ieee_64_bit_cas(verifying atomicInterlockedOr64initial load, 1/2-window HLSL DXC compile, and 1/2/heap-window Direct DXIL validation) andgpu_atomic_fcmpswap_x2(±0.0swaps,qNaNkeeps, contended shared cells).gpu_float_cas_uses_ieee_equalityverifying LDS (ds_cmpst_rtn_f32), 32-bit/64-bit buffer/global/flat (*_atomic_fcmpswap[_x2]), image UAV (image_atomic_fcmpswap), and bitwise integer controls across 8 edge cases (-0/+0,+0/-0,qNaN,sNaN, denormal vs+0, finite match/mismatch,-inf) on both HLSL and Direct DXIL.Tested
0ef1bc386), DXC 1.9.2609.5 (01b62ad4), release build.atomic_fcmpswap_x2_uses_ieee_64_bit_cas(CPU) andgpu_float_cas_uses_ieee_equality(RTX 4060 GPU:hlsl lane 0 case 0: ds_cmpst_rtn_f32kept0x80000000instead of swapping-0.0vs+0.0to1.0f) fail before the fix.cargo test --release -p xcl --lib gpu::recomp::tests::atomic_fcmpswap_x2_uses_ieee_64_bit_cas -- --nocapture: 1 passed, 0 failed, 0 ignored.cargo test --release -p xcl --lib gpu_float_cas_uses_ieee_equality -- --nocapture: 1 passed, 0 failed, 0 ignored (both HLSL and Direct DXIL executed on RTX 4060).gpu_atomic_fcmpswap_x2(default HLSL andXCL_DIRECT_DXIL=1) andgpu_images_sample_load_store_atomic(XCL_DIRECT_DXIL=1): all passed, 0 failed.cargo build --release --workspace+cargo test --release --workspace -- --test-threads=4: 991 passed, 0 failed, 45 ignored across 20 test binaries.SKIPPEDGPU/runtime tests on this adapter (24 lines):no wave64subcases acrossgpu::recomp::lower::tests(4),gpu::recomp::lower_dxil::tests(13), andgpu::recomp::tests(2)#1426refusals (V_MUL_F16,V_PK_MUL_F16,V_CVT_F16_F32) ingpu::recomp::lower_dxil::testsshaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required)heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windowsRegression run
scripts/smoke.ps1onmain(8e87fc7b62a87ea589ccb9ea6182f514016cf7db) and on this PR's head commit (990b9d4795ca4707ca5c71f2fd93aca5071e4a35):Not tested
MODE.FP_DENORM=0(f32 denormal-flushed mode, where RDNA2 flushes denormals to±0.0before comparing): XCL currently preserves denormals and does not tracks_denorm_modefor float atomics.ds_cmpst[_rtn]_f64(64-bit LDS atomics are not currently implemented in XCL).--release).AI use
emit.rs,lower_mem.rs, andlower_image.rs, implemented the fix, CPU/GPU regression tests, and PR description; every line of the diff, test run, and smoke check was verified on local RTX 4060 hardware.