cuda.core.experimental.DeviceMemoryResource#

class cuda.core.experimental.DeviceMemoryResource(device_id: int | Device, options=None)#

Create a device memory resource managing a stream-ordered memory pool.

Parameters:
  • device_id (int | Device) – Device or Device ordinal for which a memory resource is constructed.

  • options (DeviceMemoryResourceOptions) –

    Memory resource creation options.

    If set to None, the memory resource uses the driver’s current stream-ordered memory pool for the specified device_id. If no memory pool is set as current, the driver’s default memory pool for the device is used.

    If not set to None, a new memory pool is created, which is owned by the memory resource.

    When using an existing (current or default) memory pool, the returned device memory resource does not own the pool (is_handle_owned is False), and closing the resource has no effect.

Methods

__init__(
self,
device_id: int | Device,
options=None,
)#
allocate(
self,
size_t size,
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

close(self)#

Close the device memory resource and destroy the associated memory pool if owned.

deallocate(
self,
ptr: DevicePointerT,
size_t size,
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.

classmethod from_shared_channel(
cls,
device_id: int | Device,
IPCChannel channel: IPCChannel,
) DeviceMemoryResource#

Create a device memory resource from a memory pool shared over an IPC channel.

share_to_channel(
self,
IPCChannel channel: IPCChannel,
)#

Attributes

property attributes: DeviceMemoryResourceAttributes#
property device_id: int#

The associated device ordinal.

property handle: cuda.bindings.driver.CUmemoryPool#

Handle to the underlying memory pool.

property is_device_accessible: bool#

Return True. This memory resource provides device-accessible buffers.

property is_handle_owned: bool#

Whether the memory resource handle is owned. If False, close has no effect.

property is_host_accessible: bool#

Return False. This memory resource does not provide host-accessible buffers.

property is_imported: bool#

Whether the memory resource was imported from another process. If True, allocation is not permitted.

property is_ipc_enabled: bool#

Whether this memory resource has IPC enabled.