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
reduce
def reduce[params: ContextParams, //, TileFn: def[ws: Int, _r: Int](IndexList[_r]) -> None & ImplicitlyCopyable](row_coords: Coord, axis_size: Int, ctx: Context[params], tile_fn: TileFn)
Drives tile_fn over the reduce axis, CPU-side, with no monoid state β pure per-tile iteration for map/emit terminals (see the state-carrying overload below for reduce phases).
Tiers mirror the state-carrying overload; see there for the per-tier walk description.
Parameters:
- βparams (
ContextParams): Comptime dispatch parameters. - βTileFn (
def[ws: Int, _r: Int](IndexList[_r]) -> None&ImplicitlyCopyable): The value-closure type oftile_fn.
Args:
- βrow_coords (
Coord): The current row's coords. - βaxis_size (
Int): Length of the reduce axis. - βctx (
Context[params]): The dispatch bundle (unused on CPU beyond comptime params reads). - βtile_fn (
TileFn): Per-tile callback; closes over input/output closures.
def reduce[State: ReduceOp, params: ContextParams, //, TileFn: def[ws: Int, _r: Int](mut State, IndexList[_r]) -> None & ImplicitlyCopyable](row_coords: Coord, axis_size: Int, ctx: Context[params], mut state: State, tile_fn: TileFn) where (eq TileFn.State, State)
Drives tile_fn over the reduce axis, CPU-side.
Two tiers, picked from params.emit_tile_width:
emit_tile_width == 1: walk axis insimd_widthchunks, 8-way unrolled (matches legacy_reduce_along_inner_dimension), then SIMD and scalar tails.tile_fn[ws]is called withws β {simd_width, 1}; the monoid's width-polymorphicreduce[w]collapses each tile.emit_tile_width > 1: scalar axis walk,tile_fn[W]per step. The body holdsWparallel accumulators (the monoidMat widthW); each step issues one SIMD load on the innermost-non-axis dim, spreading lanes across the accumulators.
tile_fn is a value closure (its copy-captured state β input
closures, side-loaded tensors β rides the value); it takes the
caller's monoid state as a mut argument rather than capturing it,
since a captured accumulator can't be mutated through a value
closure (captures are immutable) but an inout argument can.
Parameters:
- βState (
ReduceOp): The monoid type being accumulated. - βparams (
ContextParams): Comptime dispatch parameters. - βTileFn (
def[ws: Int, _r: Int](mut State, IndexList[_r]) -> None&ImplicitlyCopyable): The value-closure type oftile_fn.
Args:
- βrow_coords (
Coord): The current row's coords. - βaxis_size (
Int): Length of the reduce axis. - βctx (
Context[params]): The dispatch bundle (unused on CPU beyond comptime params reads). - βstate (
State): The caller's monoid accumulator, threaded through bymutreference and mutated in place bytile_fn. - βtile_fn (
TileFn): Per-tile callback; closes over input closures and folds each tile intostate.