Skip to content

ggml-agx: Bare-metal Apple Silicon AGX3 backend for M4 Max (Inkling 2 Mini + DSpark) - #2

Draft
astaff wants to merge 160 commits into
masterfrom
agx/ggml-agx
Draft

astaff wants to merge 160 commits into
masterfrom
agx/ggml-agx

Conversation

@astaff

@astaff astaff commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

ggml-agx: Bare-Metal Apple Silicon AGX3 (drm_asahi + CDM + Borealis) Backend for llama.cpp

A six-pillar bare-metal compute backend targeting Apple Silicon AGX3 (G16C B1 / M4 Max, 40 cores, 4 clusters x 10 cores, 1578 MHz, aurora drm_asahi, HAL200/G17P CDM + Borealis JIT compiler, coopmat=1) with first-class support for Inkling 2 Mini (looped 48-pass MoE, 128 experts top-8, NVFP4 + Q8_0 + BF16 + F32, hybrid SWA/Full attention, shortconv, FWHT, SITU) and DSpark speculative decoding.

Architecture (Six Pillars)

  1. Pillar 1 — Bare-Metal drm_asahi + HAL200/G17P CDM + Borealis (agx-drm, agx-cdm, agx-compiler, ggml-agx.cpp)
    • Direct DRM_IOCTL_ASAHI_SUBMIT CDM command stream submission with zero-encode steady-state CDM graph replay (GGML_AGX_NO_REPLAY=1 toggle, atomic bo_epoch/record_gen invalidation -> cpu_encode = 0.000 ms, drm_oh = 0.141 ms), 256-slot Fibonacci fast cache, baked arg_bo hi32 + precomputed G17P launch headers (32.5 ns/dispatch cold encode), 40-bit USC executable Ioto arena (AGX_BO_EXEC), SLC cache policy separation (SLC_STREAM vs SLC_PIN vs DEVICE_LOCAL), 32 MiB auto-flushing arg ring, persistent timeline syncobj with ASAHI_BARRIER_NONE on retired synchronous submits, and zero-split offload (AGX0 + AGX0_Repack).
    • Online GLSL -> SPIR-V -> Borealis AGX3B native binary compilation with strict hardware shaderdb 0:0 spill & <= 96 GPR32 auditing.
  2. Pillar 2 — FTZ-Safe Weight Repacking & Software-Pipelined 8x8 MMA GEMM (agx-repack, agx-gemm, kernels/{dequant_supertile,nvfp4_vecmat,mxfp8_q8_vecmat,agx_mma_gemm})
    • Lossless NVFP4_32x16 and Q8_0_8BLK supertile repacking with 6-op branchless min(raw, fma(raw, 2h, -1h)) SWAR2 E2M1 -> f16vec2 and overflow-proof Q8_0 magic-bias decoding, full F32/F16/BF16/Q8_0/NVFP4/MXFP8 support.
    • Vectorized M <= 8 vecmat (482.30 GB/s NVFP4, 517.68 GB/s Q8_0 LM head) and 4x1 TILE_K=32 split-phase software-pipelined 8x8 simdgroup_matrix (coopmat=1) prefill GEMM on double-buffered 0-bank-conflict sh_x (8.48 / 8.29 TFLOPS NVFP4/Q8_0).
  3. Pillar 3 — VA-Dependency Wave Scheduler, Q8_0 SET_ROWS, Inkling 2 Mini DAG Fusion & DSpark MTP (agx-inkling2, agx-graph-exec, kernels/{fused_ctrl_gates_sram,fused_loop_prep_qkv_conv,fused_softcap_argmax,dspark_mtp})
    • Exact ASAP VA-dependency wave scheduler (RAW/WAR/WAW + internal scratch, toggleable via GGML_AGX_NO_WAVE_SCHED=1): cuts B=1 STRONG_USC barriers 3,408 -> 2,039 (-40.2%) and dispatches 4,239 -> 2,806 (-33.8%) with cos = 1.00000000 vs unfused AGX0.
    • Full GGML_TYPE_Q8_0 SET_ROWS support (enabling -ctk q8_0 -ctv q8_0 with 0 CPU splits!) + 13 gallocr-safe DAG fusions (prep_norm_fwht_store, full_shortconv, rel_bias_gather, router_topk_norm, LLM_FFN_SITU, SOFTCAP, control() 13-op DAG, mix() depth-mix attention, moe_wsum, RMS_NORM*w, ADD->SCALE, SIGMOID->MUL, L2_CLIP, plus GGML_OP_ARANGE).
  4. Pillar 4 — Hybrid SWA/Full 8x8 coopmat Flash Attention (agx-kv-hybrid, kernels/{fused_swa_ring_attn,fused_full_flash_decode})
    • Unified GGML_OP_FLASH_ATTN_EXT with F16/F32/BF16/Q8_0 KV (magic-bias Q8_0 KV decode, 0 spills), GQA, causal/SWA masks, logit softcapping, learned attention sinks, Flash-Decoding split-KV reduction, PASS_MODE=3 (BQ=32, 8x8 coopmat prefill), and 2-SG D-split PASS_MODE=4 (BQ=8, 64 GPR32, 0:0 spills across F32/F16/Q8_0 KV).
  5. Pillar 5 — Direct M=1 & GPU-Indirect Prefill MoE Execution (agx-moe, kernels/{moe_bitonic_bucket,fused_moe_gate_up_situ_down})
    • Zero-bucketing direct M=1 roofline fastpath (PASS_STAGE=4: 64 rows/WG, 64 GPR32, 892 instrs, 6-op SWAR2 + 2x K-unroll prefetch) and 4x1 TILE_K=32 hoisted prefill MoE GEMM (PASS_STAGE=2/3: 60 GPR32, 972 instrs, 4.99 KB SRAM) + zero-CPU-round-trip bitonic bucketing & sparse skip-zero across NVFP4, Q8_0, BF16, F16, and F32.
  6. Pillar 6 — Formal TLA+ Barrier & Coherency Verification (formal/AgxBarrier.{tla,cfg})
    • Formal safety & liveness model of CDM barrier elision (AGX_BARRIER_NONE, WEAK_WFI, STRONG_USC, MEMORY_HOST) and 40-WG SLC-pinned sense-reversing atomic barriers.

