Skip to content

compute: lower op_sel on VOP3 v_fma_f16 in direct compute - #3234

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
Leyukaka:fma-f16-opsel
Nov 28, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
Leyukaka:fma-f16-opsel

Conversation

@Leyukaka

Copy link
Copy Markdown
Collaborator

Fixes #3233. Part of #2935. Target branch main.

Change (src/gfx1013_direct_compute.inl, the binary16 FMA lowering in DirectCompute::float_alu): VOP3 v_fma_f16 accepts op_sel.

  • Bits 0 to 2 read bits [31:16] of the matching VGPR source instead of [15:0]. Abs and neg apply after the selection.
  • Bit 3 writes the binary16 result to D[31:16] and keeps D[15:0]. Without it the result goes to D[15:0] and D[31:16] is kept, as before.
  • The half selection follows LLVM's AMDGPU modifier syntax (VOP3 op_sel: "the last value controls destination", 0 selects the low bits and 1 the high bits). That page does not say what happens to the other destination half. Keeping it mirrors what main already does for the low-half write. I have not measured it on console hardware.
  • Still refused:
    • op_sel on an SGPR or constant source, with the new message "unsupported v_fma_f16 high-half op_sel on non-VGPR source";
    • op_sel with clamp;
    • v_fmac_f16 with op_sel;
    • DPP and SDWA.
  • tests/native_fma_f16_check.py: the one refusal control that used a VGPR source selection now uses an inline-constant source, which stays refused.

Tests. The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, on main 14d56502 plus this commit.

  • New native_fma_f16_opsel_ir and native_fma_f16_opsel_hardware (wave32 request, groups 0 and 1, EXEC set before the per-lane setup) cover the seven forms found in the captured requests.
    • Every source VGPR holds different values in its two halves: (1, 2), (3, 4) and (5, 16).
    • Each destination starts at 0xABCD1234, so a wrong destination half also changes the kept half.
    • Expected words come from tests/f16_packed_model.py: 0xABCD4980, 0xABCD4880, 0xABCD4A80, 0x4E001234, 0x4D001234, 0x4CC01234 and 0x45001234.
    • Three refusal controls: an SGPR source selection, v_fmac_f16 DPP, and clamp with op_sel.
  • Run with main's native_compute_ir_dump, the new test fails with "unsupported v_fma_f16 high-half op_sel".
  • 27 tests pass with -R "native_fma_f16|native_f16|native_sdwa_f16|native_packed|native_cvt_f16|native_direct_container".
  • Mutation check by hand: reading the low half for a selected source fails both new tests.

Measured with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests, on main 14d56502 and with this commit.

AI-assisted.

Source op_sel bits 0-2 read the high half [31:16] of a VGPR source;
op_sel bit 3 writes the binary16 result to D[31:16] and keeps D[15:0].
Without bit 3 the result still goes to D[15:0] with D[31:16] kept.
op_sel on an SGPR or constant source, with clamp, on v_fmac_f16, DPP and
SDWA stay refused.

New test native_fma_f16_opsel (IR and hardware) covers the six source and
destination selections against tests/f16_packed_model.py, with a
sentinel in the kept half, plus three refusal controls.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review of 728b5fe integrated over main 7364e6a, tree a63cbe956636157d3cab71a4d025619540f81bc0. The VOP3 selector reads the requested VGPR halves before abs/neg and preserves the other destination half. The three refusal cases still reject selected non-VGPR operands, DPP on FMAC and clamp on the new op_sel path. The replay checks 14 exact result words across two groups and all guards.

Debug and Release /O2 each passed all nine tested entries, including the existing packed F16 and slot-67 wave-size checks. Windows 11 26200.9974, RTX 4060 Laptop driver 32.0.16.1656. No skips. Main has since added #3229's runtime-only output diagnostics and its fixture, outside the compiler and standalone replay inputs tested here.

ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^native_(fma_f16_.*|packed_f16_inline_(ir|controls|compute_hardware)|slot67_wave_size_hardware)$'

@R0Y00
R0Y00 merged commit 57e9466 into R0Y00:main Nov 28, 2026
5 checks passed
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.

direct compute: lower op_sel on VOP3 v_fma_f16

2 participants