IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /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. /get-started.md).

Mojo function

block_prefix_sum

def block_prefix_sum[dtype: DType, //, num_elements: Int, thread_base: Int = Int(0), n_scoped_threads: Int = Int(0), barrier_id: Int = Int(-1)](_val: Scalar[dtype]) -> Scalar[dtype]

Performs a prefix sum (scan) operation across all threads in a block.

Parameters:

  • ​dtype (DType): Element type of the values being scanned (inferred).
  • ​num_elements (Int): Number of active threads in the block that contribute values to the scan.
  • ​thread_base (Int): Absolute thread_idx.x of the first participating thread (0 in the standalone kernels; the FFN thread count when a comm thread-class runs the scan in a fused megakernel). All indices are relative to this base.
  • ​n_scoped_threads (Int): Thread count the scan's block barriers scope to when barrier_id >= 0 (the comm thread-class size).
  • ​barrier_id (Int): Named-barrier id for the scan's barriers, or negative (the default) for the full-block barrier().

Args:

  • ​_val (Scalar[dtype]): The per-thread value to contribute to the inclusive prefix sum.

Returns:

Scalar[dtype]

Was this page helpful?