cuda.core.Buffer#
- class cuda.core.Buffer(*args, **kwargs)#
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 | GraphBuilder | None = 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|GraphBuilder, 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 | GraphBuilder,
Copy from the src buffer to this buffer asynchronously on the given stream.
- Parameters:
src (
Buffer) – Source buffer to copy data fromstream (
Stream|GraphBuilder) – Keyword argument specifying the stream for the asynchronous copy
- copy_to(
- self,
- Buffer dst: Buffer = None,
- *,
- stream: Stream | GraphBuilder,
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 fromstream (
Stream|GraphBuilder) – Keyword argument specifying the stream for the asynchronous copy
- fill(
- self,
- value: int | BufferProtocol,
- *,
- stream: Stream | GraphBuilder,
Fill this buffer with a repeating byte pattern.
- Parameters:
value (int |
collections.abc.Buffer) –int: Must be in range [0, 256). Converted to 1 byte.
collections.abc.Buffer: Must be 1, 2, or 4 bytes.
stream (
Stream|GraphBuilder) – Stream for the asynchronous fill operation.
- Raises:
TypeError – If value is not an int and does not support the buffer protocol.
ValueError – If value byte length is not 1, 2, or 4. If buffer size is not divisible by value byte length.
OverflowError – If int value is outside [0, 256).
- static from_handle(
- ptr: DevicePointerT,
- size_t size,
- MemoryResource mr: MemoryResource | None = None,
- owner: object | None = None,
Create a new
Bufferobject from a pointer.- Parameters:
ptr (
DevicePointerT) – Allocated buffer handle objectsize (int) – Memory size of the buffer
mr (
MemoryResource, optional) – Memory resource associated with the bufferowner (object, optional) – An object holding external allocation that the
ptrpoints to. The reference is kept as long as the buffer is alive. Theownerandmrcannot be specified together.
- classmethod from_ipc_descriptor(
- cls,
- mr: DeviceMemoryResource | PinnedMemoryResource,
- IPCBufferDescriptor ipc_descriptor: IPCBufferDescriptor,
- Stream stream: Stream = None,
Import a buffer that was exported from another process.
- get_ipc_descriptor(self) IPCBufferDescriptor#
Export a buffer allocated for sharing between processes.
Attributes