NVIDIA / NVIDIA/cudf

[ENH] Support more input data layouts in `cudf.from_dlpack`

Open
#10,849 3 comments 0 reactions 1 assignee Claimed by @seberg View on GitHub
feature request libcudf Python
Dominant language
C++
Stars
9.8k
Forks
1.1k
Avg merge
3d 6m
Merged PRs (30d)
278

Description

Related to #10754, the current implementation of `from_dlpack` requires unit-stride fortran order, and produces appropriate error messages in the unsupported cases

Consider

```python
import cudf
import cupy
a = cupy.arange(10)
b = a[::2]
c = cudf.from_dlpack(b.__dlpack__())
=> RuntimeError: from_dlpack of 1D DLTensor only for unit-stride data
b = cupy.broadcast_to(a[1], (10,)) # b is stride-0
=> RuntimeError: from_dlpack of 1D DLTensor only for unit-stride data

a = cupy.arange(12).reshape(3, 4).copy(order="F")
b = a[::2, :]
c = cudf.from_dlpack(b.__dlpack__())
=> RuntimeError: from_dlpack of 2D DLTensor only for column-major unit-stride data
```

Since `from_dlpack` copies in all cases right now, I think that things can be handled like so:

1. Non-fortran-order: useful error
2. unit-stride: current `cudaMemcpyAsync` one column at a time
3. fastest-dimension is stride-0 (broadcasted arrays): `std::fill` for the 1D case, just getting the strides right for the 2D case
4. fastest-dimension is stride-N (sliced arrays): `cudaMemcpy2DAsync` with appropriate choices of pitch and stride for the source array

However, I'm not really sure of the performance implications of these choices, and if the current approach of producing an error and requiring that the caller copy to contiguous fortran-order first before calling `from_dlpack` is not better. For example, for case 4 is it faster to copy to a contiguous buffer first rather than copying column by column?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.