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
ThreadScope
struct ThreadScope
Represents the scope of thread operations in GPU programming.
This struct defines the scope at which thread operations are performed,
particularly for operations like tensor distribution and synchronization.
It provides two main scopes: BLOCK and WARP, which correspond to
different levels of thread grouping in GPU programming models.
Example:
from layout.layout_tensor import copy_dram_to_sram, ThreadScope
# Distribute tensor at block level (all threads in block participate)
copy_dram_to_sram[layout, thread_scope=ThreadScope.BLOCK](dst, src)
# Distribute tensor at warp level (only threads in same warp participate)
copy_dram_to_sram[layout, thread_scope=ThreadScope.WARP](dst, src)Performance:
- WARP scope operations typically have lower synchronization overhead than BLOCK scope operations.
- BLOCK scope operations allow coordination across all threads in a block, which is necessary for certain algorithms.
- The choice of scope can significantly impact performance and correctness of parallel algorithms.
Notes:
- The appropriate scope depends on the specific algorithm and hardware.
- WARP scope operations may be more efficient for operations that only require coordination within a warp.
- BLOCK scope operations are necessary when threads from different warps need to coordinate.
- The actual size of a warp or block is hardware-dependent.
Implemented traitsβ
AnyType,
Copyable,
ImplicitlyCopyable,
ImplicitlyDeletable,
Movable,
RegisterPassable,
TrivialRegisterPassable,
Writable
comptime membersβ
BLOCKβ
comptime BLOCK = ThreadScope(Int(0))
Represents operations at the thread block level, where all threads in a block participate.
WARPβ
comptime WARP = ThreadScope(Int(1))
Represents operations at the warp level, where only threads within the same warp participate.
Methodsβ
__init__β
def __init__(value: Int) -> Self
Initialize a ThreadScope with the given integer value.
Args:
- βvalue (
Int): An integer representing the thread scope (0 forBLOCK, 1 forWARP).
__eq__β
def __eq__(self, other: Self) -> Bool
Compare two ThreadScope objects for equality.
Args:
- βother (
Self): AnotherThreadScopeobject to compare with.
Returns:
Bool: True if the thread scopes are equal, False otherwise.
__ne__β
def __ne__(self, other: Self) -> Bool
Compare two ThreadScope objects for inequality.
Args:
- βother (
Self): AnotherThreadScopeobject to compare with.
Returns:
Bool: True if the thread scopes are not equal, False otherwise.
write_toβ
def write_to(self, mut writer: T)
Write the ThreadScope as a human-readable string representation.
Aborts: If the thread scope has an invalid value.
Args:
- βwriter (
T): The writer to write the string representation to.
__int__β
def __int__(self) -> Int
Convert the ThreadScope to an integer value.
Returns:
Int: The integer value of the thread scope (0 for BLOCK, 1 for WARP).