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 module

lamport

Shared primitives for the barrier-free Lamport communication protocol.

A Lamport-style exchange replaces an explicit cross-GPU readiness flag with a reserved value embedded inside the data pack: negative zero. Because IEEE-754 defines -0.0 == +0.0 and x + (-0.0) == x, a producer can sanitize its real data so that no lane ever holds the -0.0 bit pattern, and a consumer can then treat "this pack still contains a -0.0 lane" as "the producer has not written here yet." The 16-byte single-copy-atomic store couples "data present" with "sentinel gone", so no separate flag word and no hot-path atomic are required.

The three functions here are the dtype- and width-parameterized building blocks of that protocol, with no allreduce-specific logic so broadcast and other comm kernels can reuse them:

  • remove_neg_zero: producer-side sanitize (map -0.0 lanes to +0.0).
  • has_neg_zero: consumer-side readiness poll (any lane still the sentinel).
  • set_neg_zero: produce the all-sentinel "not ready" pack.

LamportGeneration owns the three-buffer generation rotation (flag % 3) that defends against the classic Lamport write-after-read hazard, so the kernel body and any future consumer share identical generation semantics.

See the internal Lamport allreduce design doc, section "Design > 1. Shared sentinel primitive", for the protocol context.

comptime values​

LAMPORT_SENTINEL_U32​

comptime LAMPORT_SENTINEL_U32 = UInt32(2147483648)

The universal Lamport "not ready" sentinel, as a uint32 (fp32 -0.0).

Structs​

Functions​

Was this page helpful?