IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Mojo struct

LoopBody

struct LoopBody

Declarative specification of one loop iteration's operations and deps.

A directed graph where vertices are OpNode values (operations with resource + latency) and edges are DepEdge values (producer→consumer with loop distance d). Engineers specify WHAT (operations + dependencies), and the framework derives WHEN (schedule order) and HOW (synchronization primitives).

Currently implemented:

  1. ASAP/ALAP times for priority-based scheduling
  2. Structural validation (bounds, self-loop detection)
  3. Synchronization derivation (wait counts, barriers)

Not yet implemented (future work):

  • MII = max(ResMII, RecMII) initiation interval derivation
  • C2 (data dependence) and C4 (resource contention) validation

The graph design draws on LLVM's ScheduleDAG layering and modulo scheduling theory (Rau 1994, GAG96), but the current scheduler optimizes within-iteration makespan, not inter-iteration initiation interval. See DESIGN.md for scope and limitations.

Fields

  • ops (List[OpNode]):
  • edges (List[DepEdge]):

Implemented traits

AnyType, Copyable, ImplicitlyDestructible, Movable

Methods

__init__

__init__(out self)

compute_asap

compute_asap(self) -> List[Int]

Compute ASAP (As Soon As Possible) times for each operation.

ASAP(op) = max over all predecessors p of: ASAP(p) + latency(p) if d == 0 (same iteration) 0 if d >= 1 (loop-carried, skip)

Operations with no same-iteration predecessors get ASAP = 0. This is computed via a fixed-point iteration (handles any DAG order).

Returns:

List[Int]

compute_alap

compute_alap(self, makespan: Int) -> List[Int]

Compute ALAP (As Late As Possible) times for each operation.

ALAP(op) = min over all same-iteration successors s of: ALAP(s) - latency(op)

Operations with no same-iteration successors get ALAP = makespan - latency(op).

This is the backward dual of compute_asap(). The difference ALAP(op) - ASAP(op) gives the scheduling slack (mobility).

Note: currently used in tests only. Future schedulers may use ALAP-based priority to improve ordering heuristics.

Args:

  • makespan (Int): Target schedule length to compute ALAP relative to. Typically the ASAP critical path length.

Returns:

List[Int]

validate

validate(self)

Validate the loop body graph structure.

Checks:

  • All edge indices are in bounds
  • No self-loops with d=0
  • Resource assignments are consistent with op tag