Skip to content

Recompiler: translate v_mullit_f32 and v_cvt_off_f32_i4 as RDNA2 runs them - #2241

Draft
NWProgramming00 wants to merge 1 commit into
xcl-dev:mainfrom
NWProgramming00:recomp/mullit-cvt-off
Draft

NWProgramming00 wants to merge 1 commit into
xcl-dev:mainfrom
NWProgramming00:recomp/mullit-cvt-off

Conversation

@NWProgramming00

Copy link
Copy Markdown

Both backends refused v_mullit_f32 (VOP3) and v_cvt_off_f32_i4 (VOP1). This translates both as RDNA2 hardware runs them. I measured the hardware first, because the ISA text for v_mullit_f32 does not spell out its special cases.

Measured on an RDNA2 gfx1036 (2,656 input rows: 18 special S0 / S1 values × 8 S2 values, plus 64 cvt_off inputs with high bits set):

  • v_cvt_off_f32_i4: bits 3:0 are a signed 4-bit number in sixteenths (1 → 0.0625, 8 → -0.5, 15 → -0.0625). Bits 31:4 are ignored.
  • v_mullit_f32:
    • The result is -MAX_FLOAT (0xff7fffff) when S2 is not above +0 (that is, +0, -0, negative or NaN), or when S1 is -MAX_FLOAT, -inf or NaN.
    • Otherwise it is S0 × S1 with 0 × anything = +0, as v_mul_legacy_f32. For example, 0 × +inf = +0 and 0 × -1 = +0.
    • A NaN in S0 comes out as that NaN, quieted.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: both instructions, plus a mullit() helper in the HLSL prelude. It decides on the operand bits, so no float compare can be folded away.
  • crates/xcl/src/gpu/dxil/lower_valu.rs: the same rule in the direct DXIL translator.
  • crates/xcl/src/gpu/recomp/tests.rs: gpu_mullit_and_cvt_off_match_rdna2 runs both backends (HLSL + DXC, and direct DXIL) and checks them against hardware values:
    • 41 v_mullit_f32 rows: every special S1 with a positive S2, every S2, every non-NaN S0, and the zero products;
    • 64 v_cvt_off_f32_i4 inputs.
    • Rows with a NaN S0 are left out, because NaN payload bits differ between hosts. Rows with a denormal operand or result are left out too, because the kernel's default float mode flushes them.

Tested

  • Windows 11, NVIDIA GeForce RTX 5070 Ti 16 GB (wave64 as two halves) and an AMD Radeon RDNA2 iGPU (gfx1036, native wave64, XCL_ADAPTER=radeon). Rust 1.100 MSVC, release.
  • All 2,656 measured rows through xcl's kernel path on each adapter, in both backends, compared with the gfx1036's results:
    • v_cvt_off_f32_i4: 2656/2656 equal everywhere.
    • v_mullit_f32: 2458 equal on the RTX 5070 Ti and 2488 on the Radeon, in each backend. Every other row is either a NaN result that differs only in payload bits (60 / 30) or a row with a denormal (138). No other difference.
  • The new test passes on both adapters. It fails with each of six deliberate mistakes:
    • the -inf check dropped (HLSL, and separately direct DXIL);
    • the -MAX_FLOAT check dropped (HLSL);
    • the NaN check dropped (direct DXIL);
    • the S2 rule changed to S2 < 0 only (HLSL);
    • the cvt_off scale changed (direct DXIL).
  • The whole suite: cargo build --release --workspace, then cargo test --release --workspace --no-fail-fast -- --test-threads=4, with and without XCL_DIRECT_DXIL=all, against base 568e7db on the same machine:
Adapter Mode base 568e7db this PR (d7df3f9)
RTX 5070 Ti default 1150 passed, 4 failed, 46 ignored 1151 passed, 4 failed, 46 ignored
RTX 5070 Ti XCL_DIRECT_DXIL=all 1148 passed, 6 failed 1149 passed, 6 failed
Radeon gfx1036 default 1153 passed, 1 failed 1154 passed, 1 failed
Radeon gfx1036 XCL_DIRECT_DXIL=all 1151 passed, 3 failed 1152 passed, 3 failed

The +1 is the new test. The failing tests are the same on base and PR, and all are tracked: fuzz_validate_and_gpu_0..3 on NVIDIA (#1905), fuzz_validate_and_gpu_1 seed 540 on RDNA2 (#2115, #2170), gpu_image_get_resinfo_1d_array with direct DXIL (#2046) and offline_compute_pipeline_is_reused_by_a_second_process with direct DXIL (#1674).

Regression run
No usable pair yet, for the reason given on #2222. On this machine the title currently exits at the same point on main (rechecked on 568e7db just before opening this) as on the PR heads. That holds with fresh data and shader caches and on both adapters. This PR stays a draft until I can add a main / head pair whose runs reach their end.

Not tested

  • A denormal S0 / S1 / S2 under a program's float mode that keeps denormals (the test keeps the default mode).
  • v_mullit_f32 in a program that sets a non-default f32 rounding mode. The rounding-mode path (valu_f32_rm) does not cover it, so it rounds to nearest.
  • RDNA3 / RDNA4, Intel, and whether a retail program uses either instruction.

AI use

  • Claude Code (Claude Opus 5.5) did the work: it measured the hardware, wrote both lowerings and the test, ran the comparisons, the mutation checks and the suites, and wrote this description.

🤖 Generated with Claude Code

… them

Both instructions were refused by both backends. Their behaviour was
measured on an RDNA2 gfx1036 (2,656 rows):

- v_cvt_off_f32_i4: bits 3:0 as a signed 4-bit number in sixteenths
  (-0.5 .. 0.4375); bits 31:4 are ignored.
- v_mullit_f32: -MAX_FLOAT when S2 is not above +0 (-0, negative or NaN)
  or S1 is -MAX_FLOAT, -inf or NaN; otherwise S0 * S1 with 0 * anything
  = +0 (as v_mul_legacy_f32).

The HLSL path gets a `mullit` prelude helper, the direct DXIL path the
same rule on the operand bits. gpu_mullit_and_cvt_off_match_rdna2 checks
both backends against hardware values (rows with a NaN S0 or a denormal
left out).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant