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__()

Initialize self. See help(type(self)) for accurate signature.

Methods

copy_from_device Copy data from device to device.
copy_from_host Copy data from host to device.
copy_to_host Copy memory from GPU device to CPU host
equals(self, Buffer other) Determine if two buffers contain exactly the same data.
export_for_ipc Expose this device buffer as IPC memory which can be used in other processes.
from_buffer Convert back generic buffer into CudaBuffer
from_numba Create a CudaBuffer view from numba MemoryPointer instance.
slice Return slice of device buffer
to_numba Return numba memory pointer of CudaBuffer instance.
to_pybytes Return device buffer content as Python bytes.

Attributes

address The buffer’s address, as an integer.
context Returns the CUDA driver context of this buffer.
is_mutable Whether the buffer is mutable.
parent
size The buffer size in bytes.
address

The buffer’s address, as an integer.

context

Returns the CUDA driver context of this buffer.

copy_from_device()

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()

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 devive 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()

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()

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()

Convert back generic buffer into CudaBuffer

Parameters:buf (Buffer) – Specify buffer containing CudaBuffer
Returns:dbuf (CudaBuffer) – Resulting device buffer.
static from_numba()

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.
is_mutable

Whether the buffer is mutable.

parent
size

The buffer size in bytes.

slice()

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()

Return numba memory pointer of CudaBuffer instance.

to_pybytes()

Return device buffer content as Python bytes.