Verification Gate Summary (Apple M4 Max, G16C B1, 40c AGX3, aurora 1.0.0, 0 GPU Faults)

Gate Result Details
CMake + Ninja Build (-DGGML_AGX=ON) PASS Clean build (0 warnings in ggml-agx targets)
TLA+ TLC (AgxBarrier.tla) PASS 4,072 states generated, 1,371 distinct states, depth 73, 0 errors
Borealis AGX3B shaderdb Audit (test_agx_shaderdb_all) PASS 43/43 kernels PASS — 0:0 spills across 100%, max 95 GPR32 (<= 96 cap; fused_full_flash_dspark 64 GPR32 across F32/F16/Q8_0, fused_moe_direct 64 GPR32 / 892 instrs, fused_moe_gemm32 60 GPR32 / 972 instrs)
Touched test-backend-ops test -b AGX0 PASS SET_ROWS 55/55 (incl. Q8_0), MUL_MAT 627/627, MUL_MAT_ID 515/515, FLASH_ATTN_EXT 1,561/1,561 (100.00% PASS, 0 GPU faults; full suite 6,832/6,832)
Differential Logit Parity (600,174 logits, 3 steps) PASS All 13 Fusions + Wave Sched + Replay vs Unfused AGX0: cos = 1.00000000, rmse = 0.000608, max_abs = 0.0037; vs Pure CPU FP32: 0 NaN / 0 Inf, cos = 0.99965592 (matching unfused FP16 coopmat 0.99965642), top1 = 3/3 (100%), top5 = 5/5
Real Generation (F16 & -ctk q8_0 -ctv q8_0 KV) PASS 0 CPU splits (splits = 1/1), exact coherent "The capital of France is Paris." on both F16 and Q8_0 KV
DSpark Speculative Decoding (dspark-Inkling-2-Mini-Q8_0.gguf) PASS 0 CPU splits, coherent CoT + "Paris is the capital of France." (12.7 t/s, Wave 4 target: M=8 MoE/vecmat -> 75+ t/s)

Measured M4 Max Hardware Roofline (AGX0, Bare-Metal drm_asahi + CDM)

Raw Silicon & Barrier Microbenchmarks (test_agx_roofline)

Benchmark Measured Notes
DRAM Read Bandwidth (256 MiB, SLC_STREAM) 511.94 GB/s 93.7% of 546.1 GB/s theoretical peak
SLC Read Bandwidth (16 MiB x 8, SLC_PIN) 1,639.31 GB/s 1.64 TB/s sustained SLC bandwidth
FP16 8x8 simdgroup_matrix MMA 15.67 TFLOPS 9 GPR32, 0:0 spills
144 Barrier Transitions — CDM STRONG_USC vs ELIDED 311.3 us vs 29.3 us 203 ns / transition (10.6x reduction)

Pillar 2 Repacked Kernel Roofline & Numerical Parity (test_agx_gemm_roofline, Wave 3)

Shape & Layout Wave 2 Wave 3 (Verified) cosine_sim NaN
Q8_0_8BLK LM Head (2304 x 201024, M=1) 514.09 GB/s 514.72–517.68 GB/s (0.952 ms, 94.8% peak) 1.0000000 0
Q8_0_8BLK (2304 x 3072, M=1) 442.95 GB/s 438.33–454.71 GB/s 1.0000000 0
NVFP4_32x16 (2304 x 65536, M=1) 374.40 GB/s 473.91–482.30 GB/s (+28.8%, 88.3% peak) 0.9999999 0
NVFP4_32x16 (2304 x 2304, M=5) 1,671.9 GFLOP/s 1,849.8 GFLOP/s (0.115 ms) 0.9999999 0
NVFP4_32x16 4x1 TILE_K=32 MMA (2304 x 2304, M=512) 6.76 TFLOPS 8.43–8.48 TFLOPS (0.641 ms, +25.4%) 1.0000000 0
Q8_0_8BLK 4x1 TILE_K=32 MMA (2304 x 2304, M=512) 7.23 TFLOPS 8.27–8.29 TFLOPS (0.656 ms, +14.7%) 1.0000000 0

