Skip to content

agx: keep unmodified f16 GPR sources native in AGX3C F32 FFMA - #683

Closed
DjDeveloperr wants to merge 1 commit into
aurora-wipfrom
perf/agx3c-ffma-native-f16-src
Closed

DjDeveloperr wants to merge 1 commit into
aurora-wipfrom
perf/agx3c-ffma-native-f16-src

Conversation

@DjDeveloperr

Copy link
Copy Markdown

Summary

  • In src/asahi/compiler/agx_compile.c:agx_lower_agx3_fma_sources(), allow unmodified all-scalar-register F32 FFMA instructions on AGX3C (non-G18G) to consume single-use f16 GPR sources directly instead of emitting redundant fadd h, #-0.0 widening moves.
  • agx3_try_float_modifier() / agx3_falu_fma_mod_runtime() already encode per-operand width bits for mixed f16/f32 scalar GPR operands on AGX3C. Modified, G18G (emit_agx3d), AGX3B, and uniform-mixed forms keep their existing widening paths.
  • Add compiler regression test NativeForms.Agx3cFfmaKeepsUnmodifiedHalfGprNative in src/asahi/compiler/test/test-native-form-regressions.cpp covering unmodified AGX3C GPR preservation, modified/uniform/G18G/AGX3B fallback widening, and end-to-end AGX3C compute packing.

Hardware Results (Apple M5 Pro / G17S B1, Borealis Vulkan)

Baseline aurora-wip commit: f3016978f09 | PR head: 6d232900a3b6bfe86f74f00fe96fb0b6c37c40b7

Verified in the M5 Pro Geekbench 6.7.1 Vulkan compiler stack (mw-mega11 vs prior baseline, pushing overall Geekbench 6.7.1 Vulkan to 142,881 / 101.82% of macOS 27.0 Metal 140,326):

  • Shader codegen: convolve_H 189i/73g -> 153i/63g, convolve_V 204i/67g -> 168i/63g
  • Gaussian Blur: 4.099 ms -> 3.204 ms (-21.8%)
  • Background Blur: 3.414 ms -> 2.940 ms (-13.9%)

Verification (Apple M5 Pro / G17S B1, Borealis Vulkan, MESA_SHADER_CACHE_DISABLE=1)

  • agx_tests: 1218/1218 Pass (0 fail, 1 pre-existing skip in test-rte-fma.cpp; includes NativeForms.Agx3cFfmaKeepsUnmodifiedHalfGprNative)
  • Isolated PR targeted VK CTS (vulkan-cts-1.4.7.1):
    • dEQP-VK.glsl.builtin.precision.fma.*: 8/8 supported Pass (0 fail, 2 Not supported)
    • dEQP-VK.glsl.builtin.precision_fp16_storage16b.fma.*: 4/4 supported Pass (0 fail, 1 Not supported)
    • dEQP-VK.glsl.builtin.precision_fp16_storage32b.fma.*: 4/4 supported Pass (0 fail, 1 Not supported)
    • dEQP-VK.spirv_assembly.instruction.compute.float16.arithmetic.*: 76/76 Pass (0 fail)
    • dEQP-VK.spirv_assembly.instruction.graphics.float16.arithmetic.*: 380/380 Pass (0 fail)
    • Total isolated targeted VK CTS: 472/472 supported Pass (0 fail) (and 2,203/2,203 VK CTS Pass in the combined M5 Pro validation run)
  • gb-gaussian (exact-ssbo-gaussian, horizontal.spv + vertical.spv): 12/12 checked Pass
  • Kernel dmesg: 0 GPU faults
  • Policy check: DEFAULT_BRANCH=aurora-wip bash .github/aurora/agent-policy.sh pr HEAD -> clean

