Repository navigation
Recompiler: v_cvt_f16_u16 / v_cvt_f16_i16 round to nearest even - #515
ic3bear-ai wants to merge 1 commit into
Conversation
In the default mode (no dynamic f16 round mode) the 16-bit integer to f16 conversions ended in the legacy f32tof16, which rounds toward zero: 2051 became 2050 instead of 2052. The integer is exact in binary32, so rounding it once with f32_to_f16_rm gives the exactly rounded f16, as xcl-dev#166 did for v_mul_f16. Measured on an RTX 3070 (driver 616.92) over all 65 536 inputs of each instruction: 29 184 (u16) and 26 624 (i16) results were one step toward zero, exactly the inputs where truncation and rounding to nearest even differ (counted separately); 0 after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 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, 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. 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. |
|
Independent AMD verification for Tested on Radeon RX 9060 XT (driver
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. |
|
A negative control for the RDNA4 run above, on the same card model: AI use
|
|
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 1. This 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
Same shape as your run, e.g. 3. The retail pack contains neither instruction. Counted over the 26 503 disassemblies of the carved corpus (programs / uses):
The whole integer-to-f16 group is absent, while f32-to-f16 conversions are common and f16 arithmetic is rare. The 4. Suite on the merged tree: 679 passed, 0 failed, 41 ignored across 16 binaries; 5. Still open here
AI use: written with Cline; every run above is from my machine, and the counts are tool output. |
|
Native RDNA2 ( This answers "the console itself: the reference is IEEE round to nearest even as documented" from Not tested. I ran
So the hardware rounds to nearest even by default and never truncates there. It follows On the same RDNA2 iGPU through D3D12, the PR's Tested
Not tested
AI use
|
|
Closing this as covered by #842 (group D24 in #1607): it makes 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. |
The HLSL path converted the f32 result of v_add / sub / subrev / fma / fmac / fmamk / fmaak / ldexp_f16 and v_pk_add / pk_fma / pk_fmac_f16 with f32tof16, which rounds toward zero on NVIDIA (RDNA2's default is nearest even). Only v_mul_f16 / v_pk_mul_f16 used f32_to_f16_rm. Measured on an RTX 3080 Ti: v_add_f16(0x3C01, 2^-11) gave 0x3C01 (want 0x3C02), v_pk_add_f16 hi lane 0xbfff (want 0xc000), v_ldexp_f16 into the denormals 0x207 (want 0x208). add / sub / ldexp are exact enough in binary32 (2p+2 bits), so they go through the same rounded conversion as v_mul_f16. fma needs one rounding: fma_rto computes the exact product, the TwoSum error of the sum, and rounds the f32 result to odd, so the later binary16 rounding sees the exact value's side of every tie (fma(0x3C01, 0x0FFE, 0x3C01) is 0x3C01; an RNE f32 sum gives 0x3C02). v_cvt_f16_u16 / i16 (xcl-dev#515), the directed modes (xcl-dev#128) and v_fma_mix*_f16 are not touched. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hri58aiQKmMwqS6K8CHq2s
v_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