cuda.core.experimental.Buffer#

class cuda.core.experimental.Buffer(*args, **kwargs)#

Bases: _cyBuffer, MemoryResourceAttributes

Represent a handle to allocated memory.

This generic object provides a unified representation for how different memory resources are to give access to their memory allocations.

Support for data interchange mechanisms are provided by DLPack.

Methods

__init__(*args, **kwargs)#
close(self, stream: Stream = None)#

Deallocate this buffer asynchronously on the given stream.

This buffer is released back to their memory resource asynchronously on the given stream.

Parameters:

stream (Stream, optional) – The stream object to use for asynchronous deallocation. If None, the behavior depends on the underlying memory resource.

copy_from(self, Buffer src: Buffer, *, stream: Stream)#

Copy from the src buffer to this buffer asynchronously on the given stream.

Parameters:
  • src (Buffer) – Source buffer to copy data from

  • stream (Stream) – Keyword argument specifying the stream for the asynchronous copy

copy_to(
self,
Buffer dst: Buffer = None,
*,
stream: Stream,
) Buffer#

Copy from this buffer to the dst buffer asynchronously on the given stream.

Copies the data from this buffer to the provided dst buffer. If the dst buffer is not provided, then a new buffer is first allocated using the associated memory resource before the copy.

Parameters:
  • dst (Buffer) – Source buffer to copy data from

  • stream (Stream) – Keyword argument specifying the stream for the asynchronous copy

static from_handle(
ptr: DevicePointerT,
size_t size,
MemoryResource mr: MemoryResource | None = None,
) Buffer#

Create a new Buffer object from a pointer.

Parameters:
  • ptr (DevicePointerT) – Allocated buffer handle object

  • size (int) – Memory size of the buffer

  • mr (MemoryResource, optional) – Memory resource associated with the buffer

classmethod from_ipc_descriptor(
cls,
DeviceMemoryResource mr: DeviceMemoryResource,
IPCBufferDescriptor ipc_buffer: IPCBufferDescriptor,
stream: Stream = None,
) Buffer#

Import a buffer that was exported from another process.

get_ipc_descriptor(self) IPCBufferDescriptor#

Export a buffer allocated for sharing between processes.

Attributes

close(self, stream: Stream = None)#

Deallocate this buffer asynchronously on the given stream.

This buffer is released back to their memory resource asynchronously on the given stream.

Parameters:

stream (Stream, optional) – The stream object to use for asynchronous deallocation. If None, the behavior depends on the underlying memory resource.

copy_from(self, Buffer src: Buffer, *, stream: Stream)#

Copy from the src buffer to this buffer asynchronously on the given stream.

Parameters:
  • src (Buffer) – Source buffer to copy data from

  • stream (Stream) – Keyword argument specifying the stream for the asynchronous copy

copy_to(
self,
Buffer dst: Buffer = None,
*,
stream: Stream,
) Buffer#

Copy from this buffer to the dst buffer asynchronously on the given stream.

Copies the data from this buffer to the provided dst buffer. If the dst buffer is not provided, then a new buffer is first allocated using the associated memory resource before the copy.

Parameters:
  • dst (Buffer) – Source buffer to copy data from

  • stream (Stream) – Keyword argument specifying the stream for the asynchronous copy

device_id#

int

Return the device ordinal of this buffer.

Type:

Buffer.device_id

static from_handle(
ptr: DevicePointerT,
size_t size,
MemoryResource mr: MemoryResource | None = None,
) Buffer#

Create a new Buffer object from a pointer.

Parameters:
  • ptr (DevicePointerT) – Allocated buffer handle object

  • size (int) – Memory size of the buffer

  • mr (MemoryResource, optional) – Memory resource associated with the buffer

classmethod from_ipc_descriptor(
cls,
DeviceMemoryResource mr: DeviceMemoryResource,
IPCBufferDescriptor ipc_buffer: IPCBufferDescriptor,
stream: Stream = None,
) Buffer#

Import a buffer that was exported from another process.

get_ipc_descriptor(self) IPCBufferDescriptor#

Export a buffer allocated for sharing between processes.

handle#

DevicePointerT

Return the buffer handle object.

Caution

This handle is a Python object. To get the memory address of the underlying C handle, call int(Buffer.handle).

Type:

Buffer.handle

is_device_accessible#

bool

Return True if this buffer can be accessed by the GPU, otherwise False.

Type:

Buffer.is_device_accessible

is_host_accessible#

bool

Return True if this buffer can be accessed by the CPU, otherwise False.

Type:

Buffer.is_host_accessible

memory_resource#

MemoryResource

Return the memory resource associated with this buffer.

Type:

Buffer.memory_resource

size#

int

Return the memory size of this buffer.

Type:

Buffer.size