Repository navigation
borealis: add small K=32 cmat tiles, dw_a pair reuse, and tile_n=48 GEMM+DW - #1089
Merged
Merged
Conversation
…EMM+DW Extend the Borealis AGX3 cooperative-matrix GEMM and compute-pair fusion builder with four targeted optimizations: - Add four unguarded K_step=32 GEMM tile shapes (32x32, 32x16, 16x32, 16x16), using 64-thread workgroups for tile_m=16, unrolled 4-slice B pipelining on narrow-N tiles, a 48-workgroup floor for 64x64, and a 32x16-to-64x16 fallback when fused depthwise-into-A has K%32!=0. - Add stride-1 horizontal pixel-pair reuse in fused depthwise-into-A for n_m_tiles<=2, sharing 6/9 input vec4s, all 9 weight vec4s, and bias across adjacent rows (22 vs 38 vec4 global loads) in exact IEEE FMA order, with 4-wide parallel input load bursts on <=4-accumulator tiles. - Hoist im2col-into-A row/column coordinates and base coordinates across the K-loop for both unguarded and guarded fast_a paths (n_m_tiles<=2), and pack the 4-scalar non-vec4 channel loop into a single vec4 store. - Support tile_n=48 in fused GEMM+pad4+depthwise for K<=16 (N%48==0) with cooperative-matrix f32matmad8x8 halo evaluation in the existing shared-memory halo region, keeping smaller tile_n on higher-occupancy scalar halo loops for larger K. - Add bit-exact NIR evaluation and compile/occupancy unit tests for all new tile shapes, im2col-into-A, depthwise-into-A, and tile_n=48 GEMM+DW. Signed-off-by: Diljit Singh <hey@djdev.me>
Author
|
Tested (
|
satchlj
approved these changes
Nov 25, 2026
satchlj
left a comment
Member
There was a problem hiding this comment.
Verdict: MERGE at 90e1fdfb4f10
Blockers: none
Checked:
- Clean-room diff with no copyrighted Apple material; all cooperative-matrix tiling,
im2col_a,dw_a, andGEMM+DWhalo paths are original Borealis NIR code and unit tests. - No chip, board, or firmware gates, no new parameters or hacks, and no hardcoded hardware-safety limits; tile selection uses shape alignment and existing capability checks (
hk_g17p_compute_shader_supported). - Single commit (
90e1fdfb4f10) carries human authorship and humanSigned-off-by:DCO with zero AI attribution in commit, PR text, or diff. - Exact-head hardware rows cover two distinct AGX3 GPU generations at
90e1fdfb4f10:J714s(M5 ProG17S B1,AGX3C) andJ700(MacBook Neo A18 ProG17P B1,AGX3B), both with same-boot ABBA performance measurements, zero conformance regressions, and clean host health. - Mesa CI waiver applies (
aurora-silicon/mesadoes not gate on GitHub CI); hardware rows plus release/assert unit tests (210/210,207/207,322/322DRM-shim) and Clang-Werror(8/8) are the gate.
Evidence
- Audited full diff (
+1043 / -154acrosssrc/asahi/vulkan/hk_cmd_dispatch.c,hk_compute_pair.h,hk_nir_match_pointwise_clamp.c,hk_queue.c, andtests/test-hk-compute-pair.c). - Verified subgroup row/column indexing (
emit_cmat_sg_row/emit_cmat_sg_col) and 64-thread shared-memory offsets (a_sh_floats = 512,a_half_v4_off = 64,a_half_v4_shift = 6) for32x32,32x16,16x32, and16x16K_step=32tiles, plus refusal of guarded andgemm_dwpaths on small tiles. - Verified
dw_astride-1 horizontal pixel-pair reuse bounds (both_int_s1,in_w >= 4,in_h >= 3,ox0 + 1 < out_w) and IEEE FMA accumulation order, hoistedim2col_acoordinates on guarded and unguardedfast_apaths, andtile_n=48GEMM+DWhalo staging (halo_v4_base = 768,halo_v2_base = 1536, max read index1791 < 1944, barrier before drain,hp_c < 17guard, exactfloor(x / 12)division for0..767). - Verified
hk_queue.cCMAT32X16_UNGUARDED->64x16fallback whenK % 32 != 0 && K % 16 == 0withexec_threads[1] / 2scaling in both packing and replay paths. - Hardware row 1 (
J714sM5 ProG17S B1,90e1fdfb4f10vsd3cbba0905bf): Geekbench 6.7.1 Vulkan ABBA-4.68%Background Blur,-2.68%Face Detection, 8-workload geomean0.9927,1110/1110deqp-vk+ Zinkglctspass, 0 GPU faults/kernel errors/AVCs/failed units. - Hardware row 2 (
J700MacBook Neo A18 ProG17P B1,90e1fdfb4f10vsd3cbba0905bf): Geekbench 6.7.1 Vulkan ABBA-1.43%Face Detection,-0.15%Background Blur, siblings flat,711 Pass / 144 NotSupported / 0 Failtargeted Vulkan CTS,5/5compute CRCs,210/210default +322/322assert DRM-shim tests pass, 0 GPU faults/AVCs/failed units.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What: Extend the Borealis AGX3 cooperative-matrix GEMM and compute-pair fusion builder with four unguarded
K_step=32small tiles (32x32,32x16,16x32,16x16), stride-1 horizontal pixel-pair reuse in fused depthwise-into-A, hoisted/vectorizedim2col_apaths, andtile_n=48cooperative-matrix halo support in fusedGEMM+pad4+depthwiseforK <= 16. Cuts Background Blur by-116 µs(-4.68%) and Face Detection by-84 µs(-2.68%;-111 µs/-3.54%on the quietest pair) in Geekbench 6.7.1 Vulkan with zero regressions on sibling workloads.Tested: J714s M5 Pro (
G17S B1) at90e1fdfb4f10: same-machine ABBA across all 8 Geekbench 6.7.1 Vulkan workloads (-4.68%Background Blur,-2.68%Face Detection, geomean0.9927, 0 regressions); release210/210and assert207/207meson test --suite asahi+MALLOC_PERTURB_=114 hk_compute_pair_testpass; Clang-Werror8/8pass (0fail);deqp-vk+ Zinkglcts1110/1110pass (0fails,0flips vs baseline);crashed=0,quarantined=0,0GPU faults/kernel errors/AVC denials/new failed units.Risk: two-way door · AGX3 Macs (M3, M4, M5, A18 Pro / Neo; generic cooperative-matrix compute-pair paths only, no UAPI or on-disk state changes)
Not yet: On-hardware ABBA on AGX3B Macs (M3, M4, A18 Pro / Neo); multi-chip native AGX3B/AGX3C compile and occupancy tests pass in
hk_compute_pair_test.Details
K_step=32cooperative-matrix GEMM tiles (32x32,32x16,16x32,16x16):a_sh_floats=512,a_half_v4_off=64) fortile_m=16(16x32,16x16) and unrolled 4-slicepipe_bwheren_n_tiles <= 2.64x64dispatch workgroup floor from25to48, gates32x32to small grids ((M/64)*(N/32) < 48) so wide grids do not double B reads, and adds a32x16 -> 64x16fallback incompute_pair_dw_gemm_match/hk_pack_runswhen fused depthwise-into-A hasK % 32 != 0 && K % 16 == 0.dw_a):n_m_tiles <= 2, interior stride-1 horizontal pixel pairs(oy0, ox0)and(oy0, ox0 + 1)share 6 of 9 input vec4 loads, all 9 weight vec4 loads, and bias (22 vs 38 vec4 global loads per pair) while preserving exact per-pixel IEEE FP32 FMA order.ACCESS_CAN_REORDERburst on low-accumulator tiles (n_m_tiles * n_n_tiles <= 4), streamingx2/x3ordered on 8-accumulator tiles (32x64) to stay within register occupancy budgets.im2col_a:yb0/xb0/yb1/xb1forn_m_tiles <= 2) andim2_kyxacross the K-loop on both unguarded and guardedfast_apaths.wg_col == 0).tile_n=48in fusedGEMM+pad4+depthwiseforK <= 16:CMAT48_UNGUARDEDwhenN % 48 == 0 && K <= 16(where cutting A-matrix re-reads outweighs 2-WG/core shared-memory occupancy), leavingK > 16on higher-occupancytile_n=24/32(3-4 WGs/core).tile_n=48with cooperative-matrixf32matmad8x8reusing the freea_sh[64 * 48 ..]halo region (zero extra shared memory) with exact border zeroing andHK_PACK_LOOP_PARAM_GEMM_K_ITERSloop bounds.G16G/G17P/G17Snative compile + occupancy tests intest-hk-compute-pair.ccovering all fourK_step=32tiles,im2col_a(new tiles, K-tails, non-vec4),dw_a(new tiles, odd widths, stride-2), andtile_n=48GEMM+DW(K=16, 24, 32, fast path and fallback).Evidence
Testing
apple,j714s,G17S B1,AGX3C)7.3.0-m5-cdirect15 #120 SMP PREEMPT Tue Nov 24 23:56:59 UTC 2026d3cbba0905bf820513648784599af17dc7c11311,libvulkan_asahi.soSHA-256fbe8014c340677c168f8d9230a5c73d96e767b17f59d55adbb667798063edb3590e1fdfb4f10d121775fcceafc45dc82f918bff2,libvulkan_asahi.soSHA-256d4a21307d8005baed09a1bdb5c76c681cb3e92bb281a84e759299c18ad689737-Dbuildtype=release -Db_ndebug=true(ABBA + release tests + CTS) and-Dbuildtype=debugoptimized -Db_ndebug=false(assert tests),MESA_SHADER_CACHE_DISABLE=1, headless WSI,PrivateNetwork=yes.Geekbench 6.7.1 Vulkan ABBA (20 iterations/workload, GPU busy median ms/iter)
Unit Tests & Clang
-Werror-Db_ndebug=true):MALLOC_PERTURB_=114 hk_compute_pair_testPASS;meson test --suite asahi: 210 Ok, 0 Fail.-Db_ndebug=false):MALLOC_PERTURB_=114 hk_compute_pair_testPASS;meson test --suite asahi: 207 Ok, 0 Fail.-Werroracross all 4 touched C files in both release and assert configs: PASS=8, FAIL=0.Conformance (deqp-vk / Zink GLES31 CTS, cts1471 / gl1471)
dEQP-VK.compute.pipeline.basic.*dEQP-VK.glsl.loops.*dEQP-VK.subgroups.basic.*dEQP-VK.robustness.buffer_access.compute.*dEQP-GLES31.functional.compute.*(Zink)dEQP-GLES31.functional.synchronization.in_invocation.*(Zink)System Health
crashed=0,quarantined=0,0GPU fault lines,0kernel error lines,0SELinux AVC denials,0new failed systemd units, and unchanged boot ID.