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:
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:
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.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!