pyarrow.cuda.CudaBuffer¶
-
class
pyarrow.cuda.
CudaBuffer
¶ Bases:
pyarrow.lib.Buffer
An Arrow buffer with data located in a GPU device.
To create a CudaBuffer instance, use Context.device_buffer().
The memory allocated in a CudaBuffer is freed when the buffer object is deleted.
-
__init__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(*args, **kwargs)Initialize self.
copy_from_device
(self, buf, …)Copy data from device to device.
copy_from_host
(self, data, …)Copy data from host to device.
copy_to_host
(self, int64_t position=0, …)Copy memory from GPU device to CPU host
equals
(self, Buffer other)Determine if two buffers contain exactly the same data.
export_for_ipc
(self)Expose this device buffer as IPC memory which can be used in other processes.
from_buffer
(buf)Convert back generic buffer into CudaBuffer
from_numba
(mem)Create a CudaBuffer view from numba MemoryPointer instance.
hex
(self)Compute hexadecimal representation of the buffer.
slice
(self[, offset, length])Return slice of device buffer
to_numba
(self)Return numba memory pointer of CudaBuffer instance.
to_pybytes
(self)Return device buffer content as Python bytes.
Attributes
The buffer’s address, as an integer.
Returns the CUDA driver context of this buffer.
Whether the buffer is CPU-accessible.
Whether the buffer is mutable.
The buffer size in bytes.
-
address
¶ The buffer’s address, as an integer.
The returned address may point to CPU or device memory. Use is_cpu() to disambiguate.
-
context
¶ Returns the CUDA driver context of this buffer.
-
copy_from_device
(self, buf, int64_t position=0, int64_t nbytes=-1)¶ Copy data from device to device.
- Parameters
buf (CudaBuffer) – Specify source device buffer.
position (int) – Specify the starting position of the copy in device buffer. Default: 0.
nbytes (int) – Specify the number of bytes to copy. Default: -1 (all from source until device buffer, starting from position, is full)
- Returns
nbytes (int) – Number of bytes copied.
-
copy_from_host
(self, data, int64_t position=0, int64_t nbytes=-1)¶ Copy data from host to device.
The device buffer must be pre-allocated.
- Parameters
data ({Buffer, array-like}) – Specify data in host. It can be array-like that is valid argument to py_buffer
position (int) – Specify the starting position of the copy in device buffer. Default: 0.
nbytes (int) – Specify the number of bytes to copy. Default: -1 (all from source until device buffer, starting from position, is full)
- Returns
nbytes (int) – Number of bytes copied.
-
copy_to_host
(self, int64_t position=0, int64_t nbytes=-1, Buffer buf=None, MemoryPool memory_pool=None, bool resizable=False)¶ Copy memory from GPU device to CPU host
Caller is responsible for ensuring that all tasks affecting the memory are finished. Use
<CudaBuffer instance>.context.synchronize()
when needed.
- Parameters
position (int) – Specify the starting position of the source data in GPU device buffer. Default: 0.
nbytes (int) – Specify the number of bytes to copy. Default: -1 (all from the position until host buffer is full).
buf (Buffer) – Specify a pre-allocated output buffer in host. Default: None (allocate new output buffer).
memory_pool (MemoryPool) –
resizable (bool) – Specify extra arguments to allocate_buffer. Used only when buf is None.
- Returns
buf (Buffer) – Output buffer in host.
-
equals
(self, Buffer other)¶ Determine if two buffers contain exactly the same data.
- Parameters
other (Buffer) –
- Returns
are_equal (True if buffer contents and size are equal)
-
export_for_ipc
(self)¶ Expose this device buffer as IPC memory which can be used in other processes.
After calling this function, this device memory will not be freed when the CudaBuffer is destructed.
- Returns
ipc_handle (IpcMemHandle) – The exported IPC handle
-
static
from_buffer
(buf)¶ Convert back generic buffer into CudaBuffer
- Parameters
buf (Buffer) – Specify buffer containing CudaBuffer
- Returns
dbuf (CudaBuffer) – Resulting device buffer.
-
static
from_numba
(mem)¶ Create a CudaBuffer view from numba MemoryPointer instance.
- Parameters
mem (numba.cuda.cudadrv.driver.MemoryPointer) –
- Returns
cbuf (CudaBuffer) – Device buffer as a view of numba MemoryPointer.
-
hex
(self)¶ Compute hexadecimal representation of the buffer.
- Returns
bytes
-
is_cpu
¶ Whether the buffer is CPU-accessible.
-
is_mutable
¶ Whether the buffer is mutable.
-
parent
¶
-
size
¶ The buffer size in bytes.
-
slice
(self, offset=0, length=None)¶ Return slice of device buffer
- Parameters
offset (int, default 0) – Specify offset from the start of device buffer to slice
length (int, default None) – Specify the length of slice (default is until end of device buffer starting from offset). If the length is larger than the data available, the returned slice will have a size of the available data starting from the offset.
- Returns
sliced (CudaBuffer) – Zero-copy slice of device buffer.
-
to_numba
(self)¶ Return numba memory pointer of CudaBuffer instance.
-
to_pybytes
(self)¶ Return device buffer content as Python bytes.
-