Skip to content

Tests: f32 and f16 transcendentals on the GPU against f64 references - #643

Open
acaracargo wants to merge 2 commits into
xcl-dev:mainfrom
acaracargo:fork/transcendental-gpu-tests
Open

acaracargo wants to merge 2 commits into
xcl-dev:mainfrom
acaracargo:fork/transcendental-gpu-tests

Conversation

@acaracargo

Copy link
Copy Markdown

Adds GPU tests for v_rcp, v_rsq, v_sqrt, v_log, v_exp, v_sin and v_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:

  • f32: 2^-21 relative (4 ulp), and 2^-10 absolute for sin / cos.
  • f16: 2^-9 relative, and 2^-8 absolute for sin / cos.

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_f32 and gpu_transcendental_f16.

Tested

  • NVIDIA GeForce RTX 4060 (32-lane waves only), driver 610.88; Intel Core i5-13400F; Windows 11 Pro 26300; Rust 1.100.0 x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug.
  • cargo test --workspace -- --test-threads=4 on 232ee73: 686 passed, 0 failed, 41 ignored (main 9ce2070: 684 / 0 / 41).
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).
  • Incorrect angle scaling, replacing log2() with log(), replacing exp2() with exp() and removing the 2pi factor from the f16 cosine translation all cause the tests to fail (checked locally, reverted).

Regression run

  • Test-only change, no runtime regression run.

Not tested

AI use

  • Claude Code (Claude Opus 5.5) wrote the tests and the original description and ran the tests and mutation checks. ChatGPT assisted with editing the PR description.

acaracargo and others added 2 commits November 24, 2026 04:59
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
@acaracargo acaracargo changed the title Fork/transcendental gpu tests Tests: f32 and f16 transcendentals on the GPU against f64 references Nov 24, 2026
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 232ee73f36c7b8fa0c4e9fe30c96e29a4b3063f0 on AMD RDNA4 (native wave64). I merged it onto current main 63cdc25 locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 694 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 654 passed, 0 failed, 21 ignored
  • 0 SKIPPED; gpu_transcendental_f32 and gpu_transcendental_f16 pass.

Review: v_sin / v_cos take their input in turns (turn(x, f64::sin)), as the hardware does, and inputs past |x| > 256 are left out where the hardware's own reduction differs; the special values are compared exactly and the rest within a relative tolerance (absolute for sin / cos). 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.

@NAbobo101

Copy link
Copy Markdown

Test run of 232ee73f36c7b8fa0c4e9fe30c96e29a4b3063f0 on NVIDIA Blackwell with an older DXC than the PR's run (1.8 instead of 1.9), tested as is (it also merges cleanly onto current main dd2ae9a).

Tested

  • NVIDIA GeForce RTX 5060 8 GB (Blackwell, 32-lane waves only), driver 621.14 (32.0.16.2114); AMD Ryzen 7 5700G, 32 GB; Windows 11 Pro 26300; Rust 1.100.0 x86_64-pc-windows-msvc; DXC 1.8.2502.11 (Windows SDK 10.0.26100); debug.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 686 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • gpu_transcendental_f32 and gpu_transcendental_f16 pass, and three more runs of both (--nocapture) printed the same worst errors each time:
    • f32: rcp 0, rsq 8.43e-8, sqrt 7.45e-8, log 1.19e-7, exp 1.09e-7, sin 6.77e-5, cos 9.57e-5 – the same as the description's RTX 4060 / DXC 1.9 figures.
    • f16: rcp 8.24e-4, rsq 4.29e-4, sqrt 4.88e-4, log 6.51e-4, exp 6.93e-4, sin 4.88e-4, cos 4.88e-4 – within the 2^-9 relative / 2^-8 absolute tolerances with a margin of about 2.4x at the worst (rcp).

