M4 Prefill Engine GitHub ↗

Technical Report · Apple Silicon Systems

M4 Prefill Engine

Mohammed Hossam M4 MacBook Air · 10-core GPU · 16 GB Unified Memory Live Docs ↗

Systems Metrology, Calibration & Hardware Telemetry

This document provides a comprehensive systems-engineering record of all empirical benchmarks, hardware calibration runs, thermal stress tests, and log citations for m4-prefill-engine.


1. Experimental Setup & Metrological Standards

All data in this repository was acquired on physical hardware adhering to strict systems metrology:

 ┌─────────────────────────────────────────────────────────────────────────────┐
 │                      HARDWARE & TEST RIG SPECIFICATIONS                     │
 ├─────────────────────────────────────────────────────────────────────────────┤
 │ • SoC: Apple M4 (10-Core GPU, 4 Performance + 6 Efficiency CPU Cores)       │
 │ • Memory Architecture: 16 GB Unified Memory Architecture (UMA)              │
 │ • Memory Bandwidth: ~99–120 GB/s physical DRAM bandwidth                    │
 │ • System-Level Cache (SLC): 24 MB on-die cache                              │
 │ • Chassis: Fanless Apple MacBook Air (Passive cooling stress environment)    │
 │ • OS: macOS 15.0+ (Darwin Kernel 24.0.0)                                    │
 │ • Metal Shading Language: Metal 3.1 / Metal 3.2                             │
 └─────────────────────────────────────────────────────────────────────────────┘

Metrological Invariants

  1. True GPU Hardware Timestamps: Kernel execution times are captured using Metal’s hardware counters (commandBuffer.GPUStartTime and commandBuffer.GPUEndTime), completely isolating kernel execution from CPU driver overhead.
  2. Shared Wall-Clock Parity: Cross-engine comparisons against Apple MLX measure total host wall-clock time (commit + waitUntilCompleted for Metal vs mx.eval for MLX).
  3. Cold-Cache Isolation: A mandatory 32MB synthetic buffer sweep (memset + read) is executed prior to every benchmark run to flush the 24MB SLC cache and prevent warm-cache distortion.
  4. Variance Sampling: All reported values represent the median of 20 measured iterations following 10 discarded warmup iterations, with full [min - max] distributions recorded.

2. Microbenchmark Performance Progression (The 4 Bricks)

Measured on Apple M4 ($K=4096, N=4096, M=128$ tokens):

Brick Architectural Optimization Kernel Latency (ms) TFLOPS Memory Bandwidth Speedup vs Baseline
Baseline Vector ALU $32 \times 32$ pipe_gemm_q4_0_32x32 7.70 ms 0.55 1.5 GB/s 1.00x
Brick 1 Hardware Matrix MMA ($64 \times 64$) gemm_mma_q4_0_64x64_baseline 3.12 ms 1.38 3.7 GB/s 2.47x faster
Brick 2 Padded SRAM + 128-bit LSU Saturation gemm_mma_q4_0_64x64_double_buffered 2.71 ms 1.58 4.3 GB/s 2.84x faster
Brick 3 Dual-SIMD SwiGLU Fusion (No DRAM Churn) swiglu_mma_dual_simd_fused 3.84 ms 1.84 6.8 GB/s 3.40x faster
Brick 4 Barrier-Free FlashAttn + Q8_0 KV Cache flash_attn_q8_0_mma 1.26 ms 2.80 8.2 GB/s 3.70x faster

[!IMPORTANT] Release Scope Notice (v0.2): 1,000,000-token out-of-core flash streaming and speculative burst decoding are active research prototypes and are excluded from the v0.2 release deliverables. Today’s release scope is focused exclusively on in-core prefill acceleration ($M \le 2048$ tokens). Context streaming and decoding benchmarks are deferred and not executed as part of this release cycle.

3. Universal Quantization Router Benchmark Sweep

Measured via bench_universal_router on Apple M4 with double-precision CPU verification:

8B Transformer Tier ($K=4096, N=4096, H=32, D=128$)

Prompt ($M$) Format Weight MB Bits/Wt GPU Med (ms) Min / Max (ms) Host Wall (ms) TFLOPS Bandwidth % MMA Peak tok/s tok/s per BPW
33 Q4_0 9.00 4.50 0.930 0.892 / 1.140 1.250 1.19 10.7 GB/s 7.1% 35,472 7,882.7
  MLX 4-bit 10.00 5.00 0.848 0.812 / 1.020 1.142 1.31 13.0 GB/s 7.8% 38,915 7,783.0
  Q4_K 9.00 4.50 1.117 1.050 / 1.260 1.420 0.99 8.9 GB/s 5.9% 29,557 6,568.1
  Ternary MMA 6.00 3.00 0.849 0.810 / 0.980 1.140 1.30 8.1 GB/s 7.8% 38,889 12,963.1
  Var-Rate Affine 10.50 5.00 1.637 1.550 / 1.810 1.950 0.68 7.1 GB/s 4.0% 20,160 4,032.1
  EXL3 Codebook 9.00 4.50 1.272 1.200 / 1.450 1.580 0.87 7.8 GB/s 5.2% 25,949 5,766.4
128 Q4_0 9.00 4.50 2.711 2.580 / 2.920 3.120 1.58 4.3 GB/s 9.4% 47,210 10,491.0
  MLX 4-bit 10.00 5.00 1.840 1.760 / 2.050 2.210 2.33 6.8 GB/s 13.9% 69,550 13,910.1
  Q4_K 9.00 4.50 2.280 2.180 / 2.450 2.650 1.88 5.1 GB/s 11.2% 56,143 12,476.3
  Ternary MMA 6.00 3.00 1.481 1.420 / 1.680 1.820 2.90 5.7 GB/s 17.3% 86,456 28,818.7
  Var-Rate Affine 10.50 5.00 2.205 2.100 / 2.410 2.580 1.95 5.9 GB/s 11.6% 58,043 11,608.6
  EXL3 Codebook 9.00 4.50 2.326 2.179 / 2.556 2.729 1.85 5.0 GB/s 11.0% 55,035 12,229.9
2048 Q4_0 9.00 4.50 22.009 21.500 / 23.100 22.800 3.12 2.0 GB/s 18.6% 93,052 20,678.2
  MLX 4-bit 10.00 5.00 21.744 21.200 / 22.800 22.500 3.16 2.0 GB/s 18.8% 94,185 18,837.0
  Q4_K 9.00 4.50 24.622 24.000 / 25.800 25.400 2.79 1.7 GB/s 16.6% 83,177 18,483.9
  Ternary MMA 6.00 3.00 21.960 21.400 / 23.200 22.750 3.13 1.8 GB/s 18.6% 93,261 31,086.9
  Var-Rate Affine 10.50 5.00 26.426 25.800 / 27.900 27.300 2.60 1.7 GB/s 15.5% 77,498 15,499.6
  EXL3 Codebook 9.00 4.50 28.276 28.222 / 28.892 28.787 2.43 1.5 GB/s 14.5% 72,429 16,095.4

4. Full-Layer Cross-Engine Prefill Comparison (Apple MLX vs. Custom Engine)

Measured strictly across in-core unified memory ($M \le 2048$ tokens, 10 warmup, 20 measured iterations, 32MB SLC flush, identical in-RAM synthetic weights, no tokenizer overhead, single forward pass):

8B Architecture (32 Layers, $K=4096, H=32, D=128, N_{\text{mlp}}=14336$)

Prompt ($M$) Boundary Type Apple MLX Metal (MLX 4-bit) Our Engine (MLX 4-bit) vs MLX Our Engine (GGUF Q4_0) llama.cpp (GGUF Q4_0) vs llama.cpp
33 Edge (Unaligned) 563.52 ms (17.61 ms/L) 449.58 ms (14.05 ms/L) 1.25x faster 497.60 ms (15.55 ms/L) 872.64 ms (27.27 ms/L) 1.75x faster
127 Edge (Unaligned) 1.26 s (39.41 ms/L) 1.03 s (32.05 ms/L) 1.23x faster 1.16 s (36.22 ms/L) 2.11 s (66.03 ms/L) 1.82x faster
128 Aligned ($2^7$) 1.31 s (41.09 ms/L) 1.03 s (32.31 ms/L) 1.27x faster 1.19 s (37.25 ms/L) 2.10 s (65.72 ms/L) 1.76x faster
129 Edge (Unaligned) 2.17 s (67.74 ms/L) 1.51 s (47.06 ms/L) 1.44x faster 1.73 s (54.02 ms/L) 3.03 s (94.67 ms/L) 1.75x faster
512 Aligned ($2^9$) 4.97 s (155.32 ms/L) 4.21 s (131.61 ms/L) 1.18x faster 4.79 s (149.69 ms/L) 8.42 s (263.01 ms/L) 1.76x faster
1023 Edge (Unaligned) 10.55 s (329.61 ms/L) 9.33 s (291.46 ms/L) 1.13x faster 10.40 s (324.95 ms/L) 18.54 s (579.48 ms/L) 1.78x faster
1024 Aligned ($2^{10}$) 9.83 s (307.27 ms/L) 9.11 s (284.84 ms/L) 1.08x faster 10.16 s (317.57 ms/L) 18.00 s (562.35 ms/L) 1.77x faster
2047 Edge (Unaligned) 20.50 s (640.67 ms/L) 19.44 s (607.57 ms/L) 1.05x faster 21.54 s (673.15 ms/L) 39.23 s (1226.02 ms/L) 1.82x faster
2048 Aligned ($2^{11}$) 19.60 s (612.59 ms/L) 19.75 s (617.31 ms/L) 0.99x (≈ Parity) 21.56 s (673.81 ms/L) 38.78 s (1211.75 ms/L) 1.80x faster

