cuda.core.experimental.MemoryResource

class cuda.core.experimental.MemoryResource(*args, **kwargs)

Abstract base class for memory resources that manage allocation and deallocation of buffers.

Subclasses must implement methods for allocating and deallocation, as well as properties associated with this memory resource from which all allocated buffers will inherit. (Since all Buffer instances allocated and returned by the allocate() method would hold a reference to self, the buffer properties are retrieved simply by looking up the underlying memory resource’s respective property.)

Methods

abstract __init__(*args, **kwargs)

Initialize the memory resource.

Subclasses may use additional arguments to configure the resource.

abstract allocate(size: int, stream: Stream = None) Buffer

Allocate a buffer of the requested size.

Parameters:
  • size (int) – The size of the buffer to allocate, in bytes.

  • stream (Stream, optional) – The stream on which to perform the allocation asynchronously. If None, it is up to each memory resource implementation to decide and document the behavior.

Returns:

The allocated buffer object, which can be used for device or host operations depending on the resource’s properties.

Return type:

Buffer

abstract deallocate(ptr: CUdeviceptr | int | None, size: int, stream: Stream = None)

Deallocate a buffer previously allocated by this resource.

Parameters:
  • ptr (DevicePointerT) – The pointer or handle to the buffer to deallocate.

  • size (int) – The size of the buffer to deallocate, in bytes.

  • stream (Stream, optional) – The stream on which to perform the deallocation asynchronously. If None, it is up to each memory resource implementation to decide and document the behavior.

Attributes

abstract property device_id: int

The device ordinal for which this memory resource is responsible.

Raises:

RuntimeError – If the resource is not bound to a specific device.

Type:

int

abstract property is_device_accessible: bool

True if buffers allocated by this resource can be accessed on the device.

Type:

bool

abstract property is_host_accessible: bool

True if buffers allocated by this resource can be accessed on the host.

Type:

bool