Not tested

  • AMD GPUs and native wave64.
  • Mutations of the translation (the description's checks were not repeated here).

AI use

  • Claude Code (Claude Opus 5.5) ran the build and tests and drafted this comment; I checked the results.

@lordon1a

Copy link
Copy Markdown

Independent GPU test report on 232ee73:

Tested

  • Hardware: NVIDIA GeForce RTX 3070 Ti Laptop GPU (driver 616.64, wave32, SM 6.6), Intel i7-12700H, Windows 11 Home 26H2 (build 26200), rustc 1.100.0 (x86_64-pc-windows-gnullvm), debug build, DXC 1.9.2609.5 (01b62ad4)
  • Command: cargo test -p xcl --lib gpu_transcendental_ -- --nocapture
  • Result: 2 passed, 0 failed, 0 ignored in 0.97s (gpu_transcendental_f32 max err: rcp 0.0, rsq 8.43e-8, sqrt 7.45e-8, log 1.19e-7, exp 1.09e-7, sin 6.77e-5, cos 9.57e-5; gpu_transcendental_f16 max err: rcp 8.24e-4, rsq 4.29e-4, sqrt 4.88e-4, log 6.51e-4, exp 6.93e-4, sin/cos 4.88e-4)

Not tested

  • AMD / wave64, Intel GPU, retail title

AI use

  • Antigravity (Google DeepMind agent) — fetched 232ee73 in a detached worktree, audited the diff, ran the GPU test, and posted this report.

@acaracargo

Copy link
Copy Markdown
Author

@lordon1a Eline sağlık.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

For when this lands: #818 (fix for #796) reduces v_sin / v_cos in turns before scaling. With this PR's gpu_transcendental_f32 / _f16 applied locally, both pass on main and with #818 (RTX 3070, driver 616.56). The worst sin/cos errors drop from 6.8e-5 / 9.6e-5 (f32) to 1.2e-7 / 6.0e-8, and f16 sin from 4.9e-4 to 2.6e-4. So after #818 the f32 sin/cos tolerance could tighten well below 2^-10, and the skip of inputs above 256 turns could go: the RDNA2 ISA's own examples include sin(-MaxFloat) = 0 and cos(-MaxFloat) = 1.

AI-assisted (Claude Code).

@pvfreis pvfreis mentioned this pull request Nov 24, 2026
@ivall ivall added the off-goal Does not bear on the current goal (world loading); waits until it is reached label Nov 24, 2026
@JJAutoCompare

Copy link
Copy Markdown

Tested

PR #643 was open at 232ee73f36c7b8fa0c4e9fe30c96e29a4b3063f0 before and after the run. The checkout was clean and detached at that commit. The PR discussion and issue #42 contained no equivalent Arc result at either check.

  • STOR-WINLAB, native Windows 11 Enterprise Evaluation 25H2 x64 build 26200.9974, Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust/Cargo 1.100.0 x86_64-pc-windows-msvc, DXC/DXIL 1.9.2609.5, debug test profile with debuginfo disabled.

  • cargo test --locked -p xcl --lib --no-run --message-format=json finished in 39.90 s outside the Arc lock, with two build jobs, incremental compilation disabled, dev/test debuginfo set to 0, and TEMP/TMP under L:/XclTooling/pr643/temp.

  • With XCL_ADAPTER=A770, XCL_DIRECT_DXIL=0, and XCL_DXC_DIR=%LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64, the lock wrapper ran the two prebuilt fixtures. $fixtureBinary came from Cargo's artifact output.

    & $fixtureBinary gpu::recomp::tests::gpu_transcendental_f32 --exact --nocapture --test-threads=1
    & $fixtureBinary gpu::recomp::tests::gpu_transcendental_f16 --exact --nocapture --test-threads=1
  • 2 passed, 0 failed, 0 ignored, 0 capability skips. Both fixtures reached their final assertions after GPU dispatch and readback. From the fixture loops, f32 evaluated 175 result comparisons (0.60 s) and f16 evaluated 159 (0.21 s) across reciprocal, reciprocal square root, square root, log2, exp2, sine and cosine. They exercised signed-zero inputs, infinities, NaN and turn-based angles where the fixtures include those cases. Both used split logical wave64 on 32-lane Arc hardware, as selected by the checked-in runner.

  • The Cargo build, both native fixture processes, and the Arc wrapper each returned 0. The wrapper logged release of the GPU lock.

Not tested

Native wave64, standalone logical wave32, direct DXIL, rsq(-0), f16 results filtered by the fixture's overflow guard, angles outside the fixture's domain, console parity, other fixtures, the workspace suite, and retail smoke runs.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the verification and wrote this report. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr643/{f32,f16}.stdout.log and published.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

off-goal Does not bear on the current goal (world loading); waits until it is reached

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants