Expand description
The front end of the one IR: the whole-program walk — every tensor statement of a program lifted, in order,
into a typed spec over the shared recognizers, with its dataflow and its carried state named. Every tensor backend
enters here (the CUDA lane, the older forward, the spatial pipeline, the D5005 engine); it is also reached by its
older path, spatial::passes::recognize_stages.
recognize_any in crate::spatial::pipeline lifts ONE op out of a source; an authored forward is a hundred.
This walk reads the program’s top-level statements one at a time (each tensor sugar desugars to one
Stmt::Splice, so a statement is an op) and tries the recognizers in RECOGNIZER_ORDER — the CUDA
orchestrator’s order, composite blocks first so their inner loops are never claimed by a simpler shape.
What it cannot lift it RETURNS: unrecognized lists the statement by index and binder, so a composition
refuses by name and a ledger can print the gap. Nothing is skipped silently.
The result names everything by variable: links is the dataflow (the producer stage of every tensor
and the stages that read it) and state_tensors the carried state (what a step reads AND writes in
place — the conv rings, the GDN memories; the KV cache joins through the masked attention form). These
are the inputs the section composer takes; the lowering of each spec is the composer’s other half.
Structs§
- Declared
Tensor - A tensor the program declares (
Let A be a R by C tensor of T): its flat length and the fill the program gives it (the declaration’s zero fill plus everySet itemoverride). - Link
- A tensor’s producer stage and the stages that read it — the dataflow edge by variable name. A stage whose output nothing reads (the program’s result) has no consumers.
- Recognized
Program - The walk’s result: the stages in program order, the tensor statements it could not lift (by top-level index and binder), the declared tensors, and the names of every symbol the specs mention.
- Recognized
Stage - One lifted statement: the spec, where it sits in the top-level statement list, and its binder and operands
by name (in
TensorOpSpec::insorder).
Enums§
- Tensor
OpSpec - One recognized tensor op — the typed spec the shared recognizers lift. The variant set is the language’s tensor sugar; the lowering of each to a spatial template lives with the composer.
Constants§
- RECOGNIZER_
ORDER - The recognizers a statement is tried against, in order — the CUDA orchestrator’s order, extended with the exact-shape recognizers it has no stage for. The composite blocks (moe, attention) go first: they contain matmul-like loops and a softmax the simpler recognizers would otherwise claim.
Functions§
- carried_
state - The state a step CARRIES to the next —
state_tensorswithout the tables the step assembles whole. A table every row of which the step writes at a literal row (Set row 2 of X,Set rows from 1 of X, a block gated delta’s output) before any stage reads it begins each step with nothing the step can see: a chunk’s stacked rows, its RoPE block. The KV cache is carried — it is written at a position the data gives and read far beyond it — and so are the conv rings and the memories, which every step reads before it writes. - float_
tensors - Which tensors of a walked program hold FLOAT data, propagated forward from the declarations, each name as its last write leaves it.
- links
- The dataflow by variable name: for every stage, the later stages that read its output.
- recognize_
stages - Walk a program’s top-level statements into typed specs.
Erronly when the source does not parse; a statement that parses but is no op the walk knows is reported inunrecognized. - state_
tensors - The state, in first-appearance order: every tensor some stage reads and writes back in place, and every table an
op assembles a row at a time (
TensorOpSpec::assembled_rows). - walk
recognize_stagesover statements already parsed — every backend’s front end: the CUDA forward refuses what this walk reports asunrecognizedorunlifted_writes, so both lanes agree on what a program’s statements are. The shape table is the caller’s to add (it comes from the parse, not the statements).