pyarrow.cuda.CudaBuffer#

class pyarrow.cuda.CudaBuffer#

Bases: 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)#

Methods

__init__(*args, **kwargs)

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

address

The buffer's address, as an integer.

context

Returns the CUDA driver context of this buffer.

is_cpu

Whether the buffer is CPU-accessible.

is_mutable

Whether the buffer is mutable.

parent

size

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:
bufCudaBuffer

Specify source device buffer.

positionint

Specify the starting position of the copy in device buffer. Default: 0.

nbytesint

Specify the number of bytes to copy. Default: -1 (all from source until device buffer, starting from position, is full)

Returns:
nbytesint

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

positionint

Specify the starting position of the copy in device buffer. Default: 0.

nbytesint

Specify the number of bytes to copy. Default: -1 (all from source until device buffer, starting from position, is full)

Returns:
nbytesint

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:
positionint

Specify the starting position of the source data in GPU device buffer. Default: 0.

nbytesint

Specify the number of bytes to copy. Default: -1 (all from the position until host buffer is full).

bufBuffer

Specify a pre-allocated output buffer in host. Default: None (allocate new output buffer).

memory_poolMemoryPool
resizablebool

Specify extra arguments to allocate_buffer. Used only when buf is None.

Returns:
bufBuffer

Output buffer in host.

equals(self, Buffer other)#

Determine if two buffers contain exactly the same data.

Parameters:
otherBuffer
Returns:
are_equalbool

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_handleIpcMemHandle

The exported IPC handle

static from_buffer(buf)#

Convert back generic buffer into CudaBuffer

Parameters:
bufBuffer

Specify buffer containing CudaBuffer

Returns:
dbufCudaBuffer

Resulting device buffer.

static from_numba(mem)#

Create a CudaBuffer view from numba MemoryPointer instance.

Parameters:
memnumba.cuda.cudadrv.driver.MemoryPointer
Returns:
cbufCudaBuffer

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:
offsetint, default 0

Specify offset from the start of device buffer to slice

lengthint, 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:
slicedCudaBuffer

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.