Repository navigation
asahi/compiler: wire AGX3 matmad zero_accumulator/c_zero and enable M5 FTZ32 and graphics native subgroups - #1187
Conversation
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict at 8928b337d5fc: no code blockers found. Not approving yet: CI hasn't run, the cooperative-matrix CTS is missing, and the hardware rows below are still owed.
Blockers: none.
Checked:
- Zero-accumulator detection (
agx_emit_intrinsic()).- Only on AGX3C, not AGX3D (G18G), and only for 32-bit accumulators, so the
AGX3_MATRIX_ACCUM_F16matmad8 path is unaffected. - Every component must be a bit-exact
0u, either directly constant or through a vec of constants.-0.0(0x80000000), undefs and loop-carried zeros keep the normal path. - Bit 9 doesn't overlap the input-type nibbles (bits 0–7) or
AGX3_MATRIX_ACCUM_F16(bit 8).
- Only on AGX3C, not AGX3D (G18G), and only for 32-bit accumulators, so the
- Encoding (
agx3_pack_binary()).- Both packers refuse a ZERO_ACCUM instruction whose
src[2]isn't null, check onlysrc[0..1], and setzero_accumulator(gemm16) orc_zerowithc = 0(mma8). - The gemm16 dest==acc tie is required only without the bit, and its existing refusals (compute only, AGX3C, eight 32-bit dest channels and so on) still apply.
agx_read_registers()reports 0 registers for a null accumulator, andagx_lower_agx3_matrix_sources()skips the tied copy only for ZERO_ACCUM gemm16.
- Both packers refuse a ZERO_ACCUM instruction whose
- Register allocation.
- ZERO_ACCUM gemm16 no longer takes the tied-accumulator special case, so its destination is allocated normally.
- The new generic early-kill exclusion keeps the destination off A/B, which is always legal.
- FTZ32 native min/max reduce.
agx_nir_flush_subgroup_minmax()runs first inagx_nir_lower_subgroups_internal()and rewrites every 32-bit fmin/fmax reduce and scan source tox + (-0.0)undernir_fp_no_fast_math.- The native reduce therefore only sees flushed inputs, and min/max returns one of them, so no denormal comes out.
DenormPreserve 32still takes the shuffle tree, and G18G keeps both options off (!g18g).
- Graphics stages.
native_shuffle_xorandm5_float_minmaxnow also apply outside compute.optimize_ballot_countstill excludes fragment shaders.- The PR's subgroup CTS (
arithmeticandshuffle,framebuffer/graphics/compute) has 0 failures and 0 status changes against base on J716c.
- The PR's subgroup CTS (
- Build and tests. With the CI job's options (
-Dgallium-drivers=asahi -Dvulkan-drivers=asahi -Dplatforms=wayland,x11 -Dbuild-tests=true -Dtools=drm-shim, ccache clang),meson test --suite asahi --suite polypasses 337/337. That includes the threeM5FloatMinMaxReduceGTests andagx3_g17p_producers.- No new warnings in the changed files. The ones shown,
agx3_pack_binary.c:10435and lines 36–40/159 of the GTest, are on lines this PR doesn't touch.
- No new warnings in the changed files. The ones shown,
- Merge and text. The PR merges into current
aurora-wip(8ac326f31d4f) without conflicts, and no compiler commit has landed since its base. Signed-off-by, with no attribution lines.
Owed before merge:
- The RA change reaches M4 too, so narrow it or test it there.
- The early-kill exclusion in
agx_ra_assign_local()(I->op != MATMAD16_AGX3 && I->op != MATMAD8_AGX3) applies to every matmad, not only ZERO_ACCUM ones. That includes AGX3B (M4) matmad8 whenever the matmad8 in-place special case doesn't fire (accumulator not killed, misaligned, or of a different width). - That conflicts with "M4/AGX3B and AGX2 are untouched".
- Either restrict it to
I->matrix_type & AGX3_MATRIX_ZERO_ACCUM(if the concern is the destination landing on A/B once it is no longer tied to C), or add a J773g row with the cooperative-matrix CTS and say so in the PR.
- The early-kill exclusion in
- Cooperative-matrix CTS on M5.
VK_KHR_cooperative_matrixis exposed (hk_physical_device.c), and this is the first use of thezero_accumulator/c_zeroencodings from the compiler. Please rundEQP-VK.compute.pipeline.cooperative_matrix.*(both shapes, f16 and f32 inputs, and the zero and non-zero accumulator cases) against base. The one 16×16×16 sample doesn't cover them.- It would also show whether a hardware zero accumulator can return
-0.0whereproducts + (+0.0)gives+0.0.
- It would also show whether a hardware zero accumulator can return
- A compiler test for the new path. The encoder fields have tests, but nothing checks that a constant
+0.0accumulator emits ZERO_ACCUM with a nullsrc[2], no tied move, and the bit in the encoding, or that-0.0doesn't. - A second M5 chip. The subgroup change reaches graphics stages on every M5 part, but the rows are J716c (G17C) only. A J714s (G17S) row with the same subgroup CTS slices is needed.
- CI at the exact head. GitHub reports no checks on this branch.
- Nit:
FlushToZeroKeepsTheFlushedTreenow asserts that the native reduce is kept; a name likeFlushToZeroFlushesInputsAndKeepsNativeReducewould match.
Evidence
Head 8928b337d5fcfdde02e4f67648d9954121fdaaf3, base aurora-wip 41fe336dffae. Reviewed in a scratch repository (alternates only). Linux aarch64 host, clang + ccache, Meson 1.12.1.
| Check | Result |
|---|---|
meson test --suite asahi --suite poly |
Ok: 337, Fail: 0; M5FloatMinMaxReduce 3/3 OK |
| warnings in changed files | none new |
git merge-tree origin/aurora-wip (8ac326f31d4f) |
clean |
gh pr checks |
no checks reported |
Code read at this head: agx_emit_intrinsic() (cooperative-matrix multiply-add), agx_lower_agx3_matrix_sources(), agx3_pack_binary() (MATMAD16_AGX3/MATMAD8_AGX3), agx_ra_assign_local() (the matmad8 in-place case and the generic early-kill block), agx_read_registers(), agx_subgroup_options_for_target(), agx_nir_flush_subgroup_minmax() / flush_reduced_value(), and agx_nir_lower_subgroups_internal().
…5 FTZ32 and graphics native subgroups Two AGX3C (M5) codegen improvements using existing hardware encodings: 1. Add AGX3_MATRIX_ZERO_ACCUM (1u << 9) for MATMAD16_AGX3 (fGeMM16x16x16 zero_accumulator) and MATMAD8_AGX3 (mma8 c_zero) when the NIR cooperative-matrix multiply-add accumulator is a +0.0 constant vector. Pass agx_null() as src[2], skip tied-accumulator moves and accumulator register reads in lowering/RA/validation, and encode zero_accumulator / c_zero directly in agx3_pack_binary(). Also avoid in-place RA source aliasing on MATMAD16_AGX3 / MATMAD8_AGX3. 2. Enable native_shuffle_xor and m5_float_minmax across M5 graphics stages (VS/FS) and under DenormFlushToZero 32 (where agx_nir_flush_subgroup_minmax() flushes lane inputs before reduction; DenormPreserve 32 stays lowered). Update M5FloatMinMaxReduce GTests for FTZ32, DenormPreserve 32, and graphics stages. Signed-off-by: oreater <145754695+oreater@users.noreply.github.com>
8928b33 to
63a5915
Compare
|
Thanks for the thorough review! Updated at
|
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 63a591528222
Blockers:
src/asahi/compiler/test/test-agx3-cmat-mixed-mma8.c:444:nir_const_value cv[8];is not zeroed, and only.u32is set beforenir_build_imm(), so the upper bytes of each constant are stack garbage. With asserts on,nir_validaterejects the load_const (nir_validate.c:1277, "NIR validation failed after nir_opt_copy_prop", shader "gemm16 +0.0 on AGX3C") andagx3_cmat_mixed_mma8aborts. Reproduced on this head merged alone intoaurora-wip90211df6816(329/330, only this test fails) and in a batch build. Fix:nir_const_value cv[8] = {0};(or memset). With that one-line change the test passes locally (1/1 OK).
Checked: Read the whole diff. The zero-accumulator detection only matches exact 0u bit patterns (so -0.0 keeps the accumulator), the tied-accumulator copy is skipped only when the flag is set, and the M5 subgroup changes keep DenormPreserve 32 on the shuffle tree; under FTZ32 the native reduce relies on agx_nir_flush_subgroup_minmax() flushing the inputs first. M5-only (!g18g, AGX3C). Also: the Tested line is at 8928b337d5f, not this head; please re-run at the fixed head.
Evidence
Local Mesa gate (stands in for CI; buildbox x86 docker aurora/hk6356-mesa-x86-tests:local, clang release with asserts, -Dbuild-tests=true -Dtools=asahi,drm-shim, meson test --suite asahi --suite poly):
- base
aurora-wip90211df6816: 335/335 OK. - batch build:
90211df6816with 22 open PR heads merged on top (#1133 #1137 #1155 #1136 #1140 #1157 #1158 #1160 #1164 #1165 #1167 #1168 #1170 #1171 #1172 #1175 #1182 #1183 #1185 #1187 #1190 #1191; each also merges cleanly alone, and into currentaurora-wipd2e883ab2e3): 335/336 OK. The one failure,agx3_cmat_mixed_mma8, reproduces with #1187 alone on the base (329/330) and is caused by that PR's new test; nothing else in the batch fails. - #1187 alone on
90211df6816:meson test --suite asahiOk 329 / Fail 1 (agx3_cmat_mixed_mma8, SIGABRT from nir_validate). Same build withcv[8] = {0}:agx3_cmat_mixed_mma8OK.
…at test
nir_build_imm() validates all 64 bits of each nir_const_value union entry
when asserts are enabled, so leaving cv[8] uninitialized before writing
only cv[i].u32 triggered nir_validate failures depending on stack contents
(and deterministically under -ftrivial-auto-var-init=pattern).
Zero-initialize cv[8] = {0} before filling .u32.
Signed-off-by: Satya Benson <satya@benson.earth>
|
Pushed the 1-line uninitialized-constant fix at Exact-head verification at
|
There was a problem hiding this comment.
Verdict: HOLD for applicable hosted checks, final hardware gates and the outside-contributor landing policy. The test initialization finding is resolved.
Checked: The sole new diff zero-initializes the NIR constant array before filling its 32-bit lanes, so upper bytes consumed by validation are defined. The author reply reports 334/334 native GCC assert tests at this head with stack pattern initialization enabled, and a J775c cooperative-matrix row with zero failures among supported cases. This App approval covers the revised head. Please have the owner of the earlier personal change request resolve that review before landing.
Resolved at 429037e: the one blocker (uninitialized nir_const_value in test-agx3-cmat-mixed-mma8.c:444) is fixed by the zero-initializer; the aurora-silicon-review App approval covers that head. Dismissing my earlier change request; merge still waits on the lab regression rows.
|
@DjDeveloperr, code-owner heads-up: this PR has an aurora-silicon-review App approval at |
|
Merge-train landing at
Revert: |
Resolve conflicts with merged #1187 (AGX3_MATRIX_ZERO_ACCUM / FP16xFP16->FP16 coopmat) and #1278 (cooperativeMatrixWorkgroupScope): - Move AGX3_MATRIX_SATURATE to (1u << 10) alongside AGX3_MATRIX_ZERO_ACCUM (1u << 9) - Combine zero_accum and is_int8 operand checks in agx3_pack_binary.c and agx_validate.c - Skip INT8/UINT8 in 8x8-dependent workgroup wg_shapes (32x16@128, 32x32@256) in hk_physical_device.c and guard needs_16x16_pieces()/agx_nir_lower_cmat_workgroup() against falling back to 8x8 tiles for INT8/UINT8 (iGeMM16x16x16 is 16x16 only) Signed-off-by: Satya Benson <satya@benson.earth>
What: Wire existing AGX3 hardware
zero_accumulator(fGeMM16x16x16) andc_zero(mma8) bits viaAGX3_MATRIX_ZERO_ACCUMwhen a cooperative-matrix multiply-add starts from a+0.0accumulator (eliminating dead zero-init moves and freeing 16 GPR halves on the first K-step), and enable M5 nativeshuffle_xorandsimd_reducefloat min/max across graphics stages andDenormFlushToZero 32(keepingDenormPreserve 32lowered).Tested: J716c Apple M5 Max at 8928b33: Clang 22.1.8 debugoptimized
meson test --suite asahi --suite poly334/334 pass (0 fail, including updatedM5FloatMinMaxReduceGTests); live 3-round ABBA vs41fe336dffashows FTZ32subgroupMin/Maxloop392 -> 20instrs (-94.9%),3920 -> 268 Bcode,35 -> 9GPRs, wall-clock20.650 -> 8.415 ms(-59.2%, 2.45x, bit-exact hash33017f33e4cd2325including1e-40fsubnormals), and 16x16x16coopMatMulAddwith zero accumulator73 -> 65instrs,63 -> 47GPRs (-16 halves), wall-clock0.174 -> 0.146 ms(-16.2%, 1.19x, exact1024.0); Vulkan CTSsubgroups.{arithmetic,shuffle}.{framebuffer,graphics,compute}207/419 pass across two slices (0 fail, 0 status diffs).Risk: two-way door · M5 (G17G / G17S / G17C; G18G excluded via
!g18g) —AGX3_MATRIX_ZERO_ACCUMmatches exact0ubit patterns (+0.0, never-0.0);DenormPreserve 32remains on the shuffle-tree fallback.Not yet: Upstream CI run at
63a59152822, and a second M5 chip row (J714s / G17S) covering the graphics subgroup CTS slices and cooperative-matrix CTS.Details & benchmark data
Scope
src/asahi/compiler/agx3_matrix_core.h,agx3_pack_binary.c,agx_compile.c,agx_register_allocate.c,agx_validate.c: detect+0.0constant accumulators oncmat_muladd_agx, setAGX3_MATRIX_ZERO_ACCUMwithagx_null()src[2], skip tied-accumulator copy/RA reads, and encodezero_accumulator/c_zero.src/asahi/compiler/agx_nir_lower_subgroups.c,test/test-m5-float-minmax-reduce.cpp: enablenative_shuffle_xoracross graphics/compute andm5_float_minmaxacross graphics/compute and FTZ32 (!preserve32).Live M5 Max 3-round ABBA (
MESA_SHADER_CACHE_DISABLE=1, base41fe336dffaSHA-2560ea0ee4efd3bvs head SHA-256ca8e22d277fc)subgroupMin/Maxloop (65536 threads x 4096 iters)392->20instrs,35->9GPRs, bit-exact33017f33e4cd2325coopMatMulAdd16x16x16 zero accumulator (256 WGs x 64 iters, 64x)73->65instrs,63->47GPRs, exact1024.0Vulkan CTS (
dEQP-VK.subgroups.{arithmetic,shuffle}.{framebuffer,graphics,compute}.*,MESA_SHADER_CACHE_DISABLE=1)Slice 1 (272 cases): Base 120/272 Pass, 0 Fail; Head 120/272 Pass, 0 Fail, 0 diffs
Slice 2 (147 targeted framebuffer/graphics/compute min/max/shuffle_xor): Base 87/147 Pass, 0 Fail; Head 87/147 Pass, 0 Fail, 0 diffs
Review follow-up at
63a59152822:agx_ra_assign_local()toAGX3_MATRIX_ZERO_ACCUMonly so AGX3B (M4) and non-zero-accum matmad are untouched.FlushToZeroKeepsTheFlushedTree->FlushToZeroFlushesInputsAndKeepsNativeReduce.test-agx3-cmat-mixed-mma8.c:gemm16 +0.0(15instrs,zero_accumulator=1) vs-0.0(23instrs,zero_accumulator=0),mma8 +0.0(12instrs,c_zero=1) vs-0.0(14instrs,c_zero=0), andmma8 +0.0untouched onAGX3B(c_zero=0).dEQP-VK.compute.pipeline.cooperative_matrix.khr_r.*matrixmuladd*(f16/f32) +op_constant_null.*A/B on J716c:154/1064 PASS,910 NotSupported,0 FAIL,0diffs.A=-1.0, B=+0.0, C=+0.0andA=-0.0, B=+0.0, C=+0.0):f32matmad8x8(c_zero=1) returns0x00000000(+0.0, identical to explicitC=+0.0);fGeMM16x16x16(zero_accumulator=1) returns0x80000000(-0.0) vs0x00000000(+0.0) for explicitC=+0.0(permitted under Vulkan /VK_KHR_cooperative_matrixdefault float semantics).