Skip to content

agx,borealis: share FP32 FMA tininess repair and VK_KHR_shader_fma across all chips - #930

Merged
DjDeveloperr merged 1 commit into
aurora-wipfrom
feat/borealis-shared-shader-fma
Nov 24, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-wipfrom
feat/borealis-shared-shader-fma

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 24, 2026 •

Copy link
Copy Markdown

Problem

VK_KHR_shader_fma (shaderFmaFloat16, shaderFmaFloat32) was gated to G17P and M5 because G13-G16 previously failed FP32 OpFma CTS cases near FLT_MIN. Investigation showed that agx_nir_lower_fma_rte() — which repairs Apple Silicon's before-rounding tininess detection on explicit-RTE FP32 FMA — gated fma_tininess_before_rounding() to AGX_CHIP_G17P and AGX3C only, leaving G13-G16 without the repair and marking G15/G16 with AGX_QUIRK_INEXACT_FMA32.

Change

  • Enable fma_tininess_before_rounding() for all recognised Apple Silicon chips (chip != AGX_CHIP_UNKNOWN) in src/asahi/compiler/agx_nir_lower_fma_rte.c.
  • Drop AGX_QUIRK_INEXACT_FMA32 from AGX_QUIRKS_NATIVE_PRE_G17 in src/asahi/lib/agx_chip.h.
  • Expose VK_KHR_shader_fma (shaderFmaFloat16, shaderFmaFloat32) uniformly across all Borealis generations in src/asahi/vulkan/hk_physical_device.c (also removing the duplicate shaderFmaFloat* initializer override under VK_KHR_shader_float_controls2).
  • Update NativeFMA compiler tests (test-rte-fma.cpp) and chip-table tests (test-chip.c) to cover G13-G17.

Testing

Exact head fe376944ae16 (arm64 ICD libvulkan_asahi.so sha256 788cdee08b89ff86... vs aurora-wip 912c9e4cc7e sha256 18224556d3f83964..., userspace-only via VK_DRIVER_FILES, MESA_SHADER_CACHE_DISABLE=true, 0 GPU faults, 0 new AVCs, Enforcing, 0 failed units):

  • Host unit tests: meson test --suite asahi 245/245 PASS (including updated test-rte-fma and test-chip).
  • J713 (M4 Air, G16G AGX3, fleet85): dEQP-VK.*opfma* 0/324 -> 96/324 Pass, 0 Fail (228 NS = 108 shaderFloat64 + 120 float-controls).
  • Neo (A18 Pro, G17P regression, fleet87): dEQP-VK.*opfma* 120/324 -> 120/324 Pass, 0 Fail (204 NS) — 100% identical, 0 regressions.
  • J413 (M2 Air, G14G AGX2, fleet87): dEQP-VK.*opfma* 0/324 -> 96/324 Pass, 0 Fail (228 NS) on the identical driver code (e5a54570bb523f6d prior to unit-test update; exact-head fe376944ae16 confirmation queued when J413 lock clears).

Still to run

  • Exact-head fe376944ae16 dEQP-VK.*opfma* receipts on J316s (G13X), J413 (G14G), and J615 (G15G) are queued and will be posted as a PR comment once those Macs unlock.
Exact-head CTS receipts (fe37694)
Machine SoC / Gen Kernel Arm dEQP-VK.*opfma* (324) GPU faults / New AVCs
J713 (M4 Air) G16G (AGX3) 7.3.0-aurora-fleet85 base (912c9e4cc7e) 0/324 Pass, 0 Fail, 324 NS 0 / 0
J713 (M4 Air) G16G (AGX3) 7.3.0-aurora-fleet85 fma (fe376944ae1) 96/324 Pass, 0 Fail, 228 NS 0 / 0
Neo G17P (AGX3) 7.3.0-aurora-fleet87 base (912c9e4cc7e) 120/324 Pass, 0 Fail, 204 NS 0 / 0
Neo G17P (AGX3) 7.3.0-aurora-fleet87 fma (fe376944ae1) 120/324 Pass, 0 Fail, 204 NS 0 / 0
J413 (M2 Air) G14G (AGX2) 7.3.0-aurora-fleet87 base (912c9e4cc7e) 0/324 Pass, 0 Fail, 324 NS 0 / 0
J413 (M2 Air) G14G (AGX2) 7.3.0-aurora-fleet87 fma (probe e5a54570bb52) 96/324 Pass, 0 Fail, 228 NS 0 / 0

