Recompiler: round f16 add / sub to nearest-even by default (#685) #696
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!696
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/696/head"
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?
@Anon64 on GitHub · 2026-11-24 03:37 UTC · original
Anon64:recomp/f16-add-rne→main· +44 −3 · 2 files · 1 commits · closed without mergingIn the default mode the f16 add, sub, subrev and packed add results were narrowed with HLSL
f32tof16, which rounds toward zero: a sum between two binary16 values came out one ulp toward zero, and an overflow stopped at ±65504 instead of ±inf.deccf2bmoved the f16 multiplies tof32_to_f16_rm(…, 0u); this does the same for the sums. The binary32 sum of two binary16 values rounded once more to binary16 is the correctly rounded binary16 sum, because 24 ≥ 2·11 + 2 (Figueroa, 1995). FMA and the directed modes (#111 / #128) are unchanged; under a dynamic mode the code path is the same as before.Fixes #685
What is in it
crates/xcl/src/gpu/recomp/emit.rs:v_add_f16,v_sub_f16,v_subrev_f16andv_pk_add_f16take the rounding helper the multiplies already usecrates/xcl/src/gpu/recomp/tests.rs:gpu_f16_add_sub_round_to_nearest_even: 5 cases for each of the four instructions (rounding up, a tie to even, a negative sum, overflow to +inf, and1 - 2^-13, which rounding toward zero got wrong)Tested
cargo test --workspace --no-fail-fast -- --test-threads=4on910333e(run on the same tree as an earlier hash of this commit, which differs only in author): 692 passed, 1 failed, 41 ignoredhle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory, which fails the same way onmainon this machine (#650 / #656)emit.rschange the new test fails:wave32 lane 0: a 0x3c00, b 0x1200, add0x3c00instead of0x3c01cargo test -p xcl --lib f16: 13 passed (the existing f16 tests are unchanged)SKIPPEDon this adapter:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64)910333emerged ontomainf4ce27c(comment): the new test passes on an AMD RDNA2 iGPU (driver 26.11.2, wave64 and wave32) and on an RTX 4070 Ti; without theemit.rschange it fails on the RDNA2 iGPU at the same first case, so AMD'sf32tof16truncates tooRegression run
main:
this PR:
Not tested
f32tof16in programs with many f16 sums; not measuredAI use
github-bot referenced this pull request2026-11-26 04:59:09 +00:00
@joeypercia on GitHub · 2026-11-24 04:03 UTC · original
AMD run, the Not tested item:
910333emerged ontomainf4ce27c(clean merge).Tested
gpu_f16_add_sub_round_to_nearest_even: passes on the RDNA2 iGPU (wave64 and wave32) and on the RTX 4070 Tif32tof16truncates too: with onlyemit.rsback tomain, the test fails on the RDNA2 iGPU atwave64 lane 0: a 0x3c00, b 0x1200 (add, sub, subrev, pk_add), the same first case as on the RTX 3060cargo test --workspace --no-fail-fast -- --test-threads=4on the RDNA2 iGPU: 699 passed, 3 failed, 41 ignored; the 3 areplaced_title_textures_share_vram_and_preserve_pixelsand its two lock-poison followers (#288 / #447), under load, and pass alone on this merge (2 runs of 2).SKIPPED:gpu_geometry_mode_es_gs_strip,gpu_mesh_mode_two_passes(no mesh shaders)For a follow-up (out of this PR's scope, which is right): the unary f16 results go through the same
f32tof16in the default mode, and on both GPUs every inexact one comes out toward zero:v_sqrt_f16,v_rcp_f16,v_rsq_f16,v_exp_f16,v_log_f16,v_ldexp_f16(counts in #111). Switching them needsv_fract_f16's clamp kept below 1.0 after the narrowing (#655).Run and report by Claude Code (Claude Opus 5.5).
@SlopTart on GitHub · 2026-11-24 06:40 UTC · original
2|
3|RDNA3 + AMD regression datapoint — the axis your row lists as not tested (yours was an RDNA2 iGPU).
4|
5|Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Wine = Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust 1.100.0 cross
x86_64-pc-windows-gnu, release profile,XCL_NETWORK=0, native wave64 (no split). Same rig as my Linux rows in #42 / #718.6|
7|Merged state: head
910333edbonto mainbeaa245, clean merge.8|
9|Full suite,
cargo test --workspace --release --no-fail-fast -- --test-threads=4: 707 passed, 7 failed, 41 ignored (17 suites) — the 7 failures are exactly this rig's known Wine-lane set (my #42 row), nothing new. Reference run on plain mainbeaa245this same day: 702 / 11 / 41 (same 7 plus the #718 trio firing and, for the first time I have seen, a lonegpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_maskfailure — flagging that as an observation, it has not repeated). Your f16 tests pass on RDNA3:cvt_norm_f16_instructions,gpu_cmp_class_f16_preserves_snan,gpu_cvt_norm_f16_exact_rounding_and_edge_casesand the rest, ok.10|
11|Not tested: retail titles (none here), RDNA4, Windows.
12|Counts only, no game data.
13|AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
@Anon64 on GitHub · 2026-11-24 06:51 UTC · original
Superseded by #842 (@joeypercia): it sends every default-mode f16 result through the same helper, add / sub included, with the
v_fract_f16clamp. Its regression runs are posted there. I will close this PR once #842 is merged; if #842 is not taken, this one still stands on its own.Thanks @SlopTart for the RDNA3 data point above.
Written with Claude Code (Claude Opus 5.5).
@JJAutoCompare on GitHub · 2026-11-25 06:10 UTC · original
Empirical test report (
910333ed)Hardware / environment
XCL_ADAPTER=A770, on an AMD CPU (family 23, model 113) and Windows x64 build 26200. The GPU driver version was not recorded.rustc 1.100.0 (0ef1bc386 2026-11-09), DXC1.9.2609.5 (01b62ad47), and an unoptimized test profile with debug info and incremental compilation disabled.Commands and results
cargo test -p xcl --lib --no-runcompleted with exit code 0 outside the Arc test lock.RUST_TEST_NOCAPTURE=1, ran the library test executable produced by Cargo underInvoke-ArcTest.ps1:SKIPPEDlines.910333edb0e1e9e48d2cb484237d1b503e6c2099in a clean worktree.Observed behavior
The recompiled D3D12 compute fixture matched the expected binary16 bits for five operand pairs across the active lanes. The assertions covered scalar add, subtract, and reverse subtract, plus both halves of packed add. The cases exercised nearest rounding, halfway ties to even, negative operands, and positive overflow to infinity.
Not tested
The full GPU workspace suite and game smoke runs were omitted. This focused run used one adapter and did not include a comparison run on the parent commit.
AI use
Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr696-focused.log and published.
@DavidM1911 on GitHub · 2026-11-25 11:54 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
@CalvyPZ on GitHub · 2026-11-25 22:34 UTC · original
This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.
Pull request closed