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

Mojo struct

SharedMemoryManager

struct SharedMemoryManager[SMBP: SharedMemoryBasePtr]

Manages bump allocation of tiles and arrays from a shared memory base pointer.

Allocates SMemTile, SMemTileArray, and SMemArray instances by advancing an offset over a shared memory base pointer provided by the SMBP parameter.

Parameters​

  • ​SMBP (SharedMemoryBasePtr): Shared memory base pointer provider implementing SharedMemoryBasePtr.

Fields​

  • ​base_ptr (Pointer[Int8, MutUntrackedOrigin, address_space=AddressSpace.SHARED, _safe=False]):
  • ​offset (Int):

Implemented traits​

AnyType, ImplicitlyDeletable

comptime members​

Array​

comptime Array[type: TrivialRegisterPassable, size: Int] = SMemArray[type, size]

Parameters​

Tile​

comptime Tile[dtype: DType, layout: Layout] = LayoutTensor[dtype, layout, MutAnyOrigin, address_space=AddressSpace.SHARED, alignment=SMBP.alignment]

Parameters​

TileArray​

comptime TileArray[dtype: DType, layout: Layout, num_tiles: Int] = SMemTileArray[dtype, layout, num_tiles, SMBP.alignment]

Parameters​

Methods​

__init__​

def __init__(out self)

Initialize the shared memory manager.

build​

def build[dtype: DType, layout: Layout, //, T: AnyStruct[LayoutTensor[dtype, layout, MutAnyOrigin, address_space=AddressSpace.SHARED, alignment=SMBP.alignment]]](mut self) -> T

Allocate a single tile.

Parameters:

  • ​dtype (DType): Element type of the allocated tile.
  • ​layout (Layout): Memory layout of the allocated tile.
  • ​T (AnyStruct[LayoutTensor[dtype, layout, MutAnyOrigin, address_space=AddressSpace.SHARED, alignment=SMBP.alignment]]): The allocated SMemTile type (inferred).

Returns:

T: Allocated tile.

def build[dtype: DType, layout: Layout, num_tiles: Int, //, T: AnyStruct[SMemTileArray[dtype, layout, num_tiles, SMBP.alignment]]](mut self) -> T

Allocate a tile array.

Parameters:

  • ​dtype (DType): Element type of each tile in the array.
  • ​layout (Layout): Memory layout of each tile in the array.
  • ​num_tiles (Int): Number of tiles in the array.
  • ​T (AnyStruct[SMemTileArray[dtype, layout, num_tiles, SMBP.alignment]]): The allocated SMemTileArray type (inferred).

Returns:

T: Allocated tile array.

def build[type: TrivialRegisterPassable, size: Int, //, T: AnyStruct[SMemArray[type, size]]](mut self) -> T

Allocate a regular array.

Parameters:

  • ​type (TrivialRegisterPassable): Element type stored in the array.
  • ​size (Int): Number of elements in the array.
  • ​T (AnyStruct[SMemArray[type, size]]): The allocated SMemArray type (inferred).

Returns:

T: Allocated array.