perf: v_max_f32/v_min_f32 are the host's FMax/FMin alone on NVIDIA (2.2x on a 4060 Laptop) #587
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/587"
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:37:24Z.
Stacked on #586 (perm), #585 (rndne), #581 and #570. It uses #581's bench and #585's bulk harness. Only the last commit is new. Full
victory-shadersuite and pytest results: see #585 (run on this branch).What
On hosts other than AMD,
v_max_f32/v_min_f32and the like (max3/min3, andmed3between constants since #581) write a fix-up after FMax/FMin: an or, a mask, a compare, a bitwise op and a select. That fix-up orders -0 below +0, which DXIL's FMax/FMin do not promise.I measured each host's own FMax/FMin on two zeros:
NVIDIA's FMax/FMin already are RDNA 2's maximum and minimum. Over all the inputs below, plain FMax/FMin give the same bits as the fix-up, denormals and NaN payloads included. So on NVIDIA the translator now writes them alone.
How it works:
victory-gpusetsemit::set_host_zero_orderfrom the adapter's PCI vendor (orders_zeros: 0x10DE).host_rdna()givesrdna::MAX_MIN, the bit AMD hosts already use, so the shader cache keys on it.VICTORY_RDNA_FLOAT=0switches it off, as on AMD.Intel UHD orders the zeros too, but plain FMax keeps a denormal that the fix-up form flushes (
v_med3_f32 1e-45, 0, 1.0:0x00000001against0x00000000). Intel therefore keeps the fix-up, as does WARP. The offlinevictory translateand replay paths do not call it, so they keep writing the fix-up, which is valid everywhere.I looked for a universal cheaper exact form first. None beat the current 5 instructions with the same bits on all three adapters:
FMax(a,b) & FMax(b,a): WARP's two-NaN results break it;TRANSLATOR_VERSION24.Bench (RTX 4060 Laptop, 8 dependent chains x 256 rounds, median of 3 alternating rounds; the bench now translates as the runtime does for the host)
v_max_f32registersv_min_f32registersv_med3_f32 (x, 0, 1)v_max_f32 (x, 0)v_max_f32 (x, 0.5),v_min_f32 (x, 1.0),med3 (x,-1,1),med3 (x,a,b)Tests
max_min_tests::max_min_on_a_zero_ordering_host_are_one_operation(shape): on a zero-ordering host, a max/min of registers has no select and is ≥ 5 instructions shorter than with the fix-up.orders_zerosholds for NVIDIA only. It fails before (no such host setting:TEST_ZERO_ORDER/orders_zerosdo not exist, and the old lowering writes the fix-up on every non-AMD host).max_min_tests::max_min_as_written_for_each_host_match_rdna2coversv_max_f32,v_min_f32,v_max3_f32,v_min3_f32andv_med3_f32 (x, 0, 1)on 135,972 lanes:For each host, the form the runtime writes there gives the fix-up's bits on every lane, and RDNA 2's result wherever no denormal is involved. It passes on the RTX 4060 Laptop (plain FMax), WARP and Intel UHD (fix-up).
max_min_tests::max_min_match_the_interpreter_away_from_zeros_and_nans: the reference interpreter agrees on 114,779 lanes per form. It is left out where it is not RDNA 2: it uses Python'smax/min, which keep the first of two equal zeros and order NaNs by comparison.AI use: written with Claude Code (Claude Opus 5.5): the host measurement, lowering, tests, benches on my machine. The vendor gate rests on our RTX 4060 Laptop (Ada) only; other NVIDIA generations are not measured.
VICTORY_RDNA_FLOAT=0turns it off.🤖 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.