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 struct

SplitCounterSync

struct SplitCounterSync[pipeline_stages: Int, block_rows: Int, warp_rows: Int, reads_per_warp_block: Int]

Split counter synchronization strategy.

Uses separate producer and consumer counters per tile to reduce atomic contention. Producers only write to producer counters, consumers only write to consumer counters.

Phase progression:

  • Producer phase advances by reads_per_warp_block (waits for N consumers)
  • Consumer phase advances by writes_per_warp_block (waits for 1 producer)
  • This asymmetry reflects the 1-producer-to-N-consumers relationship

Parameters​

  • ​pipeline_stages (Int): Number of pipeline stages in the ring buffer.
  • ​block_rows (Int): Total number of rows in the work block.
  • ​warp_rows (Int): Number of rows processed by a single warp.
  • ​reads_per_warp_block (Int): Number of consumer read operations per warp block.

Fields​

  • ​producer_counters (SplitCounterSync[pipeline_stages, block_rows, warp_rows, reads_per_warp_block].ProducerCounterArray):
  • ​consumer_counters (SplitCounterSync[pipeline_stages, block_rows, warp_rows, reads_per_warp_block].ConsumerCounterArray):

Implemented traits​

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

comptime members​

block_warps​

comptime block_warps = (block_rows // warp_rows)

ConsumerCounterArray​

comptime ConsumerCounterArray = SMemArray[Int32, SplitCounterSync[pipeline_stages, block_rows, warp_rows, reads_per_warp_block].total_tiles]

ProducerCounterArray​

comptime ProducerCounterArray = SMemArray[Int32, SplitCounterSync[pipeline_stages, block_rows, warp_rows, reads_per_warp_block].total_tiles]

total_tiles​

comptime total_tiles = (SplitCounterSync[pipeline_stages, block_rows, warp_rows, reads_per_warp_block].block_warps * pipeline_stages)

writes_per_warp_block​

comptime writes_per_warp_block = 1

Methods​

__init__​

def __init__() -> Self

Initialize with internally allocated producer and consumer counters.

get_staged_idx​

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

Returns:

Int

wait_producer_acquire​

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

Producer waits on consumer counter.

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).
  • ​phase (Int32): Counter threshold to wait for before acquiring the tile.

signal_producer_release​

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

Producer increments producer counter.

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).

wait_consumer_acquire​

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

Consumer waits on producer counter.

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).
  • ​phase (Int32): Counter threshold to wait for before acquiring the tile.

signal_consumer_release​

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

Consumer increments consumer counter by 1.

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).

get_producer_phase_increment​

def get_producer_phase_increment(self) -> Int32

Producer phase advances by reads_per_warp_block.

Returns:

Int32

get_consumer_phase_increment​

def get_consumer_phase_increment(self) -> Int32

Consumer phase advances by writes_per_warp_block.

Returns:

Int32

Was this page helpful?