Repository navigation
asahi,borealis: enable M5 16x16x16 INT8/UINT8 cooperative matrix (iGeMM16x16x16) - #1275
Conversation
…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>
|
Exact-head
|
There was a problem hiding this comment.
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_grouploop uses per-operandsrc_comps = 2fors < 2on int8MATMAD16_AGX3so 2-componentCOLLECTsources are safely bounded, andconvert_matrix_value()fixes integer-to-bfloat16via 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_null4/4,khr_r.subgroupscope.matrixmuladd.*140/140,convert*50/50 PASS,vkpeakint8-matrix125.6 TOPS, 0 GPU faults.
|
@DjDeveloperr, code-owner heads-up: this PR has an aurora-silicon-review App approval at |
|
@satchlj, #1187 (oreater's AGX3 matmad zero-accumulator) just landed on aurora-wip, and this PR now conflicts with it in |
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>
|
Forward-merged Conflict resolution with merged
Exact-head verification (
|
There was a problem hiding this comment.
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.
|
Merge-train landing at
Revert: |
What
Enables native 16x16x16 8-bit integer (
SINT8/UINT8->SINT32/UINT32)VK_KHR_cooperative_matrixandVK_NV_cooperative_matrix2flexible-dimension configurations on Apple M5 (AGX3C) using the hardwareiGeMM16x16x16matrix instruction:agx3_matrix_core.{h,c}): EncodesAGX3_MN_iGeMM16x16x16with independentA/Bsignedness (f12/f23), 4-half-register alignment for packed 8-byte-per-laneA/Boperands, 16-half-register alignment for 32-bitC/Daccumulators, and signed 32-bit saturating accumulation (f40).nir_intrinsics.py,agx_nir_lower_cmat.c,agx_compile.c,agx_validate.c,agx_register_allocate.c,agx3_pack_binary.c): AddsSATURATEindex and independent A/B component counts (src_comp=[-1, -1, 0]) tocmat_muladd_agx, packs 8x8-bit lane operands intou32vec2foriGeMM16x16x16, implements 8-bit subgroup shuffle-xor, propagatescmat_signed_maskinto conversions/transposes/muladds, fixes integer-to-bfloat16conversion, and updates validation/RA/packing for 2-component 32-bit packedA/Binputs.hk_physical_device.c): Exposes 9 subgroup-scope16x16x16INT8/UINT8 combinations (including mixed-sign and signed 32-bit saturating variants) inhk_GetPhysicalDeviceCooperativeMatrixPropertiesKHRandhk_GetPhysicalDeviceCooperativeMatrixFlexibleDimensionsPropertiesNVonAGX3C.test-native-form-regressions.cpp): AddsNativeForms.M5IGemm16x16x16EncodingAndAlignmentverifying encoding, signedness/saturation bits, and alignment checks.Tested
meson test -C build --suite asahi: 337/337 OK (0 failures), includingNativeForms.M5IGemm16x16x16EncodingAndAlignment.J775c,G17C B1, 40-core GPU), 0 GPU faults indmesg:vkpeak:int8-matrixjumped from0.00to125,608.47 GIOPS(125.6 TOPS) —2.00xfp16-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
AGX3C(max_size >= 16) andagx3_matrix_input_is_int8(); existing FP32/FP16/BF16 cooperative matrix paths remain unchanged and passed fullkhr_r.subgroupscope.matrixmuladd.*regression testing.matrix_grouploop now uses per-operandsrc_compsinstead ofmat_compsso 2-component packedu32vec2A/B collects never index pastdef->src[1].Not yet
UINT8 x UINT8 -> UINT32withsaturatingAccumulation = VK_TRUE): hardwaref40performs signed 32-bit saturation, so unsigned saturating accumulation is intentionally left unadvertised.VK_SCOPE_WORKGROUP_KHRcooperative matrix support (cooperativeMatrixWorkgroupScope) is tracked separately.