perf: v_rndne_f32 rounds with the host's float addition, sine and cosine too (2.85x / 1.97x on a 4060 Laptop) #585
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/585"
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?
Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-28T16:36:43Z.
Stacked on #581 (which is stacked on #570): it uses #581's per-instruction bench (
skinning_bench::op_loop_bench). Only the last commit is new; merge #570 and #581 first.What
v_rndne_f32was rounded in integer bit arithmetic (32 instructions), so as not to use DXILRound_ne. The NVIDIA driver foldsRound_newrongly for half-way literals after a barrier, and it replaces NaN payloads.Below 2^23 the magnitude is now rounded by the host's own float addition.
|x| + 2^23lies in [2^23, 2^24), where every float is a whole number, so the sum is|x|rounded to nearest even. Taking 2^23 off again is exact, and the sign is or-ed back, so -0.4 gives -0.|x| >= 2^23, infinities and NaNs keep the old rule: unchanged, and a NaN is quieted with its payload kept. A denormal gives a zero of its sign, whether the host flushes it or not.v_rndne_f32: 32 instructions become 12.v_sin_f32/v_cos_f32: their turn reduction isx - rndne(x), so they go from 42 to 22.TRANSLATOR_VERSION22.Is the driver bug still there? Yes, on 610.47
I tested plain
Round_ne(opcode 26) on our RTX 4060 Laptop, driver 610.47, with a literal afters_barrier:The same values read at run time round correctly everywhere (65,536 half-way values). NaN payloads come out as
0x7FFFFFFFon NVIDIA. SoRound_nestays out. The addition form gives the right bits for the literal cases on all three adapters; the existing testv_rndne_f32_ties_to_even_and_specialscovers it.Bench (RTX 4060 Laptop, 8 dependent chains x 256 rounds, 8192 x 32 threads; median of 3 alternating rounds)
v_rndne_f32round)v_sin_f32sin(x*2pi), not exact)Command:
cargo test -p victory-shader --release --lib skinning_bench::op_loop_bench -- --ignored --nocapture. The before and after binaries ran alternately under one GPU lock.Tests (fail before / exact)
rndne_tests::rndne_rounds_with_the_hosts_addition(shape):v_rndne_f32must be ≤ 16 instructions andv_sin_f32≤ 26. It fails on #581's head ("v_rndne_f32 writes 32 instructions").rndne_tests::rndne_matches_rdna2_on_every_lane: 283,648 lanes checked against RDNA 2's rule:It ran on the RTX 4060 Laptop, on Intel UHD (
VICTORY_D3D12_ADAPTER=Intel) and on WARP. Through the new bulk harness it also compares against the reference interpreter (crates/anyxboxx-rdna2-ref, viaANYXBOXX_RDNA2_REFortarget/) on 281,678 of them. The interpreter keeps a signalling NaN unquieted; the translation has always quieted it, as IEEEroundToIntegraldoes, so those 1,970 lanes are left out of the interpreter comparison only. Worth settling on hardware (PortBridge).rndne_tests::sin_and_cos_reduce_whole_turns_exactly:v_sin_f32andv_cos_f32of each angle must give the same bits as of its fraction of a turn, computed exactly on the CPU. This proves the reduction loses nothing on all three adapters. The sine itself is the host's, so no interpreter has its bits.New
exact_tests.rs: a bulk harness. One instruction runs on thousands of lanes, each with its own 4 dwords. The harness also runs the same instruction through the reference interpreter, 128 blocks of 32 lanes per run.The full
victory-shadersuite (top of the stack, with #586 and #587) passes on the RTX 4060 Laptop and WARP (380 passed). On Intel UHD 370 pass; the same 10 wave64/FP64/BVH tests also fail on #581's head there (the adapter refuses those pipelines). pytest: 1454 passed, 529 skipped.AI use: written with Claude Code (Claude Opus 5.5): lowering, tests, measurements on my machine. The driver check and the benches ran on my RTX 4060 Laptop and Intel UHD.
🤖 Generated with Claude Code
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.