Expand description
SpatialProgram — the spatial IR proper.
Tensors live in global memory. Stages move tiles (Load/Store), receive multicast blocks (Recv),
compute on tiles (Compute) or run a scalar dataflow body (Scalar). Stages exchange tiles through
bounded Buffers along typed Edges. The tile pass fixes the per-site block plan, place pins
every stage to a Site and engine, fuse_readers introduces multicast Groups, size_buffers
fixes depths and offsets, synthesize_handshakes emits the per-engine Schedule of ChoreoOps,
and verify attaches the certificate. Every phase marker is an Option in strict order — a program is
always in exactly one Phase and SpatialProgram::validate holds after every pass.
There is deliberately NO strategy enum in this file: PlanSummary REPORTS the emergent plan (how many
multicast groups, which block shape, how many engine-program classes) from the structure itself.
Structs§
- Access
Pattern - A rectangular block of tiles read or written per step:
block_h × block_wtiles starting atorigin, consecutive tilesstride_wapart along a row and rowsstride_hapart. - Block
Plan - The per-site block plan the
tilepass fixes. - Block
Shape - The compute block shape in tiles: output sub-block
osh × osw, inner-dimension blockibw. - Buffer
- Buffer
At - Buffer
Id - A buffer.
- ChipId
- WHICH RDU. A tensor-parallel program is one program over many chips; the chip is a COORDINATE of a site, not a separate compilation. Absent (or zero) everywhere in a single-chip program, so every artifact and fixture written before tensor parallelism serializes and parses byte-identically.
- Edge
- EdgeId
- An edge.
- Elem
Access - A FLAT, SIGNED affine map from the iteration space to one operand’s element offset:
base + Σ var·stride, over the operand’s page read as a row-major plane oftile.rowsrows andpage_tiles · tile.colscolumns. The evaluator recovers(row, col) = (off / width, off % width), and an offset outside the plane reads 0.0 — never a fault — so an unselectedTensorBody::Selectbranch may point past the page. - Elem
Shape - Engine
Program - Engine
Slot - Group
- GroupId
- A multicast group.
- Indirect
Term - A value-dependent element term:
(operand's value at this point) · stride, taken modulomodulus— the element-level gather (a top-k index into a row, a token id into a table row). Declared in B-P3 as a type (validated:operandmust be one of the stage’s operands,modulusnonzero); its evaluation and certificate semantics are B-P5, and until then the evaluator REFUSES a map that carries one rather than dropping the term. - Indirect
Tile - A value-dependent tile address: the tile is chosen by an INDEX read from a buffer, not by the loop variables — an embedding row, a KV-cache slot, a flash-attention block, a chosen expert’s weights.
- Inner
Loop - Iter
Spec - One axis of a
ComputeOp::Genericiteration space. - Link
Point - ★ A HALT AT A SECTION BOUNDARY, FOR WHAT CROSSES THE LINK. One chip’s program of a program split over chips
(
compile_program_to_chips) stops here so its tensors can cross: firstsends, which the sections before it have written and another chip reads, are taken from it; thenreceives, which another chip writes and the sections after it read, are put into it; then it continues. - LoopVar
- A loop variable of the choreography.
- Memory
Map - NocId
- A NOC channel index.
- Placement
- Plan
Summary - The emergent plan, REPORTED from structure — never an input.
- Rect
- An inclusive rectangle of sites.
- Rendezvous
- The rendezvous that closes a section: its gather and its release semaphore.
- Requirements
- What a pass recorded the program as needing from its target (kept on the program so
validatestays target-free while the pipeline gates the requirements against the descriptor). - Scalar
Body - A scalar dataflow body (the CGRA’s
LoopCelldatapath) applied element-wise over its input tiles. - Schedule
- Section
Span - One SECTION of a composed program: the half-open range this section owns in every id space, the plan and work list it was lowered under, the tensor it writes, and the rendezvous every engine passes through before the next section begins.
- SemId
- A semaphore.
- Semaphore
- Site
- A LOGICAL mesh coordinate. Physical (NOC) coordinates are a lowering concern and never enter the IR.
- Site
Items - Every site’s work items, section by section — see
SpatialProgram::site_items. - Spatial
Program - Stage
- StageId
- A stage.
- Tagged
Op - Tensor
Decl - Tensor
Id - A global tensor.
- Tile
Addr - A tile id that is affine in the choreography’s loop variables:
base + Σ env[var]·stride, plus an optional value-dependent term (IndirectTile). - Tile
Grid - Tile
Rect - Trip
- ★ A LOOP COUNT THE PROGRAM READS FROM ITS OWN DATA. Element
elemof the inputtensor— a program argument, set before the program runs and never written by it — givesv, and every loop run to the trip runsn = ⌈(v + bias) / per⌉times. The program admits the valuesadmit.0 ..= admit.1, stated in the value’s own units — a position against the cache it indexes — so a value outside them is refused before anything runs, by the same range the program’s own checks hold it to, never as a clamped or wrapped count. The counts run fromTrip::lotoTrip::hi, the bound every static question takes (a loop’sLoopCount::Trip::maxis exactly it). - TripId
- A loop count the program reads from its data (
Trip). - Work
Item - Work
Item Id - A work item (one output block).
- Work
List
Enums§
- AccPolicy
- The accumulator format of a tile matmul.
- AccRead
- How an
AccMapreads an operand for elementeof accumulator tilek. - Arch
Cond - Barrier
Phase - The two halves of a centralized barrier over
nengine programs. - Buffer
Kind - Choreo
Op - One step of a site engine’s choreography.
- Compute
Op - Compute
Shape - A
ComputeOpas the shapes a printer that computes in software tells apart: a tile product, an elementwise map over the acquired accumulator, the general form, a scalar body. Such a printer matches on what an op computes and never on which epilogue it is. Requant, bias and ReLU are each anAccMap, whose body it prints as it prints a Generic’s. - DimAxis
- One of a tensor’s two tile-grid extents.
- Direction
- Engine
- Which engine of a site runs a stage.
- Engine
Packing - Which movement engine carries which stream. Engines run concurrently, so the packing decides what overlaps what: keeping both operand loads together serialises them against each other, while giving one operand an engine to itself and pairing the other with the store overlaps block k’s output write with block k+1’s operand reads. Both are legal on any target with two movement engines; which one wins is measured.
- Fold
Level - Where a stage runs in its item’s fold over K blocks — see
SpatialProgram::fold_levels. - Granularity
- Whether the matrix engine is driven one tile per call or one sub-block per call.
- Handshake
- IrViolation
- A structural invariant the program breaks. Every arm is a lock.
- Iter
Kind - Whether an axis survives into the output or is folded away.
- Layout
- Loop
Count - How many times a loop runs.
- MemSpace
- Numerics
Claim - What the program claims about its result versus the exact integer reference.
- Numerics
Policy - Whether a partial sum may round when it spills to a narrower intermediate buffer.
- Operand
- Phase
- Pred
- An axis predicate: which side of a bound the current point of the iteration space is on.
- PredRhs
- The bound of an axis predicate.
- Reduce
Pool - The pooling function of a reduction (over whichever axis is marked
IterKind::Reduce). - RowXform
Kind - How a reduced per-row scalar becomes the multiplier the rescale broadcasts back across the row.
- SemCond
- SemRole
- SemValue
- Sfpu
Kind - The SFPU’s element-wise repertoire. A new transform is a new KIND, never a new
ComputeOp. - Site
Role - Stage
Kind - Tensor
Body - The scalar expression a
ComputeOp::Genericapplies at each point of its iteration space. - Tensor
Init - How a tensor’s contents are produced — recognized from the source’s array-build loop, so a host can reproduce the data and the numerics claim can bound the operand range.
- Tensor
Role - Tensor
Space
Functions§
- body_
ops - The untagged ops of a loop body.
- walk_
ops - Walk a choreography with loop multiplicities:
f(op, multiplicity)for every op reached. A loop run to a trip counts its trip’s greatest count here (LoopCount::bound). - walk_
tagged - Walk a tagged choreography:
f(tagged op, multiplicity)for every op reached, loop bodies included, each loop run to a trip counted at its greatest count. - walk_
tagged_ counted walk_taggedwith each loop counted bycount—LoopCount::boundfor the static bound, a trip’s count at a position for the run a position makes.- walk_
tagged_ ops walk_opsover a tagged choreography.