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 function

optimal_schedule

optimal_schedule(body: LoopBody, max_vgpr: Int = 999999) -> List[Int]

Find the minimum-makespan execution ordering via backtracking search.

Explores all valid orderings (respecting d=0 dependency edges) and returns the one with minimum simulated within-iteration makespan. Among equal-makespan solutions, prefers lower peak VGPR pressure.

When max_vgpr is set (default: no limit), rejects orderings whose peak VGPR pressure exceeds the budget. This enables occupancy exploration: "What is the fastest schedule that fits in N VGPRs?"

Uses iterative backtracking with explicit state — no recursion.

Returns:

List[Int]: Permutation of [0, num_ops) with minimum makespan (and lowest pressure among equal-makespan solutions).