Repository navigation
Tests: f32 and f16 transcendentals on the GPU against f64 references - #643
acaracargo wants to merge 2 commits into
Conversation
v_rcp, v_rsq, v_sqrt, v_log, v_exp, v_sin and v_cos (f32) had no GPU test. 26 inputs: zeros of both signs, infinities, NaN, negative inputs, overflow, denormal-free small values and sin / cos arguments up to 255 turns. Special results are compared exactly, the rest within 2^-21 relative (rcp, rsq, sqrt, log, exp) or 2^-10 absolute (sin, cos; D3D allows 8e-4). rsq(-0) is left out: IEEE says -inf, and what the console gives is not settled here. The sin / cos argument is in turns. The translation multiplies it by 6.2831853 before sin(), so the error grows with the number of turns: sin(1 turn) is -1.9e-7 instead of 0, and the worst absolute error over the inputs is 6.8e-5 (sin) and 9.6e-5 (cos), at 200-255 turns. Past about 50 turns the radian argument also leaves D3D's +-100pi accuracy range, so other drivers may do worse. Not changed here. 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. Worst relative errors: rcp 0, rsq 8.4e-8, sqrt 7.4e-8, log 1.2e-7, exp 1.1e-7. Scaling sin by pi or translating v_log_f32 to log() in emit.rs fails the test. Assisted-by: Claude Code (Claude Opus 5.5) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v_rcp, v_rsq, v_sqrt, v_log, v_exp, v_sin and v_cos (f16) on 25 binary16 inputs (zeros, infinities, NaN, negative inputs, the smallest normal, the largest finite value, sin / cos arguments up to 100 turns), with another value in the high half of the source. D[15:0] is compared with the f64 result: special results exactly, the rest within 2^-9 relative or 2^-8 absolute for sin / cos. Results past the binary16 range are left out: in the default mode the f16 result goes through the legacy f32tof16, which rounds toward zero, so v_exp_f16(16) gives 65504 (0x7bff) where round-to-nearest gives +inf. That is the default-mode rounding reported in xcl-dev#111 for add / sub / fma; it affects these instructions too. The worst errors measured (rcp 8.2e-4 relative, about 1.6 ulp) come from the same truncation. Measured: RTX 4060 (wave32), Windows 11 Pro 26300, Rust 1.100, debug. cargo test --workspace -- --test-threads=4: 679 passed, 0 failed, 41 ignored; SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware. Translating v_exp_f16 to exp() or v_cos_f16 without the 2pi scale in emit.rs fails the test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WsgnReN2iZK9RUNckZAhrv
|
Test run of Tested
Review: 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
|
|
Independent GPU test report on Tested
Not tested
AI use
|
|
@lordon1a Eline sağlık. |
|
For when this lands: #818 (fix for #796) reduces AI-assisted (Claude Code). |
Adds GPU tests for
v_rcp,v_rsq,v_sqrt,v_log,v_exp,v_sinandv_cos, in both f32 and f16, against f64 references.Special results such as zeros, infinities, NaN and overflow are checked exactly. Other results are checked within the following tolerances:
The worst measured f32 errors were 0 for rcp, 8.4e-8 for rsq, 7.4e-8 for sqrt, 1.2e-7 for log, 1.1e-7 for exp, 6.8e-5 for sin and 9.6e-5 for cos. The f16 error was about 1.6 ulp at most.
The sin / cos results also show that converting turns to radians before range reduction increases the error with larger arguments. This is worth investigating separately rather than changing the translation in a test-only PR.
#530 covers the f64 forms of rcp and rsq, which these tests do not touch.
What is in it
crates/xcl/src/gpu/recomp/tests.rs:gpu_transcendental_f32andgpu_transcendental_f16.Tested
x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug.cargo test --workspace -- --test-threads=4on232ee73: 686 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).log2()withlog(), replacingexp2()withexp()and removing the 2pi factor from the f16 cosine translation all cause the tests to fail (checked locally, reverted).Regression run
Not tested
rsq(-0)because console behavior is unverified.AI use