Repository navigation
GPU tests: what translated 16-bit float math costs against the host's (34x on an RTX 5070 Ti; for #2384) - #2806
0xkn0wh3r3 wants to merge 7 commits into
Conversation
A benchmark (ignored by default) and a check, in HLSL that does what translated programs do when they store to title memory: look the address up in the page table (an upload heap), set the bits of the pages written in the list's bitmap with atomics, store into the host copy. Variants: main's two unconditional atomics per store; a load first and an atomic only for a clear bit (Marvisak#2167's approach); one atomic per wave for lanes sharing a bitmap word (Marvisak#2755's); both; none. Each with the bitmap in system memory, as now, and in video memory; four ways of writing. RTX 5070 Ti, driver 621.24, ms per dispatch of 131,072 threads storing 16 dwords each (bitmap clear before the dispatch / already set): one page linear page/lane scattered main, system bitmap 79.8/76.5 75.8/75.0 1595/1583 336/337 test-first, system 1.6/0.33 11.5/0.35 21/20 13.0/6.7 wave, system 1.7/0.33 11.4/0.36 22/22 13.5/6.8 main, video bitmap 0.31/0.31 0.32/0.32 20/20 6.4/6.5 test-first, video 0.30/0.30 0.32/0.32 20/21 6.8/6.7 no marks 0.30/0.29 0.32/0.32 20/19 6.5/6.5 Atomics on a bitmap in system memory are what cost: up to 250 times the dispatch without marks. Loading first removes them once a page is marked; one atomic per wave adds nothing on this GPU. A bitmap in video memory costs nothing even with main's unconditional atomics, first marks included. What is left in "page per lane" and "scattered" is the stores into the host copy in system memory. `every_variant_marks_the_pages_main_marks` checks every variant, in both places, sets exactly main's bits. `dxc.exe` comes from the Windows SDK; without it or a GPU both tests do nothing. cargo test -p victory-gpu --release --lib marks_bench -- --ignored --nocapture
Two 256.5 KiB copies, the bitmap into read-back memory and zeros over it, as the video-memory bitmaps of Marvisak#2175 and Marvisak#2465 record at a list's end or after a submission: 12.2 µs on an RTX 5070 Ti (median of 20).
The translator does a console f16 operation in f32 and rounds each result with an integer sequence (`narrow16`), widening the sources with `f16tof32`; a packed instruction does it for both halves. A benchmark (ignored by default) runs a chain of packed FMAs that way, with the host's `f32tof16` instead of the sequence, and with native `half2` math. RTX 5070 Ti, driver 621.24, 262,144 threads x 1,024 packed FMAs: narrow16 1.457 ms 369 G f16 FMAs/s f32tof16 0.117 ms 4,608 G f16 FMAs/s 12.5x half2 0.042 ms 12,643 G f16 FMAs/s 34.3x `narrow16_rounds_fused_results_to_nearest_even` checks the narrow16 shader against a CPU reference: normal, denormal and tie cases, overflow, underflow and NaN. It fails with either rounding path made to truncate. The bench helpers of marks_bench (dxc, buffers, a timed queue) are shared.
kotekompotek
left a comment
There was a problem hiding this comment.
The measurement #2384 has been missing — a dependent packed-FMA chain isolates per-op rounding cost (native f32tof16 vs the narrow16 integer sequence vs unrounded f32). Stacked cleanly on #2804's harness, tests-only as claimed. LGTM on structure; the RTX 5070 Ti numbers in the title (34x for the software sequence) are a strong argument for using the host conversion where it exists.
|
Reviewed and benchmarked Review & correctness
RTX 5090
|
| variant | RTX 5090 time | throughput (G f16 FMAs/s) |
speedup vs narrow16 |
|---|---|---|---|
narrow16 |
0.583 ms |
921.4 |
1.0× |
f32tof16 |
0.051 ms |
10,512.0 |
11.4× |
half2 |
0.019 ms |
28,976.2 |
31.4× |
|
Results on AMD hardware, for comparison with the NVIDIA runs above. Setup: AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32015.7029, Intel Xeon E5-2670 v3 (times are GPU timestamps, so the CPU is not in them), Windows 11 IoT Enterprise LTSC 26100, Windows SDK 10.0.26100
So the software rounding's cost holds on AMD too: 26× here, against 34× on the RTX 5070 Ti and 31× on the RTX 5090. This is one run. AI-assisted (Claude Code). The tests and benchmark ran on the machine above. |
The translator did every console f16 operation in f32 and rounded each result to f16 in integer code (`narrow16`, about 40 operations), which costs about 34x the host's own half math (Marvisak#2806). With the new `emit::Options::native16`, `v_add/sub/subrev/mul_f16`, `v_fma/fmac_f16`, `v_min/max/min3/max3/med3_f16` and `v_pk_add/mul/fma/fmac/min/max_f16` become DXIL `half` arithmetic: 16-bit types, the native low precision shader flags, the 16-bit data layout and SFI0's native 16-bit bit, set only when a live instruction uses them. The option is for hosts that report `Native16BitShaderOpsSupported` (D3D12 OPTIONS4; SM 6.6 is required anyway) and round a 16-bit FMad once, as the console's v_fma_f16 does (`Host::rounds_f16_fmad_once`, a dispatch of Marvisak#2384's case, run once as `fuses_fmad` is). The RTX 5070 Ti does. WARP rounds in f32 first and keeps the f32 path, which since Marvisak#1387 rounds v_fma_f16 once itself. Results: sums, differences and products are the same as the f32 path's (rounding in f32 first never changes the f16 result), as are minima, maxima and medians (exact; the -0/+0 order and the clamp, which gives +0 for NaN and -0, are done on the bits). NaN payloads are the host's where the f32 path quiets them. Fused multiply-adds round once; the f32 path still rounds the packed ones twice. Programs that round toward zero (the title's around its 16-bit interpolation) or toward an infinity keep the f32 path, as do conversions, interpolation, v_mad/mac_f16, v_fma_mix* and the transcendental and rounding operations. victory-gpu asks the host once (`host::native16`, off with `VICTORY_F16_IN_F32=1`) and puts the answer in `shader_cache::options()` and the cache key, so one path's entries never serve the other. Tests (RTX 5070 Ti, driver 621.24; WARP is refused and skips them): the 16-bit probes natively; the fused inputs the f32 path rounds twice, Marvisak#2384's three cases and 8,192 random finite triples (denormals included) rounded once natively; every 16-bit probe and the random triples lowered both ways, native never further from the model (they differ on 1 input, a packed one); the toward-zero mode natively; the host check (WARP refused); flags and validation of the lowered modules (dxil.dll 1.6). A translated benchmark (ignored; 262,144 threads, dependent chains of 512 instructions, best of five, GPU timestamps): v_pk_fma_f16 f32 path 0.221 ms native 0.006 ms 37x v_fma_f16 f32 path 0.129 ms native 0.006 ms 23x v_mul_f16 + v_add_f16 f32 path 0.221 ms native 0.011 ms 21x
…costs From bench/wave64-split-cost (5a066b8), on demo: the ignored benchmark wave64_split_cost times one console wave64 program split for a 32-lane host against the same words as a wave32 program (and native wave64 where the adapter runs it), checking every run against a model of the console. demo's test host already has dispatch_timed (Marvisak#2806), which gives the seconds for all the dispatches: the benchmark divides by their count.
Review: the benchmark spawned the SDK's dxc.exe. It now loads the SDK's dxcompiler.dll and compiles through IDxcCompiler3 in the test process (D3DCompile has no shader model 6, which the wave variant needs), signed by the SDK's dxil.dll where there is one. Without the SDK the tests still do nothing. The benchmark also times each case as four submissions of a quarter of the groups, summed: main's slowest case takes about 1.6 s for all of them, near the host's 2 s device reset, and a busy GPU pushed it over.
# Conflicts: # crates/victory-gpu/src/marks_bench.rs
Its PC-bytecode dispatch and Marvisak#2806's timed dispatch share dispatch_with_views (native_pc, times).
…costs From bench/wave64-split-cost (5a066b8), on demo: the ignored benchmark wave64_split_cost times one console wave64 program split for a 32-lane host against the same words as a wave32 program (and native wave64 where the adapter runs it), checking every run against a model of the console. demo's test host already has dispatch_timed (Marvisak#2806), which gives the seconds for all the dispatches: the benchmark divides by their count.
|
On an RTX 5080 the native I ran
For a shorter-chain comparison, I changed only the runtime
The long chain reproduces the reported arithmetic gain. The shorter dispatches show how strongly the speedup depends on the amount of arithmetic between loads and stores in this kernel. I did not measure a game frame. The PR's rounding test also passed on both the RTX 5080 and WARP. I posted an all-normal FMA regression pair and a 16,384-input precision comparison in #2384. Tested locally with Codex assistance. |
|
Automated triage for the maintainers. Thanks for confirming. Nothing has changed since the last review (same head): the PR still carries #2804, and whether about 1,000 lines of benchmark code belong in the tree needs the maintainer's decision. Rebasing onto CI: passing. Generated by Claude Code |
|
RTX 3060 (driver 610.88, Windows 11 26200, dxc 10.0.26100.0), on AI use: Claude Code ran the benchmarks on this machine and drafted this comment. |
|
Agreed on both points. The f16 benchmark uses #2804's helpers ( |
…ts against the host's (34x on an RTX 5070 Ti; for Marvisak#2384)
Stacked on #2804, whose benchmark helpers this shares. Only the last commit is new. It's tests only: nothing outside tests changes.
#2384 asks whether translated 16-bit float math is worth doing natively. Nobody had measured what the translator's software rounding costs per operation. This measures it.
What
The translator does a console f16 operation in f32 and rounds each result to f16 with an integer sequence (
Lower::narrow16, round to nearest even), widening each source withf16tof32. A packed instruction such asv_pk_fma_f16does that for both halves.crates/victory-gpu/src/f16_bench.rsruns a dependent chain of packed FMAs in three ways:narrow16: as translated, with the rounding sequence ported to HLSL;f32tof16: the same, with the host's conversion instead of the sequence. This is not correct as a translation: on some GPUs the host's conversion rounds toward zero.half2: the host's native 16-bit math (-enable-16bit-types, SM 6.2+). This is what a native path on hosts withNative16BitShaderOpsSupportedwould emit.Results
RTX 5070 Ti, driver 621.24: 262,144 threads × 1,024 packed FMAs, median of 5.
narrow16narrow16f32tof16half2So each translated f16 operation costs about 34 native ones, in any program that is ALU-bound on f16 math.
How much of a world frame that is depends on how much f16 math the hot shaders do. Measuring that needs the title's shaders, which are not here.
One caveat for a native path is rounding. The probes on #2384 found that an RTX 4070 Ti's native half FMA rounds once, as RDNA2's
v_fma_f16does. The current widen, fuse in f32, then round path rounds twice, so it can differ in rare cases. WARP's native FMA differs from both.Tests
narrow16_rounds_fused_results_to_nearest_evenchecks thenarrow16shader against a CPU reference. The cases are:mad, so either rounded result is accepted. A NaN result may lose its payload in the host's f32 math, so any NaN is accepted for one.#[ignore]d:dxcompiler.dll, as GPU tests: what marking written title pages costs, per way of marking (benchmark for #2167, #2175, #2465, #2755) #2804 does, and need it and a GPU, or do nothing.cargo clippy -p victory-gpu --all-targets -- -D warningsis clean, with and without--features diagnostics.Not done