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_launch
def reduce_launch[num_reductions: Int, rank: Int, dtype: DType, InputFnType: def[dtype: DType, width: Int](Coord[**?]) -> SIMD[dtype, width] & RegisterPassable & ImplicitlyCopyable, OutputFnType: def[dtype: DType, width: SIMDLength](Coord[**?], StaticTuple[SIMD[dtype, width], num_reductions]) -> None & RegisterPassable & ImplicitlyCopyable, ReduceFnType: def[ty: DType, width: SIMDLength, reduction_idx: Int](SIMD[ty, width], SIMD[ty, width]) -> SIMD[ty, width] & RegisterPassable & ImplicitlyCopyable, //, *, reduce_dim: Int](shape: IndexList[rank], init: StaticTuple[Scalar[dtype], num_reductions], input_fn: InputFnType, output_fn: OutputFnType, reduce_fn: ReduceFnType, ctx: DeviceContext)
Selects and launches the appropriate GPU reduction kernel based on the tensor shape, axis, and device saturation level.
Three-tier dispatch:
- Thread-saturated (many rows, non-contiguous axis): one row per thread
via
saturated_reduce_kernel. - Block-saturated (enough rows to fill SMs at one block per row):
reduce_kernelorsmall_reduce_kernel. - Under-saturated (too few rows to fill the device): multiple blocks per
row via
twophase_reduce_kernelwith a two-phase atomic finish.
Parameters:
- num_reductions (
Int): The number of fused reductions to perform. - rank (
Int): The tensor rank. - dtype (
DType): The data type of the elements. - InputFnType (
def[dtype: DType, width: Int](Coord[**?]) -> SIMD[dtype, width]&RegisterPassable&ImplicitlyCopyable): The type ofinput_fn(inferred). - OutputFnType (
def[dtype: DType, width: SIMDLength](Coord[**?], StaticTuple[SIMD[dtype, width], num_reductions]) -> None&RegisterPassable&ImplicitlyCopyable): The type ofoutput_fn(inferred). - ReduceFnType (
def[ty: DType, width: SIMDLength, reduction_idx: Int](SIMD[ty, width], SIMD[ty, width]) -> SIMD[ty, width]&RegisterPassable&ImplicitlyCopyable): The type ofreduce_fn(inferred). - reduce_dim (
Int): The axis along which to reduce.
Args:
- shape (
IndexList[rank]): The shape of the input tensor. - init (
StaticTuple[Scalar[dtype], num_reductions]): The identity values for each reduction. - input_fn (
InputFnType): The lambda to load input elements. - output_fn (
OutputFnType): The lambda to store output elements. - reduce_fn (
ReduceFnType): The binary reduction function. - ctx (
DeviceContext): The device context for GPU execution.
Raises:
If the GPU kernel launch fails.