llama-bench Progression (Inkling-2-Mini-UD-Q4_K_XL.gguf, 26.07B MoE, 48 Loop Layers, 0 CPU Splits, -r 3)

Test Baseline (f3c4e3cab) Wave 1 (cf1cdb121) Wave 2 (1a0a25872) Wave 3 F16 KV (d7ea93e3c) Wave 3 Q8_0 KV Total Speedup
pp128 135.22 ± 0.03 t/s 207.32 ± 0.14 t/s 215.10 ± 4.04 t/s 253.66 ± 5.30 t/s 252.00 ± 5.24 t/s 1.88x
pp512 232.73 ± 0.26 t/s 328.21 ± 0.28 t/s 349.74 ± 1.13 t/s 403.83 ± 1.40 t/s 399.87 ± 1.52 t/s 1.74x
pp2048 — — — 349.36 ± 0.27 t/s — —
tg32 4.82 ± 0.00 t/s 24.67 ± 0.18 t/s 27.19 ± 0.20 t/s 32.89 ± 1.11 t/s 32.46 ± 0.80 t/s 6.82x
tg128 4.82 ± 0.00 t/s 24.65 ± 0.04 t/s 27.30 ± 0.05 t/s 34.13 ± 0.33 t/s 33.58 ± 0.31 t/s 7.08x

