Interop Dlpack#

group interop_dlpack

Functions

std::unique_ptr<table> from_dlpack(DLManagedTensor const *managed_tensor, rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref())#

Convert a DLPack DLTensor into a cudf table.

The device_type of the DLTensor must be kDLCPU, kDLCuda, or kDLCUDAHost, and device_id must match the current device. The ndim must be set to 1 or 2. The dtype must have 1 lane and the bitsize must match a supported cudf::data_type.

Note

The managed tensor is not deleted by this function.

Throws:

cudf::logic_error – if the any of the DLTensor fields are unsupported

Parameters:
  • managed_tensor – a 1D or 2D column-major (Fortran order) tensor

  • stream – CUDA stream used for device memory operations and kernel launches

  • mr – Device memory resource used to allocate the returned table’s device memory

Returns:

Table with a copy of the tensor data

DLManagedTensor *to_dlpack(table_view const &input, rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref())#

Convert a cudf table into a DLPack DLTensor.

All columns must have the same data type and this type must be numeric. The columns may be nullable, but the null count must be zero. If the input table is empty or has zero rows, the result will be nullptr.

Note

The deleter method of the returned DLManagedTensor must be used to free the memory allocated for the tensor.

Throws:

cudf::logic_error – if the data types are not equal or not numeric, or if any of columns have non-zero null count

Parameters:
  • input – Table to convert to DLPack

  • stream – CUDA stream used for device memory operations and kernel launches

  • mr – Device memory resource used to allocate the returned DLPack tensor’s device memory

Returns:

1D or 2D DLPack tensor with a copy of the table data, or nullptr