Verba/Rapida

Experiments #114

Persistent megakernel feasibility, synthetic Metal benchmark before any engine change...

done

What was tested

Persistent megakernel feasibility, synthetic Metal benchmark before any engine change (`2026-10-31-mac-engine-audit/megakernel-114.md`): grid-barrier cost on device atomics at 20 to 80 threadgroups and a bounded-spin hang check; 150 dependent uint4 reads at the step's real sizes as separate dispatches, one persistent kernel with grid barriers, and the same with next-read weights staged before each barrier; plus a seam norm recomputed per threadgroup. Build option (a), a per-layer persistent kernel with bit-exact replayed bodies, only if a barrier costs at most 1.5 us and staging saves at least 0.8 ms per 30-layer chain

Model and setup

the best

Expected gain

+4 to +15% if built (inferred: 0.5 to 1.5 ms of 11.57 at 8k); the benchmark itself is a diagnostic

Where the idea came from

rows 82, 83s, 94, 101s, 105

Outcome

done 2026-10-31 (`kb114/`): barrier 0.55 us (Metal 3.1) / 0.74 (3.2), staged chain saves 0.71 / 0.78 ms per 30 layers, verdict SEAM-ONLY (option (c) seam prologue only); Metal 3.1 needs atomic stores for cross-threadgroup data (README ยง Diagnostic, row 114)

Lesson

on the M4 a device-atomic grid barrier is cheap (0.55 us at Metal 3.1), and a persistent kernel with staged next-level loads takes a weight chain to 95% of peak bandwidth (0.71 to 0.78 ms per 30 layers over separate dispatches), just under the build bar. Data crossing the barrier must be written with atomic stores at Metal 3.1, or fenced at 3.2: a plain store before `threadgroup_barrier(mem_device)` is not published to other threadgroups about half the time.

Adopted

no (diagnostic; SEAM-ONLY verdict).

Want to see what these experiments produced? Lesto, the Gemma 4 inference engine for Apple silicon Macs, is on lestoengine.com

Made by Federico Andrioli, @fedeandri on X A research lab's own measurements, generated from its files. Data built