-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Struct binary comparison op functionality for spark rapids #11153
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 137 commits
262c2a2
a865fe0
ce4440c
1472c5f
4a31fb6
ce2d727
10c95f9
12cd09e
b6fa590
d64c1f9
57900da
f170149
de129a1
5e84e89
b632192
4266f8c
367ec07
5a1f016
1f29168
1d6263e
97bd5e1
48d0355
6cf0e16
9ec2acf
3016abf
b2a7973
191da69
2cf2b28
2b634c4
19f1afb
f316a0a
c684ef1
7f36241
8cf0660
2abefd5
8cc05e2
1bde152
470acfe
ce21d90
83fa370
2b77739
de09cec
8ad9545
251d607
703aaf8
43e451b
9ec4a41
201a89b
cc164d6
1bb1534
6c6c8ab
42e58ae
475c896
1dae04a
62224cf
a35600d
b6f0397
fcc1dd2
5abf2a8
9d50ac0
8628c24
a836a96
a537805
f7af41f
1af4643
4d929d9
2298988
bf1c6ee
5d87db2
fd716b9
2dd2045
7ba960e
84833e7
a944b4f
4d197ea
08092fe
d8986c5
548dcf1
1dd1159
eaffdea
a657b14
3d2a475
e518668
c99e3c5
bb00193
798d6c5
c5f9961
0d4e798
f35d9e3
d7fca8c
e4cee95
58d2663
3a6cd68
6d57678
49be087
d0f64f2
0576e6c
1bd5405
70da3b4
e4a7029
1240c85
3304615
97c116e
b1bc702
4f80b1c
9ca2d29
933b25d
51938fd
3f545fe
fe4fc60
d0c58a6
2eb8103
2e1c9a3
576fab0
44ac4e0
1138c5a
fc5f339
944e05c
feede52
b9337df
7239675
20d76e7
8bdac0d
6e6a476
f32aba5
7fe1fb5
aec885f
1ada1be
b828d37
5424aa1
fd3ae69
589abe4
8116a23
f9c2c5c
d7cd266
9767653
f8a2910
b18a277
a27732c
5f9e565
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,136 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Copyright (c) 2022, NVIDIA CORPORATION. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * limitations under the License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #pragma once | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "binary_ops.hpp" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "operation.cuh" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <cudf/binaryop.hpp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <cudf/column/column_device_view.cuh> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <cudf/column/column_view.hpp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <cudf/detail/iterator.cuh> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <cudf/table/experimental/row_operators.cuh> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <rmm/cuda_stream_view.hpp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <rmm/exec_policy.hpp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace cudf::binops::compiled::detail { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template <class T, class... Ts> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inline constexpr bool is_any_v = std::disjunction<std::is_same<T, Ts>...>::value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template <typename DeviceComparator, class AdaptableUnaryFunction, class Iterator> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
rwlee marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| struct device_comparison_functor { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using optional_iterator = thrust::transform_iterator<AdaptableUnaryFunction, Iterator>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
rwlee marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| device_comparison_functor(optional_iterator const& optional_iter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool const is_lhs_scalar, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool const is_rhs_scalar, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DeviceComparator const& comparator) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : _optional_iter(optional_iter), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _is_lhs_scalar(is_lhs_scalar), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _is_rhs_scalar(is_rhs_scalar), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _comparator(comparator){}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool __device__ operator()(size_type i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return _optional_iter[i].has_value() && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _comparator(cudf::experimental::row::lhs_index_type{_is_lhs_scalar ? 0 : i}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cudf::experimental::row::rhs_index_type{_is_rhs_scalar ? 0 : i}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| optional_iterator const _optional_iter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool const _is_lhs_scalar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool const _is_rhs_scalar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DeviceComparator const _comparator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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. Regarding the comment about this adding net lines of code: it's fine to skip the constructor and use list initialization since the parameters are fairly self-contained. Also this doesn't need so many template parameters, you can just write Finally, don't take iterators by reference. They're cheap to copy. See #11084. (But this is moot if we remove the constructor.) I would try this:
Suggested change
No code changes should be needed at the calling sites.
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. FYI: If you have public member variables then you don't need the constructor and can directly use initializer list for instantiating the struct. If the member variables are private then you must have a constructor.
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. That's why we use
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 had tried this originally (implicit constructor from initializer list), but it has compilation failures. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template <class BinaryOperator, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typename PhysicalElementComparator = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cudf::experimental::row::lexicographic::sorting_physical_element_comparator> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void apply_struct_binary_op(mutable_column_view& out, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| column_view const& lhs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| column_view const& rhs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool is_lhs_scalar, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool is_rhs_scalar, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PhysicalElementComparator comparator = {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rmm::cuda_stream_view stream = cudf::default_stream_value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto compare_orders = std::vector<order>(lhs.size(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is_any_v<BinaryOperator, ops::Greater, ops::GreaterEqual> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? order::DESCENDING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : order::ASCENDING); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto tlhs = table_view{{lhs}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto trhs = table_view{{rhs}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto table_comparator = cudf::experimental::row::lexicographic::two_table_comparator{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tlhs, trhs, compare_orders, {}, stream}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
rwlee marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto outd = column_device_view::create(out, stream); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto optional_iter = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cudf::detail::make_optional_iterator<bool>(*outd, nullate::DYNAMIC{out.has_nulls()}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto nullate = nullate::DYNAMIC{has_nested_nulls(tlhs) || has_nested_nulls(trhs)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
rwlee marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto tabulate_device_operator = [&](auto device_comparator) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| thrust::tabulate( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rmm::exec_policy(stream), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| out.begin<bool>(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| out.end<bool>(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| device_comparison_functor{optional_iter, is_lhs_scalar, is_rhs_scalar, device_comparator}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is_any_v<BinaryOperator, ops::LessEqual, ops::GreaterEqual> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? tabulate_device_operator(table_comparator.less_equivalent(nullate, comparator)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : tabulate_device_operator(table_comparator.less(nullate, comparator)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template <typename PhysicalEqualityComparator = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cudf::experimental::row::equality::physical_equality_comparator> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void apply_struct_equality_op(mutable_column_view& out, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| column_view const& lhs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| column_view const& rhs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool is_lhs_scalar, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool is_rhs_scalar, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| binary_operator op, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PhysicalEqualityComparator comparator = {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rmm::cuda_stream_view stream = cudf::default_stream_value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CUDF_EXPECTS(op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Unsupported operator for these types"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto tlhs = table_view{{lhs}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto trhs = table_view{{rhs}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto table_comparator = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cudf::experimental::row::equality::two_table_comparator{tlhs, trhs, stream}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto device_comparator = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| table_comparator.equal_to(nullate::DYNAMIC{has_nested_nulls(tlhs) || has_nested_nulls(trhs)}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| null_equality::EQUAL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| comparator); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto outd = column_device_view::create(out, stream); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto optional_iter = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cudf::detail::make_optional_iterator<bool>(*outd, nullate::DYNAMIC{out.has_nulls()}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| thrust::tabulate(rmm::exec_policy(stream), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| out.begin<bool>(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| out.end<bool>(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [optional_iter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is_lhs_scalar, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is_rhs_scalar, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| preserve_output = (op != binary_operator::NOT_EQUAL), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| device_comparator] __device__(size_type i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto lhs = cudf::experimental::row::lhs_index_type{is_lhs_scalar ? 0 : i}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto rhs = cudf::experimental::row::rhs_index_type{is_rhs_scalar ? 0 : i}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return optional_iter[i].has_value() and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (device_comparator(lhs, rhs) == preserve_output); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } // namespace cudf::binops::compiled::detail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
rwlee marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.