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 struct
Context
struct Context[params: ContextParams]
Per-block dispatch bundle. Comptime tier identity and widths flow through params; runtime per-block plumbing (split-K scratch + position) sits in var fields. The body forwards ctx to rowwise.reduce / rowwise.once and treats it as opaque, reading only the plainly-named members (ctx.axis, ctx.accumulator_width, ...). The _-prefixed members (ctx._tier, ctx._partials_base, ...) are scaffolder internals.
On CPU the runtime fields hold sentinels via Context.empty() and
are never read.
Parametersβ
- βparams (
ContextParams): Comptime tier parameters (axis, BLOCK_SIZE, tier discriminator, SIMD widths, target).
Implemented traitsβ
AnyType,
Copyable,
Deinitable,
ImplicitlyCopyable,
Movable,
RegisterPassable,
TrivialRegisterPassable
comptime membersβ
accumulator_widthβ
comptime accumulator_width = Int(1) if (params > Int(1)) else params.simd_width
Reduce-op accumulator width a body should use for its M[dtype, accumulator_width] state: 1 on the tiled tier (each output lane is a separate accumulator), else the full simd_width. Centralized here so every reduction picks the same width.
axisβ
comptime axis = params.axis
Axis being reduced (mirrors Self.params.axis).
BLOCK_SIZEβ
comptime BLOCK_SIZE = params.BLOCK_SIZE
Threads per block (mirrors Self.params.BLOCK_SIZE).
emit_tile_widthβ
comptime emit_tile_width = params.emit_tile_width
Rows-per-thread (mirrors Self.params.emit_tile_width).
simd_widthβ
comptime simd_width = params.simd_width
SIMD width (mirrors Self.params.simd_width).
targetβ
comptime target = params.target
Backend target (mirrors Self.params.target).
Methodsβ
__init__β
def __init__(partials_base: Pointer[UInt8, MutUntrackedOrigin], counters_base: Pointer[Int32, MutUntrackedOrigin], blocks_per_row: Int32, block_in_row: Int32, row_idx: Int32, is_last_block: Bool, phase: Int32 = Int32(0)) -> Self
Initializes a Context with the per-block runtime values.
Args:
- βpartials_base (
Pointer[UInt8, MutUntrackedOrigin]): Split-K partials scratch (or sentinel). - βcounters_base (
Pointer[Int32, MutUntrackedOrigin]): Split-K per-row counters (or sentinel). - βblocks_per_row (
Int32): Blocks cooperating on this row (or 0). - βblock_in_row (
Int32): This block's position in its row (or 0). - βrow_idx (
Int32): The row this block is reducing (or 0). - βis_last_block (
Bool): Initialized to False; set byrowwise.reduceafter the atomic finish (GPU). - βphase (
Int32): Per-element-output split-K launch phase (or 0).
alignmentβ
static def alignment[dtype: DType, ws: Int]() -> Int
Store/load alignment for a width-ws tile of dtype on this Context's target β element-natural on CPU, SIMD-natural on GPU.
A @staticmethod so it's usable in a comptime initializer:
the receiver in ctx.alignment[dtype, ws]() is only a type
carrier (runtime value never read), which comptime allows.
Delegates to the module-level tile_alignment, the single
source of truth shared with the public-op wrappers' loads.
Parameters:
Returns:
Int: The alignment in bytes.
emptyβ
static def empty() -> Self
Returns a Context with zeroed runtime fields. Used by CPU bodies and non-split-K GPU kernels.
Returns:
Self: A Context[params] with sentinel pointers and zero counters.