Assisted-by: LLM (Google:Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown

The exactness argument holds: f16 to f32 is exact, and the fast path needs every register source to be unmodified (agx_compile.c:5258-5268). The packer already routes AGX3C FMA with half registers through the per-operand width encoder (agx3_pack_binary.c:772-775). A few points:

  • The title, the comment at agx_compile.c:5279 and the test say "single-use", but nothing checks the use count. Either drop the word or add the check if it was meant.
  • all_scalar_regs accepts AGX_INDEX_REGISTER sources, but the skip at agx_compile.c:5282 only applies to AGX_INDEX_NORMAL, so precoloured half registers are still widened. Please make the two match, or say why they differ.
  • Encoding coverage: test-agx3-alu-core.c:6524/6534 pin exact bytes for an unmodified half src1 and a half addend, but not for an unmodified half src0. Your new test puts the half in src0 and only checks binary_size > 0. An exact-byte vector for fma(half a, b, c) would pin the field you rely on.
  • Numerics: please add one M5 run where the native half slot gets f16 denormals (0x0001, 0x8001, 0x03ff), -0.0h and a NaN payload, compared bit-for-bit against the widened path. The listed precision.fma groups do not feed f16 denormals into an f32 fma.
  • The commit message has an Assisted-by: trailer. Please drop it from the commit and keep it in the PR body only.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr changed the title agx: keep single-use f16 GPR sources native in unmodified AGX3C F32 FFMA agx: keep unmodified f16 GPR sources native in AGX3C F32 FFMA Nov 22, 2026
@DjDeveloperr
DjDeveloperr force-pushed the perf/agx3c-ffma-native-f16-src branch from 6d23290 to af1486d Compare November 22, 2026 10:22
@DjDeveloperr

Copy link
Copy Markdown
Author

Updated in af1486dcd15 to address all review points:

  1. Removed "single-use" wording: Updated the PR title, commit message, code comment in agx_lower_agx3_fma_sources(), and test comments to accurately describe all unmodified f16 GPR sources (use count is not checked).
  2. AGX_INDEX_REGISTER parity with all_scalar_regs: Dropped the I->src[s].type == AGX_INDEX_NORMAL restriction on if (native_half_gpr) so precoloured AGX_INDEX_REGISTER half sources are handled consistently with SSA half sources, and added the agx3c_precoloured_gpr case to NativeForms.Agx3cFfmaKeepsUnmodifiedHalfGprNative.
  3. Explicit src0_16 encoding vector: Added an exact-byte agx3_falu_fma_mod_runtime(..., &h, ...) test for h.src0_16 = true (09011e08810402c0) alongside the existing src1_16 and addend_16 vectors in src/asahi/compiler/test/test-agx3-alu-core.c.
  4. M5 Pro hardware numerics proof (denormals / signed zero / NaN / inf across all 3 slots): Ran a dedicated Vulkan compute probe (MESA_SHADER_CACHE_DISABLE=1) on M5 Pro (G17S) testing 16 f16 edge values (0x0001, 0x8001, 0x03ff, 0x83ff, -0.0h, +0.0h, 0x7e01, 0x7e55, 0x7c01, ±inf, ±1.0h, min normal, max finite) × 4 (b, c) combinations across src0 (even half), src1 (odd half r4h), and src2 (addend half). Confirmed agx_compile dropped all 3 widening fadds (15 -> 12 instrs, 102 -> 86 bytes, emitting native ffma ^r4l, ^r5, ^r6, ffma $r5, ^r4h, ^r2, ffma $r5, $r6, ^r1l) and all 64 × 3 = 192 hardware outputs matched the widened baseline bit-for-bit. (Keeping this PR scoped to AGX3C as requested; AGX3B is handled separately.)
  5. Trailers: Dropped Assisted-by: from the commit message (kept in PR description only).

Verification (af1486dcd15, MESA_SHADER_CACHE_DISABLE=1)

  • meson test --suite asahi: 155/155 PASS (including agx3_alu_core and agx_tests)
  • M5 Pro f16 FFMA numerics probe (denormals / -0.0h / NaN payloads / inf, all 3 slots): 192/192 bit-identical vs widened baseline
  • dEQP-VK.glsl.builtin.precision.fma.*: 8/8 PASS (2 NotSupported)
  • dEQP-VK.spirv_assembly.instruction.compute.float16.arithmetic.*: 76/76 PASS
  • DEFAULT_BRANCH=aurora-wip bash .github/aurora/agent-policy.sh pr HEAD: clean; 0 GPU faults.

Assisted-by: LLM (Google:Gemini 4 Neon)

Extend #702's agx_lower_agx3_fma_sources() native half-GPR path cleanly
from AGX3B to all non-G18G AGX3 encodings (AGX3B and AGX3C): on AGX3C
(non-G18G), unmodified all-scalar-register F32 FFMA natively encodes
per-operand width bits (src0_16, src1_16, addend_16) via
agx3_falu_fma_mod_runtime(). Skip the redundant f16->f32 widening move
for both SSA and precoloured half GPR sources while keeping AGX3B native
and preserving widening for modified sources, uniform-mixed forms, and
G18G.

Add exact-byte src0_16 encoding coverage in test-agx3-alu-core.c and
update/extend test-native-form-regressions.cpp for AGX3C (including
precoloured AGX_INDEX_REGISTER half sources and end-to-end AGX3C shader
compilation).

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr force-pushed the perf/agx3c-ffma-native-f16-src branch from af1486d to ca2987f Compare November 22, 2026 14:18
@DjDeveloperr

Copy link
Copy Markdown
Author

Rebased cleanly onto origin/aurora-wip (c90b9140c855, post-#702 / #601) at ca2987fdcc69 (MERGEABLE).

  • Deduplicated against merged agx: keep f16 GPR sources native in unmodified AGX3B F32 FFMA #702: extends agx: keep f16 GPR sources native in unmodified AGX3B F32 FFMA #702's shared agx_lower_agx3_fma_sources() check cleanly from AGX_ISA_ENCODING_AGX3B to agx_isa_is_agx3(ctx->key->dev.encoding) && !g18g with zero duplicate code or AGX3B regression, and updates/extends test-native-form-regressions.cpp for both AGX3B and AGX3C.
  • Exact-head M5 Pro (G17S B1, -Dbuildtype=release -Db_ndebug=true, MESA_SHADER_CACHE_DISABLE=1): meson test --suite asahi 155/155 PASS (agx_tests 1,222/1,222 passed, 1 skipped, 0 fail); gb-gaussian checked 12/12 PASS (0 fail); 0 new dmesg GPU faults; agent-policy.sh pr PASS.

@DjDeveloperr

Copy link
Copy Markdown
Author

Closing as superseded by merged #386 (bc937edc540a), which keeps multi-reader half register FFMA operands native on AGX3C while intentionally keeping single-reader half FFMA operands widened (avoiding the half-register FFMA dependency-chain stall measured on G17C).

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.

2 participants