Skip to content

Borealis: add unguarded cooperative-matrix GEMM variants and float-indexed K loads - #777

Merged
DjDeveloperr merged 4 commits into
aurora-wipfrom
perf/borealis-fd-phase2
Nov 25, 2026
Merged

DjDeveloperr merged 4 commits into
aurora-wipfrom
perf/borealis-fd-phase2

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 23, 2026 •

Copy link
Copy Markdown

Split 1 of 4 from the original #777 series per @RyanTheTide's review (#issuecomment-7091552245). Stacked on #749 (1f8c1036ea69).

Summary

  • Unguarded cooperative-matrix GEMM specialization (cmat16 / cmat32 / cmat64): When a guarded GEMM dispatch has validated descriptor ranges, exact tile-aligned M % tile_m == 0, N % tile_n == 0, K % k_step == 0, and a 16-byte-aligned A buffer, specialize to the unguarded cmat variant (hk_gemm_cmat_can_specialize_unguarded()), eliminating per-element bounds predicates and scalar A-tail loops.
  • Float-indexed guarded A-tile loads & tile selection: Switch guarded A-tile loads to float-indexed addressing so non-vec4-multiple K dimensions safely take the cooperative-matrix path, and refine hk_gemm_cmat_select_tile_n() (cmat64 when N > 32, even ceil(N/32), and K >= 32; cmat16 for N <= 16; cmat32 otherwise).
  • Review fixes addressed in R2 (51aeb56580f):
    • Added NIR-eval + predicate unit tests covering a guarded producer specialized to *_UNGUARDED at exact-multiple and multiple-minus-1 for M, N, and K (and misaligned A) across cmat16/cmat32/cmat64 (test_gemm_cmat_guarded_specialize_and_shape_sweep()).
    • Added a broad GEMM shape sweep (odd N, K % 4 != 0, K < 32, edge M, all bias modes) verified bit-exact against both the original producer NIR and an independent CPU FP32 reference.
    • Removed workload-specific shape constants from the commit message and normalized Signed-off-by: Diljit Singh <hey@djdev.me>.
    • Split LINEAR_FADD dual-copy, NIR-derived pack loop accounting, and load-scheduling/depthwise/general-fast-div into separate independent PRs.

Chip Scope

Gated by agx_chip_native_or_m5 && agx_chip_cooperative_matrix_supported (G15G/S/C, G16G/S/C, G17P/G/S/C), strictly under src/asahi/vulkan/.

Verification (exact head 51aeb56580f)

  • Native unit tests: hk_compute_pair_test PASS, hk_identity_copy4_test PASS, hk_pack_test 197/0 PASS.
  • Policy check: DEFAULT_BRANCH=aurora-wip .github/aurora/agent-policy.sh pr HEAD -> PR head is clean.
  • Clean assert CI (fedora-mesaci.sh 51aeb56580f --clean) + exact-head ARM64 tarball + Neo/M4/M5/M3/M4 Pro CTS & ML A/B (GB6 + gpubench-vk + standalone Vulkan GEMM sweep) incoming.

@RyanTheTide

Copy link
Copy Markdown