Wave 3 Steady-State B=1 Telemetry (GGML_AGX_STATS=1, [REPLAY #N]): 1 submit (cpu_encode = 0.000 ms, gpu = 28.26 ms, drm_oh = 0.141 ms, disp = 2,806 (-33.8%), strong_usc = 2,039 (-40.2%), elided = 766, fusions: prep=192 sconv=192 rel=23 rtr=48 cont=169 rms=58 situ=48 ctrl=96 mix=98 wsum=48 clip=144 sc=1 sigm=48).


Wave 4 Verified Scoreboard (92cbea69f) — Overtakes Vulkan S24 B=1 by 1.66x!

Key Wave 4 Breakthroughs (d7ea93e3c..92cbea69f):

  • Pillar 1/6 (a574a85ab): Static 8 MiB AGX_BO_SLC_PIN activation arena + 128B sense-reversing barrier BO, TLC-verified formal/AgxMegakernelW4.{tla,cfg}, megakernel interception hook (GGML_AGX_NO_MEGAKERNEL=1 fallback, dual-path CDM replay), and AGX0_Repack zero-size probe fix (16,340.95 MiB, 193 model tensors now live on AGX0_Repack + AGX_BO_SLC_STREAM!).
  • Pillar 2 (2305e521e): Load-time vertical weight coalescing (W_attn_in Q8_0_8BLK, Theorem W4.1) + agx_gemm_dispatch_raw_q8_0, double-buffered XOR-swizzled M=2..8 vec-mat (Q8_0 M=8: 136 -> 254.10 GB/s, NVFP4 M=5/8: 49 -> 134.81 / 105.10 GB/s), and transposed-RowMajor direct-epilogue agx_mma_gemm (NVFP4 M=512: 8.48 -> 9.38 TFLOPS, Q8_0 M=512: 8.29 -> 8.79 TFLOPS).
  • Pillar 4/5 (be09b327f): Fused 2-stage M=1 MoE (PASS_STAGE=5/6: gate_up + scale2 + SiTU -> SLC -> down + scale2 + wsum, 2 dispatches + 1 barrier), deduplicated BATCH_CAP=4 + gemm32 M=2..8 MoE, and PASS_MODE=3 single-read sh_ep mask cache + split P*V Flash-Attention.
  • Pillar 3 (a10bd8783): 48-pass agx-inkling2 megakernel engine on static SLC_PIN arena (auto-discovery + W_attn_in coalescing + fused qkv_prep_store + vectorized stage_prep STAGE_MODE=0..7 + fused K=64 loop controllers + exp_probs_b.bias + per-expert NVFP4 scale2) cutting B=1 dispatches 2,806 -> 871 (-69.0%) and STRONG_USC barriers 2,039 -> 700 (-65.7%), plus 40-core DSpark Markov head accelerator (25.1 ms -> 4.56 ms, 5.5x faster!).
  • Wave 4 Verification (92cbea69f): 68/68 Borealis AGX3B shaderdb audit (0:0 spills across 100% of kernels, max 92 GPR32 <= 96) and live unaliased step-1 logit tracer.
Gate / Benchmark (M4 Max AGX0, -r 3, 0 GPU Faults) Wave 3 (d7ea93e3c) Wave 4 (92cbea69f) Vulkan S24 Ref Wave 4 Delta
Build (-DGGML_AGX=ON) 0 warnings 0 warnings — 100% clean
Borealis shaderdb Audit 43/43 PASS 68/68 PASS (0:0 spills, max 92 GPR32) — 100% PASS
Touched test-backend-ops -b AGX0 100% SET_ROWS 55/55, MUL_MAT 627/627, MUL_MAT_ID 515/515, FLASH_ATTN_EXT 1,561/1,561 — 100.00% PASS (0 faults)
Logit Parity (600,174 logits, 3 steps) cos=0.99966 MK vs NOMK: cos=0.99998294 (0.99999997 on Pass-8); MK vs Pure CPU: cos=0.99961749, 0 NaN/Inf, top1=3/3, top5=5/5 — 100% PASS
Q8_0 / NVFP4 M=1 Roofline 517.7 / 482.3 GB/s 511.8–516.4 / 471.0–475.4 GB/s 450+ GB/s 94% / 87% DRAM peak
Q8_0 / NVFP4 M=5..8 Roofline 136 / 49 GB/s 254.10 / 134.81 (M=5) / 105.10 (M=8) GB/s — +87% / +114%
NVFP4 / Q8_0 M=512 MMA 8.48 / 8.29 TFLOPS 9.38 / 8.74–8.79 TFLOPS (cos=1.0000000) 11–14 TFLOPS +10.6% / +6.0%
B=1 tg128 F16 KV (llama-bench -r 3) 34.13 ± 0.33 t/s 63.79 ± 0.54 t/s (tg32 = 63.02 ± 1.87 t/s) 38.43 t/s +86.9% vs W3 / 1.66x Vulkan / 13.23x baseline!
B=1 tg128 Q8_0 KV (-ctk q8_0 -ctv q8_0) 33.58 ± 0.31 t/s 62.53 ± 0.53 t/s (tg32 = 61.52 ± 1.84 t/s) — +86.2% vs W3
pp128 / pp512 / pp2048 F16 KV (-r 3) 253.7 / 403.8 / 349.4 363.95 / 500.53 / 418.40 t/s (Q8 KV: 362.3 / 495.6 / 414.2) 1,093 t/s (pp2048) +43.5% / +23.9% / +19.8%
DSpark (-md -c 4096 -n 128, "Capital of France") 12.7 t/s 43.0 t/s (draft 25.1 -> 4.56 ms, verify 196 -> 42.0 ms, "Paris.") ~79 t/s 3.39x vs W3

Wave 4 Steady-State B=1 Telemetry (GGML_AGX_STATS=1, [REPLAY #N]): cpu_encode = 0.000 ms, gpu = 14.89–14.94 ms, wait = 15.06–15.09 ms, drm_oh = 0.155 ms, disp = 871 (-69.0%), strong_usc = 700 (-65.7%), elided = 170.


Wave 5 Verified Scoreboard (f083af0d7) — Breaks 70+ t/s B=1 (1.83x Vulkan S24), 10.12 TFLOPS Q8_0 MMA, 552 t/s pp512, 497 t/s pp2048, 95/95 shaderdb!

Key Wave 5 Breakthroughs (92cbea69f..f083af0d7):

  • Pillar 0 (de5110f01): TLC-verified formal/AgxPersistentW5.{tla,cfg} modeling 128B non-coherent USC L1 dirty-line ownership (NoUscFalseSharing), exact 48-pass arena liveness + DSpark layer_inp_dev export (DsparkExportFresh), and persistent 40-WG SENSE_BARRIER deadlock-freedom.
  • Pillar 1 (0fd787678): sh_w-staged 64N × 64M cooperative-dequant prefill MMA (TILE_MODE=0, 68 GPR32, 0:0 spills, 9.5 KB SRAM = 3 WGs/core -> 10.12 TFLOPS Q8_0 / 9.90 TFLOPS NVFP4) and native 8×8 M=2..8 MMA (TILE_MODE=3/4, software-pipelined W prefetch -> 393.5–397.3 GB/s Q8_0 M=8 (+55%) and 135.0–135.5 GB/s NVFP4 M=8 (+28.9%)).
  • Pillar 2 (3dc10238e): matQ[16]-pinned RowMajor PASS_MODE=3 Flash-Attention prefill (8.00 KB SRAM = 4 WGs/core, 0:0 spills -> 2.22x faster FLASH_ATTN_EXT), transposed RowMajor + direct-epilogue PASS_STAGE=2/3 Bucketed-MMA MoE (5.5 KB SRAM = 6 WGs/core, 68 GPR32), and single-pass BATCH_CAP=8 + lean 1-super-tile sh_x M=2..8 MoE verify (42.0 -> 33.8 ms).
  • Pillar 3 (a3a2de82d): Lean 44–64 GPR32 40-WG SENSE_BARRIER hybrid B=1 super-stages (agx_inkling2_attn_in_b1.comp, agx_inkling2_hybrid_b1.comp, opt-in full-persistent agx_inkling2_persist_b1.comp down to 14 disp / 13 STRONG_USC), collapsing steady-state B=1 dispatches 871 -> 341 (-60.8%) and STRONG_USC barriers 700 -> 340 (-51.4%) (gpu = 13.57–13.67 ms, 70.37–70.66 t/s); fixed DSpark M=4 l_out-4 megakernel discovery (disp: 4,019 -> 971, 46.8–49.8 t/s sustained); lifted agx-graph-exec.cpp:4997 rel_bias_gather n_kv <= n_extent + 1 cap (pp2048 452 -> 497.0 t/s, +18.8% vs W4); added Lean-mirrored 128B static_asserts and fail-loud AGX0_Repack/exp_probs_b/scale2 guardrails.
  • Wave 5 Verification (f083af0d7): Expanded Borealis AGX3B shaderdb audit to 95/95 kernels (100% 0:0 spills, <= 96 GPR32).
Gate / Benchmark (M4 Max AGX0, -r 3, 0 GPU Faults) Wave 4 (92cbea69f) Wave 5 (f083af0d7) Vulkan S24 Ref Wave 5 Delta
Build (-DGGML_AGX=ON) 0 warnings 0 warnings — 100% clean
Borealis shaderdb Audit 68/68 PASS 95/95 PASS (0:0 spills, max 96 GPR32) — 100% PASS
Touched test-backend-ops -b AGX0 2,758/2,758 SET_ROWS 55/55, MUL_MAT 627/627, MUL_MAT_ID 515/515, FLASH_ATTN_EXT 1,561/1,561 — 100.00% PASS (2.22x FA)
Logit Parity (test_agx_diff_logits) cos=0.999983 MK vs NOMK: cos=0.99999999 (3st) / 0.99999998 (4st, max_abs=0.00731); MK vs CPU: cos=0.99971726, 0 NaN/Inf, top1=4/4, top5=5/5 — 8-nines exact!
Q8_0 / NVFP4 M=8 Roofline 254.1 / 105.1 GB/s 393.5–397.3 / 135.0–135.5 GB/s (cos=1.0000000) — +55% / +28.9%
Q8_0 / NVFP4 M=512 MMA 8.79 / 9.38 TFLOPS 10.12 / 9.90 TFLOPS (0.537 / 0.549 ms, 68 GPR32, cos=1.0000000) 11–14 TFLOPS +15.1% / +5.5%
B=1 tg128 F16 KV (llama-bench -r 3) 63.79 ± 0.54 t/s 70.37 ± 0.68 t/s (tg32 = 67.88 ± 1.73 t/s, peak 70.66) 38.43 t/s +10.3% vs W4 / 1.83x Vulkan / 14.6x baseline!
B=1 tg128 Q8_0 KV (-ctk q8_0 -ctv q8_0) 62.53 ± 0.53 t/s 69.40 ± 0.77 t/s (tg32 = 67.16 ± 1.69 t/s) — +11.0% vs W4
pp128 / pp512 / pp2048 F16 KV (-r 3) 363.95 / 500.53 / 418.40 385.42 / 552.62 / 497.00 t/s (Q8 KV: 382.7 / 545.8 / 491.9) 1,093 t/s (pp2048) +5.9% / +10.4% / +18.8%
DSpark (-md -c 4096) 43.0 t/s (31.4 long) 47.9–49.8 t/s ("Paris.", verify=33.8 ms, 971 disp) / 46.8 t/s sustained (-n 256, 3.05 tok/step!) ~79 t/s +15% short / +49% sustained!

Wave 5 Steady-State B=1 Telemetry (GGML_AGX_STATS=1, [REPLAY #2]): cpu_encode = 0.000 ms, gpu = 13.572 ms, wait = 13.698 ms, drm_oh = 0.126 ms, disp = 341 (-60.8% vs W4, -92.0% vs baseline), strong_usc = 340 (-51.4% vs W4, -90.0% vs baseline), elided = 0.


Wave 6 Verified Scoreboard (71a594dd0) — Breaks 614 t/s pp512, 551 t/s pp2048, 74.1 t/s DSpark "Paris.", 70.61 t/s B=1, 10.17 TFLOPS Q8_0 MMA, 100/100 shaderdb!

Key Wave 6 Breakthroughs (f083af0d7..71a594dd0):

  • 6A+6B (9e61b0438): Software-pipelined W-only uvec2 prefetch + direct epilogue store (no sh_y) + unbranched active_im==4u in 64N×32M Bucketed-MMA MoE (8,064 B = 4 WGs/core, 60–64 GPR32, 0:0 spills), trimmed s0/s1 m_cnt==1 live regs (-530 ins, -0.62 ms on DSpark M=4), and lean 128T lockstep L1D X-sharing s5/s6 (64/68 GPR32, 0 barriers / 0 B SRAM on s5, deferred UE4M3 scales -> 70.61 t/s F16 / 69.54 t/s Q8_0 B=1).
  • 6C+6C-2 (e57017654): Full 22-op ITEM_FUSED_MOE prefill fusion (48/48 MoE blocks fused) + non-adjacent DAG ITEM_MIX_ATTN matching (119–120/120 hits), cutting prefill dispatches 3,413 -> 2,543 (-870) and STRONG_USC barriers 2,357 -> 1,610 (-747), plus 5 zero-divide vec4/uvec4 0-ULP fastpaths (bin_op, CONCAT(dim=1), CPY/CONT/DUP, multi-query mix_attn, 4-wide rel_bias_gather) -> pp512 = 613.96 t/s (+11.1%) & pp2048 = 551.03 t/s (+10.9%).
  • 6D-2 (6cae349f8): Lean M=2..4 40-WG SENSE_BARRIER DSpark verify hybrid super-stages (HYBRID_MODE=3/4, 4 explicit scalar accumulators a0..a3, 22.9–38.0 KiB, 64–80 GPR32, 0:0 spills, M=1 untouched), cutting DSpark M=4 verify dispatches 971 -> 609 (-362) and STRONG_USC barriers 748 -> 436 (-312) -> verify [REPLAY] 33.77 -> 30.87–31.46 ms ("Paris." 74.1 t/s; -n 256 sustained verify med 37.27 -> 33.48 ms, -10.2%).
  • 6E (7d5b05bdd): Routed M=2..4 dense GEMMs off 50%-padded 8×8 MMA to upgraded f16vec2 vec-mat (Q8_0 X_ALIGNED4=1 + W-prefetch + adaptive WG_SGS=4/8 at 64 GPR32; NVFP4 direct f16vec4 sh_x + fused f16vec2 FMA at 72 GPR32), shared f16vec4 sh_w TILE_MODE=3/4 (Q8_0 M=8 = 404.23 GB/s), and T=0 X_ALIGNED4=1 (68 GPR32 -> 10.17 / 9.93 TFLOPS Q8_0 / NVFP4 M=512).
  • Wave 6 Verification (71a594dd0): Expanded Borealis AGX3B shaderdb audit to 100/100 kernels (100% 0:0 spills, <= 96 GPR32) and verified 3,292/3,292 test-backend-ops across 12 ops.
Gate / Benchmark (M4 Max AGX0, -r 3, 0 GPU Faults) Wave 5 (f083af0d7) Wave 6 (71a594dd0) Vulkan S24 Ref Wave 6 Delta
Build (-DGGML_AGX=ON) 0 warnings 0 warnings — 100% clean
Borealis shaderdb Audit 95/95 PASS 100/100 PASS (0:0 spills, max 96 GPR32) — 100% PASS
Touched test-backend-ops -b AGX0 2,758/2,758 (4 ops) 3,292/3,292 PASS (12 ops: SET_ROWS 55, MUL_MAT 627, MUL_MAT_ID 515, FLASH_ATTN_EXT 1,561, ADD/SUB/MUL/DIV/CONCAT/CPY/CONT/DUP 534) — 100.00% PASS (0 faults)
Logit Parity (test_agx_diff_logits) MK vs NOMK 0.99999998 MK vs TRUE-NOMK (4st): cos=0.99994109 (top1=4/4); MK vs CPU (3st): cos=0.99960118 (TRUE-NOMK vs CPU 0.99972759, top1=3/3, 0 NaN/Inf) — 100% PASS
Q8_0 / NVFP4 M=1 Roofline 513 / 471 GB/s 515.10 / 470.86 GB/s (cos=1.0000000) 450+ GB/s 94.3% DRAM peak
Q8_0 / NVFP4 M=8 Roofline 393.5 / 135.0 GB/s 404.23 (6.01 TFLOPS) / 136.30 GB/s (cos=1.0000000) — +2.7% / +1.0%
Q8_0 / NVFP4 M=512 MMA 10.12 / 9.90 TFLOPS 10.17 / 9.93 TFLOPS (0.534 / 0.547 ms, 68 GPR32, cos=1.0000000) 11–14 TFLOPS New all-time highs!
B=1 tg128 F16 KV (llama-bench -r 3) 70.37 ± 0.68 t/s 70.61 ± 0.70 t/s (tg32 = 68.06 ± 1.66 t/s, [REPLAY #1] = 13.644 ms) 38.43 t/s 1.84x Vulkan / 14.65x baseline!
B=1 tg128 Q8_0 KV (-ctk q8_0 -ctv q8_0) 69.40 ± 0.77 t/s 69.54 ± 0.63 t/s (tg32 = 67.13 ± 1.62 t/s) — New high!
pp128 / pp512 / pp2048 F16 KV (-r 3) 385.4 / 552.6 / 497.0 417.44 / 613.96 / 551.03 t/s (Q8 KV: 413.5 / 609.1 / 547.5) 1,093 t/s (pp2048) +8.3% / +11.1% / +10.9%!
DSpark (-md -c 4096) 47.9–49.8 (ver 33.8 ms, 971 disp) 74.1 t/s ("Paris.", ver 30.87–31.46 ms, 609 disp / 436 strong_usc) / 46.1–49.0 t/s (-n 256, ver med 33.48 ms vs 37.27, drf 4.76 ms) ~79 t/s -362 disp / -10.2% verify ms!

Wave 64 (244ea9a98..7eab29bd9) — Multi-Slot (-np 2) Megakernel + DSpark Support

  • Multi-seq speculative ubatch splitter (244ea9a98): GGML_AGX_SPLIT_MULTI_SEQ_SPEC=1 (default ON) in src/llama-batch.cpp splits n_keep_tail > 0 && n_seqs > 1 ubatches into 1-seq ubatches so concurrent speculative decoding slots hit the megakernel cleanly.
  • build_rs states_extra in Inkling-2 megakernel (fbeb1cfd4): Lazily allocates a 2-slot ping-pong BO (~1.07 MiB, 0 new shaders, 0 extra barriers; GGML_AGX_W64_STATES_EXTRA=1, up to 7 extra slots) to gather s_copy[n_seqs..n_rs-1] before attn_in's STRONG_USC barrier and scatter to disjoint r_l[il] rows after hm4.
  • is_large_pp decode fix (9f6312bd9): Restricted is_large_pp in ggml-agx.cpp to GGML_OP_GET_ROWS on token_embd.weight (ne[0] > 8) so non-token ops (rel_bias/rel_pos) no longer falsely skip agx_inkling2_try_execute().
  • DSpark unselected sampler guard (7eab29bd9): Added GGML_TENSOR_FLAG_COMPUTE == 0 guard in agx_i2_discover_dspark_draft_cgraph() so inactive ggml_build_forward_select top_k chains on -np >= 2 / adaptive n_draft < n_max do not reject the DSpark megakernel.
-np 2 :8080 (NVFP4-15G + Q8_0 KV + DSpark n=7 adaptive) Before Wave 64 After 7eab29bd9 Gain
1-slot 128-tok probe 47.9 t/s 95.66 t/s +99.7% (2.0×)
2-slot 128-tok probe (combined / decode sum) 37.99 / 41.2 t/s 62.28 / 70.34 t/s +63.9% / +70.6%
Live 2-slot pi sessions (concurrent, 7–12K ctx) ~35 t/s ~85 t/s combined (40.9 + 44.5 t/s) 2.4×
Live 1-slot pi turns (8–15K ctx) ~38–50 t/s 80–109 t/s (29.1 ms/step) ~2×

Iterating Locally on m4-nixos

Build tree: /home/astaff/llama/llama-ggml-agx (launcher: /home/astaff/llama/inkling-server, symlinked at ~/.local/bin/inkling-server).

# 1. Incremental rebuild (~5-10s; safe while qwen-server.service is running)
nix-shell -p cmake ninja --run \
  "cmake --build /home/astaff/llama/llama-ggml-agx/build --target llama-server llama-agx-logit-parity -j 8"

# 2. Restart service and verify health
systemctl --user restart qwen-server.service
curl -sf http://127.0.0.1:8080/health && echo " OK"

# 3. Live logs & slot status
tail -f "$(ls -td /home/astaff/llama/results/*-server | head -n 1)/stderr"
curl -s http://127.0.0.1:8080/slots | jq '.[] | {id, is_processing, n_ctx, id_task}'

Diagnostic env vars (temporary drop-in at ~/.config/systemd/user/qwen-server.service.d/debug.conf, then systemctl --user daemon-reload && systemctl --user restart qwen-server.service):

  • GGML_AGX_MK_DEBUG=1 — log megakernel hits and MK DISCOVER FAIL / DSPARK MK DISCOVER FAIL reasons.
  • GGML_AGX_STATS=1 — per-submit GPU/CPU encode ms, dispatch and barrier counts.
  • GGML_AGX_W64_STATES_EXTRA=0 / GGML_AGX_SPLIT_MULTI_SEQ_SPEC=0 — A/B toggles for Wave 64 features.

Standalone parity test (stop qwen-server.service first to stay under the 31.12 GiB per-client GEM limit):

systemctl --user stop qwen-server.service
LD_LIBRARY_PATH=/home/astaff/llama/llama-ggml-agx/build/bin \
  /home/astaff/llama/llama-ggml-agx/build/bin/llama-agx-logit-parity \
  -m /home/astaff/llama/models/Inkling-2-Mini-NVFP4-15G.gguf \
  -md /home/astaff/llama/models/dspark-Inkling-2-Mini-Q8_0.gguf
systemctl --user start qwen-server.service

@github-actions github-actions Bot added documentation Improvements or additions to documentation ggml labels Nov 27, 2026
…n DRM submit

- Add in-place steady-state CDM graph replay (toggleable via GGML_AGX_NO_REPLAY=1)
  with atomic bo_epoch / record_gen invalidation: cuts steady-state cpu_encode
  from 2.62 ms -> 0.000 ms on decode steps.
- Bake arg_bo hi32 + precomputed launch header words into agx_ioto_template,
  expand fast cache 64 -> 256 slots, and inline 44B launch+barrier emission
  (2.8x faster cold encode).
- Track completed_timeline for ASAHI_BARRIER_NONE on synchronous submits and
  add shared-BO VM status mirror fallback (drm_oh 0.54 ms -> 0.141 ms).
… MMA (8.48 TFLOPS)

- Introduce 6-op branchless min(raw, fma(raw, 2h, -1h)) SWAR2 E2M1 decoder and
  overflow-proof Q8_0 magic-bias norm decoder in dequant_supertile.glsl.
- Upgrade nvfp4_vecmat.comp & mxfp8_q8_vecmat.comp for M=1..8 (8 rows/WG K_SGS=4,
  ffma16): NVFP4 M=1 rises 374.40 -> 473.91-482.30 GB/s; Q8_0 LM head 515.78 GB/s.
- Switch agx_mma_gemm.comp TILE_MODE=0 to 4x1 TILE_K=32 split-phase software
  pipelining on double-buffered 0-bank-conflict sh_x: NVFP4/Q8_0 M=512 MMA rises
  from 6.76 / 7.23 -> 8.48 / 8.29 TFLOPS (cos=1.0000000, 0:0 spills).
…V & MoE SWAR2

- Upgrade fused_full_flash_decode.comp PASS_MODE=3 (M>=16, BQ=32) and add 2-SG
  D-split PASS_MODE=4 (M=2..15, BQ=8, 64 GPR32, 0:0 spills across F32/F16/Q8_0 KV)
  using hardware FP16 8x8 coopmat with FP32 online softmax.
- Upgrade Q8_0 KV decode in fused_full_flash_decode.comp & fused_swa_ring_attn.comp
  to magic-bias f16vec2/f16vec4 dequantization (0 spills, 1,561/1,561 FLASH_ATTN_EXT).
- Upgrade fused_moe_gate_up_situ_down.comp PASS_STAGE=0/1/4 to 6-op SWAR2 + 2x
  K-unroll prefetch (64 GPR32 / 892 instrs direct, 60 GPR32 / 972 instrs gemm32,
  515/515 MUL_MAT_ID PASS).
… & micro-op fusions

- Add exact ASAP VA-dependency wave scheduler (RAW/WAR/WAW + internal scratch,
  toggleable via GGML_AGX_NO_WAVE_SCHED=1): cuts B=1 STRONG_USC barriers
  3,408 -> 2,039 (-40.2%).
- Add GGML_TYPE_Q8_0 support to SET_ROWS (55/55 PASS; enables -ctk q8_0 -ctv q8_0
  with 0 CPU splits) and bit-exact fused prep_norm_fwht_store (192/tok).
- Fuse full_shortconv (192/tok), rel_bias_gather (48/tok), router_topk_norm
  (48/tok), mix_attn backward-absorb, and strided CONT inputs: cuts B=1 dispatches
  4,239 -> 2,806 (-33.8%) at cos=1.00000000 vs unfused AGX0.
…fline tests

- Audit PASS_MODE=3/4 F16 & Q8_0 KV flash attention and BATCH_M=8 NVFP4/Q8_0
  vecmat kernels in test_agx_shaderdb_all (43/43 PASS, 0:0 spills).
- Add M=8 NVFP4 (2304x2304) and Q8_0 LM head (2304x201024) cases to
  test_agx_gemm_roofline (10/10 PASS).
…, -0.62ms/step 32k, bit-exact, GGML_AGX_W62_MOE=1)
… 64)

Handle non-empty build_rs states_extra copies (n_rs > n_seqs, up to 7
extra slots) inside the 48-pass Inkling-2 megakernel so multi-slot (-np >= 2)
single-sequence ubatches and split speculative batches hit the megakernel
instead of falling back to the generic graph.

Uses a lazily allocated 2-slot ping-pong BO (~1.07 MiB) with zero new
shaders and zero extra barriers:
- Phase A (start of visit v): k_w4_gather_f32 gathers r_l[il] rows from
  s_copy[n_seqs..n_rs-1] into slot (v & 1), overlapping with attn_in and
  draining at attn_in's STRONG_USC barrier before qkv_prep/hm3/hm4 mutate
  r_l[il] (WAR-safe even under cell swaps or rollback-slot gathers).
- Phase B (after hm4 in visit v): k_copy_f32 scatters slot (v & 1) to
  states_extra_dst_va (disjoint rows of r_l[il]), overlapping with visit
  v+1's attn_in on slot ((v+1) & 1) and draining before lm_head/graph exit.

Gated behind GGML_AGX_W64_STATES_EXTRA (default ON; set 0 to disable).
…decode

is_large_pp previously scanned the first 64 cgraph nodes for any
GGML_OP_GET_ROWS (src1->ne[0] > 8) or GGML_OP_MUL_MAT (src1->ne[1] > 8),
which falsely triggered on non-token ops (e.g. rel_bias/rel_pos) on
multi-slot / large-ctx graphs and bypassed agx_inkling2_try_execute().

Restrict is_large_pp detection to GGML_OP_GET_ROWS on token_embd.weight
(src1->ne[0] > 8). Restores Inkling-2 target megakernel on -np 2 with
states_extra: 2-slot combined throughput jumps 37.99 -> 55.35 t/s (+45.7%),
1-slot jumps 47.9 -> 60.8 t/s.
Mirror the target megakernel's GGML_TENSOR_FLAG_COMPUTE == 0 guard in
agx_i2_discover_dspark_draft_cgraph() so unselected ggml_build_forward_select
top_k sampler chains (e.g. inactive slots on -np 2 or adaptive n_draft < n_max)
do not collide on row 0 and force DSpark onto the generic graph.

On -np 2 llama-server: 1-slot decode jumps 60.77 -> 95.66 t/s (+57.4%),
2-slot combined decode jumps 55.35 -> 62.28 t/s (pure decode sum 70.34 t/s).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation ggml model server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant