Skip to main content
Log in

Mojo function

sum

sum[val_type: DType, simd_width: Int, //](val: SIMD[val_type, simd_width]) -> SIMD[val_type, simd_width]

Computes the sum across the warp.

Parameters:

  • val_type (DType): The type of the SIMD value.
  • simd_width (Int): The width of the SIMD value.

Args:

  • val (SIMD[val_type, simd_width]): The SIMD value to sum.

Returns:

A SIMD value with the sum of all lanes.

sum[intermediate_type: DType, *, reduction_method: ReductionMethod, output_type: DType](x: SIMD[type, size]) -> SIMD[output_type, 1]

Performs a warp level reduction using either a warp shuffle or tensor core operation. If the tensor core method is chosen, then the input value is cast to the intermediate type to make the value consumable by the tensor core op.

Parameters:

  • intermediate_type (DType): The type of the intermediate value.
  • reduction_method (ReductionMethod): The method to use for the reduction.
  • output_type (DType): The type of the output value.

Args:

  • x (SIMD[type, size]): The value to reduce.

Returns:

The reduced value.