Mojo struct
SMemTileArray2DRowMajor
@register_passable(trivial)
struct SMemTileArray2DRowMajor[dtype: DType, dim0: Int, dim1: Int, num_tiles: Int, alignment: Int = 128]
Array of TileTensor tiles in shared memory with row_major layout.
Unlike SMemTileArray2D which uses swizzled internal_k_major layout, this type uses simple row_major layout. Suitable for 1D vectors (like A-scales) or output tiles where swizzling is not needed.
Example: comptime MyArray = SMemTileArray2DRowMajor[DType.float32, 1, 64, 4]
var array = MyArray.stack_allocation() var tile = array[0] # Returns TileTensor with row_major layout
Parameters
- dtype (
DType): Tile element data type. - dim0 (
Int): First dimension (rows). - dim1 (
Int): Second dimension (columns). - num_tiles (
Int): Number of tiles in the array. - alignment (
Int): Memory alignment (default 128 for shared memory).
Fields
- ptr (
LegacyUnsafePointer[Scalar[dtype], address_space=AddressSpace.SHARED]):
Implemented traits
AnyType,
Copyable,
ImplicitlyCopyable,
ImplicitlyDestructible,
Movable,
RegisterType,
TrivialRegisterType
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
num_elements
comptime num_elements = (SMemTileArray2DRowMajor[dtype, dim0, dim1, num_tiles, alignment].tile_size * num_tiles)
Storage
comptime Storage = InlineArray[Scalar[dtype], SMemTileArray2DRowMajor[dtype, dim0, dim1, num_tiles, alignment].num_elements]
storage_size
comptime storage_size = (SMemTileArray2DRowMajor[dtype, dim0, dim1, num_tiles, alignment].num_elements * size_of[dtype]())
Tile
comptime Tile = TileTensor[dtype, Layout[ComptimeInt[dim0], ComptimeInt[dim1], ComptimeInt[dim1], ComptimeInt[1]], MutAnyOrigin, address_space=AddressSpace.SHARED]
tile_layout
comptime tile_layout = row_major[dim0, dim1]()
tile_size
comptime tile_size = (dim0 * dim1)
Methods
__init__
__init__(ref[AddressSpace._value._mlir_value] storage: InlineArray[Scalar[dtype], SMemTileArray2DRowMajor[dtype, dim0, dim1, num_tiles, alignment].num_elements]) -> Self
Initialize from inline storage.
Args:
- storage (
InlineArray): The inline storage array.
Returns:
Self: A new SMemTileArray2DRowMajor pointing to the storage.
__init__[mut: Bool, //, origin: Origin[mut=mut]](unsafe_ptr: LegacyUnsafePointer[Scalar[dtype], address_space=AddressSpace.SHARED, origin=origin]) -> Self
Initialize with a shared memory pointer.
Args:
- unsafe_ptr (
LegacyUnsafePointer): Pointer to shared memory storage.
__getitem__
__getitem__[T: Intable](self, index: T) -> SMemTileArray2DRowMajor[dtype, dim0, dim1, num_tiles, alignment].Tile
Get tile at the given index.
Args:
- index (
T): The tile index.
Returns:
SMemTileArray2DRowMajor: A TileTensor-based tile at the given index with row_major layout.
slice
slice[length: Int](self, start: Int) -> SMemTileArray2DRowMajor[dtype, dim0, dim1, length, alignment]
Get a slice of the array.
Parameters:
- length (
Int): The length of the slice.
Args:
- start (
Int): The starting index.
Returns:
SMemTileArray2DRowMajor: A new SMemTileArray2DRowMajor representing the slice.
stack_allocation
static stack_allocation() -> Self
Allocate the array on the stack (in shared memory).
Returns:
Self: A new SMemTileArray2DRowMajor backed by stack-allocated shared memory.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!