Repository navigation
Conversation
In 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. deccf2b moved the f16 multiplies to f32_to_f16_rm; do the same for the sums. The binary32 sum of two binary16 values rounded once more to binary16 is the correctly rounded binary16 sum, since 24 >= 2·11 + 2 (Figueroa). FMA and the directed modes (xcl-dev#111) are unchanged. Fixes xcl-dev#685 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
AMD run, the Not tested item: Tested
For a follow-up (out of this PR's scope, which is right): the unary f16 results go through the same Run and report by Claude Code (Claude Opus 5.5). |
|
2| |
|
Superseded by #842 (@joeypercia): it sends every default-mode f16 result through the same helper, add / sub included, with the Thanks @SlopTart for the RDNA3 data point above. Written with Claude Code (Claude Opus 5.5). |
…l-dev#111) In the default mode every f16 result that is narrowed from binary32 went through HLSL f32tof16, which rounds toward zero: on an RTX 4070 Ti and an RDNA2 iGPU every inexact v_add/sub/sqrt/rcp/rsq/exp/log/ldexp_f16 result came out one binary16 step low, and an overflow stopped at 65504 instead of inf. Native RDNA2 rounds to nearest even (luckyteagirl's measurements on xcl-dev#672). to_f16_expr now narrows with f32_to_f16_rm(e, 0u) in the default mode, the helper the multiplies already use (xcl-dev#166); under a dynamic mode nothing changes. v_fract_f16 clamps its binary32 result below 1.0, and 1 - 2^-24 narrows to 1.0 by nearest even, so its binary16 result is kept at 0x3BFF (xcl-dev#655). Supersedes xcl-dev#696, whose add / sub cases this covers. Assisted-by: Claude Code (Claude Opus 5.5)
Empirical test report (910333e)Hardware / environment
Commands and results
& $testExe gpu::recomp::tests::gpu_f16_add_sub_round_to_nearest_even --exact --nocapture --test-threads=1
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. |
In 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. deccf2b moved 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 (Tests: align XMemVirtualQuery buffers and verify CPU flags #650 / Tests: align the XMemVirtualQuery output buffer #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