Skip to main content

Module runtime_fused

Module runtime_fused 

Source
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§

RuntimeFusedOpEntry
A runtime-registered fused op’s metadata (the graph-side recipe).

Enums§

RelAttrError
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. The field names the CONCRETE sibling the rel field resolves into ("target_shape", "slice_start", "slice_len", "axis", "dims").
RuntimeFusedError
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.scalars is empty (a baked value is a pattern constant, not a slot). This is the length of the scalars vec match_region_extract returns for a match, and of the FusedOpParams::Runtime { scalars } the fused node must carry for decompose_region to 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). If id is 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 + input NodeIds — e.g. the reference realization during candidate-kernel verification, which has a raw region and freshly-pushed Op::Const input nodes rather than a Fused node already in the graph). scalars fill the region’s open scalar slots in pre-order (the canonical order match_region_extract recorded them in); pass &[] for a parameterless region. Thin wrapper over the private emit; the same re-emittability caveat applies (a non-re-emittable OpTag panics inside emit — validated decomposes never carry one). Second panic risk: emit’s scalar-cursor fill (scalars.split_at(arity)) panics if scalars is shorter than the region’s total open-slot count. decompose_region (the node-driven caller) guards this with its own length check before ever calling emit; emit_region deliberately does NOT — it’s a thin wrapper, so validating the length is the caller’s job. Callers must pass a scalars slice 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’s expect — rel-attr callers use try_emit_region, which surfaces it as a typed RelAttrError instead.
register_runtime_fused
Register a runtime fused op for region, returning its runtime FusedOpId. 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-concrete OpAttrs ready for the unchanged tag_to_op → primitive_shape path. 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-shaped decompose for runtime ops: re-emit the region. The scalar extract: substitution rides on the NODE (its FusedOpParams::Runtime { scalars } fills the region’s open slots inside decompose_region), so the rule-shaped params argument stays unused.
runtime_name
A runtime op’s name (telemetry / op_short_name routing).
runtime_region
The region (recipe) for a runtime fused op, or None if id is not a registered runtime op.
try_emit_region
The FALLIBLE re-emit entry (Increment C slice 1, T3): like emit_region but surfacing a shape-relative attr resolution failure (D2) as a typed RelAttrError instead of a panic. This is the resolving entry the registry decompose_via_recipe bridge calls (any failure ⇒ return id, the G2 fixpoint). Concrete-attr regions can never hit the Err arm — for them this is exactly the legacy emit_region. The emit_region panic caveats (non-re-emittable OpTag, short scalars slice) apply unchanged.