Recompiler: round f16 add / sub / fma / ldexp results to nearest even #1841
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!1841
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1841"
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?
@vladbondarenko97 on GitHub · 2026-11-24 21:39 UTC · original
vladbondarenko97:f16-rne-v2→main· +168 −9 · 2 files · 1 commits · openIn the HLSL path the f32 result of
v_add/sub/subrev/fma/fmac/fmamk/fmaak/ldexp_f16andv_pk_add/pk_fma/pk_fmac_f16was converted withf32tof16, which rounds toward zero on NVIDIA; RDNA2's default is round to nearest even. Onlyv_mul_f16/v_pk_mul_f16usedf32_to_f16_rm(#166). Found on an RTX 3080 Ti (reported on #1269 and #128):v_add_f16(0x3C01, 2^-11)gave0x3C01(want0x3C02),v_pk_add_f16high half0xbfff(want0xc000),v_ldexp_f16into the denormals0x207(want0x208).What is in it
crates/xcl/src/gpu/recomp/emit.rs:v_pk_add_f16use the same rounded conversion asv_mul_f16(the f32 result is exact or correctly rounded with 2p+2 bits, so one rounding to f16 is right).v_pk_fma_f16/v_pk_fmac_f16use a new prelude helperfma_rto: the exact product plus the TwoSum error, rounded to odd in f32, so the following binary16 rounding is a single correct rounding (fma(0x3C01, 0x0FFE, 0x3C01)=0x3C01; an RNE f32 sum gives0x3C02).fma_rtois inPRELUDE, so every program's DXIL cache entry is rebuilt once.crates/xcl/src/gpu/recomp/tests.rs:gpu_f16_arithmetic_rounds_to_nearest_even: 8 results × 4096 lanes against an exact integer reference, with ties, subnormals and the double-rounding case.v_cvt_f16_u16/i16(#515), directed rounding modes (#128),v_fma_mix*_f16,v_mad_f16, and the transcendental f16 ops (stillf32tof16).Tested
cargo test -p xcl --lib gpu_f16_arithmetic_rounds -- --test-threads=1: without theemit.rschange FAILED, 13780 wrong (e.g.v_add_f16 a=3c01 b=1000: got 3c01, want 3c02;v_fma_f16 a=9008 b=9130 c=823a: got 8234, want 8235); with it 1 passed (on this head,89724e5, and on the same change before the rebase,4c4b190).cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4on this head89724e5: 960 passed, 0 failed, 43 ignored.gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware,the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu,cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu,coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu,a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu,a_per_lane_2d_or_3d_group_runs_on_the_gpuand the wave64 halves off16/f32/f64/integer_programs_on_the_gpu; their per-lane halves that the per-lane form refuses;pso_measurement_compiles_an_exact_synthetic_record(cannot disable the driver cache);heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).Regression run
main:
this PR:
Not tested
f32tof16may already round to nearest); the f16 ops listed above as not in it; a game that depends on these results (the regression run is a 120 s boot/menu run).AI use
Related: #128, #515, #1269
🤖 Generated with Claude Code
https://claude.ai/code/session_01Hri58aiQKmMwqS6K8CHq2s
@upipibi on GitHub · 2026-11-24 22:04 UTC · original
Checked on Ampere: RTX 3070 8 GB, driver 616.56, Windows 11, debug,
89724e5merged ontomain.gpu_f16_arithmetic_rounds_to_nearest_evenpasses on the HLSL path.The direct DXIL backend still has the same bug. The test compiles the HLSL itself, so
XCL_DIRECT_DXIL=1doesn't reach the direct translator. I changed one line locally todirect_or(&code, &opt, dxc::compile(..)). WithXCL_DIRECT_DXIL=1it then fails at the first case:#1742 doesn't cover these. It moves only
v_mul_f16/v_pk_mul_f16(andv_cvt_f16_f32) toto_f16_rounded. Theto_f16calls for add / sub / fma / fmac / ldexp,v_pk_add/v_pk_fmaandv_fma_mixlo/histay (lower_wide.rsaround 66 and 417,lower_valu.rsaround 512). I could not run the two PRs together: #1742 currently conflicts withmaininkernel.rs/core_tests.rs. Making the test go throughdirect_orhere would keep both backends covered once the direct side is fixed.AI-assisted (Claude Code). Synthetic tests only.
@thehollowedone on GitHub · 2026-11-24 22:46 UTC · original
Independent HLSL check of 89724e5 on an RTX 3080 Ti (621.35), Windows 11 build 26300, Rust 1.99.1 MSVC debug, DXC 1.8.2502.11.
I extended the existing exact-integer reference test to cover
v_subrev_f16,v_fmamk_f16,v_fmaak_f16, both halves ofv_pk_fmac_f16, and the low half ofv_pk_fma_f16. All 57,344 results matched. For a packed FMAC whose two halves straddle different rounding midpoints, the GPU returned the expected0x3C013C01. Replacing the emitter with the version from the PR parent gave0x3C003C01for that pair and 25,878 mismatches across the extended test.cargo test --offline --locked -p xcl --lib <filter> -- --nocapture --test-threads=1passed 1/1 for each ofgpu_f16_arithmetic_rounds_to_nearest_evenandscratch_f16_arithmetic_all_changed_encodings. Zero skips. Synthetic inputs through the HLSL translator.AI-assisted. Codex (GPT-6 family, exact variant unavailable) extended and ran the test and drafted this report.
@futurepro62 on GitHub · 2026-11-24 23:02 UTC · original
Full-suite run on NVIDIA and the AMD iGPU, to go with the targeted checks above. Tested exact head
89724e5(on its basec4d37be).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu: 955 passed, 0 failed, 43 ignored. SKIPPED (no wave64):a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu,a_per_lane_2d_or_3d_group_runs_on_the_gpu,coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu,cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu,gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware,the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.gpu_f16_arithmetic_rounds_to_nearest_even.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 960 passed, 0 failed, 43 ignored. SKIPPED:f16_programs_on_the_gpu(f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).--skipleaves out five tests where this PR's base has them. They fail on main689f2dbtoo, not because of this PR: underXCL_REQUIRE_GPU=mesh,runner::skip_testturns their skips into failures. These areheap_window_out_of_memory_falls_back_to_the_switch_form(#1651) and the fourgpu::recomp::lower_dxil::tests::*_programs_on_the_gputests (follow-up on #1651). The AMD run does not setXCL_REQUIRE_GPU.hle::d3d12x::real::readback_routing_tests::coherent_buffer_sanitizes_console_flags_and_statefailed (real.rs,left != rightwith both 0). This PR does not touch D3D12.X, and the same test failed once the same way under load on #1735. The run above was alone on the machine and is clean.Not tested
AI use
@DavidM1911 on GitHub · 2026-11-25 01:03 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
@raylitebull on GitHub · 2026-11-25 01:08 UTC · original
Both AMD and NVIDIA GPU checks and CI are green on
89724e5.Remaining before merge: please address @upipibi's review suggestion to route the new test through
direct_or(or note whyXCL_DIRECT_DXIL=1parity should stay separate), after which this looks ready to merge.@JJAutoCompare on GitHub · 2026-11-25 03:27 UTC · original
XCL PR #1841 independent Arc A770 verification
Tested
89724e5d42699db4b7c6d1d4d8f8a3abd0aee07bbefore and after the run. The reused detached checkout was clean at that SHA both times. The PR discussion and issue #42 contained no equivalent Arc report at the time of verification.26200.9974on an AMD Ryzen 7 3800X with Intel Arc A770 driver32.0.101.9175. Cargo and rustc were1.100.0onx86_64-pc-windows-msvc. Cargo built the unoptimized test profile with debug info disabled. The fixture logged the loaded DXC and DXIL DLLs as1.9.2609.5from the configured directory.gpu::recomp::tests::gpu_f16_arithmetic_rounds_to_nearest_evenran the HLSL/DXC path and finished in 0.76 s with 1 passed, 0 failed, 0 ignored, 0 explicit skips (933 filtered out). The checked-in loops compared eight GPU results per lane across 128 batches of 32 lanes against an exact integer reference. All 32,768 comparisons matched bit-for-bit, with 0 mismatches. The successful run reached the fixture's final assertion that the mismatch list was empty.The prebuild ran outside the mutex. The test wrapper logged mutex acquisition and release, and the process exited
0. The run directory containscargo.log,gpu.stdout.log, andgpu.stderr.log.Not tested
Direct DXIL, other adapters or drivers, other fixtures, the full suite, and retail-title smoke runs.
AI use
T3 Code / Codex (
gpt-6.2-sol) ran the checked-in fixture and wrote this report.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.