cuda.core.ManagedMemoryResource#
- class cuda.core.ManagedMemoryResource(options=None)#
A managed memory resource managing a stream-ordered memory pool.
Managed memory is accessible from both the host and device, with automatic migration between them as needed.
- Parameters:
options (ManagedMemoryResourceOptions) –
Memory resource creation options.
If set to None, the memory resource uses the driver’s current stream-ordered memory pool. If no memory pool is set as current, the driver’s default memory pool 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 managed memory resource does not own the pool (is_handle_owned is False), and closing the resource has no effect.
Notes
IPC (Inter-Process Communication) is not currently supported for managed memory pools.
Methods
- __init__(*args, **kwargs)#
- allocate(
- self,
- size_t size,
- stream: Stream | GraphBuilder | None = None,
Allocate a buffer of the requested size.
- Parameters:
size (int) – The size of the buffer to allocate, in bytes.
stream (
Stream|GraphBuilder, 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:
- close(self)#
Close the device memory resource and destroy the associated memory pool if owned.
- deallocate(
- self,
- ptr: DevicePointerT,
- size_t size,
- stream: Stream | GraphBuilder | None = 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|GraphBuilder, optional) – The stream on which to perform the deallocation asynchronously. If the buffer is deallocated without an explicit stream, the allocation stream is used.
Attributes
- attributes#
_MemPoolAttributes
Memory pool attributes.
- Type:
_MemPool.attributes
- device_id#
int
The associated device ordinal.
- Type:
_MemPool.device_id
- handle#
object
Handle to the underlying memory pool.
- Type:
_MemPool.handle
- is_device_accessible#
bool
Return True. This memory resource provides device-accessible buffers.
- Type:
ManagedMemoryResource.is_device_accessible
- is_handle_owned#
bool
Whether the memory resource handle is owned. If False,
closehas no effect.- Type:
_MemPool.is_handle_owned
- is_host_accessible#
bool
Return True. This memory resource provides host-accessible buffers.
- Type:
ManagedMemoryResource.is_host_accessible
- is_ipc_enabled#
bool
Whether this memory resource has IPC enabled.
- Type:
_MemPool.is_ipc_enabled
- is_mapped#
bool
Whether this is a mapping of an IPC-enabled memory resource from another process. If True, allocation is not permitted.
- Type:
_MemPool.is_mapped
- peer_accessible_by#
Get or set the devices that can access allocations from this memory pool. Access can be modified at any time and affects all allocations from this memory pool.
Returns a tuple of sorted device IDs that currently have peer access to allocations from this memory pool.
When setting, accepts a sequence of Device objects or device IDs. Setting to an empty sequence revokes all peer access.
Examples
>>> dmr = DeviceMemoryResource(0) >>> dmr.peer_accessible_by = [1] # Grant access to device 1 >>> assert dmr.peer_accessible_by == (1,) >>> dmr.peer_accessible_by = [] # Revoke access
- uuid#
Optional[uuid.UUID]
A universally unique identifier for this memory resource. Meaningful only for IPC-enabled memory resources.
- Type:
_MemPool.uuid