IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /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. /get-started.md).

Mojo struct

Consistency

struct Consistency

Represents memory consistency models for GPU memory operations.

This struct defines different memory consistency levels that control how memory operations are ordered and synchronized between threads. The consistency model affects both performance and correctness of parallel algorithms.

Implemented traits​

AnyType, Copyable, Deinitable, Equatable, ImplicitlyCopyable, Movable, RegisterPassable, TrivialRegisterPassable, Writable

comptime members​

ACQUIRE​

comptime ACQUIRE = Consistency(Int(2))

Acquire consistency for synchronization operations.

Ensures all subsequent memory operations are ordered after this operation. Used in producer-consumer patterns.

RELAXED​

comptime RELAXED = Consistency(Int(1))

Relaxed consistency with basic ordering guarantees.

Provides some ordering guarantees while still allowing optimizations. Suitable for operations that don't require strict ordering.

RELEASE​

comptime RELEASE = Consistency(Int(3))

Release consistency for synchronization operations.

Ensures all previous memory operations are ordered before this operation. Paired with acquire operations for synchronization.

WEAK​

comptime WEAK = Consistency(Int(0))

Weakest consistency model with minimal ordering guarantees.

Provides maximum flexibility for hardware/compiler optimizations but requires careful synchronization by the programmer.

Methods​

__eq__​

def __eq__(self, other: Self) -> Bool

Tests if two Consistency instances are equal.

Args:

  • ​other (Self): The Consistency instance to compare against.

Returns:

Bool: True if the consistency levels are equal, False otherwise.

write_to​

def write_to(self, mut writer: T)

Writes a string representation of the consistency level.

Args:

  • ​writer (T): The object to write to.

write_repr_to​

def write_repr_to(self, mut writer: T)

Writes a string representation of the consistency level.

Args:

  • ​writer (T): The object to write to.

mnemonic​

def mnemonic(self) -> StaticString

Returns the mnemonic string for the consistency level.

Returns:

StaticString: A string literal containing the consistency level mnemonic.