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
Signal
struct Signal
A synchronization primitive for coordinating GPU thread blocks across multiple devices.
This struct provides counter-based synchronization between thread blocks on different GPUs. It maintains two sets of counters:
- self_counter: Used by blocks on the current GPU to signal their progress
- peer_counter: Used to track progress of blocks on other GPUs
Note: The counters use unsigned integers that may overflow, but this is safe since unsigned integer overflow has well-defined behavior.
Fieldsβ
-
βself_counter (
StaticTuple[StaticTuple[StaticTuple[UInt32, Int(8)], Int(1024)], Int(8)]): A 3D array of counters with shape (NUM_BARRIER_DOMAINS, MAX_NUM_BLOCKS_UPPER_BOUND, MAX_GPUS). Each counter tracks the progress of a specific thread block on the current GPU for a domain. Thread blocks increment their corresponding counter to signal completion of a phase, allowing other GPUs to detect when synchronization points are reached. The counters use atomic operations to ensure proper synchronization across devices. -
βpeer_counter (
StaticTuple[StaticTuple[StaticTuple[StaticTuple[UInt32, Int(8)], Int(1024)], Int(2)], Int(8)]): A 4D array of counters with shape (NUM_BARRIER_DOMAINS, 2, MAX_NUM_BLOCKS_UPPER_BOUND, MAX_GPUS). Each domain contains two sets of counters to handle two synchronization points safely. The dual counter design prevents race conditions where a peer block arrives at the second sync point before the current block passes the first sync point. -
βlamport_state (
StaticTuple[UInt32, Int(4)]): Device-resident state for the in-kernel Lamport generation advance:[flag, prev_num_elements, arrival, reserved].flag: monotonically-increasing generation counter (read at kernel entry, advanced once per call in the grid-barrier epilogue).prev_num_elements: previous call's element count = this call'sclear_size.arrival: per-call block-arrival counter for the exactly-once advance.- reserved: pads to 16 bytes so
lamport_regionstays 16-byte aligned (the 128-bit atomic stores require it).
Zero-fill is the correct start state (flag 0, nothing to clear). This is the sole source of the generation counter / clear extent -- the kernel reads and advances it in-kernel, so the public op needs no per-call argument.
-
βlamport_region (
StaticTuple[UInt8, Int(25165824)]): The barrier-free Lamport comm region: 3 rotating generations x MAX_GPUS rank slots x the per-slot max message. Disjoint from self_counter & peer_counter to enable a mix of lamport & barrier-based collectives on the same signal buffer.
Implemented traitsβ
comptime membersβ
flag_tβ
comptime flag_t = DType.uint32
Methodsβ
lamport_state_ptrβ
def lamport_state_ptr(mut self) -> Pointer[UInt32, MutAnyOrigin, _safe=False]
Typed pointer to this Signal's lamport_state block.
Index it with the Lamport.STATE_* constants. The field is located by
its own address (UnsafePointer(to=...)), so there is no hand-computed
byte offset to keep in sync with the field order.
Returns:
Pointer[UInt32, MutAnyOrigin, _safe=False]
lamport_region_ptrβ
def lamport_region_ptr[dtype: DType](mut self) -> Pointer[Scalar[dtype], MutAnyOrigin, _safe=False]
Typed pointer to the start of this Signal's embedded Lamport region.
Parameters:
- βdtype (
DType): The element type to reinterpret the raw region bytes as. The returned pointer is typedUnsafePointer[Scalar[dtype], ...]so callers can read and write Lamport message packs in this dtype without an extra cast.
Returns:
Pointer[Scalar[dtype], MutAnyOrigin, _safe=False]
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!