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 struct
OutputTilePipeline
struct OutputTilePipeline[opc: OutputPipelineConfig]
Pipeline for MMAβEpilogue TMEM stage synchronization.
Parametersβ
- βopc (
OutputPipelineConfig): Output pipeline configuration (stages, stride, cta_group).
Fieldsβ
- βpipeline (
OutputTilePipeline[opc].Pipeline): - βtmem (
OutputTilePipeline[opc].Tmem): - βmma_complete_mask (
UInt16):
Implemented traitsβ
AnyType,
Copyable,
ImplicitlyCopyable,
ImplicitlyDeletable,
Movable,
RegisterPassable,
TrivialRegisterPassable
comptime membersβ
BarrierArrayβ
comptime BarrierArray = SMemArray[SharedMemBarrier, (opc * Int(2))]
cta_groupβ
comptime cta_group = opc.cta_group
num_stagesβ
comptime num_stages = opc.num_stages
Pipelineβ
comptime Pipeline = ProducerConsumerPipeline[opc.num_stages]
Stageβ
comptime Stage = OutputStage[opc]
stage_stride_colsβ
comptime stage_stride_cols = opc.stage_stride_cols
Tmemβ
comptime Tmem = TmemAllocation[opc.cta_group]
Methodsβ
__init__β
def __init__(barriers_ptr: Pointer[SharedMemBarrier, MutUntrackedOrigin, address_space=AddressSpace.SHARED, _safe=False], tmem: TmemAllocation[opc.cta_group], mma_complete_mask: UInt16) -> Self
Initialize from barrier pointer, TMEM allocation, and multicast mask.
Args:
- βbarriers_ptr (
Pointer[SharedMemBarrier, MutUntrackedOrigin, address_space=AddressSpace.SHARED, _safe=False]): Pointer to shared memory barrier storage. - βtmem (
TmemAllocation[opc.cta_group]): TMEM allocation backing the MMA accumulator stages. - βmma_complete_mask (
UInt16): Multicast mask used bymma_arrive_multicaston 2-SM configurations.
init_barriersβ
static def init_barriers(storage_ptr: Pointer[SharedMemBarrier, MutUntrackedOrigin, address_space=AddressSpace.SHARED, _safe=False], producer_arv_count: Int32, consumer_arv_count: Int32)
Initialize pipeline barriers. Called once by elect_one thread.
Args:
- βstorage_ptr (
Pointer[SharedMemBarrier, MutUntrackedOrigin, address_space=AddressSpace.SHARED, _safe=False]): Pointer to shared memory barrier storage. - βproducer_arv_count (
Int32): Number of producer threads expected to arrive at each barrier. - βconsumer_arv_count (
Int32): Number of consumer threads expected to arrive at each barrier.
acquire_for_mmaβ
def acquire_for_mma(self) -> Self.Stage
Acquire stage for MMA, waiting for epilogue to finish.
Returns:
Self.Stage
release_from_mmaβ
def release_from_mma(mut self, stage: OutputStage[opc])
Signal MMA completion using mma_arrive (1-SM) or multicast (2-SM).
Args:
- βstage (
OutputStage[opc]): The acquired output stage to signal completion for.
acquire_for_epilogueβ
def acquire_for_epilogue(self) -> Self.Stage
Acquire stage for epilogue, waiting for MMA to complete.
Returns:
Self.Stage
release_from_epilogueβ
def release_from_epilogue(mut self)
Signal epilogue completion, freeing stage for MMA reuse.
producerβ
def producer[origin: MutOrigin, //](ref[opc] self) -> OutputProducer[origin, opc]
Get producer view for MMA warp.
Parameters:
- βorigin (
MutOrigin): Origin of the pipeline reference.
Returns:
OutputProducer[origin, opc]
consumerβ
def consumer[origin: MutOrigin, //](ref[opc] self) -> OutputConsumer[origin, opc]
Get consumer view for epilogue warp.
Parameters:
- βorigin (
MutOrigin): Origin of the pipeline reference.
Returns:
OutputConsumer[origin, opc]
acquire_mma_linearβ
def acquire_mma_linear[origin: MutOrigin, //](ref[opc] self) -> MmaStage[origin, opc]
Acquire a stage for MMA using linear types.
Waits for the epilogue to free the current stage, then returns a linear type handle that MUST be released (compiler-enforced).
Usage: var stage = output_pipeline.acquire_mma_linear() mma_op.mma(a_tile, b_tile, stage.tmem_offset()) mma_op.commit(stage.mbar()) stage^.release() # Signals mma_arrive and advances
Parameters:
- βorigin (
MutOrigin): Origin of the pipeline reference.
Returns:
MmaStage[origin, opc]: An MmaStage handle that must be released.
acquire_epilogue_linearβ
def acquire_epilogue_linear[origin: MutOrigin, //](ref[opc] self) -> EpilogueStage[origin, opc]
Acquire a stage for epilogue using linear types.
Waits for MMA to complete the current stage, then returns a linear type handle that MUST be released (compiler-enforced).
Usage: var stage = output_pipeline.acquire_epilogue_linear() process_tmem(stage.tmem()) stage^.release() # Advances to next stage
Parameters:
- βorigin (
MutOrigin): Origin of the pipeline reference.
Returns:
EpilogueStage[origin, opc]: An EpilogueStage handle that must be released.
get_pipelineβ
def get_pipeline(self) -> Self.Pipeline
Get underlying pipeline (used during barrier initialization).
Returns:
Self.Pipeline
per_kβ
def per_k[origin: MutOrigin, //](ref[opc] self) -> OutputKPipeline[origin, opc]
Get per-K-iteration view for kernels with per-K signaling.
Unlike producer()/consumer() which signal once per tile (after all K iterations), this view signals after each K iteration. Use for kernels with per-K accumulation patterns (e.g., blockwise FP8).
Parameters:
- βorigin (
MutOrigin): Origin of the pipeline reference.
Returns:
OutputKPipeline[origin, opc]: OutputKPipeline view that provides produce()/consume() context
managers for per-K-iteration barrier signaling.
per_k_epilogueβ
def per_k_epilogue[output_origin: MutOrigin, input_origin: MutOrigin, num_input_stages: Int](ref[opc] self, ref[output_origin] input_pipeline: ProducerConsumerPipeline[num_input_stages]) -> EpilogueKContext[output_origin, input_origin, opc, num_input_stages]
Get combined per-K epilogue context for blockwise FP8.
Bundles output pipeline (MMA->Epilogue sync) and input pipeline (A-scales consumption) into a single context manager.
Example: for k_iter in range(num_iters): with output_pipeline.per_k_epilogue(input_pipeline) as stage: accum.promote(stage, ...)
Both pipelines signaled automatically
Parameters:
- βoutput_origin (
MutOrigin): Origin of the output pipeline reference. - βinput_origin (
MutOrigin): Origin of the input pipeline reference. - βnum_input_stages (
Int): Number of stages in the input (A-scales) pipeline.
Args:
- βinput_pipeline (
ProducerConsumerPipeline[num_input_stages]): The input pipeline for A-scales consumption.
Returns:
EpilogueKContext[output_origin, input_origin, opc, num_input_stages]: EpilogueKContext context manager that handles both pipelines.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!