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 trait

PipelineBackend

Hardware backend for ProducerConsumerPipeline slot signaling.

A backend owns the per-slot full/empty signal storage and implements the four primitive operations the pipeline needs: wait on a signal, raise a signal, and their non-blocking try_* variants. It also exposes a per-slot Handle that callers use for substrate-specific extras (for example, setting the expected TMA transaction size on NVIDIA).

Conforming types must be TrivialRegisterPassable so the pipeline stays a register-passed value, matching every existing call site.

Implemented traits​

AnyType, Copyable, ImplicitlyCopyable, ImplicitlyDeletable, Movable, RegisterPassable, TrivialRegisterPassable

comptime members​

BarrierStorage​

comptime BarrierStorage

Handle​

comptime Handle

Required methods​

__init__​

def __init__[num_stages: Int](ptr: Pointer[Self.BarrierStorage, MutUntrackedOrigin, address_space=AddressSpace.SHARED, _safe=False]) -> Self

Construct from the base pointer of the backing storage array.

Parameters:

  • ​num_stages (Int): The number of pipeline stages (ring depth). Must match Self.num_stages.

Args:

Returns:

_Self

def __init__(out self, *, copy: Self)

Create a new instance of the value by copying an existing one.

Args:

  • ​copy (_Self): The value to copy.

Returns:

_Self

def __init__(out self, *, deinit move: Self)

Create a new instance of the value by moving the value of another.

Args:

  • ​move (_Self): The value to move.

Returns:

_Self

storage_elems​

static def storage_elems[num_stages: Int]() -> Int

Return the number of BarrierStorage elements to reserve in SMEM.

Parameters:

  • ​num_stages (Int): The number of pipeline stages. Must match Self.num_stages.

Returns:

Int: The element count for the backing shared-memory array.

init_barriers​

def init_barriers[num_stages: Int](self, producer_arrive_count: Int32, consumer_arrive_count: Int32)

Initialize all full/empty signals for the ring.

Must be called by a single thread before the pipeline is used.

Parameters:

  • ​num_stages (Int): The number of pipeline stages (ring depth). Must match Self.num_stages.

Args:

  • ​producer_arrive_count (Int32): Threads that arrive to mark a slot full.
  • ​consumer_arrive_count (Int32): Threads that arrive to mark a slot empty.

wait_full​

def wait_full[ticks: Optional[UInt32] = None](self, stage: UInt32, phase: UInt32)

Block until the producer has filled stage on the given lap.

Parameters:

  • ​ticks (Optional[UInt32]): Optional hardware-suspend ceiling (ns). Honored by backends whose hardware supports it (NVIDIA); ignored otherwise.

Args:

  • ​stage (UInt32): The slot index in the ring.
  • ​phase (UInt32): The monotonic lap number for this slot.

wait_empty​

def wait_empty[ticks: Optional[UInt32] = None](self, stage: UInt32, phase: UInt32)

Block until the consumer has drained stage on the given lap.

Parameters:

  • ​ticks (Optional[UInt32]): Optional hardware-suspend ceiling (ns). Honored by backends whose hardware supports it (NVIDIA); ignored otherwise.

Args:

  • ​stage (UInt32): The slot index in the ring.
  • ​phase (UInt32): The monotonic lap number for this slot.

try_full​

def try_full(self, stage: UInt32, phase: UInt32) -> Bool

Return whether the producer has filled stage (non-blocking).

Args:

  • ​stage (UInt32): The slot index in the ring.
  • ​phase (UInt32): The monotonic lap number for this slot.

Returns:

Bool: True if the slot is full for this lap, False otherwise.

try_empty​

def try_empty(self, stage: UInt32, phase: UInt32) -> Bool

Return whether the consumer has drained stage (non-blocking).

Args:

  • ​stage (UInt32): The slot index in the ring.
  • ​phase (UInt32): The monotonic lap number for this slot.

Returns:

Bool: True if the slot is empty for this lap, False otherwise.

arrive_full​

def arrive_full(self, stage: UInt32)

Raise the full signal for stage (producer side).

Args:

  • ​stage (UInt32): The slot index in the ring.

arrive_empty​

def arrive_empty(self, stage: UInt32)

Raise the empty signal for stage (consumer side).

Args:

  • ​stage (UInt32): The slot index in the ring.

full_handle​

def full_handle(self, stage: UInt32) -> Self.Handle

Return the full signal handle for stage.

Args:

  • ​stage (UInt32): The slot index in the ring.

Returns:

_Self.Handle: The backend-specific handle to the slot's full signal.

empty_handle​

def empty_handle(self, stage: UInt32) -> Self.Handle

Return the empty signal handle for stage.

Args:

  • ​stage (UInt32): The slot index in the ring.

Returns:

_Self.Handle: The backend-specific handle to the slot's empty signal.

Provided methods​

copy​

def copy(self) -> Self

Explicitly construct a copy of self, a convenience method for Self(copy=self) when the type is inconvenient to write out.

Overriding this method is not allowed.

Returns:

_Self: A copy of this value.

Was this page helpful?