Skip to main content

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, ImplicitlyDestructible, Movable, RegisterPassable, TrivialRegisterPassable

Required methods​

__init__​

__init__() -> _Self

Initialize with internally allocated sync counter.

Returns:

_Self

__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

__init__(out self: _Self, *, deinit take: _Self)

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

Args:

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

Returns:

_Self

get_staged_idx​

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​

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​

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​

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​

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​

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​

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​

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.

Returns:

_Self: A copy of this value.