Repository navigation
Tests: float-to-int conversions clamp and take NaN as 0 on the GPU - #639
acaracargo wants to merge 1 commit into
Conversation
v_cvt_i32_f32, v_cvt_u32_f32, v_cvt_flr_i32_f32, v_cvt_rpi_i32_f32, v_cvt_u16_f16 and v_cvt_i16_f16 on the edges of their range: NaN of both signs, +-inf, +-2^31 and the f32 values next to it, the largest f32 below 2^32, negative halves for floor / round, -0 and a denormal (0 whether or not it is flushed). The f16 sources carry another value in the high half. The reference is Rust's `as` (saturating, NaN -> 0), which is the ISA's rule. These conversions had no edge-value GPU test; HLSL leaves an out-of-range or NaN cast undefined, which is what the cvt_i32 / cvt_u32 helpers in emit.rs guard against. Measured: RTX 4060 (wave32), Windows 11 Pro 26300, Rust 1.100, debug. cargo test --workspace -- --test-threads=4: 678 passed, 0 failed, 41 ignored; SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware. Changing cvt_i32's NaN or overflow result fails the test. On this NVIDIA driver a plain (int) cast already saturates and maps NaN to 0, so removing the helper is not caught here; it may be on other drivers. Assisted-by: Claude Code (Claude Opus 5.5) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Test run of Tested
Review: NaN converts to 0 and out-of-range values (±inf included) clamp; 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 Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code. |
|
Test run of Tested
Not tested
AI use
|
|
Measured on RDNA2 hardware: this answers the Method. The Radeon iGPU of a Ryzen 7 9800X3D ( 1.
2. NaN in
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 What would match the hardware, as far as I can tell (not tried in For comparison, an RX 9070 XT ( Not tested: the console itself ( Kernel (one of the cases)__kernel void k(__global uint* o, __global const uint* A) {
uint i = get_global_id(0), a = A[i], r = 0xCAFEBABEu, m0, saved;
__asm__ volatile(
"s_getreg_b32 %1, hwreg(HW_REG_MODE)\n"
"s_setreg_imm32_b32 hwreg(HW_REG_MODE, 8, 2), 0\n" // DX10_CLAMP, IEEE: 0..3
"s_getreg_b32 %2, hwreg(HW_REG_MODE)\n"
"v_cvt_rpi_i32_f32 %0, %3\n"
"s_setreg_b32 hwreg(HW_REG_MODE), %1\n"
: "+v"(r), "=&s"(saved), "=&s"(m0) : "v"(a));
o[2*i] = r; o[2*i+1] = m0;
}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. |
Empirical test report (ac0b845)Hardware / environment
Commands and results
& $arcLock -Test { & $testExe gpu::recomp::tests::gpu_float_to_int_conversions_clamp_and_take_nan_as_zero --exact --nocapture --test-threads=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 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. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
HLSL 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