Expand description
N2 substrate (foundation half): per-rewrite speculation-as-substrate decision policy. Given baseline + speculative dispatch observations
- side-compile cost, returns Adopt / Reject / KeepRacing. N2 substrate (foundation half): per-rewrite speculation-as-substrate decision policy.
Generalizes I2’s trace-JIT speculation to ANY “probably profitable” rewrite (vec_pack, shared_promote, async_load_promote, …). For each candidate rewrite the runtime keeps two compiled variants - a conservative baseline and a speculative variant - and races them against the autotune DB’s recorded winner.
This module owns the pure decision: given the speculative variant’s
observed cost vs the baseline (recorded by I3 crate::autotune_store),
return crate::speculation_substrate::SpeculationVerdict::Adopt (replace baseline with speculative
in the cache) or crate::speculation_substrate::SpeculationVerdict::Reject (drop speculative,
stop racing). Pure arithmetic; no I/O, no allocation.
The runtime side (compiling both variants on a side pipeline cache
key, dispatching them in alternation, recording observations to
crate::autotune_store) lives in runtime_megakernel and is
Codex’s lane. This module is the half that’s safe to land before
that wiring exists - every consumer reads the same decision contract.
Structs§
- Speculation
Observation - Per-shape observation feeding the speculation decision.
Enums§
- Speculation
Verdict - Verdict returned by
decide_speculation.
Constants§
- MIN_
ADOPT_ SAVINGS_ BPS - Minimum savings in basis points (1 bp = 0.01%) the speculative variant must show over the baseline to be adopted, after side-compile cost amortization. 1500 bps = 15% - tuned conservative so adopting is rare but high-confidence.
- MIN_
DISPATCHES_ FOR_ VERDICT - Minimum number of dispatches per variant before a verdict can be rendered. Below this threshold the variance dominates and the decision is unreliable; the runtime keeps racing both variants.
Functions§
- decide_
speculation - Decide whether to adopt the speculative variant, reject it, or keep racing. Pure arithmetic; widened throughout so adversarial inputs cannot panic or silently clamp a release-path adoption decision.