Repository navigation
Conversation
|
Holding this one: its own GPU test fails on an RX 9070 (RDNA4), in the PR as it is (without merging anything else): |
1c4f1e2 to
34dbc3b
Compare
|
Tested on an NVIDIA RTX 5070 Ti (32-lane waves, driver 621.14), merged onto NVIDIA and denormals: this is fine. With DXC's default Verified on the GPU
Also present on
|
…vall#111) Under s_round_mode MODE[3:2] != RNE the f16 add, sub, fma (also fmac / fmamk / fmaak, the packed forms and v_fma_mix*_f16) computed in f32 with RNE and then converted to binary16 in the requested mode: when the exact result does not fit f32 (1.0 + 2^-24 needs 25 bits) the first rounding could land exactly on a binary16 value and the directed rounding had nothing left to do (1.0 + 2^-24 under +inf gave 1.0; the console gives 1 + 2^-10). - PRELUDE_F16_RM (only in programs that change MODE[3:2] and have f16 ops; PRELUDE itself is unchanged, so no other program's HLSL or DXIL cache entry changes): f32_to_f16_rm_sticky folds the sign of the f32 result's rounding error into the binary16 rounding – on a binary16 value or midpoint it decides the direction; add_f16_rm / fma_f16_rm get that error from a TwoSum (the product of two binary16 values is exact in f32), fma_mix_f16_rm from a double TwoSum (f32 sources; a double beyond f32's range is brought to 2^17 / 2^-40 first – the mode alone decides there). OMOD and CLAMP apply to the result and its error before the rounding. An exactly zero sum takes IEEE's sign (x + -x is +0, -0 under -inf; the f32 sum's RNE zero ignored the mode). - v_mad_f16 does not exist on RDNA2 (not in the ISA tables): its arm goes. - is_f64_rounded_op: exact f64 ops (conversions from f32 / i32 / u32, floor / ceil / trunc / rndne, min / max, frexp_mant) no longer make s_round_mode unsupported (v_fract_f64 = x - floor(x) rounds for a negative x and stays). - GPU tests: the helpers lane by lane (the ivall#128 review's cases: 65536 - 2^-24 under RNE overflows, mix results beyond f32's range, the zero's sign), and the ISA forms under the four modes (the ivall#111 cases, the overflow and subnormal edges, a fma whose f32 sum ties on a binary16 midpoint, OMOD and CLAMP). gpu_s_round_mode_controls_f16_rounding_across_modes: fma(-0, 1, +0) is +0 (DXC's mad(x, 1, 0) folded to x before).
34dbc3b to
19fc146
Compare
…vall#111) Under s_round_mode MODE[3:2] != RNE the f16 add, sub, fma (also fmac / fmamk / fmaak, the packed forms and v_fma_mix*_f16) computed in f32 with RNE and then converted to binary16 in the requested mode: when the exact result does not fit f32 (1.0 + 2^-24 needs 25 bits) the first rounding could land exactly on a binary16 value and the directed rounding had nothing left to do (1.0 + 2^-24 under +inf gave 1.0; the console gives 1 + 2^-10). - PRELUDE_F16_RM (only in programs that change MODE[3:2] and have f16 ops; PRELUDE itself is unchanged, so no other program's HLSL or DXIL cache entry changes): f32_to_f16_rm_sticky folds the sign of the f32 result's rounding error into the binary16 rounding – on a binary16 value or midpoint it decides the direction; add_f16_rm / fma_f16_rm get that error from a TwoSum (the product of two binary16 values is exact in f32), fma_mix_f16_rm from a double TwoSum (f32 sources; a double beyond f32's range is brought to 2^17 / 2^-40 first – the mode alone decides there). OMOD and CLAMP apply to the result and its error before the rounding. An exactly zero sum takes IEEE's sign (x + -x is +0, -0 under -inf; the f32 sum's RNE zero ignored the mode). - v_mad_f16 does not exist on RDNA2 (not in the ISA tables): its arm goes. - is_f64_rounded_op: exact f64 ops (conversions from f32 / i32 / u32, floor / ceil / trunc / rndne, min / max, frexp_mant) no longer make s_round_mode unsupported (v_fract_f64 = x - floor(x) rounds for a negative x and stays). - GPU tests: the helpers lane by lane (the ivall#128 review's cases: 65536 - 2^-24 under RNE overflows, mix results beyond f32's range, the zero's sign), and the ISA forms under the four modes (the ivall#111 cases, the overflow and subnormal edges, a fma whose f32 sum ties on a binary16 midpoint, OMOD and CLAMP). gpu_s_round_mode_controls_f16_rounding_across_modes: fma(-0, 1, +0) is +0 (DXC's mad(x, 1, 0) folded to x before).
19fc146 to
49ee291
Compare
|
A follow-up case for #111: default round-to-nearest-even can also double-round a fused half-precision multiply-add. On I checked these binary16 bit patterns using native AArch64 half-precision
The exact sums sit just below and above their respective half-precision midpoints. The binary32 intermediate lands exactly on each midpoint, so ties-to-even picks the wrong neighbor. With |
|
Not merged yet: with this PR on current main, |
|
The RX 9070 failure reproduces on NVIDIA Turing through vkd3d-proton / dxil-spirv ( if (sa > 131072.0 && sa <= 1.7976931348623157e308) s = select(s < 0.0, -131072.0, 131072.0);Tested
Not tested
🤖 Claude Opus 5.5 |
|
AMD run, as asked: RDNA3 Radeon RX 7800 XT, driver 32.0.32029.2010, Windows 11 26300, native 64-lane waves, DXC 1.8.2502.11, debug build.
- if (sa > 131072.0) s = select(s < 0.0, -131072.0, 131072.0);
+ // (finite sums only: an infinite operand gives an exact infinity in every mode; HLSL has no
+ // isinf on a double, and a NaN fails both compares)
+ if (sa > 131072.0 && sa <= 1.7976931348623157e308) s = select(s < 0.0, -131072.0, 131072.0);Not covered: RDNA4 with the line (whether the RX 9070's |
|
Tested #128
That test came to main with 93072dc ("handle s_round_mode/s_setreg*"), after this branch's base (129 commits behind), so it won't show on the branch itself. Lane 18 is +inf: under RTZ, |
|
Tested Fail, same as on RDNA2 above (so not GPU-specific): 651 passed, 1 failed ? Cause: in // an infinite or NaN source gives an infinite or NaN sum, which is not an overflow: no mode
// turns it into a finite value (the f32 sources are checked: HLSL's isinf takes a float, and
// a finite double sum such as 2^200 would test as infinite)
if (any(isinf(float3(a, b, c))) || any(isnan(float3(a, b, c)))) return f16_result_rm((float)s, 0.0f, 1.0f, clamp, rm);Note the check is on the f32 sources: my first try, With the guard on the same merge: Not tested: AMD with the guard; no game. Run and written with Claude Code (Claude Opus 5.5). |
|
A note for this PR from #111 (the details and numbers are there): on an RTX 3070 the default mode is wrong for these instructions too, so this PR may want to cover it as well.
What fixed both locally: round-to-odd in binary32 (TwoSum, then the sticky lowest bit), then I'd rather not open a PR that conflicts with this one. The exact-reference test is in #111, if it helps. Comment written with Claude Code (Claude Opus 5.5); I checked the results. |
…cl-dev#111) Under s_round_mode MODE[3:2] != RNE the f16 add, sub, fma (also fmac / fmamk / fmaak, the packed forms and v_fma_mix*_f16) computed in f32 with RNE and then converted to binary16 in the requested mode: when the exact result does not fit f32 (1.0 + 2^-24 needs 25 bits) the first rounding could land exactly on a binary16 value and the directed rounding had nothing left to do (1.0 + 2^-24 under +inf gave 1.0; the console gives 1 + 2^-10). - PRELUDE_F16_RM (only in programs that change MODE[3:2] and have f16 ops; PRELUDE itself is unchanged, so no other program's HLSL or DXIL cache entry changes): f32_to_f16_rm_sticky folds the sign of the f32 result's rounding error into the binary16 rounding – on a binary16 value or midpoint it decides the direction; add_f16_rm / fma_f16_rm get that error from a TwoSum (the product of two binary16 values is exact in f32), fma_mix_f16_rm from a double TwoSum (f32 sources; a double beyond f32's range is brought to 2^17 / 2^-40 first – the mode alone decides there). An infinite or NaN source gives inf / NaN under every mode (the review's lane 18: +inf under RTZ was taken for a finite overflow and gave 65504). OMOD and CLAMP apply to the result and its error before the rounding. An exactly zero sum takes IEEE's sign (x + -x is +0, -0 under -inf; the f32 sum's RNE zero ignored the mode). - v_mad_f16 does not exist on RDNA2 (not in the ISA tables): its arm goes. - is_f64_rounded_op: exact f64 ops (conversions from f32 / i32 / u32, floor / ceil / trunc / rndne, min / max, frexp_mant) no longer make s_round_mode unsupported (v_fract_f64 = x - floor(x) rounds for a negative x and stays). - GPU tests: the helpers lane by lane (the xcl-dev#128 review's cases: 65536 - 2^-24 under RNE overflows, mix results beyond f32's range, the zero's sign), and the ISA forms under the four modes (the xcl-dev#111 cases, the overflow and subnormal edges, a fma whose f32 sum ties on a binary16 midpoint, OMOD and CLAMP). gpu_s_round_mode_controls_f16_rounding_across_modes: fma(-0, 1, +0) is +0 (DXC's mad(x, 1, 0) folded to x before).
49ee291 to
2bc03fa
Compare
|
A data point for this PR from NVIDIA, where the default (round-to-nearest-even) case is wrong on AI use: Claude Code (Claude Opus 5.5) wrote and ran the GPU tests and this note. |
|
#842 fixes this default-mode case: AI use: Claude Code (Claude Opus 5.5) drafted this note. |
Independent AMD GPU validation — RX 7900 XTXTested PR #128 at commit Hardware and environment
Targeted f16 GPU tests Both tests passed with
F16-filtered library tests
Result: 13 passed, 0 failed. Note: this name filter also includes four UTF-16-related tests. Full GPU recompiler test group
Result:
Run with Full workspace validation Ran Result: exit code 0. One optional GPU test was skipped because the adapter does not support heap windows. The repository working tree remained clean. No source changes were made. I have not tested any game files. AI assistance disclosure: ChatGPT assisted with interpreting test results and drafting this report. I independently executed the commands and tests on my hardware and verified the results. |
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
|
Regression run of Against the limits in CONTRIBUTING.md: 101 % of AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, AI use: Claude Code (Claude Opus 5.5) built both trees and ran |
|
Tested I ran both checked-in f16 rounding fixtures from a clean checkout of Intel Arc A770 (driver $env:CARGO_TARGET_DIR='L:/XclTooling/pr1512-tiling-edges-fddfa267/target'
$env:CARGO_BUILD_JOBS='2'
$env:CARGO_INCREMENTAL='0'
$env:CARGO_PROFILE_DEV_DEBUG='0'
$env:CARGO_PROFILE_TEST_DEBUG='0'
$env:TEMP='L:/XclTooling/pr128/run-2bc03fa-20261125-035429-077/temp'
$env:TMP=$env:TEMP
$env:XCL_ADAPTER='A770'
$env:XCL_DXC_DIR="$env:LOCALAPPDATA/XclTooling/dxc-1.9.2609/bin/x64"
& 'C:/Users/ljensen/.cargo/bin/cargo.exe' test --locked -p xcl --lib --no-run --message-format=json
# Executable reported by Cargo. The Arc lock covered only execution.
# The lock wrapper ran in a PowerShell process launched with -NoProfile -ExecutionPolicy RemoteSigned.
$testExe='L:/XclTooling/pr1512-tiling-edges-fddfa267/target\debug\build\xcl/77aca8ccb20e299f\out\xcl-77aca8ccb20e299f.exe'
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
& $testExe gpu::recomp::tests::gpu_f16_rounding_helpers_fold_the_sticky_bit --exact --nocapture --test-threads=1
& $testExe gpu::recomp::tests::gpu_f16_add_and_fma_round_once_under_directed_modes --exact --nocapture --test-threads=1
}
Not tested The cause of the D3D12 pipeline rejection, other adapters or DXC versions, direct DXIL, a AI use T3 Code / Codex ( |
…111)
Under s_round_mode MODE[3:2] != RNE the f16 add, sub, fma (also fmac / fmamk / fmaak, the packed forms and v_fma_mix*_f16) computed in f32 with RNE and then converted to binary16 in the requested mode: when the exact result does not fit f32 (1.0 + 2^-24 needs 25 bits) the first rounding could land exactly on a binary16 value and the directed rounding had nothing left to do (1.0 + 2^-24 under +inf gave 1.0; the console gives 1 + 2^-10).