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, UnknownDestructibility

Aliases

__del__is_trivial

comptime __del__is_trivial

A flag (often compiler generated) to indicate whether the implementation of __del__ is trivial.

The implementation of __del__ is considered to be trivial if:

  • The struct has a compiler-generated trivial destructor and all its fields have a trivial __del__ method.

In practice, it means that the __del__ can be considered as no-op.

Required methods

__init__

__init__() -> _Self

Initialize with internally allocated sync counter.

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

Was this page helpful?