Repository navigation
agx,borealis: share FP32 FMA tininess repair and VK_KHR_shader_fma across all chips - #930
Conversation
…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>
|
Exact-head
|
|
Exact-head
|
RyanTheTide
left a comment
There was a problem hiding this comment.
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_FMA32had a single consumer,hk_shader_fma_supported(), which this PR removes. Dropping the quirk fromAGX_QUIRKS_NATIVE_PRE_G17therefore changes nothing else in codegen.- The duplicate
shaderFma*initializers underVK_KHR_shader_float_controls2are 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.
- 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 nearFLT_MINinto wrong ones. CTS would catch that inopfma, 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 twodEQP-VK.*opfma*rows at this head before merge, plus the J413 exact-head confirmation that is still pending. - G18G.
chip != AGX_CHIP_UNKNOWNalso 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. - Dead helper. After this change nothing calls
agx_chip_exact_fma32(), andAGX_QUIRK_INEXACT_FMA32is set on no row. Either remove both, along with thetest-chip.crow, or keep them and note why. As it stands, the quirk can be set on a future row without effect.
DjDeveloperr
left a comment
There was a problem hiding this comment.
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 droppingAGX_QUIRK_INEXACT_FMA32fromAGX_QUIRKS_NATIVE_PRE_G17and newly advertisingVK_KHR_shader_fma). - CI:
asahibuild-teston mirror branchci/train-pr930(DjDeveloperr/mesarun45384836038) is still in progress (aurora-agent-policyrun45384836019passed;statusCheckRolluponaurora-silicon/mesa#930is empty).
Checklist Audit (§1–§6)
- §1 No model gating — PASS: Removes the per-chip gates on
fma_tininess_before_rounding(),AGX_QUIRK_INEXACT_FMA32, andhk_shader_fma_supported(), unifying FP32 FMA tininess repair andVK_KHR_shader_fmaacross all recognised Apple Silicon generations. - §2 Production-ready — PASS: Minimal change, no hacks or runtime knobs. Also cleans up the duplicate
.shaderFmaFloat*designated initializers underVK_KHR_shader_float_controls2insrc/asahi/vulkan/hk_physical_device.c. Non-tininess shaders remain unaffected:agx_nir_lower_fma_rte()runs before algebraic optimization (only touching strictnir_op_ffmafromOpFmaKHR/ OpenCLfma(), notffma_weak), only whenFLOAT_CONTROLS_ROUNDING_MODE_RTE_FP32is set withoutFLOAT_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 at2^-126 - 2^-150rounds to even±FLT_MIN), and its 64-bit integer ops lower throughnir_lower_int64on both AGX2 and AGX3.- Note on tininess-after-rounding hardware: because
agx_nir_fma_rte_fixup()only entersrepair_tininess()when(native & 0x7fffffff) == 0, any chip that already rounds[2^-126 - 2^-150, 2^-126)to±FLT_MINskips 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), andfma_rte_applies()already defers toagx_nir_lower_denorm_preserve()whenFLOAT_CONTROLS_DENORM_PRESERVE_FP32is active.
- §4 Clean-room & attribution — PASS: Single commit
fe376944ae168dc2e1e4b828c33f2c2b81db502ewith human author andSigned-off-by: Ryan Murray <ryan@aurorasilicon.org>. - §5 Evidence — PENDING: Exact-head
fe376944ae168dc2e1e4b828c33f2c2b81db502edEQP-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 andasahibuild-testcompletion. - §6 Naming — PASS: Consistently uses Borealis across title, commit message, and PR description.
Non-blocking cleanup notes
- 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 andagx_chip_exact_fma32()(src/asahi/lib/agx_chip.h:1137-1144) has no callers outsidesrc/asahi/lib/tests/test-chip.c:157(and returnstrueunconditionally, even forAGX_CHIP_UNKNOWN, with a stale comment claiming G15/G16G remain unqualified). Consider removing both along with thetest-chip.crow either here or in a follow-up. - Stale comments:
src/asahi/compiler/agx_nir_lower_fma_rte.c:11still saysG17P and M5 detect FMA tininess before rounding.src/asahi/vulkan/hk_physical_device.c:1522-1526still saysOn 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.
|
Exact-head
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
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) andasahibuild-test(45384836038) both PASS onfe376944ae168dc2e1e4b828c33f2c2b81db502e. - Exact-head hardware (§5): J615 (M3 Air, G15G) receipt posted (
dEQP-VK.*opfma*96 Pass / 0 Fail / 228 NS,0GPU faults,0new AVCs, SELinux Enforcing,0failed units), completing exact-head PASS coverage across all five generations (G13X J316s, G14G J413, G15G J615, G16G J713, G17P Neo).
|
Merged into
|
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>
Problem
VK_KHR_shader_fma(shaderFmaFloat16,shaderFmaFloat32) was gated to G17P and M5 because G13-G16 previously failed FP32OpFmaCTS cases nearFLT_MIN. Investigation showed thatagx_nir_lower_fma_rte()— which repairs Apple Silicon's before-rounding tininess detection on explicit-RTE FP32 FMA — gatedfma_tininess_before_rounding()toAGX_CHIP_G17PandAGX3Conly, leaving G13-G16 without the repair and marking G15/G16 withAGX_QUIRK_INEXACT_FMA32.Change
fma_tininess_before_rounding()for all recognised Apple Silicon chips (chip != AGX_CHIP_UNKNOWN) insrc/asahi/compiler/agx_nir_lower_fma_rte.c.AGX_QUIRK_INEXACT_FMA32fromAGX_QUIRKS_NATIVE_PRE_G17insrc/asahi/lib/agx_chip.h.VK_KHR_shader_fma(shaderFmaFloat16,shaderFmaFloat32) uniformly across all Borealis generations insrc/asahi/vulkan/hk_physical_device.c(also removing the duplicateshaderFmaFloat*initializer override underVK_KHR_shader_float_controls2).NativeFMAcompiler tests (test-rte-fma.cpp) and chip-table tests (test-chip.c) to cover G13-G17.Testing
Exact head
fe376944ae16(arm64 ICDlibvulkan_asahi.sosha256788cdee08b89ff86...vsaurora-wip912c9e4cc7esha25618224556d3f83964..., userspace-only viaVK_DRIVER_FILES,MESA_SHADER_CACHE_DISABLE=true, 0 GPU faults, 0 new AVCs, Enforcing, 0 failed units):meson test --suite asahi245/245 PASS (including updatedtest-rte-fmaandtest-chip).fleet85):dEQP-VK.*opfma*0/324 -> 96/324 Pass, 0 Fail (228 NS = 108shaderFloat64+ 120 float-controls).fleet87):dEQP-VK.*opfma*120/324 -> 120/324 Pass, 0 Fail (204 NS) — 100% identical, 0 regressions.fleet87):dEQP-VK.*opfma*0/324 -> 96/324 Pass, 0 Fail (228 NS) on the identical driver code (e5a54570bb523f6dprior to unit-test update; exact-headfe376944ae16confirmation queued when J413 lock clears).Still to run
fe376944ae16dEQP-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)
dEQP-VK.*opfma*(324)7.3.0-aurora-fleet85base(912c9e4cc7e)7.3.0-aurora-fleet85fma(fe376944ae1)7.3.0-aurora-fleet87base(912c9e4cc7e)7.3.0-aurora-fleet87fma(fe376944ae1)7.3.0-aurora-fleet87base(912c9e4cc7e)7.3.0-aurora-fleet87fma(probee5a54570bb52)ICD SHA-256:
base(912c9e4cc7e):18224556d3f839649cc03e525696211342944e49dc5b3b3d3efc8686a5d37797fma(fe376944ae168dc2e1e4b828c33f2c2b81db502e):788cdee08b89ff86fd6390fbaabe53e0dd61a443cdb1f406a065b064145066ba