Repository navigation
hk: fuse compute producer/clamp pairs lazily and widen depthwise to vec4 - #688
Conversation
|
I reviewed the commit on top of #687 at 2c06578.
Assisted-by: LLM (Claude:Opus 5.5) |
4300093 to
d74cf83
Compare
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>
2c06578 to
d917335
Compare
|
Thanks for the thorough review
Assisted-by: LLM (Antigravity:Gemini 4 Neon) |
|
Clean-room Apple M5 Pro ( 1. Correctness & Stability
2. Three Concrete Findings on M5 Pro (
|
|
Follow-up on Apple M5 Pro ( Exact Root Causes & Minimal Fixes (3 surgical hunks)
Live M5 Pro Verification Results (stacked
|
d74cf83 to
7f319bd
Compare
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>
d917335 to
d92fc36
Compare
|
Pushed R3 (
Assisted-by: LLM (Antigravity:Gemini 4 Neon) |
Clean-room M5 Pro (
|
| Check | Result |
|---|---|
meson test --suite asahi (-Db_ndebug=true) |
157/157 OK, 0 fail (hk_identity_copy4 OK 0.01s, hk_compute_pair OK 0.02s, hk_pack OK 1.12s) |
HK_PACK_CDM_TRACE=1 live fusion counts (GB6 Vulkan) |
Background Blur: 37/37 per iter (740 total across 20/20 iters); Face Detection: 48/48 per iter (960 total across 20/20 iters) |
gb-gaussian (checked, 2 repeats/case) |
12/12 PASS (bit-exact vs CPU reference) |
Vulkan CTS 1.4.7.1 (/tmp/cts-mega12.txt) |
522/678 pass / 0 fail / 0 warn / 156 unsupported |
Geekbench 6.7.1 Vulkan spills (sp>0) & dmesg |
0 spills / 0 new dmesg lines / 0 GPU faults |
Interleaved A/B/C -> C/B/A Geekbench 6.7.1 Vulkan (busy/iter median ms, HK_FRAME_ANATOMY_TS=all)
| Workload | Base f3016978f09e (avg) |
#687 R3 7f319bd7a50f (avg) |
#688 R3 d92fc36fa6bb (C1 / C2 / avg) |
#688 vs #687 |
#688 vs Base |
|---|---|---|---|---|---|
| Background Blur | 7.410 | 7.287 | 6.943 / 6.943 (6.943) |
-4.72% (1.050x) | -6.31% (1.067x) |
| Face Detection | 10.961 | 10.451 | 8.910 / 8.904 (8.907) |
-14.78% (1.173x) | -18.74% (1.231x) |
| Horizon Detection | 6.149 | 6.172 | 6.186 / 6.181 (6.184) |
+0.18% | +0.56% |
| Edge Detection | 4.960 | 4.936 | 4.962 / 4.962 (4.962) |
+0.53% | +0.05% |
| Gaussian Blur | 6.984 | 6.986 | 6.989 / 6.989 (6.989) |
+0.04% | +0.06% |
| Feature Matching | 15.823 | 15.843 | 15.787 / 15.705 (15.746) |
-0.61% | -0.49% |
| Stereo Matching | 7.239 | 7.398 | 7.086 / 7.395 (7.240) |
-2.13% | +0.01% |
| Particle Physics | 24.646 | 24.631 | 24.615 / 24.627 (24.621) |
-0.04% | -0.10% |
| 8-WL Geomean | 1.0000x | 1.0054x | 1.0345x vs Base | 1.0290x (-2.82%) |
1.0345x (-3.34%) |
M5 Pro (AGX3C) signoff: GREEN (37/37 BG Blur & 48/48 Face Detection live fusions, -14.78% Face Detection / -4.72% Background Blur over #687 R3, 157/157 release unit tests, 12/12 gb-gaussian, 0 CTS fails, 0 spills, 0 GPU faults).
Assisted-by: LLM (Antigravity:Gemini 4 Neon)
…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>
7f319bd to
0f86446
Compare
d92fc36 to
85d3fbd
Compare
|
Ported onto rebased Port summary:
|
0f86446 to
0b79f9e
Compare
9574085 to
ba75e6a
Compare
Signed-off-by: Diljit Singh <hey@djdev.me>
|
Verdict at BlockersNone. Checked
|
Summary
Fuse adjacent single-dispatch compute producer/pointwise-clamp pairs (depthwise convolution or tiled GEMM followed by a 1D FP32 clamp epilogue) lazily at submit time in
hk_pack_runs(), and add a generalized vec4 depthwise convolution alternate on native AGX3 and M5 GPUs (agx_chip_native_or_m5()).Stacked on
#687(perf/hk-vec4-compute-alternates@d74cf837d62eb6cb0819a3223e7674de35b7ac44).Round 2 Changes (Addressing
@RyanTheTide#issuecomment-7076609180+ M5 Cross-Chip Support)hk_cs_invalidate_compute_pair(cs)clearscs->compute_pairon any second dispatch (dispatch_grid()), stream merge (hk_cs_merge_cdm_until()), or stream teardown (hk_cs_destroy()).hk_compute_pair_stream_eligible(cs)enforces strict single-dispatch CDM invariants (stats.cmds == 1 && stats.calls == 1 && pack_dispatches == 1, nostream_linked,calls_stream,sib_indirect,uses_global_atomics,imm_writes,query_access,query_reset_pending, timestamps,gen1_native_rq,as_build,alias_sites, org18_dispatch_sealed) on both producer and consumer streams at submit time.hk_csorrecord_resulthacks:hk_csallocation (compute_pair_alternate) andcmd->vk.record_result = VK_SUCCESSmutation.struct hk_compute_pair_producerholds cloned preprocessed producer NIR and references onset_layouts[], lazily compiling and caching up to 8 fused shader variants per producer undersimple_mtx_t.hk_emit_fused_compute_dispatch()emits fused CDM dispatches directly into a submission-owned IOTO BO (AGX_BO_EXEC | AGX_BO_LOW_VA) supporting both HAL200 (G17P/G16) and HAL300 (M5), with clean unfused fallback on failure.hk_cmd_pending_begin()to acceptextra_bos/extra_bo_countso every fused shader BO and submission IOTO BO is pinned for the lifetime of the submission.src/compiler/nir/{nir.h,nir_clone.c,nir_serialize.c}(0 lines diff vs#687R2).hk_compile_shaders()on post-preprocess NIR without adding fields tonir_shader.depthwise_vec4:fmax(x, lo), upper-onlyfmin(x, hi), or both in either order (fmin(fmax(x, lo), hi)/fmax(fmin(x, hi), lo)), arbitrary finite bounds, preservedfp_math_ctrl(validated againstnir_op_infos[fmin/fmax].valid_fp_math_ctrl) and matchingfloat_controls_execution_mode.hk_nir_build_depthwise_vec4(..., epilogue)supporting biased (flag-guarded or unconditional) and biasless kernels with arbitrary push-constant layouts.rows_per_thread, guarded or unguarded stores, and 0/1/2/3 bias arms (both store-per-arm and load-per-arm forms).hk_nir_splice_epilogue().hk_compute_pair_info_serialize()/hk_compute_pair_info_deserialize()(zero struct-padding reads).agx_chip_native_agx3()toagx_chip_native_or_m5()so M5 (G17G/G17S/G17C) gets full compute-pair fusion anddepthwise_vec4support out of the box.Verification
FEDORA-CI:158/0PASS ond91733575ad20a3b3c015d54ed1b4a4986b0a724(0 failures, 0 skipped, includes newhk_compute_pair_test+ updatedhk_pack_test).test-hk-compute-pair: bit-exacthk_eval_dispatchverification across all 5 clamp shapes (G17P + M5 preprocess), biased/biasless/unconditional-biasdepthwise_vec4+ fused variants, and generalized GEMM (4 & 8 rows/thread, 0/1/2/3 bias modes, guarded/unguarded).test-hk-pack:190 tests, 0 failures(20 newtest_compute_pair_stream_safetyassertions).DEFAULT_BRANCH=aurora-wip .github/aurora/agent-policy.sh pr HEAD: clean.