Tests: float-to-int conversions clamp and take NaN as 0 on the GPU #639
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!639
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-639"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@acaracargo on GitHub · 2026-11-24 02:47 UTC · original
acaracargo:fork/cvt-int-gpu-tests→main· +66 −0 · 1 files · 1 commits · openHLSL leaves an out-of-range or NaN float-to-int cast undefined. The ISA clamps and maps NaN to 0, which is what the
cvt_i32/cvt_u32helpers inemit.rsare for.This adds GPU coverage for
v_cvt_i32_f32,v_cvt_u32_f32,v_cvt_flr_i32_f32,v_cvt_rpi_i32_f32,v_cvt_u16_f16andv_cvt_i16_f16.The inputs cover NaN of both signs, infinities, integer range boundaries, negative halves, negative zero and a denormal. The reference uses Rust's
asconversion, which saturates and maps NaN to zero. The f16 sources carry another value in their high half.#515 covers the opposite conversion direction and does not overlap with this test.
What is in it
crates/xcl/src/gpu/recomp/tests.rs:gpu_float_to_int_conversions_clamp_and_take_nan_as_zero.Tested
x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug.cargo test --workspace -- --test-threads=4onac0b845: 685 passed, 0 failed, 41 ignored (main9ce2070: 684 / 0 / 41).gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64).cvt_i32causes the test to fail (checked locally, reverted).(int)cast already saturates and maps NaN to 0, so removing the helper altogether is not caught here.Regression run
Not tested
v_cvt_rpi_i32_f32of 0.49999997, wherefloor(x + 0.5)in f32 rounds up. The ISA text does not specify whether the addition is rounded.AI use
@MesshM on GitHub · 2026-11-24 03:18 UTC · original
Test run of
ac0b845698d82b765b5436cd0151cef6feb0127con AMD RDNA4 (native wave64). I merged it onto currentmain63cdc25locally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 693 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 653 passed, 0 failed, 21 ignoredSKIPPED;gpu_float_to_int_conversions_clamp_and_take_nan_as_zeropasses.Review: NaN converts to 0 and out-of-range values (±inf included) clamp;
v_cvt_flr_i32_f32is floor(x) andv_cvt_rpi_i32_f32floor(x + 0.5) before the conversion, and the f16 sources carry another value in the high half, as the ISA describes. This is the first AMD run.Not tested: no retail title (not needed for a test-only change), release build; the PR's head on its old base was not run, only its merge onto
main.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@marquezinii on GitHub · 2026-11-24 04:31 UTC · original
Test run of
ac0b845698d82b765b5436cd0151cef6feb0127con NVIDIA Blackwell with a newer driver than the one in the description. I merged it onto currentmainf4ce27clocally (clean merge, 66 lines intests.rs) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debug; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0)cargo test --workspace -- --test-threads=4: 702 passed, 0 failed, 41 ignored;--test-threads=1: the samegpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64)gpu_float_to_int_conversions_clamp_and_take_nan_as_zeropassescvt_u32reduced toreturn (uint)f;, and separatelycvt_i32toreturn (int)f;(by hand, reverted), the test still passes. So on RTX 4060 / 610.88 and RTX 5070 / 621.24 a plain cast already saturates and maps NaN to 0, and only AMD (or another vendor) can show whether the helpers are needed.Not tested
AI use
@4usphs on GitHub · 2026-11-24 09:32 UTC · original · edited 2026-11-24 09:42 UTC
Measured on RDNA2 hardware: this answers the
v_cvt_rpi_i32_f32question under Not tested, and shows a second difference. For NaN,v_cvt_flr_i32_f32andv_cvt_rpi_i32_f32do not give 0.Method. The Radeon iGPU of a Ryzen 7 9800X3D (
gfx1036, RDNA2), Windows 11 Pro 26200, display driver 32.0.21045.29003, AMD OpenCL3652.0 (PAL,LC). Each instruction runs as inline RDNA2 assembly in an OpenCL C kernel (the #518 / #772 method), one input per work-item, VDST preset to0xCAFEBABE, in wave32 and in wave64 (-Wf,-mwavefrontsize64). There are 3 runs with identical output. The NaN and rounding cases were also run with MODE.DX10_CLAMP / MODE.IEEE set to each of the 4 combinations withs_setreg_imm32_b32(read back withs_getreg_b32:0xf0to0x3f0), and they give the same results in all 4.1.
v_cvt_rpi_i32_f32rounds exactly. The hardware computesfloor(x + 0.5)without roundingx + 0.5to f32.floor(x + 0.5f)in f32 (the test's reference, andemit.rstoday)floor(x + 0.5)0x3EFFFFFF)0x4B000001)0x4B000003)0xCB000001)emit.rstranslates it ascvt_i32(floor(x + 0.5f))(line 3281 onmain077ce40). So it gives 1 for 0.49999997 and is off by one for odd integers from 2^23 up.2. NaN in
v_cvt_flr_i32_f32/v_cvt_rpi_i32_f32takes the sign of the NaN.v_cvt_i32_f32v_cvt_u32_f32v_cvt_flr_i32_f32v_cvt_rpi_i32_f320x7FC00000, +sNaN0x7F800001,0x7FFFFFFF0x7FFFFFFF0x7FFFFFFF0xFFC00000, -sNaN0xFF8000010x800000000x80000000v_cvt_i32_f32andv_cvt_u32_f32give 0 as the test expects. Forflrandrpi, the test's first two inputs (NAN,-NAN) expect 0, which is the opposite of the hardware.emit.rsgives 0 there too, throughcvt_i32'sisnanselect.Everything else in this test matches the hardware. These are the other 18 f32 inputs for all four f32 instructions, the 12 f16 inputs for
v_cvt_u16_f16/v_cvt_i16_f16(low 16 bits), and wave32 = wave64 everywhere. Side note for #638's open point: both f16 conversions left D[31:16] at the preset0xCAFE, so the high half is kept, not zeroed.What would match the hardware, as far as I can tell (not tried in
emit.rs): forflr/rpi, NaN givesselect(asuint(x) >> 31, 0x80000000, 0x7FFFFFFF).rpirounds without the f32 addition, e.g.r = floor(x); r + (x - r >= 0.5f)(x - floor(x)is exact in f32), then clamps.For comparison, an RX 9070 XT (
gfx1201, RDNA4, OpenCL3686.0) gives the same results for everything above: exactrpirounding, the NaN signs forflr/rpi, and D[31:16] kept.Not tested: the console itself (
gfx1036is a desktop RDNA2 APU of the same generation), RDNA1, this PR's test on this GPU (it does not run D3D12 tests in my setup; RDNA4 runs are above).Kernel (one of the cases)
AI use: Claude Code (Claude Opus 5.5) wrote the OpenCL probes, ran them on my PC and wrote this comment. I have not reviewed the code.
@JJAutoCompare on GitHub · 2026-11-25 06:30 UTC · original
Empirical test report (
ac0b8456)Hardware / environment
ac0b845698d82b765b5436cd0151cef6feb0127c, verified on a clean detached HEAD.Commands and results
cargo test -p xcl --lib --no-runexited 0 outside the Arc lock. Cargo built the test executable in 30.59 s and emitted onefetch_updatedeprecation warning.$testExeis the executable printed by Cargo and$arcLockis the sharedInvoke-ArcTest.ps1script. The focused command ran withXCL_ADAPTER=A770andRUST_TEST_NOCAPTURE=1.The focused command exited 0. The log shows 1 passed, 0 failed, 0 ignored, 0 skipped, with 665 tests filtered out. The skip count is the number of case-sensitive log lines beginning with
SKIPPED. The test harness reported 0.19 s.Observed behavior
The translated compute shader matched the Rust expectations for all six conversion instructions across 20 checked lanes, including NaN to zero, clamping at integer bounds and for infinities, and the signed floor and nearest rounding with ties toward positive infinity. The two f16-source conversions also matched with nonzero bits in the high half of the source registers.
Not tested
Full GPU workspace suite and game smoke runs.
AI use
Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr639-focused.log and published.
@DavidM1911 on GitHub · 2026-11-25 12:45 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.Thanks!
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.