Skip to main content

Mojo struct

Consistency

@register_passable(trivial) 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, Equatable, ImplicitlyCopyable, ImplicitlyDestructible, Movable

comptime members

__copyinit__is_trivial

comptime __copyinit__is_trivial = True

__del__is_trivial

comptime __del__is_trivial = True

__moveinit__is_trivial

comptime __moveinit__is_trivial = True

ACQUIRE

comptime ACQUIRE = Consistency(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(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(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(0)

Weakest consistency model with minimal ordering guarantees.

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

Methods

__eq__

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

__str__

__str__(self) -> String

Returns a string representation of the consistency level.

Returns:

String: A string describing the consistency level.

mnemonic

mnemonic(self) -> StaticString

Returns the mnemonic string for the consistency level.

Returns:

StaticString: A string literal containing the consistency level mnemonic.

Was this page helpful?