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

SyncStrategy

Interface for synchronization strategies between producers and consumers.

All methods have the same signature regardless of the specific implementation, allowing the RingBuffer to be parameterized with any conforming strategy.

Phase tracking ensures producers and consumers access different tiles:

  • Producers wait until consumers have finished with a tile (phase N)
  • Consumers wait until producers have filled a tile (phase N+1)

Implemented traits​

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

Required methods​

__init__​

def __init__() -> _Self

Initialize with internally allocated sync counter.

Returns:

_Self

def __init__(out self: _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: _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

get_staged_idx​

def get_staged_idx(self: _Self, tile_idx: Int, stage: Int) -> Int

Convert tile index and stage to a flat index in the counter arrays.

Args:

  • ​tile_idx (Int): Index of the tile within a stage (0 to block_warps-1).
  • ​stage (Int): Pipeline stage (0 to pipeline_stages-1).

Returns:

Int: Flat index for accessing synchronization counters.

wait_producer_acquire​

def wait_producer_acquire(self: _Self, tile_idx: Int, stage: Int, phase: Int32)

Producer waits until it can write to the specified tile.

Blocks until all consumers have finished reading from this tile (counter >= phase).

signal_producer_release​

def signal_producer_release(mut self: _Self, tile_idx: Int, stage: Int)

Producer signals that it has finished writing to the tile.

Increments the appropriate counter to notify waiting consumers.

wait_consumer_acquire​

def wait_consumer_acquire(self: _Self, tile_idx: Int, stage: Int, phase: Int32)

Consumer waits until it can read from the specified tile.

Blocks until producer has finished writing to this tile (counter >= phase).

signal_consumer_release​

def signal_consumer_release(mut self: _Self, tile_idx: Int, stage: Int)

Consumer signals that it has finished reading from the tile.

Increments the appropriate counter to notify waiting producers.

get_producer_phase_increment​

def get_producer_phase_increment(self: _Self) -> Int32

Returns how much to advance the producer phase after each acquisition.

This determines when producers can reuse a tile after consumers finish.

Returns:

Int32

get_consumer_phase_increment​

def get_consumer_phase_increment(self: _Self) -> Int32

Returns how much to advance the consumer phase after each acquisition.

This determines when consumers can read a tile after producers finish.

Returns:

Int32

Provided methods​

copy​

def copy(self: _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.