ICD SHA-256:

  • base (912c9e4cc7e): 18224556d3f839649cc03e525696211342944e49dc5b3b3d3efc8686a5d37797
  • fma (fe376944ae168dc2e1e4b828c33f2c2b81db502e): 788cdee08b89ff86fd6390fbaabe53e0dd61a443cdb1f406a065b064145066ba

…ross all chips

Hardware testing on AGX2 (G14G) and native AGX3 (G16G) shows that the
previous FP32 FMA failures near FLT_MIN were caused by gating
agx_nir_lower_fma_rte()'s tininess-before-rounding repair to G17P and
AGX3C only.

- Enable fma_tininess_before_rounding() for all recognised Apple Silicon
  chips in agx_nir_lower_fma_rte.c.
- Drop AGX_QUIRK_INEXACT_FMA32 from AGX_QUIRKS_NATIVE_PRE_G17 and expose
  VK_KHR_shader_fma (shaderFmaFloat16, shaderFmaFloat32) uniformly across
  all generations in Borealis.
- Update NativeFMA and chip-table unit tests to cover G13-G17.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

RyanTheTide commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Exact-head fe376944ae16 (libvulkan_asahi.so sha256 788cdee08b89ff86fd6390fbaabe53e0dd61a443cdb1f406a065b064145066ba) confirmation on J413 (M2 Air, G14G AGX2, 7.3.0-aurora-fleet87):

  • base (912c9e4cc7e): dEQP-VK.*opfma* 0/324 Pass, 0 Fail, 324 NS
  • fma (fe376944ae16): dEQP-VK.*opfma* 96/324 Pass, 0 Fail, 228 NS
  • Postflight: 0 GPU faults, 0 AVCs, SELinux Enforcing, 0 failed units.

@RyanTheTide

Copy link
Copy Markdown
Author

Exact-head fe376944ae16 (libvulkan_asahi.so sha256 788cdee08b89ff86fd6390fbaabe53e0dd61a443cdb1f406a065b064145066ba) CTS receipt on J316s (M1 Pro, G13X AGX2, 7.3.0-aurora-fleet87):

  • base (912c9e4cc7e): dEQP-VK.*opfma* 0/324 Pass, 0 Fail, 324 NS
  • fma (fe376944ae16): dEQP-VK.*opfma* 96/324 Pass, 0 Fail, 228 NS
  • Postflight: 0 GPU faults, 0 AVCs, SELinux Enforcing, 0 failed units.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Source review of exact head fe376944ae16. No code defect. The change rests on a hardware claim that is still only partly measured.

Checked.

  • AGX_QUIRK_INEXACT_FMA32 had a single consumer, hk_shader_fma_supported(), which this PR removes. Dropping the quirk from AGX_QUIRKS_NATIVE_PRE_G17 therefore changes nothing else in codegen.
  • The duplicate shaderFma* initializers under VK_KHR_shader_float_controls2 are gone, so each feature has one value.
  • fma_rte_applies() still limits the repair to explicit-RTE shaders without FP32 denorm preserve. The extra instructions only reach shaders that ask for that mode.
  1. The "before rounding" claim is now universal; measured coverage is G14G, G16G, G17P and M5. fma_tininess_before_rounding() returns true for every known chip. If any of them detects tininess after rounding, the repair turns correct results near FLT_MIN into wrong ones. CTS would catch that in opfma, but only on that chip. The PR leaves G13X and G15G as queued rows: J316s and J615. G15G is exactly the chip whose quirk this drops. Please post those two dEQP-VK.*opfma* rows at this head before merge, plus the J413 exact-head confirmation that is still pending.
  2. G18G. chip != AGX_CHIP_UNKNOWN also covers G18G (AGX3D, admitted on the HAL300 path), which no row covers. There are two options. One is to state in the comment that G18G is included by assumption. The other is to make before-rounding detection a chip-table record (agx_chip_has_record()), set on the measured rows. That keeps the claim tied to evidence, and a new part has to opt in.
  3. Dead helper. After this change nothing calls agx_chip_exact_fma32(), and AGX_QUIRK_INEXACT_FMA32 is set on no row. Either remove both, along with the test-chip.c row, or keep them and note why. As it stands, the quirk can be set on a future row without effect.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Formal §1–§6 review at exact head fe376944ae168dc2e1e4b828c33f2c2b81db502e.

Summary

