-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use owning Arrow types in C++ to expose data to Python #18402
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
Changes from all commits
24b1f68
a09a31d
5d2884c
b4760ac
72ef25d
4bafc1f
17ce423
2c65d72
94a2c02
c5cd26b
219a506
6edcf13
c89c86b
bbbc422
83b6b92
e2df6b3
a820a6c
8ba32e3
69fd71f
08ae13a
2197a21
3eb72ee
f07f8cb
b226766
281ece3
b3f29eb
db92c88
7beecf6
7c917a2
04e37b4
1e4e37e
e26bd3c
a6b8284
83acdcc
05a0806
a141d21
5e7ff46
1710d4e
b7ee1bf
932b0ad
fd5ab31
3176f39
457f677
bb8a2f0
33b3cc8
1a3197c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,6 +91,21 @@ int set_buffer(std::unique_ptr<T> device_buf, int64_t i, ArrowArray* out) | |
| return NANOARROW_OK; | ||
| } | ||
|
|
||
| int set_null_mask(column::contents& contents, ArrowArray* out) | ||
| { | ||
| if (contents.null_mask) { | ||
| NANOARROW_RETURN_NOT_OK(set_buffer(std::move(contents.null_mask), validity_buffer_idx, out)); | ||
| } | ||
| return NANOARROW_OK; | ||
| } | ||
|
|
||
| int set_contents(column::contents& contents, ArrowArray* out) | ||
| { | ||
| NANOARROW_RETURN_NOT_OK(set_null_mask(contents, out)); | ||
| NANOARROW_RETURN_NOT_OK(set_buffer(std::move(contents.data), fixed_width_data_buffer_idx, out)); | ||
| return NANOARROW_OK; | ||
| } | ||
|
|
||
| struct dispatch_to_arrow_device { | ||
| template <typename T, | ||
| CUDF_ENABLE_IF(not is_rep_layout_compatible<T>() and not is_fixed_point<T>())> | ||
|
|
@@ -117,23 +132,16 @@ struct dispatch_to_arrow_device { | |
| ArrowArrayMove(tmp.get(), out); | ||
| return NANOARROW_OK; | ||
| } | ||
|
|
||
| int set_null_mask(column::contents& contents, ArrowArray* out) | ||
| { | ||
| if (contents.null_mask) { | ||
| NANOARROW_RETURN_NOT_OK(set_buffer(std::move(contents.null_mask), validity_buffer_idx, out)); | ||
| } | ||
| return NANOARROW_OK; | ||
| } | ||
|
|
||
| int set_contents(column::contents& contents, ArrowArray* out) | ||
| { | ||
| NANOARROW_RETURN_NOT_OK(set_null_mask(contents, out)); | ||
| NANOARROW_RETURN_NOT_OK(set_buffer(std::move(contents.data), fixed_width_data_buffer_idx, out)); | ||
| return NANOARROW_OK; | ||
| } | ||
| }; | ||
|
|
||
| int handle_empty_type_column(ArrowArray* array, cudf::column& column) | ||
| { | ||
| NANOARROW_RETURN_NOT_OK(initialize_array(array, NANOARROW_TYPE_NA, column.view())); | ||
| auto child_contents = column.release(); | ||
| NANOARROW_RETURN_NOT_OK(set_contents(child_contents, array)); | ||
| return NANOARROW_OK; | ||
| } | ||
|
|
||
| template <> | ||
| int dispatch_to_arrow_device::operator()<bool>(cudf::column&& column, | ||
| rmm::cuda_stream_view stream, | ||
|
|
@@ -227,8 +235,12 @@ int dispatch_to_arrow_device::operator()<cudf::struct_view>(cudf::column&& colum | |
| for (size_t i = 0; i < size_t(tmp->n_children); ++i) { | ||
| ArrowArray* child_ptr = tmp->children[i]; | ||
| auto& child = contents.children[i]; | ||
| NANOARROW_RETURN_NOT_OK(cudf::type_dispatcher( | ||
| child->type(), dispatch_to_arrow_device{}, std::move(*child), stream, mr, child_ptr)); | ||
| if (child->type().id() == cudf::type_id::EMPTY) { | ||
| NANOARROW_RETURN_NOT_OK(handle_empty_type_column(child_ptr, *child)); | ||
| } else { | ||
| NANOARROW_RETURN_NOT_OK(cudf::type_dispatcher( | ||
| child->type(), dispatch_to_arrow_device{}, std::move(*child), stream, mr, child_ptr)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit paranoid on this: Do we have a guarantee that the initialization
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that we are safe because while we may not be guaranteed anything about the order in which the two parameters are evaluated, we are guaranteed that all of the parameters are evaluated before the function call begins. |
||
| } | ||
| } | ||
|
|
||
| ArrowArrayMove(tmp.get(), out); | ||
|
|
@@ -253,8 +265,12 @@ int dispatch_to_arrow_device::operator()<cudf::list_view>(cudf::column&& column, | |
| NANOARROW_RETURN_NOT_OK(set_buffer(std::move(offsets_contents.data), 1, tmp.get())); | ||
|
|
||
| auto& child = contents.children[cudf::lists_column_view::child_column_index]; | ||
| NANOARROW_RETURN_NOT_OK(cudf::type_dispatcher( | ||
| child->type(), dispatch_to_arrow_device{}, std::move(*child), stream, mr, tmp->children[0])); | ||
| if (child->type().id() == cudf::type_id::EMPTY) { | ||
| NANOARROW_RETURN_NOT_OK(handle_empty_type_column(tmp->children[0], *child)); | ||
| } else { | ||
| NANOARROW_RETURN_NOT_OK(cudf::type_dispatcher( | ||
| child->type(), dispatch_to_arrow_device{}, std::move(*child), stream, mr, tmp->children[0])); | ||
|
vyasr marked this conversation as resolved.
|
||
| } | ||
|
|
||
| ArrowArrayMove(tmp.get(), out); | ||
| return NANOARROW_OK; | ||
|
|
@@ -535,8 +551,12 @@ unique_device_array_t to_arrow_device(cudf::table&& table, | |
| for (size_t i = 0; i < cols.size(); ++i) { | ||
| auto child = tmp->children[i]; | ||
| auto col = cols[i].get(); | ||
| NANOARROW_THROW_NOT_OK(cudf::type_dispatcher( | ||
| col->type(), detail::dispatch_to_arrow_device{}, std::move(*col), stream, mr, child)); | ||
| if (col->type().id() == cudf::type_id::EMPTY) { | ||
| NANOARROW_THROW_NOT_OK(handle_empty_type_column(child, *col)); | ||
| } else { | ||
| NANOARROW_THROW_NOT_OK(cudf::type_dispatcher( | ||
| col->type(), detail::dispatch_to_arrow_device{}, std::move(*col), stream, mr, child)); | ||
|
vyasr marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| return create_device_array(std::move(tmp), stream); | ||
|
|
@@ -548,8 +568,12 @@ unique_device_array_t to_arrow_device(cudf::column&& col, | |
| { | ||
| nanoarrow::UniqueArray tmp; | ||
|
|
||
| NANOARROW_THROW_NOT_OK(cudf::type_dispatcher( | ||
| col.type(), detail::dispatch_to_arrow_device{}, std::move(col), stream, mr, tmp.get())); | ||
| if (col.type().id() == cudf::type_id::EMPTY) { | ||
| NANOARROW_THROW_NOT_OK(handle_empty_type_column(tmp.get(), col)); | ||
| } else { | ||
| NANOARROW_THROW_NOT_OK(cudf::type_dispatcher( | ||
| col.type(), detail::dispatch_to_arrow_device{}, std::move(col), stream, mr, tmp.get())); | ||
|
vyasr marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return create_device_array(std::move(tmp), stream); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think were missing type stubs
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because this file pretty much exclusively exposes pure Cython functions. There is nothing visible to Python except the ColumnMetadata type, but that is (for the moment) primarily publicly exposed via the interop module that already has the type stubs for that. |
||
|
|
||
| from pylibcudf.libcudf.interop cimport column_metadata | ||
|
|
||
| cdef void _release_schema(object schema_capsule) noexcept | ||
|
|
||
| cdef void _release_array(object array_capsule) noexcept | ||
|
|
||
| cdef column_metadata _metadata_to_libcudf(metadata) | ||
Uh oh!
There was an error while loading. Please reload this page.