Skip to content

GPU tests: what translated 16-bit float math costs against the host's (34x on an RTX 5070 Ti; for #2384) - #2806

Open
0xkn0wh3r3 wants to merge 7 commits into
Marvisak:mainfrom
0xkn0wh3r3:bench/f16-math
Open

0xkn0wh3r3 wants to merge 7 commits into
Marvisak:mainfrom
0xkn0wh3r3:bench/f16-math

Conversation

@0xkn0wh3r3

@0xkn0wh3r3 0xkn0wh3r3 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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 with f16tof32. A packed instruction such as v_pk_fma_f16 does that for both halves.

crates/victory-gpu/src/f16_bench.rs runs 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 with Native16BitShaderOpsSupported would emit.

Results

RTX 5070 Ti, driver 621.24: 262,144 threads × 1,024 packed FMAs, median of 5.

Variant ms G f16 FMAs/s Speed vs narrow16
narrow16 1.457 369 1×
f32tof16 0.117 4,608 12.5×
half2 0.042 12,643 34.3×

So 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_f16 does. 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_even checks the narrow16 shader against a CPU reference. The cases are:
  • Negative controls: with either the normal or the denormal rounding changed to truncate, it fails.
  • The host may or may not fuse f32 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.
  • The benchmark is #[ignore]d:
cargo test -p victory-gpu --release --lib f16_bench -- --ignored --nocapture

Not done

  • No native f16 path in the translator; this only measures.
  • Only one NVIDIA GPU.

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 kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Reviewed and benchmarked 19b53ab3 on Windows 11 + NVIDIA GeForce RTX 5090 (Blackwell) (+ WARP).

Review & correctness

  • Clean, DCE-proof benchmark (steps = 1024 from runtime cbuffer, loop-carried x = fma2(x, b, c) dependency, non-degenerate normal/subnormal inputs, copies kept outside timed dispatch).
  • narrow16_rounds_fused_results_to_nearest_even passed on both RTX 5090 and WARP; cargo clippy --locked -p victory-gpu --all-targets (default & diagnostics): 0 warnings; cargo xtask policy: 186 files ok (stacked cleanly on #2804).

RTX 5090 --release results (f16_bench --ignored --nocapture)

4,096 groups × 64 threads × 1,024 packed FMAs each, median of 5:

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×

@xndbogdan

xndbogdan commented Nov 25, 2026 •

Copy link
Copy Markdown

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 dxc.exe, 19b53ab, --release. No game data.

  • narrow16_rounds_fused_results_to_nearest_even: passed.
  • f16_bench (4,096 groups × 64 threads × 1,024 packed FMAs, median of 5):
Variant ms G f16 FMAs/s Speed vs narrow16
narrow16 1.668 321.8 1×
f32tof16 0.101 5,332.4 16.6×
half2 0.064 8,372.9 26.0×

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.

0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 25, 2026
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
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 25, 2026
…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
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
Its PC-bytecode dispatch and Marvisak#2806's timed dispatch share dispatch_with_views (native_pc, times).
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
…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.
@steven-seagull27

Copy link
Copy Markdown

On an RTX 5080 the native half2 path was 33.7× faster at 1,024 packed FMAs per thread. At one packed FMA per thread the dispatch times were 3.74 µs for narrow16 and 3.55 µs for half2.

I ran 5dfeaf69 in release mode on Windows 26300.10075, driver 621.40, SDK 10.0.26100.0. I checked the actual D3D12 device LUID against DXGI. Five fresh processes ran the PR's benchmark with unchanged HLSL, inputs and timing loop. Each process took its median of five GPU timestamps after warm-up, at 4,096 × 64 threads. The values below are medians across the five processes.

Variant Dispatch ms (range of process medians) G scalar f16 FMAs/s Paired speedup vs. narrow16
narrow16 1.141 (1.106–1.165) 470.5 1×
f32tof16 0.090 (0.089–0.093) 5,996.1 12.5× (12.4–13.0)
half2 0.034 (0.033–0.035) 15,963.1 33.7× (32.6–35.0)

For a shorter-chain comparison, I changed only the runtime steps constant between dispatches, held thread count and buffer traffic fixed, and rotated variant order across nine timed samples per variant after warm-up. Medians from that run:

Packed FMAs per thread narrow16 µs f32tof16 µs half2 µs half2 speedup
1 3.744 3.392 3.552 1.05×
8 11.200 3.776 3.936 2.85×
64 71.936 8.064 4.512 15.94×
1,024 1,111.584 89.664 33.440 33.24×

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.

Marvisak commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

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 main once #2804 is settled, as you suggest, would make it reviewable on its own.

CI: passing.


Generated by Claude Code

@liandraraiane

Copy link
Copy Markdown

RTX 3060 (driver 610.88, Windows 11 26200, dxc 10.0.26100.0), on 19b53ab (before the in-process compile commit), 7 runs, ms per dispatch: narrow16 5.086 (5.059–5.283), f32tof16 0.670 (0.668–0.671, 7.6x), half2 0.136 (0.136–0.137, 37.4x). narrow16_rounds_fused_results_to_nearest_even passes on hardware.

AI use: Claude Code ran the benchmarks on this machine and drafted this comment.

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

Agreed on both points. The f16 benchmark uses #2804's helpers (marks_bench::{compile_hlsl, dxc, heap, buffer, Gpu}), which is why it's stacked on that PR. Once #2804 is decided, I'll rebase this onto main so the diff is only f16_bench.rs. If #2804 closes, I'll keep just the helpers it needs. Whether ~1,000 lines of benchmark code belong in the tree is your call; the measurements are already on #2384, so this can close without losing them.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
…ts against the host's (34x on an RTX 5070 Ti; for Marvisak#2384)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants