Commit da0b67c
committed
perf(metal): recorded ICB fans global-layer SDPA over the 2-pass pair — deep decode un-collapsed
The arch ICB recorded MLX's single-pass sdpa_vector once at session open: one
threadgroup per head serially streaming the WHOLE cache. The re-encode lane's
sdpa2PassMinKV switch cannot happen inside a recorded command buffer, so decode
at depth collapsed far below bandwidth physics (E2B @52k: 44 tok/s measured vs
~115 expected from the ~6% attention-read overhead; E4B worse — more globals).
GLOBAL layers now record the 2-pass pair: sdpa_vector_2pass_1 (blocks baked as
function constant 26, supportIndirectCommandBuffers; N bound via the rebindable
nGlobalBuf; K/V at binds 1/2 exactly as the single-pass op so the replay's rebind
indices are untouched) + the 2pass_2 merge. Sliding layers keep single-pass —
their window bounds n below the knee. blocks = sdpa2PassBlocks(maxLen), fixed at
record time and safe at ANY smaller n: a block whose strided key walk starts past
N writes finite_min/0 partials the merge zeroes. Gated on maxLen >= 1024 so short
sessions — and every synthetic byte-parity fixture — keep the pure single-pass
layout. Shared per-replay partials/sums/maxs + scalarI32(blocks) are registered
resident (an ICB op reading a non-resident buffer is undefined — the #343 class).
New plumbing: emitSDPA2Pass1NAt (N-from-buffer variant of the shared emitter),
sdpaVector2Pass1PipelineICB / sdpaVector2Pass2PipelineICB.
Receipts (E2B 4bit, tg128 temp0 think, quiet GPU): 6.6K 126.4 -> 149.7, 26K 71.0
-> 136.7, 52K 44.0 -> 114.4 (the physics prediction), 97K 25.7 -> 87.7 (+241%).
Zero-depth unregressed: E2B 175.2, 26B MoE 146.0. Deep-session (131072) tokens
byte-identical to the single-pass receipt and deterministic across reps; ICB
parity suites green; full engine/metal suite 1436 green.
Co-Authored-By: Virgil <virgil@lethean.io>1 parent 582409b commit da0b67c
3 files changed
Lines changed: 159 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1210 | 1210 | | |
1211 | 1211 | | |
1212 | 1212 | | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
1213 | 1250 | | |
1214 | 1251 | | |
1215 | 1252 | | |
| |||
1411 | 1448 | | |
1412 | 1449 | | |
1413 | 1450 | | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
1414 | 1465 | | |
1415 | 1466 | | |
1416 | 1467 | | |
| |||
1538 | 1589 | | |
1539 | 1590 | | |
1540 | 1591 | | |
1541 | | - | |
| 1592 | + | |
| 1593 | + | |
1542 | 1594 | | |
1543 | 1595 | | |
1544 | 1596 | | |
| |||
1743 | 1795 | | |
1744 | 1796 | | |
1745 | 1797 | | |
1746 | | - | |
1747 | | - | |
1748 | | - | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
1749 | 1815 | | |
1750 | 1816 | | |
1751 | 1817 | | |
| |||
1846 | 1912 | | |
1847 | 1913 | | |
1848 | 1914 | | |
1849 | | - | |
| 1915 | + | |
1850 | 1916 | | |
1851 | 1917 | | |
1852 | 1918 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
388 | | - | |
| 388 | + | |
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
394 | 404 | | |
395 | 405 | | |
396 | 406 | | |
397 | 407 | | |
398 | 408 | | |
399 | 409 | | |
400 | 410 | | |
401 | | - | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
402 | 416 | | |
403 | 417 | | |
404 | 418 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
463 | 463 | | |
464 | 464 | | |
465 | 465 | | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
466 | 538 | | |
467 | 539 | | |
468 | 540 | | |
| |||
0 commit comments