IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /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. /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, Deinitable, DevicePassable, Movable, Sized

comptime members

device_type

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

Methods

__deinit__

def __deinit__(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]

Returns:

Pointer[Scalar[dtype], MutAnyOrigin]

enqueue_copy_to

def enqueue_copy_to(self, dst_ptr: Pointer[Scalar[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:

  • dst_ptr (Pointer[Scalar[dtype]]): 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]])

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]]): 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.