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 module

rowwise

CPU row-wise reduction scaffolder.

Mirrors the body-facing surface of algorithm.gpu.rowwise so the same body[params: ContextParams](row_coords, mut ctx) works for both targets. Reuses GPU's ContextParams / Context types verbatim; the GPU-only runtime fields (split-K pointers and counters) get sentinels and are never read.

Tier mapping CPU ↔ GPU:

  • Inner-axis cooperative (emit_tile_width == 1, axis == rank - 1): one worker per row, vectorize the row at simd_width. Mirrors the GPU block tier with BLOCK_SIZE = 1.
  • Inner-axis split-axis (reduce-shaped, few long rows): each row splits across workers; the last to arrive joins the partials and emits. Mirrors the GPU single-state split-K tier.
  • Inner-axis pointwise split-axis (normalize-shaped, one long row): the row splits across workers, one sync_parallelize per phase. Mirrors the GPU K+1-launch pointwise split-K tier.
  • Non-inner-axis tiled (emit_tile_width > 1, supports_tiled): one worker per slice; tile the innermost-non-axis dim with W = simd_width independent accumulators. Mirrors the GPU tiled tier.
  • Non-inner-axis cooperative (emit_tile_width == 1, !supports_tiled): one worker per output, scalar walk over the reduce axis. Mirrors the GPU cooperative-non-inner tier.

pjoin is a no-op on CPU and once runs unconditionally: one worker owns each output, so the monoid state is already final after reduce.

comptime values​

CPU_WIDE_ACCUMULATOR_FACTOR​

comptime CPU_WIDE_ACCUMULATOR_FACTOR = 4

Structs​

  • ​SerialReducer: Single-participant Reducer for CPU's serial / cooperative tier. Nothing to combine across (one worker per output), so sum/max/min/generic are identity. Routing cpu_rowwise.pjoin through it rather than skipping the call still invokes the monoid's own pjoin body, which may do per-state finalization (e.g. ReduceSum horizontally reducing its SIMD-wide accumulator into the scalar acc field exposed to bodies).

Functions​

  • ​launch: Top-level CPU scaffolder. Picks the tier from axis and supports_tiled, parallelizes over outputs (or output tiles), and invokes the body once per output (or tile).
  • ​once: CPU: runs emit unconditionally on the cooperative / tiled tiers (one worker per output), or gated on ctx._is_last_block on the split-axis tier (only the last-arriving worker emits).
  • ​pjoin: CPU: drives the monoid's pjoin body via SerialReducer in the cooperative tier, or merges the cross-worker partials buffer in the split-axis tier.
  • ​pointwise_splitk_combine: Joins the row's num_splits partials for reduce reduce_index into the finalized global state. Every worker runs this independently.
  • ​pointwise_splitk_store_partial: Stores this worker's raw width-1 partial for reduce reduce_index.
  • ​reduce: Drives tile_fn over the reduce axis, CPU-side, with no monoid state — pure per-tile iteration for map/emit terminals (see the state-carrying overload below for reduce phases).

Was this page helpful?