Documentation

Hesper.WGSL.NativeReplay

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:

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 (mainv), 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; commitToken executes them natively.

  • frozen : Mode

    FROZEN token replay (CUDA-Graphs analogue): the dispatch sequence recorded by an earlier nativeExec token 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 and commitToken (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

    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. mainv). Empty = unusable.

    • order : Array String

      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 : Array Nat

      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).

      Equations
      • One or more equations did not get rendered due to their size.
      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

                  Total threadgroup-memory upper bound: Tint packs all shared vars into one struct at [[threadgroup(0)]]; over-allocating is harmless, so pad each member to 16.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    def Hesper.WGSL.NativeReplay.tryRecordFast (device : WebGPU.Device) (key : UInt64) (dbgName : String) (namedBuffers : List (String × WebGPU.Buffer)) (numWorkgroups : Nat × Nat × Nat) (wgX wgY wgZ : Nat) :

                    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
                      def Hesper.WGSL.NativeReplay.recordSlow (device : WebGPU.Device) (key : UInt64) (wgsl dbgName : String) (namedBuffers : List (String × WebGPU.Buffer)) (writableNames : List String) (tgBytes : Nat) (numWorkgroups : Nat × Nat × Nat) (wgX wgY wgZ : Nat) :

                      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.
                          Instances For