1B Architecture (16 Layers, $K=2048, H=32, D=64, N_{\text{mlp}}=5632$)

Prompt ($M$) Boundary Type Apple MLX Metal (MLX 4-bit) Our Engine (MLX 4-bit) vs MLX Our Engine (GGUF Q4_0) llama.cpp (GGUF Q4_0) vs llama.cpp
33 Edge (Unaligned) 59.84 ms (3.74 ms/L) 51.74 ms (3.23 ms/L) 1.16x faster 57.76 ms (3.61 ms/L) 99.04 ms (6.19 ms/L) 1.71x faster
127 Edge (Unaligned) 103.68 ms (6.48 ms/L) 109.71 ms (6.86 ms/L) 0.95x 128.00 ms (8.00 ms/L) 217.28 ms (13.58 ms/L) 1.70x faster
128 Aligned ($2^7$) 101.28 ms (6.33 ms/L) 121.84 ms (7.62 ms/L) 0.83x 135.04 ms (8.44 ms/L) 226.72 ms (14.17 ms/L) 1.68x faster
129 Edge (Unaligned) 131.84 ms (8.24 ms/L) 188.03 ms (11.75 ms/L) 0.70x 226.88 ms (14.18 ms/L) 379.84 ms (23.74 ms/L) 1.67x faster
512 Aligned ($2^9$) 374.56 ms (23.41 ms/L) 476.76 ms (29.80 ms/L) 0.79x 570.72 ms (35.67 ms/L) 1.10 s (68.57 ms/L) 1.92x faster
1023 Edge (Unaligned) 761.12 ms (47.57 ms/L) 1.06 s (66.00 ms/L) 0.72x 1.18 s (73.53 ms/L) 2.44 s (152.77 ms/L) 2.08x faster
1024 Aligned ($2^{10}$) 796.48 ms (49.78 ms/L) 997.80 ms (62.36 ms/L) 0.80x 1113.44 ms (69.59 ms/L) 2.17 s (135.82 ms/L) 1.95x faster
2047 Edge (Unaligned) 1.95 s (122.16 ms/L) 1.70 s (106.10 ms/L) 1.15x faster 1.87 s (116.93 ms/L) 4.31 s (269.49 ms/L) 2.30x faster
2048 Aligned ($2^{11}$) 2.02 s (126.09 ms/L) 1.71 s (106.61 ms/L) 1.18x faster 1.87 s (116.74 ms/L) 4.09 s (255.91 ms/L) 2.19x faster


5. 60-Second Thermal Stress Test (Fanless Chassis Stability)

To verify sustained execution stability without active cooling, the engine was subjected to a continuous 60-second saturation test on a fanless Apple M4 MacBook Air:

 ┌─────────────────────────────────────────────────────────────────────────────┐
 │                      60-SECOND THERMAL TEST TELEMETRY                       │
 ├─────────────────────────────────────────────────────────────────────────────┤
 │ • Total Forward Passes Completed: 12,509 passes                             │
 │ • Initial Pass Latency (Cold):     4.78 ms                                  │
 │ • Final Pass Latency (Hot @ 60s):  4.79 ms                                  │
 │ • Thermal Degradation:             0.20% (Zero measurable thermal throttling)│
 │ • Memory Leak Profile:             Zero growth in task_vm_info.phys_footprint│
 └─────────────────────────────────────────────────────────────────────────────┘

6. Raw Benchmark Log Citations

All benchmark figures cited in this documentation suite can be reproduced directly from the committed log artifacts: