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

Open
0xkn0wh3r3 wants to merge 7 commits from upstream-pr/2806 into main
0xkn0wh3r3 commented 2026-11-25 21:05:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T21:05:49Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6613746989 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2806). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T21:05:49Z. --- 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.
kotekompotek commented 2026-11-25 22:04:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T21:18:21Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6065119395 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2806#pullrequestreview-6065119395). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T21:18:21Z. **Review:** COMMENTED --- 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 commented 2026-11-25 22:04:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T21:24:22Z.


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×
<!-- greyfinch-sync:Marvisak/VIctory:comment:7175032920 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2806#issuecomment-7175032920). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T21:24:22Z. --- 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 commented 2026-11-25 22:04:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by xndbogdan on 2026-11-25T21:53:51Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7175678773 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2806#issuecomment-7175678773). Originally posted by [xndbogdan](https://github.com/xndbogdan) on 2026-11-25T21:53:51Z. --- 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.*
steven-seagull27 commented 2026-11-26 02:07:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T01:52:05Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180221708 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2806#issuecomment-7180221708). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T01:52:05Z. --- 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://github.com/Marvisak/VIctory/issues/2384#issuecomment-7180205586). Tested locally with Codex assistance.
Marvisak commented 2026-11-26 03:05:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T02:18:40Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180676914 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2806#issuecomment-7180676914). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T02:18:40Z. --- <!-- 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)_
liandraraiane commented 2026-11-26 03:05:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by liandraraiane on 2026-11-26T02:48:11Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181132482 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2806#issuecomment-7181132482). Originally posted by [liandraraiane](https://github.com/liandraraiane) on 2026-11-26T02:48:11Z. --- 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 commented 2026-11-26 07:01:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T06:42:22Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184699727 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2806#issuecomment-7184699727). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T06:42:22Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2806:upstream-pr/2806'
git switch 'upstream-pr/2806'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2806'
git switch 'upstream-pr/2806'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2806'
git switch 'upstream-pr/2806'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2806'
git switch 'main'
git merge --squash 'upstream-pr/2806'
git switch 'main'
git merge --ff-only 'upstream-pr/2806'
git switch 'main'
git merge 'upstream-pr/2806'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2804
No description provided.