cuda.core.MemoryResource#

class cuda.core.MemoryResource#

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

__init__()#
allocate(
self,
size_t size,
*,
stream: Stream | GraphBuilder,
) Buffer#

Allocate a buffer of the requested size.

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

  • stream (Stream | GraphBuilder) – Keyword-only. The stream on which to perform the allocation asynchronously. Must be passed explicitly; pass device.default_stream to use the default stream.

Returns:

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

Return type:

Buffer

deallocate(
self,
ptr: DevicePointerType,
size_t size,
*,
stream: Stream | GraphBuilder,
)#

Deallocate a buffer previously allocated by this resource.

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

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

  • stream (Stream | GraphBuilder) – Keyword-only. The stream on which to perform the deallocation asynchronously. Must be passed explicitly; pass device.default_stream to use the default stream.

Attributes

device_id#

Device ID associated with this memory resource, or -1 if not applicable.

is_device_accessible#

Whether buffers allocated by this resource are device-accessible.

is_host_accessible#

Whether buffers allocated by this resource are host-accessible.

is_managed#

Whether buffers allocated by this resource are CUDA managed (unified) memory.