Skip to content

borealis: add small K=32 cmat tiles, dw_a pair reuse, and tile_n=48 GEMM+DW - #1089

Merged
DjDeveloperr merged 1 commit into
aurora-wipfrom
perf/agx3-face-wave5
Nov 25, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-wipfrom
perf/agx3-face-wave5

Conversation

@DjDeveloperr

Copy link
Copy Markdown

What: Extend the Borealis AGX3 cooperative-matrix GEMM and compute-pair fusion builder with four unguarded K_step=32 small tiles (32x32, 32x16, 16x32, 16x16), stride-1 horizontal pixel-pair reuse in fused depthwise-into-A, hoisted/vectorized im2col_a paths, and tile_n=48 cooperative-matrix halo support in fused GEMM+pad4+depthwise for K <= 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) at 90e1fdfb4f10: same-machine ABBA across all 8 Geekbench 6.7.1 Vulkan workloads (-4.68% Background Blur, -2.68% Face Detection, geomean 0.9927, 0 regressions); release 210/210 and assert 207/207 meson test --suite asahi + MALLOC_PERTURB_=114 hk_compute_pair_test pass; Clang -Werror 8/8 pass (0 fail); deqp-vk + Zink glcts 1110/1110 pass (0 fails, 0 flips vs baseline); crashed=0, quarantined=0, 0 GPU 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
  1. Four unguarded K_step=32 cooperative-matrix GEMM tiles (32x32, 32x16, 16x32, 16x16):
    • Uses 64-thread workgroups (a_sh_floats=512, a_half_v4_off=64) for tile_m=16 (16x32, 16x16) and unrolled 4-slice pipe_b where n_n_tiles <= 2.
    • Raises the 64x64 dispatch workgroup floor from 25 to 48, gates 32x32 to small grids ((M/64)*(N/32) < 48) so wide grids do not double B reads, and adds a 32x16 -> 64x16 fallback in compute_pair_dw_gemm_match / hk_pack_runs when fused depthwise-into-A has K % 32 != 0 && K % 16 == 0.
  2. Stride-1 horizontal pixel-pair reuse in fused depthwise-into-A (dw_a):
    • For 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.
    • Issues all 4 horizontal input loads in one ACCESS_CAN_REORDER burst on low-accumulator tiles (n_m_tiles * n_n_tiles <= 4), streaming x2/x3 ordered on 8-accumulator tiles (32x64) to stay within register occupancy budgets.
  3. Hoisted and vectorized im2col_a:
    • Hoists row/column base coordinates (yb0/xb0/yb1/xb1 for n_m_tiles <= 2) and im2_kyx across the K-loop on both unguarded and guarded fast_a paths.
    • Packs the 4-scalar non-vec4 channel loop into a single vec4 shared store (and global store when wg_col == 0).
  4. tile_n=48 in fused GEMM+pad4+depthwise for K <= 16:
    • Selects CMAT48_UNGUARDED when N % 48 == 0 && K <= 16 (where cutting A-matrix re-reads outweighs 2-WG/core shared-memory occupancy), leaving K > 16 on higher-occupancy tile_n=24/32 (3-4 WGs/core).
    • Evaluates the 17 halo pixels on tile_n=48 with cooperative-matrix f32matmad8x8 reusing the free a_sh[64 * 48 ..] halo region (zero extra shared memory) with exact border zeroing and HK_PACK_LOOP_PARAM_GEMM_K_ITERS loop bounds.
    • Preserves absolute 64-bit buffer VAs + positive element byte offsets throughout (no delta-VA arithmetic).
  5. Unit tests:
    • Adds bit-exact NIR evaluation and G16G/G17P/G17S native compile + occupancy tests in test-hk-compute-pair.c covering all four K_step=32 tiles, im2col_a (new tiles, K-tails, non-vec4), dw_a (new tiles, odd widths, stride-2), and tile_n=48 GEMM+DW (K=16, 24, 32, fast path and fallback).
Evidence

Testing

  • Machine: Apple M5 Pro (apple,j714s, G17S B1, AGX3C)
  • Kernel: 7.3.0-m5-cdirect15 #120 SMP PREEMPT Tue Nov 24 23:56:59 UTC 2026
  • Arm A (baseline): d3cbba0905bf820513648784599af17dc7c11311, libvulkan_asahi.so SHA-256 fbe8014c340677c168f8d9230a5c73d96e767b17f59d55adbb667798063edb35
  • Arm B (candidate): 90e1fdfb4f10d121775fcceafc45dc82f918bff2, libvulkan_asahi.so SHA-256 d4a21307d8005baed09a1bdb5c76c681cb3e92bb281a84e759299c18ad689737
  • Build flags: -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)

