Native Metal replay (Experiment 2 Phase A/B) #
Falsification test of the post-mortem's C2 ("the E2B gap is the dispatch layer, not the kernels"), in two phases:
Phase A (timing): capture every dispatch of ONE decode token — Tint-CLI MSL, the Dawn buffers in MSL binding order, grid/workgroup dims, threadgroup bytes — then replay the token natively (
replayRun): Serial 6.78 ms ≈ Dawn's 7.7 ms, Concurrent no-barrier 3.43 ms, per-layer barriers 3.92 ms (M4 Max, identical kernels).Phase B (real execution):
mode := .nativeExecmakes theexecuteShaderNamedhook SKIP the Dawn dispatch entirely; the token's ops are recorded and then executed ONCE bycommitTokenon Dawn's own MTLCommandQueue (single-queue FIFO keeps ordering with Dawn staging writes and readbacks) with mode-3 automatic hazard barriers (llama.cppggml_mem_ranges-style, whole-buffer granularity). Correctness is gated on the generated text.
MSL comes from running the tint CLI (HESPER_TINT_BIN, same Tint version as the pinned
Dawn) on the exact WGSL we hand Dawn; the CLI assigns its own [[buffer(i)]] indices
and may RENAME the entry point (main → v), so both are parsed from the MSL. Steady
state is served from a cache keyed by the caller's authoritative cacheKey, so the
per-dispatch host cost is a HashMap probe + buffer-pointer pushes — no WGSL regeneration.
- off : Mode
- capture : Mode
Record ops AND still execute them through Dawn (Phase A timing capture).
- nativeExec : Mode
Record ops and SKIP the Dawn dispatch;
commitTokenexecutes them natively. - frozen : Mode
FROZEN token replay (CUDA-Graphs analogue): the dispatch sequence recorded by an earlier
nativeExectoken is token-invariant from cacheLen ≥ 8 (identical buffers, grids; positions live in params-buffer CONTENT), so subsequent tokens skip both the Dawn dispatch AND the re-record — the hook returns immediately andcommitToken (reset := false)re-executes the frozen list. Kills the per-token host record cost. Correctness gate: token sequence must equal the Dawn path.
Instances For
Equations
- Hesper.WGSL.NativeReplay.instBEqMode.beq x✝ y✝ = (x✝.ctorIdx == y✝.ctorIdx)
Instances For
Equations
Kernel name per recorded dispatch, in record order (drives per-class profiling).
- msl : String
- mslEntry : String
Actual MSL entry name (Tint may rename, e.g.
main→v). Empty = unusable. Buffer names in MSL
[[buffer(i)]]order.- tgBytes : UInt32
Threadgroup bytes to bind at index 0 (0 = kernel has no threadgroup param).
- writeMask : UInt32
Bit i set ⇒ order[i] is a read_write binding (drives mode-3 hazard barriers).
perm[i] = position of order[i] in the call site's namedBuffers list (captured at build time). Steady-state emit indexes instead of string-searching; a name mismatch (different call-site ordering under the same key) falls back to find.
Instances For
Keyed by the caller's authoritative cacheKey (or hash of the WGSL when unkeyed).
Instances For
Equations
- Hesper.WGSL.NativeReplay.isActive = do let __do_lift ← ST.Ref.get Hesper.WGSL.NativeReplay.modeRef pure (__do_lift != Hesper.WGSL.NativeReplay.Mode.off)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Phase B: begin recording a token that will NOT be dispatched through Dawn.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Frozen-mode token: the hook drops every dispatch instantly; the previously
recorded list is re-executed by commitToken.
Equations
Instances For
Phase B: execute the recorded token natively (mode 3 = concurrent + hazard barriers by default) and drop back to normal Dawn dispatching. Throws if any dispatch was missed (a partial token would silently corrupt the decode).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Layer-boundary marker (honored by replayRun mode=2). No-op unless active.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Steady-state record: cache hit on the caller's authoritative key ⇒ record with no
WGSL/tint work at all. Returns false on miss (caller falls back to recordSlow).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Cold-path record: run tint, parse the entry/bindings, compute the write mask from
the declared read_write buffer names, cache under key, and record.
Equations
- One or more equations did not get rendered due to their size.
Instances For
DEVPLAN §12: per-kernel-class GPU-time budget of the captured token. Groups the recorded dispatches by kernel name and times each class alone (serial, back-to-back) — an approximation (no inter-class cache interactions) whose sum should land near the whole-token serial time. Returns one line per class, largest first.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Run the captured token natively in all four timing modes and return a report. Device-free: the MTLDevice was stashed at record time. TIMING ONLY.
Equations
- One or more equations did not get rendered due to their size.