Skip to content

asahi,borealis: enable M5 16x16x16 INT8/UINT8 cooperative matrix (iGeMM16x16x16) - #1275

Merged
RyanTheTide merged 2 commits into
aurora-wipfrom
satchlj/borealis-igemm16-int8
Nov 28, 2026
Merged

RyanTheTide merged 2 commits into
aurora-wipfrom
satchlj/borealis-igemm16-int8

Conversation

@satchlj

@satchlj satchlj commented Nov 28, 2026

Copy link
Copy Markdown
Member

What

Enables native 16x16x16 8-bit integer (SINT8/UINT8 -> SINT32/UINT32) VK_KHR_cooperative_matrix and VK_NV_cooperative_matrix2 flexible-dimension configurations on Apple M5 (AGX3C) using the hardware iGeMM16x16x16 matrix instruction:

  • ISA encoder (agx3_matrix_core.{h,c}): Encodes AGX3_MN_iGeMM16x16x16 with independent A/B signedness (f12/f23), 4-half-register alignment for packed 8-byte-per-lane A/B operands, 16-half-register alignment for 32-bit C/D accumulators, and signed 32-bit saturating accumulation (f40).
  • Compiler & NIR lowering (nir_intrinsics.py, agx_nir_lower_cmat.c, agx_compile.c, agx_validate.c, agx_register_allocate.c, agx3_pack_binary.c): Adds SATURATE index and independent A/B component counts (src_comp=[-1, -1, 0]) to cmat_muladd_agx, packs 8x8-bit lane operands into u32vec2 for iGeMM16x16x16, implements 8-bit subgroup shuffle-xor, propagates cmat_signed_mask into conversions/transposes/muladds, fixes integer-to-bfloat16 conversion, and updates validation/RA/packing for 2-component 32-bit packed A/B inputs.
  • Borealis physical device (hk_physical_device.c): Exposes 9 subgroup-scope 16x16x16 INT8/UINT8 combinations (including mixed-sign and signed 32-bit saturating variants) in hk_GetPhysicalDeviceCooperativeMatrixPropertiesKHR and hk_GetPhysicalDeviceCooperativeMatrixFlexibleDimensionsPropertiesNV on AGX3C.
  • Unit test (test-native-form-regressions.cpp): Adds NativeForms.M5IGemm16x16x16EncodingAndAlignment verifying encoding, signedness/saturation bits, and alignment checks.

Tested

  • meson test -C build --suite asahi: 337/337 OK (0 failures), including NativeForms.M5IGemm16x16x16EncodingAndAlignment.
  • Live hardware verification on Apple M5 Max (J775c, G17C B1, 40-core GPU), 0 GPU faults in dmesg:
    • vkpeak: int8-matrix jumped from 0.00 to 125,608.47 GIOPS (125.6 TOPS) — 2.00x fp16-matrix (62,804.13 GFLOPS).
    • dEQP-VK.compute.pipeline.cooperative_matrix.*int8*: 1,030/1,030 supported passed, 0 failed (4,212 not supported).
    • dEQP-VK.compute.pipeline.cooperative_matrix.*sat*: 24/24 supported passed, 0 failed (594 not supported).
    • dEQP-VK.compute.pipeline.cooperative_matrix.op_constant_null.*: 4/4 passed, 0 failed.
    • dEQP-VK.compute.pipeline.cooperative_matrix.khr_r.subgroupscope.matrixmuladd.* (FP32/FP16/BF16/INT8/UINT8 regression): 140/140 supported passed, 0 failed.
    • dEQP-VK.compute.pipeline.cooperative_matrix.khr_a.subgroupscope.convert*: 50/50 supported passed, 0 failed.

Risk

  • Low: Changes are gated on AGX3C (max_size >= 16) and agx3_matrix_input_is_int8(); existing FP32/FP16/BF16 cooperative matrix paths remain unchanged and passed full khr_r.subgroupscope.matrixmuladd.* regression testing.
  • Register allocator matrix_group loop now uses per-operand src_comps instead of mat_comps so 2-component packed u32vec2 A/B collects never index past def->src[1].

Not yet

  • Unsigned 32-bit saturating accumulation (UINT8 x UINT8 -> UINT32 with saturatingAccumulation = VK_TRUE): hardware f40 performs signed 32-bit saturation, so unsigned saturating accumulation is intentionally left unadvertised.
  • VK_SCOPE_WORKGROUP_KHR cooperative matrix support (cooperativeMatrixWorkgroupScope) is tracked separately.

…MM16x16x16

Wire up the native AGX3C iGeMM16x16x16 integer matrix multiply-accumulate
instruction for VK_KHR_cooperative_matrix (and NV flexible dimensions) on
Apple M5 (G17C / AGX3C):

- Encode AGX3_MN_iGeMM16x16x16 in agx3_matrix_encode_gemm16 with per-operand
  signedness (UINT8/SINT8 for A and B), 4-half-register alignment for packed
  8-byte-per-lane A/B inputs, 16-half-register alignment for 32-bit
  accumulators, and signed 32-bit saturating accumulation.
- Lower 8-bit cooperative matrix muladd, shuffle-xor, signedness masks, and
  integer-to-bfloat16 conversions in agx_nir_lower_cmat.
- Update cmat_muladd_agx NIR intrinsic, AGX compiler lowering, validation,
  register allocator matrix_group handling, and binary packing for 2x32-bit
  packed INT8/UINT8 A/B operands and saturation.
- Advertise 16x16x16 subgroup-scope SINT8/UINT8 -> SINT32/UINT32 matrix
  configurations (including signed 32-bit saturating variants) in Borealis
  physical device properties on AGX3C.
- Add unit coverage in test-native-form-regressions.

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj
satchlj requested review from a team and DjDeveloperr as code owners November 28, 2026 00:56
@RyanTheTide

Copy link
Copy Markdown

Exact-head 3d2be9128609 2-gen Borealis peer rows (J316s + J473): PASS

  • Build: native aarch64 Clang 23.1.4 (-Dbuildtype=release -Db_ndebug=false -Dtools=drm-shim), overlay libvulkan_asahi.so SHA-256 4d72a0780171d690d14f5fc171228a05af9e4366e86fcf5eb1f5ff32a9f4c0f2 via isolated VK_DRIVER_FILES (stock /usr/lib64/libvulkan_asahi.so untouched, verified pre/post on both Macs).
  • J316s (M1 Pro, G13S C0, 7.3.0-aurora-fleet89): meson test --suite asahi 261/261 PASS (asserts enabled, incl. agx_tests matrix core/validation tests); Vulkan CTS 86 PASS / 0 FAIL (api.smoke 8/8, compute.pipeline.basic.* 78/81 [3 NS]); 0 GPU faults/recoveries, Enforcing, 0 failed units, 0 new AVC.
  • J473 (M2 mini, G14G B0, 7.3.0-aurora-fleet89): Vulkan CTS 86 PASS / 0 FAIL (api.smoke 8/8, compute.pipeline.basic.* 78/81 [3 NS]); 0 GPU faults/recoveries, Enforcing, 0 failed units, 0 new AVC.

@aurora-silicon-review aurora-silicon-review Bot 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.

Verdict: MERGE at 3d2be912

Blockers: none.

Checked: no Apple material, no AI attribution, no new board/firmware gates (ISA capability AGX3C / agx3_matrix_input_is_int8()), human Signed-off-by, pack_8x8_to_2x32 and 8-bit subgroup shuffle-xor lowering in agx_nir_lower_cmat.c, cmat_signed_mask propagation, RA src_comps bound fix (2 for packed u32vec2 A/B inputs so def->src[k] never over-reads), NativeForms.M5IGemm16x16x16EncodingAndAlignment unit test, 337/337 asahi suite, J775c CTS 1,030/1,030 *int8*, 24/24 *sat*, 140/140 khr_r.subgroupscope.matrixmuladd.* regression, vkpeak 125.6 TOPS INT8 matrix.

Evidence
  • Inspected all 10 files (agx3_matrix_core.{h,c}, agx3_pack_binary.c, agx_compile.c, agx_nir_lower_cmat.c, agx_register_allocate.c, agx_validate.c, hk_physical_device.c, nir_intrinsics.py, test-native-form-regressions.cpp).
  • Verified RA matrix_group loop uses per-operand src_comps = 2 for s < 2 on int8 MATMAD16_AGX3 so 2-component COLLECT sources are safely bounded, and convert_matrix_value() fixes integer-to-bfloat16 via recursive float conversion.
  • Verified on J775c M5 Max (G17C B1): 337/337 asahi tests, CTS *int8* 1,030/1,030, *sat* 24/24, op_constant_null 4/4, khr_r.subgroupscope.matrixmuladd.* 140/140, convert* 50/50 PASS, vkpeak int8-matrix 125.6 TOPS, 0 GPU faults.

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: this PR has an aurora-silicon-review App approval at 3d2be9128609 from a different lane plus the author's exact-head hardware row. I plan to land it no earlier than 06:29Z, after a combined A/B regression row on two lab GPU families (M1 Pro G13S + M4 G16G). The App approval doesn't count toward the ruleset, so that merge uses --admin under the 6-point rule. Please post a review here if you want it held.