Workload 1A (ms) 4A (ms) A mean 2B (ms) 3B (ms) B mean Delta % A spread B spread
Background Blur 2.475 2.480 2.478 2.360 2.363 2.362 -0.116 -4.68% 0.004 0.002
Face Detection 3.122 3.131 3.126 3.065 3.020 3.043 -0.084 -2.68% 0.009 0.045
Horizon Detection 4.893 4.904 4.899 4.956 4.912 4.934 +0.035 +0.72% 0.011 0.045
Edge Detection 3.639 3.648 3.643 3.654 3.642 3.648 +0.005 +0.13% 0.009 0.012
Gaussian Blur 2.386 2.389 2.388 2.391 2.394 2.392 +0.005 +0.19% 0.002 0.003
Feature Matching 6.848 6.885 6.866 6.867 6.829 6.848 -0.019 -0.27% 0.037 0.038
Stereo Matching 0.673 0.670 0.671 0.684 0.670 0.677 +0.006 +0.91% 0.002 0.014
Particle Physics 8.839 8.828 8.834 8.831 8.831 8.831 -0.003 -0.03% 0.010 0.000
8-workload geomean B/A 0.9927 -0.73%

Unit Tests & Clang -Werror

  • Release (-Db_ndebug=true): MALLOC_PERTURB_=114 hk_compute_pair_test PASS; meson test --suite asahi: 210 Ok, 0 Fail.
  • Assert (-Db_ndebug=false): MALLOC_PERTURB_=114 hk_compute_pair_test PASS; meson test --suite asahi: 207 Ok, 0 Fail.
  • Clang -Werror across all 4 touched C files in both release and assert configs: PASS=8, FAIL=0.

Conformance (deqp-vk / Zink GLES31 CTS, cts1471 / gl1471)

Suite Arm A (Pass / Fail / Crash / Timeout / NotSupported / Warn) Arm B (Pass / Fail / Crash / Timeout / NotSupported / Warn) Delta
dEQP-VK.compute.pipeline.basic.* 80 / 0 / 0 / 0 / 1 / 0 80 / 0 / 0 / 0 / 1 / 0 Identical
dEQP-VK.glsl.loops.* 624 / 0 / 0 / 0 / 0 / 0 624 / 0 / 0 / 0 / 0 / 0 Identical
dEQP-VK.subgroups.basic.* 53 / 0 / 0 / 0 / 17 / 0 53 / 0 / 0 / 0 / 17 / 0 Identical
dEQP-VK.robustness.buffer_access.compute.* 138 / 0 / 0 / 0 / 66 / 0 138 / 0 / 0 / 0 / 66 / 0 Identical
dEQP-GLES31.functional.compute.* (Zink) 195 / 0 / 0 / 0 / 0 / 0 195 / 0 / 0 / 0 / 0 / 0 Identical
dEQP-GLES31.functional.synchronization.in_invocation.* (Zink) 20 / 0 / 0 / 0 / 0 / 0 20 / 0 / 0 / 0 / 0 / 0 Identical

System Health

  • Both the CTS/unit-test window and the ABBA window recorded crashed=0, quarantined=0, 0 GPU fault lines, 0 kernel error lines, 0 SELinux AVC denials, 0 new failed systemd units, and unchanged boot ID.

…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>
@DjDeveloperr
DjDeveloperr requested a review from a team as a code owner November 25, 2026 21:25
@DjDeveloperr

Copy link
Copy Markdown
Author

