Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More error checking in from_dlpack #10850

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cpp/src/interop/dlpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ std::unique_ptr<table> from_dlpack(DLManagedTensor const* managed_tensor,
CUDF_EXPECTS(tensor.shape[1] < std::numeric_limits<size_type>::max(),
"DLTensor second dim exceeds size supported by cudf");
}
if (tensor.ndim == 1) {
CUDF_EXPECTS(nullptr == tensor.strides || tensor.strides[0] == 1,
"from_dlpack of 1D tensor only for unit-stride data");
} else if (tensor.ndim == 2) {
CUDF_EXPECTS(
nullptr != tensor.strides && tensor.strides[0] == 1 && tensor.strides[1] == tensor.shape[0],
wence- marked this conversation as resolved.
Show resolved Hide resolved
"from_dlpack of 2D tensor only for column-major unit-stride data");
} else {
CUDF_UNREACHABLE("Unhandled tensor dimension in from_dlpack");
wence- marked this conversation as resolved.
Show resolved Hide resolved
}

size_t const num_columns = (tensor.ndim == 2) ? static_cast<size_t>(tensor.shape[1]) : 1;

Expand Down
1 change: 1 addition & 0 deletions docs/cudf/source/api_docs/general_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Top-level conversions
:toctree: api/

cudf.to_numeric
cudf.from_dlpack

Top-level dealing with datetimelike
-----------------------------------
Expand Down