@RyanTheTide

Copy link
Copy Markdown

@satchlj, #1187 (oreater's AGX3 matmad zero-accumulator) just landed on aurora-wip, and this PR now conflicts with it in agx3_matrix_core.h, agx3_pack_binary.c, agx_validate.c and hk_physical_device.c. Both PRs add matrix-type flag bits and encodings, so I'd rather you reconcile them than guess. Could you merge aurora-wip into the branch (a normal merge, no force push) and re-run the cooperative-matrix CTS? The App approval and the J775c row then need refreshing at the new head, and I'll land it in the next combined row.

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>
@satchlj

satchlj commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

Forward-merged origin/aurora-wip (26c48656ddf) into satchlj/borealis-igemm16-int8 at exact head 34ebcfc909cbf34482dd96231275c0a39e170d2b.

Conflict resolution with merged #1187 and #1278:

  • Moved AGX3_MATRIX_SATURATE to (1u << 10) alongside AGX3_MATRIX_ZERO_ACCUM (1u << 9).
  • Combined zero_accum and is_int8 operand checks in agx3_pack_binary.c and agx_validate.c.
  • Kept {FLOAT16, FLOAT16, FLOAT16, VK_FALSE} alongside INT8/UINT8 entries in hk_physical_device.c, skipped INT8/UINT8 in the 8x8-dependent wg_shapes (32x16@128, 32x32@256) loop, and guarded needs_16x16_pieces() / agx_nir_lower_cmat_workgroup() so INT8/UINT8 never falls back to 8x8 tiles (iGeMM16x16x16 is 16x16 only).

Exact-head verification (34ebcfc909cb, Apple M5 Max J775c, G17C B1, -Dbuildtype=release -Db_ndebug=false)

  • meson test -C build --suite asahi: 340/340 PASS, 0 FAIL
  • dEQP-VK.compute.pipeline.cooperative_matrix.*int8* (ASAHI_MESA_DEBUG=verify): 1,036/1,036 PASS (0 fail, 4,206 not supported)
  • dEQP-VK.compute.shader_object_spirv.cooperative_matrix.*int8* (ASAHI_MESA_DEBUG=verify): 1,036/1,036 PASS (0 fail, 4,206 not supported)
  • dEQP-VK.compute.shader_object_binary.cooperative_matrix.*int8* (ASAHI_MESA_DEBUG=verify): 1,036/1,036 PASS (0 fail, 4,206 not supported)
  • dEQP-VK.compute.pipeline.cooperative_matrix.*sat* (ASAHI_MESA_DEBUG=verify): 24/24 PASS (0 fail, 594 not supported)
  • vkpeak: int8-matrix = 125.65 TOPS, fp16-matrix = 62.77 TFLOPS, bf16-matrix = 29.67 TFLOPS
  • dmesg fault/hang/warn delta: 0

@aurora-silicon-review aurora-silicon-review Bot 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.

Verdict: MERGE at 34ebcfc after the merge train's combined checks.

Checked: Reviewed the packer and validator merge resolution: saturation and zero accumulation use distinct bits, with INT8 operand widths and the omitted accumulator handled together. FP16 remains exposed and INT8 avoids the 8x8-only shapes. The author reports exact J775c 340/340 and zero failures in the targeted INT8 and saturation CTS.

@RyanTheTide

Copy link
Copy Markdown

Merge-train landing at 34ebcfc909cb.

  • Review: aurora-silicon-review App APPROVE at 34ebcfc (non-author).
  • Feature row: the author's exact-head hardware row on this PR.
  • Regression: combined A/B overlay of aurora-wip plus this PR and the other queued PRs, user space, default kernel command line. M1 Pro (G13S, fleet89): 0 status changes. M4 Pro (G16S, fleet89): 0 regressions. The only flips there are a few synchronization multi_queue timeouts under 4-job load, flipping in both directions. Every flipped case passes alone on both arms, and the base arm shows the same flake. Each Mac ran 26,595 dEQP-VK + 8,153 dEQP-GLES cases, with 0 GPU firmware crashes, Enforcing, 0 failed units. Evidence traces/gpu/20261128-mergetrain-mesa.
  • --admin under the 6-point rule: the App approval does not count toward the ruleset. Dj was pinged here more than 1 h ago, and no blocking review is open.

Revert: git revert -m 1 <merge commit> on aurora-wip. A regression gets reverted first and fixed after.

@RyanTheTide
RyanTheTide merged commit 98f9fd9 into aurora-wip Nov 28, 2026
@RyanTheTide
RyanTheTide deleted the satchlj/borealis-igemm16-int8 branch November 28, 2026 09:29
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