Repository navigation
Recompiler: round direct-DXIL f16 converts and products to nearest-even - #1742
Conversation
|
Rerun on the new head
Rerun on the rebased head
Passes on NVIDIA, and on this card the old lowering rounds toward zero just as you describe. Tested
Not tested
AI use
|
|
Test report on NVIDIA GeForce RTX 5070 (12 GB)
|
|
Verification on RTX 3060 Ti (Windows 11): merge conflict with current |
35355a2 to
13d1944
Compare
|
Rebased onto
AI use: Claude Code (Claude Opus 5.5) did the rebase, ran the tests and wrote this comment. |
13d1944 to
6d2b3a7
Compare
|
Tested Intel Arc A770 passed the checked-in direct-DXIL FP16 nearest-even test on clean PR head cargo test -p xcl --lib --locked --no-run
$env:XCL_ADAPTER = 'A770'
$env:XCL_DXC_DIR = "$env:LOCALAPPDATA\XclTooling\dxc-1.9.2609\bin\x64"
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
& 'L:/XclTooling/CapabilityProbe/capabilities.exe'
& 'L:\XclTooling\pr1512-tiling-edges-fddfa267\target\debug\build\xcl\97fdf2b9ff8e1482\out\xcl-97fdf2b9ff8e1482.exe' 'gpu::dxil::core_tests::f16_conversions_and_products_default_to_round_to_nearest_even' --exact --nocapture --test-threads=1
}The prebuild ran outside the Arc lock with two Cargo jobs,
Not tested Native wave64, the HLSL backend, old lowering on Arc, other GPUs, the full workspace suite, and retail-title smoke runs. AI use Codex in T3 Code ( |
The HLSL backend rounds v_cvt_f16_f32, v_mul_f16 and v_pk_mul_f16 with to_f16_rounded_expr: round-to-nearest-even in the default mode, the program's MODE[3:2] when it sets one (xcl-dev#166). The direct DXIL backend used to_f16 for them, which without a dynamic mode is dx.op.legacyF32ToF16, rounding toward zero: 3075.0 became 0x6A01 instead of 0x6A02, 65520.0 stayed finite and products just above half the smallest denormal flushed to 0. Add Lw::to_f16_rounded (the counterpart of to_f16_rounded_expr) and use it for the three instructions; v_mad_f16's product, which already rounded this way inline, calls it too. The GPU test runs the three instructions in wave32, split wave64 and native wave64. Based on itsSio's released patch (7452171, on xcl-dev#1269). Co-authored-by: itsSio <31954644+itsSio@users.noreply.github.com> Assisted-by: T3 Code through Antigravity (Gemini 4 Neon) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6d2b3a7 to
18423c3
Compare
|
Verified on current \18423c3: both \PR description\ and \Build and test (Windows, no GPU)\ are green, and the head has dual-vendor coverage across AMD RX 7800 XT (RDNA3, native wave64 + paired smoke) and NVIDIA RTX 3060 (1112/0/46, 10/10 on \16_conversions_and_products_default_to_round_to_nearest_even), plus Intel Arc A770 on the pre-rebase commit.\n\nRe: the \TRANSLATOR_VERSION\ note above — #1947\ is merged on \main\ (\�uild.rs\ computes \XCL_DIRECT_DXIL_SOURCE_ID\ over all \gpu/dxil\ sources into \pso::direct_version, documented in \kernel.rs:39), so edits to \gpu/dxil/*\ no longer need a manual bump. |
In the direct DXIL backend (#1426),
v_cvt_f16_f32,v_mul_f16andv_pk_mul_f16went throughLw::to_f16, which without a program-setMODE[3:2]emitsdx.op.legacyF32ToF16and rounds toward zero. RDNA2 and the HLSL backend (to_f16_rounded_expr, #166) round these to nearest-even by default. On main the RX 7800 XT gives3075.0 -> 0x6A01(want0x6A02),-3075.0 -> 0xEA01,65520.0 -> 0x7BFF(want+inf), and the smallest denormal is lost. This addsLw::to_f16_rounded, the counterpart ofto_f16_rounded_expr, and uses it for those three instructions. Part of #1269.This is @itsSio's released patch (
7452171, posted on #1269 at 18:37 UTC, "If someone picks it up, we will not submit a competing PR"), rebased onto current main, with the test widened to split wave64 and an extra denormal product lane. itsSio is credited as co-author. With this in, theV_CVT_F16_F32/V_MUL_F16/V_PK_MUL_F16entries onDIFFERS_ON_1426in gefydev'sdirect-on-1426branch can be dropped.What is in it
crates/xcl/src/gpu/dxil/prelude.rs:Lw::to_f16_rounded(RNE, orVAR_FP16_RMwhen the program sets a mode);to_f16's dynamic-mode branch calls it.crates/xcl/src/gpu/dxil/lower_valu.rs,lower_wide.rs:v_cvt_f16_f32,v_mul_f16andv_pk_mul_f16use it.v_mad_f16's product already rounded this way inline and now calls it (no output change). Other f16 ops keepto_f16, as in the HLSL backend.crates/xcl/src/gpu/dxil/core_tests.rs:f16_conversions_and_products_default_to_round_to_nearest_even. It checks that nolegacyF32ToF16is emitted and runs the three instructions on the GPU in wave32, split wave64 and native wave64 (midpoints, sign, overflow to inf, denormals).Tested
85e3826with only the test added: 0 passed / 1 failed (legacyF32ToF16in the disassembly). With that check taken out, the GPU result also fails:wave32 base 0: v_cvt_f16_f32 [6a01, 6a01, 6a01, 6a04, ea01, 7bff, 0000, 0000] != [6a01, 6a02, 6a02, 6a04, ea02, 7c00, 0000, 0001].18423c3, debug.cargo build --workspacesucceeded on base and head.cargo test -p xcl --lib f16_conversions_and_products_default_to_round_to_nearest_even -- --nocapturepassed on the GPU (1 passed, 0 failed, 0 ignored, 0 skipped).cargo test --workspace --no-fail-fast -- --test-threads=4 --nocaptureon head: 1111 passed, 1 failed, 46 ignored. Seven reported skips within passing tests: six refused per-lane f16 multiply, packed multiply and f32 conversion cases across wave32/64, and one unavailable heap-window case. Sample variables were unset.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, also fails on base3da2abbwithcargo test -p xcl --lib gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 -- --exact --nocapture(0 passed, 1 failed). Both report seed 722, GPU0x1against CPU0x7fffffff.cargo clippy --workspace --all-targetsfails on three existingapprox_constantdiagnostics for TAU literals in DXIL and recompiler lowering. All three literals are present on the base.Regression run
Not tested
XCL_DIRECT_DXIL=1), so the title runs do not reach the changed lowering. They are a regression check only.MODE[3:2]through the direct backend (that path is unchanged).AI use
T3 Code through Antigravity, Gemini 4 Neon: rebased itsSio's patch, extended the GPU test, ran the first builds.
Claude Code, Claude Opus 5.5: rebased onto current main, checked the test fails on main, ran the full suite and the smoke pair, and wrote the commit message and this description.
T3 Code through Codex, gpt-6.2-astra: rebased onto
3da2abb, retained both GPU tests at the conflict, verified the builds, GPU suite and smoke pair, and updated this report. Current main hashes the DXIL source for cache invalidation.🤖 Generated with Claude Code