cuda.core.experimental.MemoryResource¶
- class cuda.core.experimental.MemoryResource(*args, **kwargs)¶
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 theallocate()
method would hold a reference to self, the buffer properties are retrieved simply by looking up the underlying memory resource’s respective property.)Methods
- abstract __init__(*args, **kwargs)¶
Initialize the memory resource.
Subclasses may use additional arguments to configure the resource.
- abstract allocate(size: int, stream: Stream = None) Buffer ¶
Allocate a buffer of the requested size.
- Parameters:
- Returns:
The allocated buffer object, which can be used for device or host operations depending on the resource’s properties.
- Return type:
- abstract 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, it is up to each memory resource implementation to decide and document the behavior.
Attributes
- abstract property device_id: int¶
The device ordinal for which this memory resource is responsible.
- Raises:
RuntimeError – If the resource is not bound to a specific device.
- Type: