Commit 154ce8f
committed
fix(path-c): split Metal FORWARD fused mega-kernel (chain_3_7) to clear MTLCompilerService XPC crash at newComputePipelineState
ROOT CAUSE (verified, full local_gb10_quarter: depth=13 hidden=3584 max_seq=4096):
The greedy direct-chain planner fuses each FORWARD segment up to the portable
kernel-buffer limit, producing the 4-op forward mega-kernel
m2rnn + residual_rmsnorm + attention_qkv_projection + sparse_mla_fp8_apply
(region local_gb10_quarter_path_c_10_12_chain_3_7). Its generated MSL device
kernel is ~176-199 KB / ~1600-2211 lines, dominated by attention_qkv_projection
(207 refs) + sparse_mla_fp8_apply (199 refs) -- a sparse top-k FP8 attention with
RoPE + softmax inlined into ONE monolithic `kernel void`. TileLang codegen +
metallib build SUCCEED (~3s, exit 0), but at runtime Metal's MTLCompilerService
crashes the final AIR->GPU-ISA pipeline-state stage inside newComputePipelineState
(lazy, inside mx.eval at tilelang tvm_ffi adapter):
InternalError: Check failed: (state != nullptr): ... for function
local_gb10_quarter_path_c_10_12_chain_3_7_kernel Compilation failed due to an
interrupted connection: XPC_ERROR_CONNECTION_INTERRUPTED.
Deterministic (3/3 runs), ~3.8s, at exec#1 on the FORWARD chain -- gates the whole
route (backward never reached). Reproduces on baseline 097693e.
Measured shader-size hierarchy (device MSL):
chain_0_3 (3 light fwd ops) ~46 KB / 669 L -> pipeline OK
chain_7_10 (3 bwd ops) ~116 KB / 1555 L -> pipeline OK
chain_3_7 (4 heavy fwd ops) ~176-199 KB -> pipeline CRASH
FIX (option a: split the fused forward segment on Metal, explicit by target):
plan_path_c_direct_fusion_chain_for_region gains forward_max_segment_nodes, a
FORWARD-only op-count cap resolved at call time from the lowering target --
METAL_FORWARD_MAX_SEGMENT_NODES = 2 on Metal, None (uncapped) on CUDA (CUDA's
compiler has no pipeline-state size limit, so CUDA fusion is byte-for-byte
unchanged). The cap is forward-only; backward keeps greedy fusion up to the
buffer limit (its reverse-time watchdog split via launcher_chunks is separate).
Selection is explicit by target, NOT a silent runtime fallback (RULE #1).
RESULT (verified, full scale): the 4-op chain_3_7 is eliminated; the forward phase
is now 4 split segments, each well under the crashing size:
chain_0_2 entry_rmsnorm+mamba3_mimo ~46 KB / 709 L
chain_2_4 residual_rmsnorm+m2rnn ~36 KB / 599 L
chain_4_6 residual_rmsnorm+attention_qkv_projection ~93 KB / 861 L
chain_6_7 sparse_mla_fp8_apply ~91 KB / 1056 L
All 4 forward segments now CREATE their Metal pipeline state (NO
XPC_ERROR_CONNECTION_INTERRUPTED) and EXECUTE. The full-scale forward route gets
fully past exec#1; execution proceeds into the backward phase and reaches a
DIFFERENT, separate failure -- a GPU watchdog timeout
(kIOGPUCommandBufferCallbackErrorTimeout) at the first backward segment
(chain_7_10) -- which is progress (a pre-existing backward-chain issue), not the
forward megakernel crash. The forward-only standalone executor test confirms the
forward phase executes status=ok end-to-end at smoke scale.
Side effect (benign): splitting sparse_mla_fp8_apply into its own segment makes
its int32 sparse-index scratch (path_c_int32_scratch_bank) kernel-internal rather
than a coalesced cross-segment logical scratch bank -> one fewer required logical
buffer (94->93). Updated the smoke-scale executor/route tests to the new correct
Metal grouping (7->9 segments, 2->4 forward, time-chunked bwd indices {3,5}->{5,7},
buffer counts shifted by the dropped int32 scratch bank). CUDA grouping unchanged.
Pre-existing failures NOT touched (confirmed identical on baseline 097693e):
test_plan_path_c_direct_fusion_chains_for_model_uses_dynamic_brick_chain,
test_direct_fusion_chain_splits_model_route_under_metal_buffer_limit,
test_direct_fusion_chain_keeps_loss_bridge_forward_boundary_separate
(stale "blocked" assertions -- mamba3_mimo_bwd no longer blocks),
test_path_c_direct_chain_runtime_value_and_grad_* (broken 'tokens' batch fixture).1 parent 097693e commit 154ce8f
3 files changed
Lines changed: 335 additions & 21 deletions
File tree
- cppmega_mlx/runtime
- scripts
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
212 | 249 | | |
213 | 250 | | |
214 | 251 | | |
| |||
14190 | 14227 | | |
14191 | 14228 | | |
14192 | 14229 | | |
| 14230 | + | |
| 14231 | + | |
| 14232 | + | |
14193 | 14233 | | |
14194 | 14234 | | |
14195 | 14235 | | |
| |||
14198 | 14238 | | |
14199 | 14239 | | |
14200 | 14240 | | |
| 14241 | + | |
| 14242 | + | |
| 14243 | + | |
| 14244 | + | |
| 14245 | + | |
| 14246 | + | |
| 14247 | + | |
| 14248 | + | |
| 14249 | + | |
| 14250 | + | |
| 14251 | + | |
| 14252 | + | |
| 14253 | + | |
| 14254 | + | |
| 14255 | + | |
| 14256 | + | |
14201 | 14257 | | |
14202 | 14258 | | |
14203 | 14259 | | |
| |||
14206 | 14262 | | |
14207 | 14263 | | |
14208 | 14264 | | |
| 14265 | + | |
| 14266 | + | |
| 14267 | + | |
| 14268 | + | |
| 14269 | + | |
| 14270 | + | |
| 14271 | + | |
| 14272 | + | |
| 14273 | + | |
| 14274 | + | |
| 14275 | + | |
| 14276 | + | |
| 14277 | + | |
| 14278 | + | |
| 14279 | + | |
| 14280 | + | |
| 14281 | + | |
14209 | 14282 | | |
14210 | 14283 | | |
14211 | 14284 | | |
| |||
14244 | 14317 | | |
14245 | 14318 | | |
14246 | 14319 | | |
| 14320 | + | |
| 14321 | + | |
| 14322 | + | |
| 14323 | + | |
| 14324 | + | |
| 14325 | + | |
| 14326 | + | |
| 14327 | + | |
| 14328 | + | |
| 14329 | + | |
| 14330 | + | |
| 14331 | + | |
| 14332 | + | |
| 14333 | + | |
| 14334 | + | |
| 14335 | + | |
| 14336 | + | |
| 14337 | + | |
14247 | 14338 | | |
14248 | 14339 | | |
14249 | 14340 | | |
| |||
14386 | 14477 | | |
14387 | 14478 | | |
14388 | 14479 | | |
| 14480 | + | |
| 14481 | + | |
| 14482 | + | |
14389 | 14483 | | |
14390 | 14484 | | |
14391 | 14485 | | |
| |||
14395 | 14489 | | |
14396 | 14490 | | |
14397 | 14491 | | |
| 14492 | + | |
| 14493 | + | |
| 14494 | + | |
| 14495 | + | |
14398 | 14496 | | |
14399 | 14497 | | |
14400 | 14498 | | |
| |||
14410 | 14508 | | |
14411 | 14509 | | |
14412 | 14510 | | |
| 14511 | + | |
14413 | 14512 | | |
14414 | 14513 | | |
14415 | 14514 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
0 commit comments