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

Open
github-bot wants to merge 7 commits from github-bot/gh-2806 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 21:05 UTC · original
0xkn0wh3r3:bench/f16-math → main · +1021 −0 · 4 files · 7 commits · open

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:
    • normal results, including the cancellation cases from #2384;
    • denormal results, and ties to even in both the normal and denormal ranges;
    • overflow to infinity, underflow, and NaN.
  • 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
  • Both tests compile their shaders in the test process with the Windows SDK's dxcompiler.dll, as #2804 does, and need it and a GPU, or do nothing.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings is clean, with and without --features diagnostics.

Not done

  • No native f16 path in the translator; this only measures.
  • Only one NVIDIA GPU.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 21:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2806) `0xkn0wh3r3:bench/f16-math` → `main` · +1021 −0 · 4 files · 7 commits · open 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: - normal results, including the cancellation cases from #2384; - denormal results, and ties to even in both the normal and denormal ranges; - overflow to infinity, underflow, and NaN. - 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 ``` - Both tests compile their shaders in the test process with the Windows SDK's `dxcompiler.dll`, as #2804 does, and need it and a GPU, or do nothing. - `cargo clippy -p victory-gpu --all-targets -- -D warnings` is clean, with and without `--features diagnostics`. ## 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 (#2167's approach); one atomic per wave for lanes
sharing a bitmap word (#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 #2175 and #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.
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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:14:42 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 21:24 UTC · original

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×
**@⁠fuzeofficlal** on GitHub · 2026-11-25 21:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2806#issuecomment-7175032920) 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×`** |
Author
Owner

@⁠xndbogdan on GitHub · 2026-11-25 21:53 UTC · original · edited 2026-11-25 21:55 UTC

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.

**@⁠xndbogdan** on GitHub · 2026-11-25 21:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2806#issuecomment-7175678773) · edited 2026-11-25 21:55 UTC 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.*
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 01:52 UTC · original

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.

**@⁠steven-seagull27** on GitHub · 2026-11-26 01:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2806#issuecomment-7180221708) 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](https://git.gtahub.st/github/Marvisak--VIctory/issues/2384). Tested locally with Codex assistance.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 02:18 UTC · original · edited 2026-11-26 07:22 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-26 02:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2806#issuecomment-7180676914) · edited 2026-11-26 07:22 UTC <!-- victory-triage v1 head=5dfeaf69ebef68710209cb5410ef03bc535513bc verdict=needs-work at=2026-11-26T07:22:48Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠liandraraiane on GitHub · 2026-11-26 02:48 UTC · original

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.

**@⁠liandraraiane** on GitHub · 2026-11-26 02:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2806#issuecomment-7181132482) 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.
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 06:42 UTC · original

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.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 06:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2806#issuecomment-7184699727) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2806/head:github-bot/gh-2806'
git switch 'github-bot/gh-2806'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2806'
git switch 'github-bot/gh-2806'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2806'
git switch 'github-bot/gh-2806'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2806'
git switch 'main'
git merge --squash 'github-bot/gh-2806'
git switch 'main'
git merge --ff-only 'github-bot/gh-2806'
git switch 'main'
git merge 'github-bot/gh-2806'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2806
No description provided.