IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /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. /get-started.md).

Mojo function

launch

def launch[Body: RowBody, //, axis: Int, simd_width: Int, target: StringSpan[ImmStaticOrigin], num_phases: Int, computationally_expensive: Bool = False, associative: Bool = False, dtype_size: Int = Int(0)](body: Body, shape: Coord, ctx: Optional[DeviceContext] = None)

Top-level scaffolder. num_phases picks reduce-shaped (num_phases == 1, output collapses the reduced axis, terminal emit) vs. normalize-shaped (num_phases > 1, output keeps the input shape, terminal elementwise) β€” see the module note above for the full picture, including the GPU tier-dispatch decision tree.

Parameters:

  • ​axis (Int): Axis being reduced.
  • ​simd_width (Int): SIMD width for tile dispatch. Bodies compute this via rowwise.pick_simd_width[...] and pass it directly.
  • ​target (StringSpan[ImmStaticOrigin]): "cpu" or "gpu" (anything non-CPU routes through the GPU backend).
  • ​num_phases (Int): Total phase count β€” 1 for reduce-shaped bodies (the reduce's own result is the final output); > 1 for normalize-shaped bodies (num_phases - 1 dependent row.reduce phases before a final per-element write). Asserted > 0.
  • ​computationally_expensive (Bool): GPU author hint β€” flips the block tier's SIMD-full threshold for compute-heavy bodies. CPU ignores.
  • ​associative (Bool): Reduce-shaped (num_phases == 1) only, CPU-only. Set True to widen the accumulator on long rows so the running total doesn't serialize into one add-per-element chain (recovers memory bandwidth). Only correct when reordering the accumulation doesn't change the result β€” additive reductions like reduce_sum / reduce_mean. Leave False for anything where element order matters (product's narrower-dtype rounding, tie-breaking in arg_max / arg_min, ...). Ignored on GPU and meaningless for normalize-shaped bodies.
  • ​dtype_size (Int): Normalize-shaped (num_phases > 1) only, GPU only. Byte size of the body's primary dtype (size_of[dtype]()), used only by the phase-aware split-K byte gate; 0 (the default) leaves that tier's runtime condition permanently false, so the extra codegen it introduces is unreachable (softmax / log-softmax pass their dtype's size to actually engage it). Meaningless for reduce-shaped bodies.

Args:

  • ​body (Body): The per-row computation. Receives a Context and the row's Coord; uses reduce / pjoin / once / simd to compose the algorithm.
  • ​shape (Coord): Tensor shape.
  • ​ctx (Optional[DeviceContext]): Optional DeviceContext; required for target="gpu", unused on CPU.

Raises:

On launch or worker failure.