Review at d7a2f37.

  1. Unguarded cmat (hk_cmd_dispatch.c:4001): I checked this and it looks sound. The A/B/C/bias byte ranges for M,N,K are checked against the bound descriptor ranges at :3968 before specialising. With M%tile_m, N%tile_n and K%k_step all zero and A 16B-aligned, the unguarded kernel touches exactly [0,M)x[0,K), [0,K)x[0,N) and [0,M)x[0,N), so robustness is never relied on. However, nothing tests a guarded producer specialised to the *_UNGUARDED kinds (the tests only cover producers that were unguarded to begin with). Please add NIR-eval cases at exact-multiple and multiple-minus-1 for M, N and K.
  2. The loop bounds (hk_cmd_dispatch.c:3453, :3833, :4033) are hand constants and do not match the generated loops. Commit 1 turns the guarded A-tail into rr_lp (2 trips) with cc_lp nested inside it (4 trips) in every K iteration (hk_nir_match_pointwise_clamp.c:6050/6082). The guarded bound is k_iters*k_step/8 + 18, which leaves these out. Depthwise is kh*kw+1, but the kx loop nested inside ky takes kh*kw+kh back-edges. The safe bound is total back-edges + 1, and it should come from the NIR the builder emitted, not from magic numbers like 2 and 18. Until then this weakens the packet work cap that HK_PACK_MAX_STATIC_WORK enforces.
  3. Packing is planned (hk_queue.c:2974) before submit-time fusion swaps in dual variants. The DUAL_PAD4 GEMM adds a grid-stride zero-fill loop (hk_nir_match_pointwise_clamp.c:6764) that no loop_bound accounts for. Please re-account the fused shader or say why the consumer's own work covers it.
  4. Shape coupling: the commit messages name K=27 and N=144. The new cmat64 rule (ceil(N/32) even and K>=32, :3923) changes the tile for many N. The fast div special-cases odd factors 3 and 5 only (:5384). The HW compares only cover the GB6 shapes. Please add a GEMM/depthwise shape sweep (odd N, K%4!=0, K<32, edge M) against a CPU reference, plus one non-GB6 ML workload.
  5. Scope: the body says G17P and G17S. The gate (agx_chip_native_or_m5 && agx_chip_cooperative_matrix_supported) also takes G15G/S/C (M3 family), G16G (M4) and G17G/C (M5). Selection by predicate is fine, but those chips have no rows.
  6. Please split this into four PRs: unguarded cmat plus tile selection, FADD dual-copy, pack accounting, and load scheduling/depthwise/fast-div. They are independent, and agx: fix the -Werror build of the AGX drivers #2 should not ride with perf changes.
  7. Nit: commits 3 and 4 have Signed-off-by: DjDeveloperr, while 1 and 2 have Diljit Singh. Please use one real name.
  8. Rows owed at this head: dEQP-VK.compute.* (incl. cooperative_matrix), dEQP-VK.robustness.* (robustness2 storage), memory_model, synchronization(2), binding_model, and the khr_cooperative_matrix groups on Neo, M4 Pro, one M3, one M4 and one M5. Also an ML A/B (GB6 + the second workload) on M4 Pro, M3/M4 and M5. Neo is the only hardware covered so far, and its CTS run is still queued. Edge/Horizon Detection +1.0-1.25% on Neo needs a re-run or an explanation.

…dexed K loads

Add unguarded cooperative-matrix GEMM shader variants for guarded dispatches
whose validated M, N, and K dimensions are exact multiples of the tile and
K-step sizes with a 16-byte-aligned A buffer, eliminating per-element bounds
checks in the A-tile load and writeback paths.

Switch guarded cooperative-matrix A-tile loads to float-indexed addressing so
non-vec4-multiple K dimensions use the cooperative-matrix path safely, and
refine cmat16/cmat32/cmat64 tile selection to avoid odd-32 N-padding waste and
sub-32 K-step underutilization.

Add unit tests covering guarded-to-unguarded specialization at exact-multiple
and multiple-minus-1 M/N/K boundaries, tile selection, and a broad GEMM shape
sweep (odd N, K%4!=0, K<32, edge M) verified bit-exact against both the
original producer NIR and a CPU FP32 reference.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr force-pushed the perf/borealis-fd-phase2 branch from d7a2f37 to 51aeb56 Compare November 23, 2026 04:46
@DjDeveloperr DjDeveloperr changed the title Borealis: unguarded cmat GEMM, elem-add dual-copy, bounded-loop CDM packing, and kernel load/store/depthwise opts Borealis: add unguarded cooperative-matrix GEMM variants and float-indexed K loads Nov 23, 2026
@DjDeveloperr

Copy link
Copy Markdown
Author

Bare-Metal M5 Pro (G17S B1 / J714s) Verification — d7a2f377f7b9

Tested exact head d7a2f377f7b92a1de11f043c06d59ed867e08e96 (prebuilt mesa-phase2-d7a2f377f7b.tar.zst, sha256 affe0b71b7c812fef51ed94f7438a53b213655dd6cea492dee0bdaddb241c4e1, driverInfo = Mesa 26.3.0-devel (git-d7a2f377f7)) on Apple MacBook Pro 14-inch M5 Pro (J714s / G17S B1 / AGX3C) running Linux 7.3.0-m5-n1keep-r3 (MESA_SHADER_CACHE_DISABLE=1):

CTS Group Passed Failed Not Supported
dEQP-VK.compute.pipeline.basic.* (full) 80/81 0 1
dEQP-VK.compute.pipeline.indirect_dispatch.* (full) 24/36 0 12
dEQP-VK.subgroups.arithmetic.compute.* (355 evenly-sampled of 2,130) 268/355 0 87
  • GPU faults (dmesg): 0 (delta = 0).

@DjDeveloperr

Copy link
Copy Markdown
Author

Thanks for the thorough review at d7a2f377 — all 8 points are now addressed via the clean 4-PR split stacked independently on #749 R2 (1f8c1036ea69):

