Skip to main content
Log in

Mojo function

sum

sum[type: DType, width: Int, //, *, block_size: Int](val: SIMD[type, width]) -> SIMD[type, width]

Computes the sum of values across all threads in a block.

Performs a parallel reduction using warp-level operations and shared memory to find the global sum across all threads in the block.

Parameters:

  • type (DType): The data type of the SIMD elements.
  • width (Int): The number of elements in each SIMD vector.
  • block_size (Int): The total number of threads in the block.

Args:

  • val (SIMD[type, width]): The SIMD value to reduce. Each thread contributes its value to the sum.

Returns:

A SIMD value where all threads contain the sum found across the entire block.