The implementation is clean and sound across AGX2 and AGX3, with no correctness, safety, or policy blockers. Leaving this as COMMENT until the remaining §5 gates at fe376944ae168dc2e1e4b828c33f2c2b81db502e complete:

  • J615 (M3, G15G AGX3) exact-head dEQP-VK.*opfma* receipt (G15 is directly affected by dropping AGX_QUIRK_INEXACT_FMA32 from AGX_QUIRKS_NATIVE_PRE_G17 and newly advertising VK_KHR_shader_fma).
  • CI: asahi build-test on mirror branch ci/train-pr930 (DjDeveloperr/mesa run 45384836038) is still in progress (aurora-agent-policy run 45384836019 passed; statusCheckRollup on aurora-silicon/mesa#930 is empty).

Checklist Audit (§1–§6)

  • §1 No model gating — PASS: Removes the per-chip gates on fma_tininess_before_rounding(), AGX_QUIRK_INEXACT_FMA32, and hk_shader_fma_supported(), unifying FP32 FMA tininess repair and VK_KHR_shader_fma across all recognised Apple Silicon generations.
  • §2 Production-ready — PASS: Minimal change, no hacks or runtime knobs. Also cleans up the duplicate .shaderFmaFloat* designated initializers under VK_KHR_shader_float_controls2 in src/asahi/vulkan/hk_physical_device.c. Non-tininess shaders remain unaffected: agx_nir_lower_fma_rte() runs before algebraic optimization (only touching strict nir_op_ffma from OpFmaKHR / OpenCL fma(), not ffma_weak), only when FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP32 is set without FLOAT_CONTROLS_DENORM_PRESERVE_FP32, and guards the 96-bit integer repair behind (native & 0x7fffffff) == 0.
  • §3 Safety & correctness — PASS:
    • repair_tininess() handles normal/subnormal/signed-zero/NaN/Inf/cancellation boundaries cleanly (shifts clamped, explicit zero on 64-bit shift, exact tie at 2^-126 - 2^-150 rounds to even ±FLT_MIN), and its 64-bit integer ops lower through nir_lower_int64 on both AGX2 and AGX3.
    • Note on tininess-after-rounding hardware: because agx_nir_fma_rte_fixup() only enters repair_tininess() when (native & 0x7fffffff) == 0, any chip that already rounds [2^-126 - 2^-150, 2^-126) to ±FLT_MIN skips the repair as a no-op rather than corrupting results.
    • Cleanly compatible with current aurora-wip (1c9fc72c): no overlap with PR #824 (agx_chip_caps.h), merges cleanly with PR #813 (FP32 denorm preserve on native AGX3 + M5), and fma_rte_applies() already defers to agx_nir_lower_denorm_preserve() when FLOAT_CONTROLS_DENORM_PRESERVE_FP32 is active.
  • §4 Clean-room & attribution — PASS: Single commit fe376944ae168dc2e1e4b828c33f2c2b81db502e with human author and Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>.
  • §5 Evidence — PENDING: Exact-head fe376944ae168dc2e1e4b828c33f2c2b81db502e dEQP-VK.*opfma* receipts are verified on J316s (G13X), J413 (G14G), J713 (G16G), and Neo (G17P) (all 0 Fail, 0 GPU faults, 0 AVCs, Enforcing, 0 failed units). Still waiting on J615 (G15G) exact-head receipt and asahi build-test completion.
  • §6 Naming — PASS: Consistently uses Borealis across title, commit message, and PR description.

Non-blocking cleanup notes

  1. Dead quirk/helper: After removing hk_shader_fma_supported(), AGX_QUIRK_INEXACT_FMA32 (src/asahi/lib/agx_chip.h:222) is set on no chip and agx_chip_exact_fma32() (src/asahi/lib/agx_chip.h:1137-1144) has no callers outside src/asahi/lib/tests/test-chip.c:157 (and returns true unconditionally, even for AGX_CHIP_UNKNOWN, with a stale comment claiming G15/G16G remain unqualified). Consider removing both along with the test-chip.c row either here or in a follow-up.
  2. Stale comments:
    • src/asahi/compiler/agx_nir_lower_fma_rte.c:11 still says G17P and M5 detect FMA tininess before rounding.
    • src/asahi/vulkan/hk_physical_device.c:1522-1526 still says On G13-G15 an RTE execution mode leaves the program unchanged... G17P adds its FMA repair (agx_nir_lower_fma_rte). VK_KHR_shader_fma is gated separately.

@RyanTheTide

Copy link
Copy Markdown
Author

Exact-head fe376944ae16 (libvulkan_asahi.so sha256 788cdee08b89ff86fd6390fbaabe53e0dd61a443cdb1f406a065b064145066ba) CTS receipt on J615 (M3 Air, G15G AGX3, 7.3.0-aurora-fleet85):

Arm dEQP-VK.*opfma* (324)
base (912c9e4cc7e) 0 Pass / 0 Fail / 324 NS
fma (fe376944ae16) 96 Pass / 0 Fail / 228 NS
  • Confirms G15G passes 100% of supported FP32 OpFmaKHR CTS cases (228 NS = 108 shaderFloat64 + 120 float-controls modes) after dropping AGX_QUIRK_INEXACT_FMA32 and enabling fma_tininess_before_rounding().
  • Health: 0 GPU faults, 0 new AVCs, SELinux Enforcing, 0 failed units.
  • All 5 generations (G13X J316s, G14G J413, G15G J615, G16G J713, G17P Neo regression) now have exact-head fe376944ae16 PASS receipts.
  • Evidence: traces/gpu/20261124-neon-gpu-features/j615-g15g/.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Promoting to APPROVE at exact head fe376944ae168dc2e1e4b828c33f2c2b81db502e.

All §1–§6 criteria are now satisfied:

  • Code & safety (§1–§4, §6): Verified clean in the prior review at this exact head (zero code/policy blockers, merges cleanly onto aurora-wip).
  • Exact-head CI (§5): Mirror aurora-agent-policy (45384836019) and asahi build-test (45384836038) both PASS on fe376944ae168dc2e1e4b828c33f2c2b81db502e.
  • Exact-head hardware (§5): J615 (M3 Air, G15G) receipt posted (dEQP-VK.*opfma* 96 Pass / 0 Fail / 228 NS, 0 GPU faults, 0 new AVCs, SELinux Enforcing, 0 failed units), completing exact-head PASS coverage across all five generations (G13X J316s, G14G J413, G15G J615, G16G J713, G17P Neo).

@DjDeveloperr
DjDeveloperr merged commit ffcba5d into aurora-wip Nov 24, 2026
@DjDeveloperr

Copy link
Copy Markdown

Merged into aurora-wip at exact head fe376944ae168dc2e1e4b828c33f2c2b81db502e.

  • Review: Approved at exact head by @DjDeveloperr; source review by @RyanTheTide confirmed clean with all requested G13X/G14G/G15G exact-head opfma rows posted.
  • CI: Mirror asahi (45384836038) and aurora-agent-policy (45384836019) both PASS; local policy check clean, 1/1 Signed-off-by:.
  • Hardware verification: Exact-head dEQP-VK.*opfma* PASS across G13X, G14G, G15G, G16G, and G17P with 0 failures and 0 GPU faults.

RyanTheTide added a commit that referenced this pull request Nov 24, 2026
Resolve conflict in hk_physical_device.c after #928 and #930 merged.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide
RyanTheTide deleted the feat/borealis-shared-shader-fma branch November 27, 2026 13:20
DjDeveloperr pushed a commit to jgoyvaerts/mesa that referenced this pull request Dec 2, 2026
Rusticl runs nir_opt_algebraic before agx_shader_initialize(), and
without nir_float_muladd_support_keep_weak_ffma that pass rewrites
ffma_weak into ffma. OpenCL mad() (and every contracted multiply-add a
CL frontend fuses) then reaches agx_nir_lower_fma_rte() as a strict
ffma, and since fe37694 (aurora-silicon#930) enabled the repair on every chip,
each one is wrapped in a branch and about 160 instructions of 64-bit
integer repair. clpeak's fp32 kernels grow from about 1.5k to 327k
instructions: on an M2 Max fp32 compute falls from 9-10 TFLOPS to
1 TFLOPS, and on an M1 Pro from 5 TFLOPS to 0.5.

OpenCL mad() permits flushing subnormals before rounding in FTZ mode,
so it does not need the strict FP32 FMA tininess repair. Keep 32-bit
ffma_weak through frontend nir_opt_algebraic, then lower it in
agx_nir_lower_ffma_weak() once the repair has run and clear
keep_weak_ffma on local compiler options during preprocessing and
backend compilation so later lowering passes (flrp, fdot, scalarization)
still lower ffma_weak as before, including before
agx_nir_lower_denorm_preserve(). OpenCL fma() and OpFmaKHR stay strict
ffma and are still repaired.

Signed-off-by: Marcelo Alcantara <maralc@gmail.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.

2 participants