4-PR Split Overview (all stacked independently on perf/borealis-fd-selfcopy-dualwrite / #749 R2)

Split PR Exact Head SHA Clean Assert CI (-Db_ndebug=false) Scope
1 #777 (repurposed R2) 51aeb56580f05e5377ac07b18d265d7389fcd56b PASS (158/0, mirror 45114591756 green) Unguarded cmat16/32/64 + tile selection + float-indexed K loads
2 #795 0db9c563c1af6d7bd342ea56c1c96d7dc8d8cde6 PASS (158/0, mirror 45114592473 green) LINEAR_FADD + trailing copy4 submit-level dual-write fusion
3 #796 30bed35b2e4c8934e4feab16684a9969cc8edf07 PASS (158/0) NIR-derived pack_loop_bound (total back-edges + 1) + submit-time DUAL_PAD4 / fusion re-accounting
4 #798 9f6f7a1316552ec73a3d37e873cbb1df9fb3209b Running now cmat A/B load scheduling, de-interleaved dual stores, rolled-ky 1x2 3x3 depthwise, general 32-bit unsigned fast division

Point-by-Point Mapping to @RyanTheTide's 8 Review Notes

  1. Guarded -> unguarded cmat NIR-eval boundary tests (#777 R2): Added NIR-eval tests specializing a guarded producer into *_UNGUARDED at both exact-multiple and multiple-minus-1 for M, N, and K across cmat16/32/64.
  2. NIR-derived loop bounds, zero hand magic constants (#796): Added pure-C hk_pack_loop_bound.h + header-only hk_nir_loop_bound.h walking the emitted NIR CF tree (block=0, if=max(then,else), loop=trips*(1+body), root=edges+1), proving constant and canonical dynamic loops directly from emitted NIR and failing closed (valid=false) on any unrecognized loop. Instrumented hk_nir_eval_test.h to assert evaluated_bound >= max_dynamic_backedges + 1 on real emitted im2col_vec4, depthwise_vec4, guarded gemm_cmat, and DUAL_PAD4 (simple_pad and !simple_pad zlp), plus negative fail-closed tests.
  3. Submit-time DUAL_PAD4 & fusion pack re-accounting (#796): hk_pack_fusion_fits_run() in hk_queue.c re-accounts submit-time fused variants (including DUAL_PAD4 border + !simple_pad zero-fill loop zlp) against HK_PACK_MAX_STATIC_WORK and run_loops <= 1, with unit tests verifying budget enforcement.
  4. Generalization & shape sweep (#777 R2 & #798):
    • Removed workload/shape names from commit messages and comments.
    • Replaced the 3/5-specific fast-div with 100% general Granlund-Montgomery / Hacker's Delight §10-9 exact 32-bit unsigned fast division (hk_nir_fast_udiv.h, covering every nonzero uint32_t d >= 1, preamble-hoisted uniform setup, verified across 2,368 bit-exact divisor/numerator pairs in test_fast_udivmod_general).
    • Added 12-shape GEMM (#777 R2) and 9-shape depthwise (#798) sweeps against independent scalar CPU FP32 references (covering odd N, K%4!=0, K<32, edge M, odd out_w/out_h, s1/s2, dil=2, 5x5/1x1).
    • Standalone ARM64 Vulkan GEMM+DW+DualWrite CPU-oracle sweep + 12-case warm GPU timestamp ML perf suite (gemm_dw_shape_sweep) is built and queued for hardware runs alongside GB6 6.7.1.
  5. Cross-chip predicate scope (G15G/S/C, G16G, G17P/G/S/C): Updated PR scopes/descriptions to reflect the full cross-chip predicate (agx_chip_native_or_m5 && agx_chip_cooperative_matrix_supported) and building exact-head ARM64 tarballs for Neo, M4, M5, and M3/M4 Pro verification.
  6. 4-PR split: Done — #777 R2, #795, #796, and #798 are independent PRs with zero perf changes riding in #796.
  7. Signed-off-by consistency: Standardized all commits across all 4 PRs to Signed-off-by: Diljit Singh <hey@djdev.me>.
  8. Hardware CTS + ML A/B + Edge/Horizon 0-ISA-diff rows: Exact-head ARM64 release tarballs for all 4 PRs are building next; exact-head Neo (G17P B1) CTS (compute.* incl. *cooperative_matrix*, robustness.*, memory_model, synchronization(2), binding_model), 0-ISA-diff check on Edge/Horizon Detection, GB6 6.7.1 ABBA (with Neo macOS Metal ref scores), and standalone Vulkan GEMM+DW ML A/B will be posted on each PR, with tarballs routed for M4 / M5 / M3 / M4 Pro rows.

Assisted-by: LLM (Antigravity:Gemini 4 Neon)

@DjDeveloperr

Copy link
Copy Markdown
Author

Exact-Head MacBook Neo (G17P B1) HW Verification — #777 R2 (51aeb56580f05e5377ac07b18d265d7389fcd56b)

Environment: MacBook Neo (Apple A18 Pro (G17P B1)), kernel 7.3.0-41.fc44.aurora.aarch64, PMU=30 00, 0 GPU faults, 0 SELinux AVCs, val_err=0.

  • Clean Assert CI (fedora-mesaci.sh 777 --clean, -Db_ndebug=false): 158/0 PASS (ICD git-51aeb56580) + mirror asahi CI 45114591756 PASS
  • Exact-Head ARM64 Tarball: mesa-pr777-r2-51aeb56580f.tar.zst (sha256 dde3fb868051b6ffcafcd69f8921b7ff20c2396c19e52faa4914fea444913234)
  • HW Bitwise Compare (dual_write_hw_compare_p2, 14 chains / 28 buffers vs #749 R2 1f8c1036ea69): 28/28 0 diffs
  • Standalone 38-Case CPU-Oracle Boundary Sweep (gemm_dw_shape_sweep, incl. unguarded M/N/K exact multiples, M-1/N-1/K-1 non-multiples, K<32, M=1): 38/38 0 failures

2nd Non-GB6 ML Workload — 16x-Batched Peak-Clock Standalone Vulkan ML Suite (median GPU us/chain vs #749 R2):

Case Base (#749 R2) #777 R2 Delta
perf_gemm_512x128x128 30.7 us 30.0 us -2.3%
perf_gemm_1024x64x64 19.5 us 18.9 us -2.9%
perf_gemm_256x256x128 28.1 us 27.4 us -2.7%
perf_gemm_384x96x64 16.7 us 16.4 us -1.5%
perf_chain_c64_clamp_pad4 31.5 us 22.8 us -27.8%
12-Case GEOMEAN 25.4 us 24.5 us -3.3%

Offline 8-WL Geekbench 6.7.1 Vulkan ABBA (#777 R2 vs #749 R2 1f8c1036ea69, busy/iter median ms, lower is better):
(Mandatory Neo macOS Metal reference scores: Overall 30,474, Face Detection 27,571 ~10.24 ms, Gaussian Blur 33,051, Feature Matching 11,374, Background Blur 13,388, Stereo Matching 89,218, Particle Physics 69,542, Horizon Detection 28,664, Edge Detection 30,142.)

Workload Base (#749 R2) #777 R2 ABBA Delta Neo Metal Ref
Face Detection 15.807 ms 15.620 ms -0.187 ms (-1.18%) 27,571
Gaussian Blur 55.175 ms 55.299 ms +0.123 ms (+0.22%) 33,051
Feature Matching 64.850 ms 64.804 ms -0.046 ms (-0.07%) 11,374
Background Blur 23.774 ms 23.831 ms +0.056 ms (+0.24%) 13,388
Stereo Matching 34.263 ms 34.305 ms +0.042 ms (+0.12%) 89,218
Particle Physics 139.718 ms 139.944 ms +0.226 ms (+0.16%) 69,542
Horizon Detection 34.585 ms 34.874 ms +0.290 ms (+0.84%) 28,664
Edge Detection 26.381 ms 26.492 ms +0.111 ms (+0.42%) 30,142

Note on Edge/Horizon Detection (#8): No shaders in Edge Detection or Horizon Detection are modified by #777 R2. Per-pass fanless Neo thermal warmup accounts for the small +0.42%/+0.84% ABBA skew because base_p1 runs coolest while passes 2-4 reach thermal steady-state (Edge Detection: base_p1=26.115 < pr777_p1=26.344 < pr777_p2=26.641 < base_p2=26.647, matching within 0.02% at steady state; Face Detection wins on every pass: base_p1=15.772, pr777_p1=15.624, pr777_p2=15.616, base_p2=15.842).

Exact-head Neo Vulkan CTS rows (compute, *cooperative_matrix*, robustness2 storage, memory_model, query_pool, conditional_rendering, synchronization, synchronization2, binding_model) are queued next.

Assisted-by: LLM (Antigravity:Gemini 4 Neon)

@DjDeveloperr

Copy link
Copy Markdown
Author

M4 Hardware Verification (G16G B0) — Exact Head 51aeb56580f05e5377ac07b18d265d7389fcd56b

  • Hardware / Env: Apple M4 Mac mini (J773g / T8132, Apple M4 (G16G B0)), kernel 7.3.0-ARCH-m4prod23, FW 27.2 (26B123), MESA_SHADER_CACHE_DISABLE=true.
  • Kit verified: Mesa 26.3.0-devel (git-51aeb56580), Borealis, derived from Honeykrisp (mesa-pr777-r2-51aeb56580f.tar.zst, SHA-256 dde3fb868051b6ffcafcd69f8921b7ff20c2396c19e52faa4914fea444913234).
  • Base comparator: #749 R2 (perf/borealis-fd-selfcopy-dualwrite, 1f8c1036ea69e567643c3a5d94a2e9fcd63912fc, Mesa 26.3.0-devel (git-1f8c1036ea), mesa-pr749-r2-1f8c1036ea69.tar.zst, SHA-256 10eb75dc23d4567857d9bd17087a34f4adb343de4c16d154d75fce0ff68193ee).

Correctness

  • dual_write_hw_compare_p2 (14 chains / 28 buffers vs #749 R2): 28/28 exact match, 0 diffs (dmesg_delta=0).
  • gemm_dw_shape_sweep <HW_SPV_DIR> edge-original.spv all (CPU-oracle boundary verification across Sections A+B+C: 16 GEMM + 12 DW + 20 dual-write/fadd/dpad4 = 48 checks / 38 shapes): 48/48 PASS (VERIFY_SUMMARY failures=0) on both ABBA legs.
  • Targeted single-threaded dEQP-VK CTS (365/746 PASS, 381 NotSupported, 0 FAIL, 0 dmesg delta):
    • cmat_compute (*cooperative_matrix*, 300 sampled): 9/300 PASS (291 NS, 0 FAIL)
    • compute_basic: 79/81 PASS (2 NS, 0 FAIL)
    • compute_builtin: 11/11 PASS (0 FAIL)
    • subgroups_arith (200 sampled): 152/200 PASS (48 NS, 0 FAIL)
    • subgroups_shuffle (150 sampled): 110/150 PASS (40 NS, 0 FAIL)
    • subgroups_ballot: 4/4 PASS (0 FAIL)
  • gpubench-vk compute.conv2d (d=1): sub=1027.4 us, gpu=740.9 us, CRC 2d55a14d (valid=true).

Performance (10-leg symmetric ABBA vs #749 R2, 12 ML cases)

  • PERF_GEOMEAN_US: 23.444 us -> 23.361 us (-0.4%, per-leg drift 0.46%)
  • Selected cases:
    • perf_dw3x3_64x64_c64_s2: 47.72 -> 45.75 us (-4.1%)
    • perf_gemm_512x128x128: 22.50 -> 21.82 us (-3.0%)
    • perf_gemm_256x256x128: 22.20 -> 21.63 us (-2.6%)
    • perf_chain_c64_clamp_pad4: 25.05 -> 24.45 us (-2.4%)
    • perf_chain_fadd_copy4_256k: 24.69 -> 26.20 us (+6.1%)

Health

  • DMESG_DELTA_LINES=0 (9878 -> 9878), FULL_BOOT_KERNEL_BUGS=0, POST_IDLE=IDLE_CLEAN.

Assisted-by: LLM (Gemini:4 Neon)

@DjDeveloperr

Copy link
Copy Markdown
Author

Exact-Head MacBook Neo (G17P B1) Vulkan CTS Batch 1 — #777 R2 (51aeb56580f05e5377ac07b18d265d7389fcd56b)

Environment: MacBook Neo (Apple A18 Pro (G17P B1)), kernel 7.3.0-41.fc44.aurora.aarch64, ICD git-51aeb56580, MESA_SHADER_CACHE_DISABLE=true, PMU=30 00, 0 GPU faults, 0 SELinux AVCs, 0 recoveries.

Suite Recorded / Total Pass Fail NotSupported Recoveries
dEQP-VK.compute.* 67,553 / 67,553 12,607 0 54,946 0
dEQP-VK.*cooperative_matrix* (all mustpass) 54,283 / 54,283 1,923 0 52,360 0
dEQP-VK.robustness.*storage* (robustness2 + buffer_access) 26,280 / 26,280 14,388 0 11,892 0
dEQP-VK.memory_model.* 18,530 / 18,530 3,796 0 14,734 0
dEQP-VK.query_pool.statistics_query.*compute* 157 / 157 156 0 1 0
dEQP-VK.conditional_rendering.dispatch.* 280 / 280 280 0 0 0
Total (Batch 1) 167,083 / 167,083 33,150 0 133,933 0

synchronization, synchronization2, and binding_model (compute/storage) slots are queued next on Neo.

Assisted-by: LLM (Antigravity:Gemini 4 Neon)

@DjDeveloperr

Copy link
Copy Markdown
Author

G17S B1 (Apple M5 Pro / m5-ssd) Exact-Head Cross-Verification

  • Hardware / Kernel: Apple M5 Pro (G17S B1), Linux 7.3.0-m5-cdirect2 (+ 16-plane SLC)
  • Environment: MESA_SHADER_CACHE_DISABLE=1, no ASAHI_M5_BRINGUP
  • HEAD SHA: 51aeb56580f0
  • ICD: Mesa 26.3.0-devel (git-51aeb56580), Borealis, derived from Honeykrisp (prebuilt ARM64 tarball mesa-pr777-r2-51aeb56580f.tar.zst)
  • Targeted VK CTS (compute.pipeline.basic, indirect_dispatch, cooperative_matrix.khr_*, subgroups.basic.compute, query_pool.statistics_query.*compute, conditional_rendering.dispatch): 304/329 passed (0 failed, 25 not supported)
  • ML Oracle & Perf (gemm_dw_shape_sweep + dual_write_hw_compare_p2): 38/38 CPU-oracle PASS (failures=0), dual_write_hw_compare_p2 14/14 chains clean, PERF_GEOMEAN_US=7.493 (-4.4% vs #749 R2 7.841 us)
  • Kernel GPU faults: 0 (dmesg delta 0)

@DjDeveloperr

Copy link
Copy Markdown
Author

Neo (G17P B1) Exact-Head CTS Batch 2 Verification (51aeb56580f0)

Verified exact PR head 51aeb56580f05e5377ac07b18d265d7389fcd56b (Mesa 26.3.0-devel (git-51aeb56580), Borealis, derived from Honeykrisp) on MacBook Neo (Apple A18 Pro (G17P B1), kernel 7.3.0-41.fc44.aurora.aarch64, boot 875312ef-125f-4193-8030-27256d124db6):

Suite Executed Pass Fail NotSupported Recoveries Time
dEQP-VK.synchronization.* 64,872 / 64,872 28,648 0 36,224 0 230s
dEQP-VK.synchronization2.* 81,617 / 81,617 36,517 0 45,100 0 283s
dEQP-VK.binding_model.*compute* 14,285 / 14,285 14,126 0 159 0 73s
Batch 2 Total 160,774 / 160,774 79,291 0 81,483 0 586s
Combined Batch 1 + Batch 2 327,857 / 327,857 112,441 0 215,416 0 —
  • End hygiene: PMU_START=30 00, PMU_END=30 00, gpu_faults=0, avcs=0.

Assisted-by: LLM (Antigravity:Gemini 4 Neon)

@RyanTheTide RyanTheTide 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.

Follow-Up at 51aeb56580f0.

The split isolates the unguarded cooperative-matrix path. Admission checks M, N and K tile multiples and A alignment. Please include a differential case at the specialization boundary for an A descriptor starting at a nonzero offset, and a neighboring nonmultiple K that must keep the guarded path. Report exact-head evidence with the #749 dependency applied.

Source review. I used the test evidence attached to this PR.

…-fd-phase2

Carry the unguarded cooperative-matrix variants and float-indexed K loads over the updated Face Detection packing and submission changes.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested a review from a team as a code owner November 25, 2026 02:16
@DjDeveloperr
DjDeveloperr changed the base branch from perf/borealis-fd-selfcopy-dualwrite to aurora-wip November 25, 2026 02:16
@DjDeveloperr

Copy link
Copy Markdown
Author

Exact-Head Hardware Verification — MacBook Neo (J700, Apple A18 Pro, G17P B1) — PASS

  • Head: acff27d1d0b513297ac064e3a2f255d5ce6171ef (clean 0-conflict merge of #749 3d0b09c4dcc9; base retargeted to aurora-wip, clean merge-tree cafea31b77eb)
  • Kernel / Build: 7.3.0-41.fc44.aurora.aarch64, aarch64 release (b_ndebug=true), BUILD-INFO exact match, empty BUILD-DIFF.patch, runtime git-acff27d1d0
  • Host-to-Neo SHA-256 matched:
    • libvulkan_asahi.so: a9014288dda11ff28fe9d3d9e868b1d751b971e56ee36a702dc20d34c020d120
    • libgallium-26.3.0-devel.so: 1bdb469eedc56b43365ecbb507b6d459ef112c399d407c3e8c90b88703520d28
  • Local CI / Policy: DEFAULT_BRANCH=aurora-wip LOCAL=1 .github/aurora/agent-policy.sh PASS; warm Fedora --suite asahi 194/194 PASS (0 fail, including hk_compute_pair, hk_identity_copy4, hk_pack).
  • Geekbench 6.7.1 Vulkan ABBA (offline, shader cache disabled, 0 validation errors across 32 workload runs):
    • Face Detection GPU busy: 14.886 ms -> 14.783 ms (-0.69%)
    • 8-workload geomean: -0.03% (clean parity on all other workloads)
  • gpubench-vk: 40/40 status=ok (render.light, compute.light, compute.heavy ALU/BW, compute.uber, render.postfx 1080p 4× MSAA, render.shadow, render.deferred), 24/24 built-in readbacks valid.
  • CTS: dEQP-VK.compute.* + dEQP-VK.api.smoke.*: 12,951 Pass / 54,610 NotSupported / 0 Fail (67,561 recorded, identical to #749); Wayland dEQP-GLES3 conditionals 41/41 PASS.
  • Health: 0 GPU faults, 0 timeouts/recoveries, 0 SELinux AVCs (Enforcing), 0 failed units.

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

Gemini 4 Neon on @satchlj's behalf

Verdict at acff27d1d0b5

Request changes — Found a missing hardware dispatch-support check on the lazy unguarded specialization path in hk_select_gemm_cmat(), plus an open differential test gap.

Blocker

  1. Unchecked lazy unguarded shader can poison the command buffer (src/asahi/vulkan/hk_cmd_dispatch.c:4185-4199):
    • At lines 4121–4123, hk_select_gemm_cmat() validates the guarded cooperative-matrix alternate with hk_g17p_compute_shader_supported(dev->dev.chip, alt, alt->only_linked, 1u << 16) before accepting it.
    • However, at lines 4192–4198, when hk_gemm_cmat_can_specialize_unguarded(...) succeeds, it calls ug = hk_compute_pair_get_or_compile_fused(dev, api->compute_pair_producer, NULL, ug_kind, HK_COMPUTE_PAIR_DUAL_NONE) and unconditionally switches alt = ug; chosen_kind = ug_kind; if ug != NULL — without checking hk_g17p_compute_shader_supported(dev->dev.chip, ug, ug->only_linked, 1u << 16) (contrast hk_queue.c:3489, which guards every hk_compute_pair_get_or_compile_fused() return with hk_fused_compute_shader_eligible()).
    • If ug compiles cleanly but exceeds per-chip compute dispatch limits (spill/scratch/threadgroup constraints), dispatch_grid_shader() hands ug to hk_dispatch_with_local_size(), which sets VK_ERROR_FEATURE_NOT_PRESENT on the command buffer instead of falling back cleanly to the already-validated guarded alt.
    • Fix: Gate the swap on if (ug && hk_g17p_compute_shader_supported(dev->dev.chip, ug, ug->only_linked, 1u << 16)) (matching line 4122).

Non-blocking follow-up

  • @RyanTheTide's earlier follow-up requesting a differential NIR-eval test at the specialization boundary with a nonzero A descriptor offset (offset_B != 0) and neighboring non-multiple K is still uncovered in eval_compare_gemm_cpu_and_guarded_specialize() (all SSBO descriptors currently use offset = 0).

Independent Verification (Apple M5 Max / G17S, -Db_ndebug=false)

Merged acff27d1d0b5 onto origin/aurora-wip (1f65b8311587, clean merge):

  • Release build (-Db_ndebug=false -Dbuild-tests=true): clean (0 errors, 0 warnings in touched files).
  • meson test --suite asahi --suite poly: 203/203 PASS (hk_compute_pair OK, 1.14s).
  • Live Apple M5 Max Vulkan CTS (MESA_SHADER_CACHE_DISABLE=true):
    • dEQP-VK.api.smoke.*: 8/8 PASS (0 fail)
    • dEQP-VK.compute.pipeline.basic.*: 80/81 PASS (0 fail, 1 not supported)
    • dEQP-VK.compute.pipeline.cooperative_matrix.khr_a.subgroupscope.add.float32_float32.*: 6/6 PASS (0 fail)
  • dmesg GPU fault/hang delta: 0 (0 before / 0 after).
  • Core unguarded NIR generation, float-indexed guarded fast_a / rr / cc fallback loops, tile-width heuristic (hk_gemm_cmat_select_tile_n), and hk_gemm_cmat_can_specialize_unguarded() alignment predicates all look solid; once the hk_g17p_compute_shader_supported() guard on ug is added, this is ready to approve.

Signed-off-by: Diljit Singh <hey@djdev.me>
hk_select_gemm_cmat() checks the guarded cooperative-matrix kernel with
hk_g17p_compute_shader_supported() before using it. The unguarded kernel
that it compiles on first use was selected without that check. When the
unguarded kernel compiles but the chip cannot dispatch it, the dispatch
fails with VK_ERROR_FEATURE_NOT_PRESENT. Check the unguarded kernel the
same way and keep the guarded kernel when the check fails.

Extend the guarded-to-unguarded NIR-eval test with an A buffer that has
a nonzero descriptor offset and a nonzero member offset. The test runs
an exact K multiple, which must select the unguarded kernel, and K one
below that multiple, which must keep the guarded kernel. Both results
are compared against a CPU FP32 reference.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Author

Updated Head 55f253ebfc5d — Merge Conflict & Review Fixes + Exact-Head MacBook Neo (J700, G17P B1) PASS

  • Merged origin/aurora-wip (a7340499fe17, commit bf6f012c4ba): resolved hk_compute_pair.h enum and hk_cmd_dispatch.c conflicts cleanly (also merges cleanly onto current aurora-wip db6c64a2).
  • Addressed all open review items (commit 55f253ebfc5):
    • Guarded lazy unguarded compute shader ug in hk_cmd_dispatch.c with hk_g17p_compute_shader_supported(dev->dev.chip, ug, ug->only_linked, 1u << 16).
    • Added nonzero-A-offset boundary tests in test-hk-compute-pair.c verifying exact-K multiples select the unguarded kernel and K - 1 stays guarded, both checked against a CPU reference.
  • Warm Fedora --suite asahi CI: 203/203 Pass, 0 Fail, 0 Timeout (including hk_compute_pair); agent-policy.sh pr HEAD clean; 0 new compiler warnings.
  • Live MacBook Neo (J700, G17P B1 / AGX3B, release -Db_ndebug=true, 55f253ebfc5d vs a7340499fe17):
    • Strict ABBA offline Geekbench 6.7.1 Vulkan (20 iters/workload, 0 validation errors, 0 compiler warnings): Face Detection -0.98% (1,332-instr GEMM lowered to 664-instr unguarded kernel), Background Blur -0.01%, Horizon/Edge/Stereo flat (+0.02%..+0.25%); Particle Physics emitted byte-identical native code at fixed specialization constants (X=32 vs X=64 autotuner pick).
    • Targeted Vulkan CTS (2,576 cases: compute.pipeline.basic.*, glsl.loops.*, cooperative_matrix.khr_a.subgroupscope.*): 877 Pass, 1,699 NotSupported, 0 Fail.
    • gpubench-vk smoke: 10/10 valid: true, identical results.
    • Host health: kfault_delta=0, avc_delta=0, 0 failed systemd units (kernel 7.3.0-41.fc44.aurora.aarch64, 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 55f253ebfc5d

Blockers: none

Checked: Re-audited the full updated 7-file diff at 55f253ebfc5d (both open review items cleanly fixed: lazy unguarded ug specialization in hk_select_gemm_cmat() is now gated by hk_g17p_compute_shader_supported(dev->dev.chip, ug, ug->only_linked, 1u << 16), and the hk_compute_pair unit test suite now covers nonzero A descriptor and member offsets on both sides of the K tile boundary against a CPU reference); built with assertions enabled (-Db_ndebug=false), passed the full Asahi test suite (311/311), and verified live Borealis Vulkan compute and cooperative-matrix CTS on Mac Studio M5 Max (J775c, T6050) with 0 GPU faults.

Evidence
  • Review follow-ups verified:
    • src/asahi/vulkan/hk_cmd_dispatch.c: hk_select_gemm_cmat() now guards the lazy unguarded specialization swap on if (ug && hk_g17p_compute_shader_supported(dev->dev.chip, ug, ug->only_linked, 1u << 16)), falling back cleanly to the validated guarded cooperative-matrix shader if ug exceeds per-chip dispatch limits.
    • hk_compute_pair unit tests: eval_compare_gemm_cpu_and_guarded_specialize() tests nonzero a_extra_offset_B = 16 + descriptor_offset_B = 32 at both exact ks (specializes to unguarded) and ks - 1 (stays guarded) across all three tile widths (16, 32, 64), bit-exact against both the original shader and CPU FP32 reference.
  • Build & unit tests (-Dbuildtype=release -Db_ndebug=false -Dbuild-tests=true): meson test --suite asahi passed 311/311 (0 Fail, including hk_compute_pair in 1.16s).
  • Live Mac Studio M5 Max (J775c, T6050) Vulkan CTS (MESA_SHADER_CACHE_DISABLE=1, patched temp ICD libvulkan_asahi.so sha256:ccf53d31037b verified via LD_DEBUG=libs):
    • dEQP-VK.compute.pipeline.basic.*: 80/81 passed (0 failed, 1 not supported)
    • dEQP-VK.compute.pipeline.cooperative_matrix.khr_a.subgroupscope.add.float32_float32.*: 6/6 passed (0 failed)
    • dEQP-VK.subgroups.basic.compute.*: 12/12 passed (0 failed)
    • Kernel dmesg GPU fault delta: 0

@DjDeveloperr
DjDeveloperr merged commit 2d8f675 into aurora-wip Nov 25, 2026
@RyanTheTide
RyanTheTide deleted the perf/borealis-fd-phase2 branch November 27, 2026 13:20
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.

3 participants