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 trait
Reducer
Parallel scalar reducer over the closed set of associative ops.
Reduces a scalar across all participants in the current parallel
scope; every participant receives the reduced value (like
MPI_Allreduce).
Concrete impls provide hardware-fast sum / max / min over a
closed set of dtypes, plus a generic fallback that combines any
ReduceOp via its join (slower; dtype-agnostic).
Implemented traitsβ
Required methodsβ
sumβ
def sum[dtype: DType](self, val: Scalar[dtype]) -> Scalar[dtype]
Returns the sum of val across all participants.
Parameters:
- βdtype (
DType): The scalar dtype.
Args:
- βval (
Scalar[dtype]): The per-participant value.
Returns:
Scalar[dtype]: The reduced sum, broadcast to every participant.
maxβ
def max[dtype: DType](self, val: Scalar[dtype]) -> Scalar[dtype]
Returns the maximum of val across all participants.
Parameters:
- βdtype (
DType): The scalar dtype.
Args:
- βval (
Scalar[dtype]): The per-participant value.
Returns:
Scalar[dtype]: The reduced maximum, broadcast to every participant.
minβ
def min[dtype: DType](self, val: Scalar[dtype]) -> Scalar[dtype]
Returns the minimum of val across all participants.
Parameters:
- βdtype (
DType): The scalar dtype.
Args:
- βval (
Scalar[dtype]): The per-participant value.
Returns:
Scalar[dtype]: The reduced minimum, broadcast to every participant.
genericβ
def generic[S: ReduceOp](self, mut state: S)
Combines state across all participants using only join β the multi-field path for monoids whose state isn't decomposable into scalar sum/max/min (Welford, ArgMax, ArgMin, β¦).
Impls pick by state size: small states (a few uint32 words) use
a register-only warp-shuffle butterfly, larger states a shmem
tree β both valid since ReduceOp is TrivialRegisterPassable.
Monoids that can decompose (ReduceSum, ReduceMax,
OnlineLogSumExp, β¦) instead call reducer.sum/max/min
directly, which compile to one hardware redux.sync per field
and are faster.
Parameters:
- βS (
ReduceOp): The monoid type being combined.
Args:
- βstate (
S): Per-participant state; on return, holds the combined value on every participant.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!