cuda.core.experimental.DeviceMemoryResource

class cuda.core.experimental.DeviceMemoryResource(device_id: int)

Create a device memory resource that uses the driver’s stream-ordered memory pool.

Parameters:

device_id (int) – Device ordinal for which a memory resource is constructed. The mempool that is set to current on device_id is used. If no mempool is set to current yet, the driver would use the default mempool on the device.

Methods

__init__(device_id: int)

Initialize the memory resource.

Subclasses may use additional arguments to configure the resource.

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, an internal stream is used.

Returns:

The allocated buffer object, which is accessible on the device that this memory resource was created for.

Return type:

Buffer

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, an internal stream is used.

Attributes

property device_id: int

the associated device ordinal.

Type:

int

property is_device_accessible: bool

this memory resource provides device-accessible buffers.

Type:

bool

property is_host_accessible: bool

this memory resource does not provides host-accessible buffers.

Type:

bool