cuda.core.experimental.VirtualMemoryResource#

class cuda.core.experimental.VirtualMemoryResource(
device,
config: VirtualMemoryResourceOptions = None,
)#

Create a device memory resource that uses the CUDA VMM APIs to allocate memory.

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

  • config (VirtualMemoryResourceOptions) – A configuration object for the VirtualMemoryResource

Methods

__init__(
self,
device,
config: VirtualMemoryResourceOptions = None,
)#
allocate(
self,
int size: int,
stream: Stream = None,
) Buffer#

Allocate a buffer of the given size using CUDA virtual memory.

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

  • stream (Stream, optional) – CUDA stream to associate with the allocation (not currently supported).

Returns:

A Buffer object representing the allocated virtual memory.

Return type:

Buffer

Raises:
  • NotImplementedError – If a stream is provided or if the location type is not device memory.

  • CUDAError – If any CUDA driver API call fails during allocation.

Notes

This method uses transactional allocation: if any step fails, all resources allocated so far are automatically cleaned up. The allocation is performed with the configured granularity, access permissions, and peer access as specified in the resource’s configuration.

deallocate(
self,
int ptr: int,
int size: int,
stream: Stream = None,
) None#

Deallocate memory on the device using CUDA VMM APIs.

modify_allocation(
self,
Buffer buf: Buffer,
int new_size: int,
config: VirtualMemoryResourceOptions = None,
) Buffer#

Grow an existing allocation using CUDA VMM, with a configurable policy.

This implements true growing allocations that preserve the base pointer by extending the virtual address range and mapping additional physical memory.

This function uses transactional allocation: if any step fails, the original buffer is not modified and all steps the function took are rolled back so a new allocation is not created.

Parameters:
  • buf (Buffer) – The existing buffer to grow

  • new_size (int) – The new total size for the allocation

  • config (VirtualMemoryResourceOptions, optional) – Configuration for the new physical memory chunks. If None, uses current config.

Returns:

The same buffer with updated size and properties, preserving the original pointer

Return type:

Buffer

Attributes

property device_id: int#

Get the device ID associated with this memory resource.

Returns:

int: CUDA device ID. -1 if the memory resource allocates host memory

property is_device_accessible: bool#

Indicates whether the allocated memory is accessible from the device.

property is_host_accessible: bool#

Indicates whether the allocated memory is accessible from the host.