IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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_add_simd

def reduce_add_simd[simd_width: SIMDLength, step_simd_width: SIMDLength, dtype: DType](mut scalar: Scalar[dtype], mut vector: SIMD[dtype, simd_width], val: SIMD[dtype, step_simd_width])

This functions adds val to either the scalar value or the vector value depending on the step_simd_width. This is useful when the simd_width varies between iterations as in vectorize.

Parameters:

  • ​simd_width (SIMDLength): The full SIMD width of the vector accumulator.
  • ​step_simd_width (SIMDLength): The width of the current step's val; when 1, val is accumulated into scalar, otherwise into vector.
  • ​dtype (DType): The element type of the accumulators and val.

Args:

  • ​scalar (Scalar[dtype]): Scalar accumulator for single-element steps; updated in place when step_simd_width is 1.
  • ​vector (SIMD[dtype, simd_width]): SIMD accumulator for full-width steps; updated in place when step_simd_width matches simd_width.
  • ​val (SIMD[dtype, step_simd_width]): The partial reduction value to accumulate into either scalar or vector.

Was this page helpful?