Repository navigation
borealis: match unit-axis load_workgroup_id as global invocation id in compute matchers - #714
Conversation
…ol, fadd, and 4D pad kernels Signed-off-by: Diljit Singh <hey@djdev.me>
Fuse adjacent single-dispatch compute producer/pointwise-clamp pairs (depthwise convolution or tiled GEMM followed by a 1D FP32 clamp epilogue) at submit time in hk_pack_runs(), and add a generalized vec4 depthwise convolution alternate on native AGX3 and M5 GPUs. Round 2 review rework (RyanTheTide #688 + M5 cross-chip support): - Single-dispatch stream safety: invalidate cs->compute_pair on any second dispatch or stream merge (hk_cs_invalidate_compute_pair) and enforce hk_compute_pair_stream_eligible() on both producer and consumer streams at submit time so multi-command streams never drop extra dispatches, barriers, queries, or side effects. - Submit-time lazy fusion without shadow hk_cs or record_result hacks: keep a refcounted hk_compute_pair_producer holding the cloned preprocessed producer NIR and set layouts, lazily compile and cache up to 8 fused variants per producer under a mutex, emit fused CDM dispatches directly on HAL200 (G17P/G16) and HAL300 (M5), and pin every fused shader BO and the submission IOTO BO via hk_cmd_pending_begin(). - Zero core NIR changes: run compute-pair matchers directly in hk_compile_shaders() on post-preprocess NIR without adding fields to nir_shader. - Generalized matchers, splicer, and vec4 depthwise builder: support arbitrary finite FP32 clamp epilogues (lower-only, upper-only, or both in either order with preserved fp_math_ctrl and float_controls_execution_mode), biased/biasless/unconditional-bias depthwise kernels with arbitrary push layouts, arbitrary GEMM rows_per_thread (1..16) and 0/1/2/3 bias arms, and one unified hk_nir_splice_epilogue(). - Explicit field-by-field serialization of hk_compute_pair_info with no struct-padding reads; widen chip capability checks to agx_chip_native_or_m5(). - Add bit-exact NIR interpreter tests in test-hk-compute-pair.c and 20 stream-safety tests in test-hk-pack.c. Signed-off-by: Diljit Singh <hey@djdev.me>
|
I reviewed eff4d8b on top of #688 at d92fc36. This depends on #688 and cannot land before #688's direction is settled. It also inherits everything still open there and on #687: the shape-specific matchers (im2col push layout, pad4d dependence on the fdiv lowering, the GEMM store shape, the [0, 6] clamp only), the missing original-vs-alternate output checks, the submit-time fusion problem, and the missing M3/M4/M4 Pro rows. This PR makes those matchers fire on more application kernels, so those points matter more here, not less. Correctness of the new matching:
Scope: the WorkgroupID/GlobalInvocationID identity is general, but it only feeds matchers that recognize specific kernel shapes. A general version would canonicalize Tests (test-hk-compute-pair.c:837-884, test-hk-identity-copy4.c:756-801):
Evidence:
The frame-anatomy accounting in Assisted-by: LLM (Claude:Opus 5.5) |
MacBook Neo (
|
| Workload | #688 R3 (ms) |
#714 (ms) |
Ratio | Delta | Est Vk Score | Neo macOS Metal | % Metal |
|---|---|---|---|---|---|---|---|
| Face Detection | 48.937 | 48.982 | 0.999x | +0.09% | 5,766 | 27,571 | 20.9% |
| Background Blur | 37.638 | 37.662 | 0.999x | +0.06% | 5,942 | 13,388 | 44.4% |
| Horizon Detection | 33.666 | 33.757 | 0.997x | +0.27% | 21,110 | 28,664 | 73.6% |
| Edge Detection | 25.458 | 25.471 | 1.000x | +0.05% | 24,749 | 30,142 | 82.1% |
| Gaussian Blur | 53.787 | 53.978 | 0.996x | +0.35% | 10,193 | 33,051 | 30.8% |
| Feature Matching | 64.802 | 64.857 | 0.999x | +0.08% | 4,376 | 11,374 | 38.5% |
| Stereo Matching | 34.259 | 34.296 | 0.999x | +0.11% | 36,239 | 89,218 | 40.6% |
| Particle Physics | 135.727 | 135.746 | 1.000x | +0.01% | 31,290 | 69,542 | 45.0% |
| 8-WL Geomean / Overall | — | — | 0.999x | +0.13% | 13,171 | 30,474 | 43.2% |
Note on #714 firing on Neo G17P: Per-shader busy breakdown confirms unit-axis load_workgroup_id matching fired on Face Detection (unfused depthwise 4f3cfce1 dropped 9.134 -> 6.091 ms, unfused ReLU6 a1d5b26e dropped 8.877 -> 5.176 ms, replaced by 5 newly fused unit-axis variants). Stacked directly on #688 R3 (scalar depthwise/GEMM), total Face Detection busy time is neutral (+0.09%, zero regression), while unlocking full unit-axis depthwise_vec4 + ReLU6 fusion when stacked with #715 / Wave 2K.
Verdict: Clean exact-head Neo G17P B1 signoff (0 faults, 0 CTS fails, 13/13 matrixpair bit-exact).
Assisted-by: LLM (Antigravity:Gemini 4 Neon)
Because agx sets has_cs_global_id = true (agx_compile.h), nir_lower_compute_system_values() preserves load_global_invocation_id (+ load_base_workgroup_id * local_size) and never folds GlobalInvocationID into load_workgroup_id. Instead, load_workgroup_id (and load_workgroup_id + load_base_workgroup_id) appears when a compute shader's SPIR-V source reads WorkgroupId (gl_WorkGroupID) directly along a unit workgroup axis (local_size[axis] == 1, where LocalInvocationID == 0 so GlobalInvocationID[axis] == WorkgroupID[axis] + base_group[axis]). - Add shared header hk_nir_wgid.h with hk_nir_match_base_wg_scaled() (preserving 32-bit width checks and deduplicating the base-scaling helper across hk_nir_copy_identity4.c and hk_nir_match_pointwise_clamp.c) and hk_nir_dispatch_zero_base() (shared across the dispatch-time nonzero-base refusal gates in hk_cmd_dispatch.c and dispatch_covers()). - Document next to is_coord_id() and is_global_id_intr() that bare load_workgroup_id[axis] (no base term) equals GlobalInvocationID[axis] only together with the dispatch-time nonzero-base fallback checks. - Allow load_workgroup_id in the intrinsic whitelists and coordinate matchers for kernels reading gl_WorkGroupID on a unit axis: depthwise conv + clamp fusion (hk_nir_match_depthwise_output, hk_nir_match_pointwise_clamp), 2D im2col / 1x1 copy (match_im2col), linear copy/offset/fadd (match_linear_1d), 4D pad (match_pad4d), and tiled GEMM output (hk_nir_match_gemm_output). - Expand test-hk-identity-copy4.c and test-hk-compute-pair.c with hk_eval_dispatch orig-vs-alt bit-exact checks for all six matchers (both bare and + load_base_workgroup_id), negative checks (local_size > 1, wrong-axis base wg.y+base.x, wrong base scale wg.y+base.y*2, and wg.x used as row with local_size[0]=32), and nonzero-base fallback checks. Signed-off-by: Diljit Singh <hey@djdev.me>
Record fused compute pair dispatches via hk_frame_anatomy_note_fs() and hk_frame_anatomy_note_grid() in hk_emit_fused_compute_dispatch() when dev->frame_anatomy is active, matching standard dispatch_grid() attribution. Signed-off-by: Diljit Singh <hey@djdev.me>
eff4d8b to
18ddc64
Compare
|
@RyanTheTide Addressed all R1 review items at
|
d92fc36 to
85d3fbd
Compare
…is-unit-axis-wgid-match Take the final mesa#687 and round-2 mesa#688 code from ba16342 for every hunk this branch carried from their older copies, and keep this branch's own changes on top of it unchanged. Signed-off-by: Diljit Singh <hey@djdev.me>
aurora-wip now defines hk_nir_dispatch_zero_base() in hk_nir_root_size.h for workgroup coalescing. hk_cmd_dispatch.c includes both headers, so the second static inline copy in hk_nir_wgid.h is a redefinition. Include hk_nir_root_size.h from hk_nir_wgid.h and drop the copy. Both copies return true only when all three base_group values are zero. Signed-off-by: Diljit Singh <hey@djdev.me>
satchlj
left a comment
There was a problem hiding this comment.
Verdict at d92da162f759
APPROVE — Clean unit-axis load_workgroup_id matching across all Borealis compute matchers, shared zero-base dispatch handling via hk_nir_dispatch_zero_base(), and safe 64-bit frame anatomy accounting for fused compute dispatches.
Blockers
None.
Checked
- Full diff & caller audit (
7changed files,+778/-61):src/asahi/vulkan/hk_nir_wgid.h+src/asahi/vulkan/hk_nir_root_size.h:hk_nir_dispatch_zero_base()is cleanly shared between workgroup coalescing and the compute matchers;hk_nir_match_base_wg_scaled()enforces 32-bit definitions, exactlocal_size == 1unscaled match, exactimulbylocal_size, and exactishlbyffs(local_size) - 1for power-of-two sizes.src/asahi/vulkan/hk_nir_copy_identity4.c&src/asahi/vulkan/hk_nir_match_pointwise_clamp.c: all matchers refuseworkgroup_size_variable, gateload_workgroup_id[axis]strictly onlocal_size[axis] == 1, verify axis and stride, and depend on zero-base direct dispatch guards (hk_record_compute_pair(),hk_select_identity_copy4(),hk_select_depthwise_vec4(), anddispatch_covers()all reject nonzerobase_groupand indirect dispatches).src/asahi/vulkan/hk_cmd_dispatch.c:hk_emit_fused_compute_dispatch()records frame anatomy viahk_frame_anatomy_note_fs()andhk_frame_anatomy_note_grid()with 64-bitthreadsandwg ? threads / wg : 0guard.src/asahi/vulkan/tests/test-hk-identity-copy4.c&src/asahi/vulkan/tests/test-hk-compute-pair.c: unit coverage for unit-axisload_workgroup_idacceptance, non-unit-axis rejection, nonzero-base rejection, and semantic equivalence.- Commit metadata verified:
Signed-off-bytrailers present and merge againstorigin/aurora-wipis conflict-free.
- Build & unit tests (Apple M5 Max, Linux 7.3, GCC 16.1.1,
-Dbuildtype=release -Db_ndebug=false):- Clean full build (
2644/2644). meson test --suite asahi: 194/194 PASS (0fail) — includinghk_identity_copy4,hk_compute_pair,hk_pack, andagx_tests.
- Clean full build (
- Live GPU Vulkan CTS (Apple M5 Max,
MESA_SHADER_CACHE_DISABLE=1):dEQP-VK.compute.pipeline.basic.copy_ssbo*: 6/6 PASSdEQP-VK.compute.pipeline.basic.indirect_after_base_dispatch: 1/1 PASSdEQP-VK.compute.pipeline.basic.branch_past_barrier: 1/1 PASSdEQP-VK.compute.pipeline.basic.max_local_size_*: 3/3 PASSdEQP-VK.compute.pipeline.workgroup_memory_explicit_layout.zero_ext.*: 3/3 PASSdEQP-VK.subgroups.basic.compute.*: 12/12 PASSdEQP-VK.subgroups.arithmetic.compute.subgroupadd_float*: 4/4 PASS- Total live CTS: 30/30 PASS (
0fail,0GPU faults indmesg).
- Untested scope: End-to-end live Vulkan benchmark workloads (such as Whisper/ncnn/llama.cpp compute dispatch traces) exercising fused identity-copy / pointwise-clamp dispatch paths on hardware were not run directly; those paths were verified via the NIR unit test suite (
hk_identity_copy4,hk_compute_pair) and code audit.
Evidence
git merge-tree --write-tree origin/aurora-wip d92da162f759: clean merge againstorigin/aurora-wip(876b22c82bd8).meson test --suite asahi(-Dbuildtype=release -Db_ndebug=false):Ok: 194, Fail: 0, Skipped: 0.- Live Vulkan CTS on Apple M5 Max (
MESA_SHADER_CACHE_DISABLE=1):30/30passed acrossdEQP-VK.compute.pipeline.basic.*,dEQP-VK.compute.pipeline.workgroup_memory_explicit_layout.zero_ext.*, anddEQP-VK.subgroups.{basic,arithmetic}.compute.*;0GPU faults/warnings indmesg.
|
d92da16 J773g (M4 Mac mini, G16G B0) PASS. Exact-head release build without LLVM or SPIRV-Tools (
At --jobs 6 the same full compute run shows about 100 scattered fails that change from run to run. An older Mesa build without this PR shows the same groups (64 fails), and all of them pass at --jobs 1, so they come from the booted kernel's concurrent-compute issue (fixed by linux#3087, not booted here), not from this PR. Not covered: none of these shaders has a unit-size workgroup axis, so the new load_workgroup_id form is not exercised directly. The row shows the matchers still select and stay exact on G16G. |
The unit-axis depthwise test from #714 dispatched the vec4 alternate on the old 2D grid. Dispatch it on the 3D grid of the 8x8x2 layout here (channels / 4, output pairs, output rows), as hk_select_depthwise_vec4() does. Signed-off-by: Diljit Singh <hey@djdev.me>
Stacked on #688 R3 (
d92fc36fa6bb46264da5b2242fcf1a2e4c200acb, branchperf/hk-compute-pair-fusion-depthwise).Summary
When a compute shader has a unit workgroup dimension (
local_size[axis] == 1),nir_lower_system_valuesfoldsGlobalInvocationID[axis]directly toload_workgroup_id[axis](and+ load_base_workgroup_id[axis]when base workgroup offsets are active) instead ofload_global_invocation_id[axis].src/asahi/vulkan/hk_nir_copy_identity4.c):is_coord_id()andis_base_wg_scaled()socoord()acceptsload_workgroup_id[axis]strictly whenlocal_size == 1(and both bareload_base_workgroup_id[axis]andimul/ishl-scaled forms).nir_intrinsic_load_workgroup_idin the three matcher intrinsic whitelists (collect_accesses,match_linear_1d,match_pad4d).src/asahi/vulkan/hk_nir_match_pointwise_clamp.c):is_global_id_intr()sosysval_id_axis()acceptsload_workgroup_id[axis]strictly whenlocal_size && local_size[axis] == 1(bare or+ match_base_wg_scaled(...)).nir_intrinsic_load_workgroup_idin the three matcher intrinsic whitelists (hk_nir_match_pointwise_clamp,match_depthwise,hk_nir_match_gemm_output).src/asahi/vulkan/hk_cmd_dispatch.c):hk_frame_anatomy_note_fs()andhk_frame_anatomy_note_grid()inhk_emit_fused_compute_dispatch()whendev->frame_anatomyis active, matchingdispatch_grid().test-hk-compute-pair.c,test-hk-identity-copy4.c):HK_EVAL_CHECK-based tests coveringwg=32x1x1(load_workgroup_id.ybare and+ load_base_workgroup_id.y, must match and emit valid vec4 NIR) andwg=32x2x1(must reject).Exact-Head Verification — M5 Pro (
J714s/G17S B1/AGX3C)Head SHA:
eff4d8b676f715ec48eed07c8cfcf9fc083d26cd(built with-Dbuildtype=release -Db_ndebug=true,MESA_SHADER_CACHE_DISABLE=1,taskset -c 12-17).meson test --suite asahi(-DNDEBUG)hk_identity_copy4OK,hk_compute_pairOK,hk_packOK,agx_testsOK)gb-gaussian(checked, 6 vertical + 6 horizontal)/tmp/cts-mega12.txt, 678 cases)HK_PACK_CDM_TRACE=1live fusion20/20iters), 48/48 Face Detection fused (20/20iters)HK_FRAME_ANATOMY_TS=all)91 → 128dispatches/iter in Background Blur,135 → 183in Face Detection); 0 spills (0/24,415cs entries)dmesg)4 → 4)DEFAULT_BRANCH=aurora-wip bash .github/aurora/agent-policy.sh prPR head is clean)Isolated Exact-Head A/B vs
#688R3 (d92fc36fa6bb→eff4d8b676f)Measured GPU busy/iter median (
measured-busy.py,HK_FRAME_ANATOMY_TS=all, 20 measured iterations,0spills,0GPU faults):#688R3 (d92fc36fa6bb)eff4d8b676f)6.949 ms6.951 ms+0.002 ms (+0.03%)8.871 ms8.905 ms+0.034 ms (+0.38%)6.191 ms6.194 ms+0.003 ms (+0.05%)4.936 ms4.969 ms+0.034 ms (+0.68%)6.992 ms6.993 ms+0.000 ms (+0.00%)15.899 ms15.685 ms-0.214 ms (-1.35%)7.399 ms7.404 ms+0.005 ms (+0.07%)24.624 ms24.641 ms+0.016 ms (+0.07%)(Ready for Neo
G17P B1verification row.)