Tested (J700 MacBook Neo, Apple A18 Pro / G17P B1, AGX3B + HAL200): PASS at exact head 90e1fdfb4f10d121775fcceafc45dc82f918bff2 vs exact parent d3cbba0905bf820513648784599af17dc7c11311 (7.3.0-41.fc44.aurora.aarch64, same-boot ABBA).

  • Geekbench 6.7.1 Vulkan (8/8 workloads, same-boot A1/B1/B2/A2, 20 measured iterations/leg, 0 validation errors):
    • Face Detection: −1.43% (12.031 → 11.859 ms, −0.172 ms; A1 12.026 / B1 11.847 / B2 11.871 / A2 12.036 ms).
    • Background Blur: −0.15% (9.737 → 9.722 ms; A1 9.754 / B1 9.744 / B2 9.700 / A2 9.720 ms).
    • Siblings: Stereo −0.29%, Feature +0.03%, Horizon +0.13%, Edge +0.30%, Particle matched-WG32 +0.11% (A2 42.913 vs B1/B2 42.959 ms; A1 ran WG64 at 46.751 ms), Gaussian +1.27% (A1 11.611 / B1 11.842 / B2 12.025 / A2 11.958 ms, normal bimodal spread).
  • Targeted Vulkan CTS (855/855 recorded): 711 Pass, 144 NotSupported, 0 Fail / 0 timeouts / 0 recoveries (compute.pipeline.basic 80/1/0, compute.pipeline.cooperative_matrix 14/86/0, ssbo 497/3/0, synchronization.smoke 12/0, subgroups.arithmetic.compute 108/54/0).
  • Compute smoke & Fedora CI: 5/5 Vulkan compute CRCs matched; 210/210 default + 322/322 assertion-enabled DRM-shim (-Dtools=drm-shim -Db_ndebug=false, including focused test-hk-compute-pair: PASS), 0 new warnings across all 5 touched files.
  • Driver identity & host health: staged libvulkan_asahi.so SHA-256 verified (0fc0a4924c74... head git-90e1fdfb4f vs d543cfc3d1e0... base); 0 GPU faults, 0 AVC denials, 0 failed units, boot ID unchanged (e2e18b4d), SELinux Enforcing.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 90e1fdfb4f10

Blockers: none

Checked:

  • Clean-room diff with no copyrighted Apple material; all cooperative-matrix tiling, im2col_a, dw_a, and GEMM+DW halo 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 human Signed-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 Pro G17S B1, AGX3C) and J700 (MacBook Neo A18 Pro G17P B1, AGX3B), both with same-boot ABBA performance measurements, zero conformance regressions, and clean host health.
  • Mesa CI waiver applies (aurora-silicon/mesa does not gate on GitHub CI); hardware rows plus release/assert unit tests (210/210, 207/207, 322/322 DRM-shim) and Clang -Werror (8/8) are the gate.
Evidence
  • Audited full diff (+1043 / -154 across src/asahi/vulkan/hk_cmd_dispatch.c, hk_compute_pair.h, hk_nir_match_pointwise_clamp.c, hk_queue.c, and tests/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) for 32x32, 32x16, 16x32, and 16x16 K_step=32 tiles, plus refusal of guarded and gemm_dw paths on small tiles.
  • Verified dw_a stride-1 horizontal pixel-pair reuse bounds (both_int_s1, in_w >= 4, in_h >= 3, ox0 + 1 < out_w) and IEEE FMA accumulation order, hoisted im2col_a coordinates on guarded and unguarded fast_a paths, and tile_n=48 GEMM+DW halo staging (halo_v4_base = 768, halo_v2_base = 1536, max read index 1791 < 1944, barrier before drain, hp_c < 17 guard, exact floor(x / 12) division for 0..767).
  • Verified hk_queue.c CMAT32X16_UNGUARDED -> 64x16 fallback when K % 32 != 0 && K % 16 == 0 with exec_threads[1] / 2 scaling in both packing and replay paths.
  • Hardware row 1 (J714s M5 Pro G17S B1, 90e1fdfb4f10 vs d3cbba0905bf): Geekbench 6.7.1 Vulkan ABBA -4.68% Background Blur, -2.68% Face Detection, 8-workload geomean 0.9927, 1110/1110 deqp-vk + Zink glcts pass, 0 GPU faults/kernel errors/AVCs/failed units.
  • Hardware row 2 (J700 MacBook Neo A18 Pro G17P B1, 90e1fdfb4f10 vs d3cbba0905bf): Geekbench 6.7.1 Vulkan ABBA -1.43% Face Detection, -0.15% Background Blur, siblings flat, 711 Pass / 144 NotSupported / 0 Fail targeted Vulkan CTS, 5/5 compute CRCs, 210/210 default + 322/322 assert DRM-shim tests pass, 0 GPU faults/AVCs/failed units.

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