IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

Scope

struct Scope

Represents memory synchronization scope levels for GPU memory operations.

Defines different scopes of memory visibility and synchronization, from thread-local to system-wide. Each scope level determines how memory operations are ordered and visible across different execution units.

The scope levels form a hierarchy, with each higher level providing stronger ordering guarantees but potentially higher synchronization costs.

Implemented traits​

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

comptime members​

BLOCK​

comptime BLOCK = Scope(Int(3))

Block-level scope. Memory operations ordered within a thread block/CTA.

CLUSTER​

comptime CLUSTER = Scope(Int(4))

Cluster-level scope. Memory operations ordered within a thread block cluster.

GPU​

comptime GPU = Scope(Int(5))

GPU-level scope. Memory operations are ordered across all threads on the GPU.

NONE​

comptime NONE = Scope(Int(0))

No memory ordering guarantees. Operations may be reordered freely.

SYSTEM​

comptime SYSTEM = Scope(Int(6))

System-wide scope. Memory operations ordered across the entire system.

THREAD​

comptime THREAD = Scope(Int(1))

Thread-level scope. Memory operations are ordered within a single thread.

WARP​

comptime WARP = Scope(Int(2))

Warp-level scope. Memory operations are ordered within a warp of threads.

Methods​

__eq__​

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

Checks if two Scope instances are equal.

Uses pointer comparison for efficiency.

Args:

  • ​other (Self): The other Scope instance to compare with.

Returns:

Bool: True if the instances are the same, False otherwise.

write_to​

def write_to(self, mut w: T)

Writes the string representation of the scope to a writer.

Args:

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

write_repr_to​

def write_repr_to(self, mut writer: T)

Writes the string representation of the scope to a writer.

Args:

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

mnemonic​

def mnemonic(self) -> StaticString

Returns the mnemonic string representation of the memory scope.

Converts the memory scope level into a string mnemonic used by LLVM/NVVM intrinsics for memory operations.

Returns:

StaticString: A string literal containing the mnemonic.