Skip to main content
Log in

Mojo struct

ThreadScope

@register_passable(trivial) 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.

Attributes: BLOCK: Represents operations at the thread block level, where all threads in a block participate in the operation. WARP: Represents operations at the warp level, where only threads within the same warp participate in the operation.

Example:

```mojo
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)
```
```mojo
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.
- 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.
- 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.

Aliases

  • BLOCK = ThreadScope(0):
  • WARP = ThreadScope(1):

Implemented traits

AnyType, Copyable, ExplicitlyCopyable, Movable, UnknownDestructibility

Methods

__init__

@implicit __init__(value: Int) -> Self

__eq__

__eq__(self, other: Self) -> Bool

__ne__

__ne__(self, other: Self) -> Bool

__str__

__str__(self) -> String

__int__

__int__(self) -> Int