Expand description
Runtime fused-op registration — the Tier-2 sidecar
(docs/specs/runtime-fused-op-registration.md).
A runtime-registered (JIT-synthesized or import-time) fused op is its
region: its identity is a runtime FusedOpId, its recipe is the §3
PatternNode region kept here, and its decompose is that region
re-emitted as primitives — so the recipe principle (total / never-panic /
primitive→self) holds for free, since OpTag is the functional-primitive
vocabulary only. No kernel field: the kernel binding lives in fuel-dispatch’s
FusedKernelRegistry (Tier-1 extensible); this sidecar holds only the
graph-side recipe + the optimizer rules built from it.
v1 scope: same-shape elementwise regions (the synthesizer’s increment-1 epilogues). Interior shape inference for broadcast/reduction regions is a follow-up — a re-emitted node takes its first operand’s shape/dtype, exact for type-preserving same-shape ops and rejected-at-registration otherwise.
Structs§
- Runtime
Fused OpEntry - A runtime-registered fused op’s metadata (the graph-side recipe).
Enums§
- RelAttr
Error - A shape-relative attr resolution failure — a typed decline, never a panic.
The emit-integration caller (T3) surfaces any of these as a decompose
fixpoint (
return id, G2); the registration-validation caller rejects the region. Thefieldnames the CONCRETE sibling the rel field resolves into ("target_shape","slice_start","slice_len","axis","dims"). - Runtime
Fused Error - A registration failure — never a panic (build-time validation).
Functions§
- count_
scalar_ slots - Count the region’s open scalar slots in pattern pre-order — scalar-param
ops whose
attrs.scalarsis empty (a baked value is a pattern constant, not a slot). This is the length of thescalarsvecmatch_region_extractreturns for a match, and of theFusedOpParams::Runtime { scalars }the fused node must carry fordecompose_regionto fill the re-emit. - decompose_
region - Decompose a runtime
Op::Fused(id, Runtime { .. })node by re-emitting its region as primitives, returning the new root (the re-emitted sink). Ifidis not a registered runtime op the node is returned unchanged (a fixpoint — no recipe, G2). The matched node’s inputs are the region’s bound external inputs in bind-index order. - emit_
region - Re-emit a validated region on the given external input nodes (public entry
for callers holding a raw
PatternNode+ inputNodeIds — e.g. the reference realization during candidate-kernel verification, which has a raw region and freshly-pushedOp::Constinput nodes rather than a Fused node already in the graph).scalarsfill the region’s open scalar slots in pre-order (the canonical ordermatch_region_extractrecorded them in); pass&[]for a parameterless region. Thin wrapper over the privateemit; the same re-emittability caveat applies (a non-re-emittableOpTagpanics insideemit— validated decomposes never carry one). Second panic risk:emit’s scalar-cursor fill (scalars.split_at(arity)) panics ifscalarsis shorter than the region’s total open-slot count.decompose_region(the node-driven caller) guards this with its own length check before ever callingemit;emit_regiondeliberately does NOT — it’s a thin wrapper, so validating the length is the caller’s job. Callers must pass ascalarsslice at least as long as the region’s open-slot count. Third (T3): a shape-RELATIVE attr (D2) that fails to resolve at these input shapes panics through the wrapper’sexpect— rel-attr callers usetry_emit_region, which surfaces it as a typedRelAttrErrorinstead. - register_
runtime_ fused - Register a runtime fused op for
region, returning its runtimeFusedOpId. Validates before allocating that the region’s bind indices form the op’s input list and that every op re-emits to primitives (totality) — a non-decomposable region is rejected, never registered. - resolve_
rel_ attrs - Resolve
attrs’ shape-RELATIVE fields (target_shape_rel,slice_start_rel/slice_len_rel,axis_last— D2) into their concrete siblings, returning a fully-concreteOpAttrsready for the unchangedtag_to_op→primitive_shapepath. Pure: no graph access. - runtime_
entries - All registered runtime ops — the optimizer iterates this to build a fusion
rule + a lowering rule per runtime op (
RuleRegistry::default_rules/lowering_only). - runtime_
lowering_ decompose - A
crate::opt::LoweringRule-shapeddecomposefor runtime ops: re-emit the region. The scalarextract:substitution rides on the NODE (itsFusedOpParams::Runtime { scalars }fills the region’s open slots insidedecompose_region), so the rule-shapedparamsargument stays unused. - runtime_
name - A runtime op’s name (telemetry /
op_short_namerouting). - runtime_
region - The region (recipe) for a runtime fused op, or
Noneifidis not a registered runtime op. - try_
emit_ region - The FALLIBLE re-emit entry (Increment C slice 1, T3): like
emit_regionbut surfacing a shape-relative attr resolution failure (D2) as a typedRelAttrErrorinstead of a panic. This is the resolving entry the registrydecompose_via_recipebridge calls (any failure ⇒return id, the G2 fixpoint). Concrete-attr regions can never hit theErrarm — for them this is exactly the legacyemit_region. Theemit_regionpanic caveats (non-re-emittableOpTag, shortscalarsslice) apply unchanged.