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
reduce_launch
def reduce_launch[num_reductions: Int, input_fn: def[dtype: DType, width: Int, rank: Int](IndexList[rank]) capturing thin -> SIMD[dtype, width], output_fn: def[dtype: DType, width: SIMDLength, rank: Int](IndexList[rank], StaticTuple[SIMD[dtype, width], num_reductions]) capturing thin -> None, reduce_fn: def[ty: DType, width: SIMDLength, reduction_idx: Int](SIMD[ty, width], SIMD[ty, width]) capturing thin -> SIMD[ty, width], rank: Int, dtype: DType, *, reduce_dim: Int](shape: IndexList[rank], init: StaticTuple[Scalar[dtype], num_reductions], 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. - βinput_fn (
def[dtype: DType, width: Int, rank: Int](IndexList[rank]) capturing thin -> SIMD[dtype, width]): The lambda to load input elements. - βoutput_fn (
def[dtype: DType, width: SIMDLength, rank: Int](IndexList[rank], StaticTuple[SIMD[dtype, width], num_reductions]) capturing thin -> None): The lambda to store output elements. - βreduce_fn (
def[ty: DType, width: SIMDLength, reduction_idx: Int](SIMD[ty, width], SIMD[ty, width]) capturing thin -> SIMD[ty, width]): The binary reduction function. - βrank (
Int): The tensor rank. - βdtype (
DType): The data type of the elements. - β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. - βctx (
DeviceContext): The device context for GPU execution.
Raises:
If the GPU kernel launch fails.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!