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

SHMEMBuffer

struct SHMEMBuffer[dtype: DType]

A typed buffer allocated from the OpenSHMEM symmetric heap.

Provides a DevicePassable typed buffer backed by shmem_malloc so that every GPU in the SHMEM job can directly address the allocation. Use SHMEMBuffer as the storage backing for cross-node collective operations where DeviceBuffer cannot be used because the memory must be symmetric.

Parameters​

  • ​dtype (DType): The element data type of the buffer.

Implemented traits​

AnyType, DevicePassable, ImplicitlyDeletable, Sized

comptime members​

device_type​

comptime device_type = Pointer[Scalar[dtype], MutAnyOrigin, _safe=False]

Methods​

__del__​

def __del__(deinit self)

get_type_name​

static def get_type_name() -> String

Returns:

String

__len__​

def __len__(self) -> Int

Returns:

Int

unsafe_ptr​

def unsafe_ptr(self) -> Pointer[Scalar[dtype], MutAnyOrigin, _safe=False]

Returns:

Pointer[Scalar[dtype], MutAnyOrigin, _safe=False]

enqueue_copy_to​

def enqueue_copy_to(self, dst_ptr: Pointer[Scalar[dtype], _safe=False])

Enqueues an asynchronous copy from this buffer to host memory.

This method schedules a memory copy operation from this device buffer to the specified host memory location. The operation is asynchronous and will be executed in the stream associated with this buffer's context.

Args:

  • ​dst_ptr (Pointer[Scalar[dtype], _safe=False]): Pointer to the destination host memory location.

def enqueue_copy_to(self, dst: HostBuffer[dtype])

Enqueues an asynchronous copy from this buffer to host memory.

This method schedules a memory copy operation from this device buffer to the specified host memory location. The operation is asynchronous and will be executed in the stream associated with this buffer's context.

Args:

Raises:

If the copy operation fails.

enqueue_copy_from​

def enqueue_copy_from(self, src_ptr: Pointer[Scalar[dtype], _safe=False])

Enqueues an asynchronous copy from host memory to this buffer.

This method schedules a memory copy operation from the specified host memory location to this device buffer. The operation is asynchronous and will be executed in the stream associated with this buffer's context.

Args:

  • ​src_ptr (Pointer[Scalar[dtype], _safe=False]): Pointer to the source host memory location.

Raises:

If the copy operation fails.

def enqueue_copy_from(self, src: HostBuffer[dtype])

Enqueues an asynchronous copy from host memory to this buffer.

This method schedules a memory copy operation from the specified host memory location to this device buffer. The operation is asynchronous and will be executed in the stream associated with this buffer's context.

Args:

Raises:

If the copy operation fails.