Recompiler: v_cvt_f16_u16 / v_cvt_f16_i16 round to nearest even #515
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!515
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/515/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?
@ic3bear-ai on GitHub · 2026-11-24 01:08 UTC · original
ic3bear-ai:recomp/cvt-f16-from-16-bit-rne→main· +126 −1 · 2 files · 1 commits · closed without mergingv_cvt_f16_u16andv_cvt_f16_i16rounded toward zero in the default mode, where RDNA rounds to nearest even. The integer is exact in binary32, so this rounds it once withf32_to_f16_rm, as #166 did forv_mul_f16. Found while measuring #111 (that issue is about add / sub / fma; these two conversions are not in its list, nor in #128).What is in it
crates/xcl/src/gpu/recomp/emit.rs: the two conversions useto_f16_rounded_expr, likev_mul_f16.crates/xcl/src/gpu/recomp/tests.rs:f16_exact/f16_round_exact: an exact reference, every f16 as an integer in units of 2^-24, rounded to nearest even in integer arithmetic;f16_exact_reference_round_trips: checks the reference against all 65 536 f16 values, plus tie, overflow and subnormal cases;gpu_cvt_f16_from_16_bit_integers_exhaustive: both instructions on every 16-bit input, against the reference.Tested
gpu_cvt_f16_from_16_bit_integers_exhaustivebefore the fix:v_cvt_f16_u16: 29 184 of 65 536 wrong;v_cvt_f16_i16: 26 624 of 65 536 wrong;cargo test --workspace --no-fail-fast -- --test-threads=4: 678 passed, 0 failed, 41 ignored on this branch (based onmain2997c9a).mainata6f5f7agave 676 passed; the only commit between the two changes a link in the README, and the 2 new tests are the difference.gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64).Regression run
I don't own a console title, so these two runs are on the repo's own test title (
tests/testtitle, the folder the e2e tests use), built frommain. Each run used its own tree'sscripts/smoke.ps1and release build, and a freshXCL_DATA_ROOT.main:This PR's head:
crashes: 1andexit: 0x1are not crashes. The title runs its checks, fails only the one that expects a--helloargument (the e2e tests pass it;smoke.ps1can't), printsdone, failures: 1and exits with status 1 after about 3 seconds. The script counts that exit line as a crash. The same happens onmain, soPR checkswill refuse this block until there's a run on a real title.If you have a title: could you run
scripts/smoke.ps1 -Game <folder>onmainand on021f71band post the two blocks here? I'll keep this a draft until then.Not tested
f32tof16also truncates.f32_to_f16_rmwithxcl_fp16_rmthere, as before).AI use
🤖 Generated with Claude Code
github-bot referenced this pull request2026-11-26 04:59:09 +00:00
@Alpha325 on GitHub · 2026-11-24 01:15 UTC · original
Independent AMD verification for
021f71bcafdea44ed1cad2c08ac285cba29b42b9.Tested on Radeon RX 9060 XT (driver
32.0.32029.2010), Windows 11 build26200.9974, Rust 1.100.0 MSVC x64, DXC 1.9.2602.17, release. Synthetic inputs only.cargo test --locked --release -p xcl --lib gpu_cvt_f16_from_16_bit_integers_exhaustive -- --nocapture --test-threads=17ebf1b8044bef8f0ef296eb36e85010cceb4633a, with only the PR's test fixture applied: wave64 checked 65,536 inputs per instruction. Unsigned had 29,184 mismatches (2051 → 2050, expected2052). Signed had zero. The wave64 assertion stopped the test before wave32.f16_exact_reference_round_tripsalso passed.The unsigned issue reproduces on this AMD setup. The signed mismatch reported above for NVIDIA did not reproduce in the AMD baseline's wave64 run.
AI use: OpenAI Codex (GPT-6.2 Sol) ran the tests and drafted this report.
@thehollowedone on GitHub · 2026-11-24 01:13 UTC · original · edited 2026-11-24 01:17 UTC
Tested
I checked the three directed rounding modes listed under “Not tested” using a local synthetic wave32 kernel at 021f71b. It set the two FP16 rounding bits with
S_SETREG_IMM32_B32, executed both conversions, and compared the GPU readback with fixed binary16 bit patterns. All 24 comparisons matched (four input bit patterns × two instructions × three modes).For example, signed −2051 rounded to −2050 toward positive infinity, −2052 toward negative infinity, and −2050 toward zero. Unsigned 65535 rounded to positive infinity, 65504, and 65504 respectively. The other inputs were 2051 and 32767.
RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, DXC 1.8.2502.11, debug. With the scratch test added,
cargo test --offline --locked -p xcl --lib gpu_check_directed_integer_half_rounding -- --nocapturereported 1 passed, 0 failed, 0 ignored.Regression run
One 60-second retail run per clean release build, same machine and title, with fresh XCL data and DXIL caches for each. The title label is anonymized. The baseline was main when the comparison started. It includes #486, which is absent from this PR head. The PR showed 463/597 frames (77.6% of baseline), below the 80% threshold. This pair does not isolate the rounding change.
Baseline 7ebf1b8
PR head 021f71b
Not tested
Exhaustive directed-mode inputs, native wave64, and the full workspace suite. Whether this retail run exercised either conversion is unknown.
AI use
Codex with GPT-6.2 Astra wrote and ran the scratch test and retail smoke comparisons and drafted this report.
@ghost on GitHub · 2026-11-24 01:32 UTC · original
A negative control for the RDNA4 run above, on the same card model:
021f71bmerged ontomain508a0c7.gpu_cvt_f16_from_16_bit_integers_exhaustivepasses (XCL_REQUIRE_GPU=wave64,mesh, full suite 682 / 0 / 41). With onlyemit.rsput back tomainit fails with29184 results differ from the exact reference, so the test catches the truncating conversion on AMD.AI use
@tugasky on GitHub · 2026-11-24 02:49 UTC · original
AMD RDNA4 (RX 9070 XT) — the two "Not tested" bullets, measured here
Machine: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32029.2010, 2026-11-18), Ryzen 7 9700X, 31.1 GB, Windows 11 Pro 26300.9550, rustc 1.98.0. I merged
main(7ebf1b8) into the PR head021f71b, no conflicts.1.
gpu_cvt_f16_from_16_bit_integers_exhaustiveon AMD, after the fixThis card reports both wave sizes, so the 64-lane bullet is covered: RDNA4 runs the test in wave64 as well and it passes.
2. Before the fix, on this driver. The PR's
tests.rsalone onmain'semit.rs(detached worktree at7ebf1b8; the only edit was to sum both wave sizes instead of panicking on the first, so both lines are from one run):v_cvt_f16_u16wrongv_cvt_f16_i16wrongSame shape as your run, e.g.
v_cvt_f16_u16(2051) = 0x6801 (2050), want 0x6802 (2052), every failure a step toward zero. So AMD's HLSL compiler truncates the unsigned conversion too, with the same count as your 3070 (29 184), while the signed one is already correct here (hypothesis: it lowers to the hardware instruction, which rounds). Theu16half of the fix is a real fix on AMD; thei16half is a no-op on this driver, so here it can only be checked as "changes nothing", which it does.3. The retail pack contains neither instruction. Counted over the 26 503 disassemblies of the carved corpus (programs / uses):
v_cvt_f16_u16v_cvt_f16_i16v_cvt_u16_f16v_cvt_i16_f16v_cvt_f32_f16v_cvt_f16_f32v_mul_f16v_add_f16v_sub_f16v_rcp_f32(control)The whole integer-to-f16 group is absent, while f32-to-f16 conversions are common and f16 arithmetic is rare. The
v_rcp_f32row is a control: an independent harness I ran for another PR reported the same 17 393 programs and 424 863 uses, so the two counters agree. Conclusion: no retail shader is affected either way, so the change is correctness-only and cannot regress the pack — and the pack cannot confirm it either.4. Suite on the merged tree: 679 passed, 0 failed, 41 ignored across 16 binaries;
mainat7ebf1b8gives 677 / 0 / 41. The +2 is exactly your two tests. The e2e binaries ran on this machine too (e2e.rs 3, gpu_compute_e2e 2, gpu_pso_e2e 7, console_dlls_e2e 13, predication_e2e 1, rpf_e2e 2, disasm_e2e 1, all passing).5. Still open here
scripts/smoke.ps1has nothing to run. Tell me when you want it and I will do themain/021f71bpair if the title is back.to_f16_rounded_expr, which isf32_to_f16_rm(e, xcl_fp16_rm)under a non-default mode — the same helperv_mul_f16uses (#166). I did not run a hardware case with a non-defaults_round_mode.AI use: written with Cline; every run above is from my machine, and the counts are tool output.
@KENAJBBY on GitHub · 2026-11-24 09:31 UTC · original
Native RDNA2 (
gfx1036): both instructions round per MODE[3:2], on all 65,536 inputsThis answers "the console itself: the reference is IEEE round to nearest even as documented" from Not tested. I ran
v_cvt_f16_u16andv_cvt_f16_i16directly on an RDNA2 GPU, on every 16-bit input, under an explicitly set MODE (s_setreg_b32, read back withs_getreg_b32before the instruction). Results were compared with an exact integer reference rounded once in that mode:v_cvt_f16_u16wrongv_cvt_f16_i16wrong0x1C0,0x3C0,0x100,0x0F30x1C4,0x3C40x1C8,0x3C80x1CC,0x3CC,0x10C,0x3FFSo the hardware rounds to nearest even by default and never truncates there. It follows
s_round_modein the directed modes, which is what this PR'sf32_to_f16_rm(…, xcl_fp16_rm)does. IEEE, DX10_CLAMP, the f32 round mode and the denorm modes change nothing. Samples:2051→0x6802at nearest even and0x6801toward zero;65520→0x7C00at nearest even and0x7BFFtoward zero;-2051→0xE801toward +inf and0xE802toward −inf, the same values as @thehollowedone's run.On the same RDNA2 iGPU through D3D12, the PR's
gpu_cvt_f16_from_16_bit_integers_exhaustiveat head021f71bgives 0 / 0 wrong in wave64 and wave32. With onlyemit.rsfrom the base2997c9ait gives 29,184 / 0, the same split as the RDNA4 runs above.Tested
gfx1036, RDNA2), driver 32.0.21030.2001, AMD OpenCL3652.0 (PAL,LC), native wave64; Windows 11 Pro 26200.s_setreg_b32 hwreg(HW_REG_MODE, 0, 10), reads it back withs_getreg_b32(checked against the requested value in every run), runs the instruction and restores MODE.cargo test -p xcl --lib gpu_cvt_f16_from_16_bit_integers_exhaustive -- --nocapture --test-threads=1,XCL_ADAPTER=radeon, debug, Rust 1.100.0 MSVC, DXC 1.9.2602.17.Not tested
AI use
@ivall on GitHub · 2026-11-24 20:49 UTC · original
Closing this as covered by #842 (group D24 in #1607): it makes
to_f16_expritself round to nearest even, andv_cvt_f16_u16/v_cvt_f16_i16narrow through it. The exhaustive conversion test here is not in #842 and is welcome as a test-only PR once #842 is merged.This says nothing about the quality of the code here. If this PR covers a case the other one does not, or #842 is closed without being merged, say so and I'll reopen it.
Thank you for the work.
AI use: Claude Code (Claude Opus 5.5) read the diffs and the checks in #1607 and wrote this comment, on the maintainer's behalf.
Pull request closed