inky-engine 3.0.2

A hand-fused Metal inference engine for Thinking Machines' Inkling 2 Mini, for Apple M5 Macs
--------------------------- MODULE ServeStepDefer ---------------------------
\* The step after the plan: serve allocates blocks for the lanes `ServeStepPlanner` picked, and a
\* lane whose blocks are not there is deferred without running (`partition_pool_exhausted` in
\* src/serve.rs, then `ServeStepPlanner::unserve`). This module adds that step to
\* ServeStepBypass.tla unchanged: its Plan, then Unserve, then its Env.
\*
\* A deferred lane was not served, and it was not runnable after all: the pool held it back, as
\* backpressure does. Its ghost stays at the 0 the plan gave it, and its `served` is cleared (a
\* prefiller that did not run cannot finish its prompt). What its counter becomes is `Defer`:
\*   "kept"          the code: the counter stays as the plan left it (0). `unserve` only marks
\*                   the lane owed, and the next plan that picks it lists it first, so serve
\*                   offers it blocks first. That is an order inside a step, not a choice of
\*                   lanes or class, so this model does not need it; the Rust tests check it
\*                   (src/scheduler/tests.rs, `a_lane_left_unserved_is_listed_first_until_a_step_serves_it`).
\*   "age_plus_one"  reversed witness, 6ee65d2 (PR 220's first fix): the age before the plan plus
\*                   one, at most W. A decoder deferred and woken at once every step reaches W,
\*                   ties a prefiller at W, and the tie goes to decode: the prefiller is passed
\*                   over W + 1 steps in a row.
\*
\* To fold into ServeStepBypass.tla once PR 222 (which changes that module) lands: Unserve becomes
\* part of its Plan, `planned` and `settled` go away, and these configs become its own.
EXTENDS ServeStepBypass

CONSTANT Defer
ASSUME Defer \in {"kept", "age_plus_one"}

\* `planned`: each lane's age before the latest plan (only the witness reads it).
\* `settled`: FALSE between a plan and serve's block allocation for it.
VARIABLES planned, settled
deferVars == <<cls, run, wait, ghost, served, phase, planned, settled>>

DeferredAge(age) == IF Defer = "age_plus_one" THEN Min(age + 1, W) ELSE 0

DeferInit ==
    /\ Init
    /\ planned = [l \in Lanes |-> 0]
    /\ settled = TRUE

DeferEnv ==
    /\ settled
    /\ Env
    /\ UNCHANGED <<planned, settled>>

DeferPlan ==
    /\ settled
    /\ Plan
    /\ planned' = IF Defer = "kept" THEN planned ELSE wait
    /\ settled' = FALSE

\* Serve finds no blocks for some of the lanes the plan picked and defers them.
Unserve ==
    /\ phase = "env"
    /\ ~settled
    /\ \E deferred \in SUBSET {l \in Lanes : served[l]} :
          /\ wait'   = [l \in Lanes |-> IF l \in deferred THEN DeferredAge(planned[l]) ELSE wait[l]]
          /\ served' = [l \in Lanes |-> served[l] /\ l \notin deferred]
    /\ settled' = TRUE
    /\ UNCHANGED <<cls, run, ghost, phase, planned>>

DeferNext == DeferEnv \/ DeferPlan \/ Unserve
DeferSpec == DeferInit /\ [][DeferNext]_deferVars

DeferTypeOK ==
    /\ TypeOK
    /\ planned \in [Lanes -> Nat]
    /\ settled \in BOOLEAN

\* BypassBound, CounterCovers and CounterBound are ServeStepBypass's, checked in every state,
\* between the plan and the deferral too.
=============================================================================