Repository navigation
Borealis: add unguarded cooperative-matrix GEMM variants and float-indexed K loads - #777
Conversation
|
Review at d7a2f37.
|
…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>
d7a2f37 to
51aeb56
Compare
Bare-Metal M5 Pro (
|
| 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).
|
Thanks for the thorough review at 4-PR Split Overview (all stacked independently on
|
| 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
- Guarded -> unguarded
cmatNIR-eval boundary tests (#777R2): Added NIR-eval tests specializing a guarded producer into*_UNGUARDEDat both exact-multiple and multiple-minus-1 forM,N, andKacrosscmat16/32/64. - NIR-derived loop bounds, zero hand magic constants (
#796): Added pure-Chk_pack_loop_bound.h+ header-onlyhk_nir_loop_bound.hwalking 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. Instrumentedhk_nir_eval_test.hto assertevaluated_bound >= max_dynamic_backedges + 1on real emittedim2col_vec4,depthwise_vec4, guardedgemm_cmat, andDUAL_PAD4(simple_padand!simple_padzlp), plus negative fail-closed tests. - Submit-time
DUAL_PAD4& fusion pack re-accounting (#796):hk_pack_fusion_fits_run()inhk_queue.cre-accounts submit-time fused variants (includingDUAL_PAD4border +!simple_padzero-fill loopzlp) againstHK_PACK_MAX_STATIC_WORKandrun_loops <= 1, with unit tests verifying budget enforcement. - Generalization & shape sweep (
#777R2 ̞):- 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 nonzerouint32_t d >= 1, preamble-hoisted uniform setup, verified across 2,368 bit-exact divisor/numerator pairs intest_fast_udivmod_general). - Added 12-shape GEMM (
#777R2) and 9-shape depthwise (#798) sweeps against independent scalar CPU FP32 references (covering oddN,K%4!=0,K<32, edgeM, oddout_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.
- 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. - 4-PR split: Done —
#777R2,#795,#796, and#798are independent PRs with zero perf changes riding in#796. Signed-off-byconsistency: Standardized all commits across all 4 PRs toSigned-off-by: Diljit Singh <hey@djdev.me>.- 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)
Exact-Head MacBook Neo (
|
| 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)
M4 Hardware Verification (
|
Exact-Head MacBook Neo (
|
| 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)
G17S B1 (
|
Neo (
|
| 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
left a comment
There was a problem hiding this comment.
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>
Exact-Head Hardware Verification — MacBook Neo (
|
satchlj
left a comment
There was a problem hiding this comment.
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
- 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 withhk_g17p_compute_shader_supported(dev->dev.chip, alt, alt->only_linked, 1u << 16)before accepting it. - However, at lines
4192–4198, whenhk_gemm_cmat_can_specialize_unguarded(...)succeeds, it callsug = hk_compute_pair_get_or_compile_fused(dev, api->compute_pair_producer, NULL, ug_kind, HK_COMPUTE_PAIR_DUAL_NONE)and unconditionally switchesalt = ug; chosen_kind = ug_kind;ifug != NULL— without checkinghk_g17p_compute_shader_supported(dev->dev.chip, ug, ug->only_linked, 1u << 16)(contrasthk_queue.c:3489, which guards everyhk_compute_pair_get_or_compile_fused()return withhk_fused_compute_shader_eligible()). - If
ugcompiles cleanly but exceeds per-chip compute dispatch limits (spill/scratch/threadgroup constraints),dispatch_grid_shader()handsugtohk_dispatch_with_local_size(), which setsVK_ERROR_FEATURE_NOT_PRESENTon the command buffer instead of falling back cleanly to the already-validated guardedalt. - Fix: Gate the swap on
if (ug && hk_g17p_compute_shader_supported(dev->dev.chip, ug, ug->only_linked, 1u << 16))(matching line4122).
- At lines
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-multipleKis still uncovered ineval_compare_gemm_cpu_and_guarded_specialize()(all SSBO descriptors currently useoffset = 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 (0errors,0warnings in touched files). meson test --suite asahi --suite poly: 203/203 PASS (hk_compute_pairOK,1.14s).- Live Apple M5 Max Vulkan CTS (
MESA_SHADER_CACHE_DISABLE=true):dEQP-VK.api.smoke.*: 8/8 PASS (0fail)dEQP-VK.compute.pipeline.basic.*: 80/81 PASS (0fail,1not supported)dEQP-VK.compute.pipeline.cooperative_matrix.khr_a.subgroupscope.add.float32_float32.*: 6/6 PASS (0fail)
dmesgGPU fault/hang delta:0(0before /0after).- Core unguarded NIR generation, float-indexed guarded
fast_a/rr/ccfallback loops, tile-width heuristic (hk_gemm_cmat_select_tile_n), andhk_gemm_cmat_can_specialize_unguarded()alignment predicates all look solid; once thehk_g17p_compute_shader_supported()guard onugis 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>
Updated Head
|
satchlj
left a comment
There was a problem hiding this comment.
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 onif (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 ifugexceeds per-chip dispatch limits.hk_compute_pairunit tests:eval_compare_gemm_cpu_and_guarded_specialize()tests nonzeroa_extra_offset_B = 16+descriptor_offset_B = 32at both exactks(specializes to unguarded) andks - 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 asahipassed 311/311 (0Fail, includinghk_compute_pairin1.16s). - Live Mac Studio M5 Max (J775c, T6050) Vulkan CTS (
MESA_SHADER_CACHE_DISABLE=1, patched temp ICDlibvulkan_asahi.sosha256:ccf53d31037bverified viaLD_DEBUG=libs):dEQP-VK.compute.pipeline.basic.*: 80/81 passed (0failed,1not supported)dEQP-VK.compute.pipeline.cooperative_matrix.khr_a.subgroupscope.add.float32_float32.*: 6/6 passed (0failed)dEQP-VK.subgroups.basic.compute.*: 12/12 passed (0failed)- Kernel dmesg GPU fault delta: 0
Split 1 of 4 from the original #777 series per
@RyanTheTide's review (#issuecomment-7091552245). Stacked on #749 (1f8c1036ea69).Summary
cmat16/cmat32/cmat64): When a guarded GEMM dispatch has validated descriptor ranges, exact tile-alignedM % tile_m == 0,N % tile_n == 0,K % k_step == 0, and a 16-byte-aligned A buffer, specialize to the unguardedcmatvariant (hk_gemm_cmat_can_specialize_unguarded()), eliminating per-element bounds predicates and scalar A-tail loops.Kdimensions safely take the cooperative-matrix path, and refinehk_gemm_cmat_select_tile_n()(cmat64whenN > 32, evenceil(N/32), andK >= 32;cmat16forN <= 16;cmat32otherwise).51aeb56580f):*_UNGUARDEDat exact-multiple and multiple-minus-1 forM,N, andK(and misaligned A) acrosscmat16/cmat32/cmat64(test_gemm_cmat_guarded_specialize_and_shape_sweep()).N,K % 4 != 0,K < 32, edgeM, all bias modes) verified bit-exact against both the original producer NIR and an independent CPU FP32 reference.Signed-off-by: Diljit Singh <hey@djdev.me>.LINEAR_FADDdual-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 undersrc/asahi/vulkan/.Verification (exact head
51aeb56580f)hk_compute_pair_testPASS,hk_identity_copy4_testPASS,hk_pack_test197/0PASS.DEFAULT_BRANCH=aurora-wip .github/aurora/agent-policy.sh pr HEAD->PR head is clean.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.