From 262c2a2799101123bbaf1789d77b06daa98c37c5 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Thu, 30 Sep 2021 11:25:22 -0700 Subject: [PATCH 01/54] struct binop first pass --- cpp/CMakeLists.txt | 1 + cpp/include/cudf/binaryop.hpp | 11 ++ cpp/src/groupby/sort/group_rank_scan.cu | 139 ++++++++++++++++++++ cpp/src/groupby/sort/group_scan.hpp | 8 ++ cpp/src/structs/utilities.cpp | 14 ++ cpp/src/structs/utilities.cu | 165 ++++++++++++++++++++++++ cpp/src/structs/utilities.hpp | 9 ++ cpp/tests/structs/utilities_tests.cpp | 45 +++++++ 8 files changed, 392 insertions(+) create mode 100644 cpp/src/structs/utilities.cu diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 079db9d144b..066e4fb115d 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -415,6 +415,7 @@ add_library(cudf src/structs/structs_column_factories.cu src/structs/structs_column_view.cpp src/structs/utilities.cpp + src/structs/utilities.cu src/table/table.cpp src/table/table_device_view.cu src/table/table_view.cpp diff --git a/cpp/include/cudf/binaryop.hpp b/cpp/include/cudf/binaryop.hpp index fe548a36cf0..1e267be233a 100644 --- a/cpp/include/cudf/binaryop.hpp +++ b/cpp/include/cudf/binaryop.hpp @@ -74,6 +74,7 @@ enum class binary_operator : int32_t { ///< ptx code INVALID_BINARY ///< invalid operation }; + /** * @brief Performs a binary operation between a scalar and a column. * @@ -288,5 +289,15 @@ std::unique_ptr binary_operation( data_type output_type, rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); } // namespace jit +namespace detail { + +std::unique_ptr make_fixed_width_column_for_output( + column_view const& lhs, + column_view const& rhs, + binary_operator op, + data_type output_type, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); +} // namespace detail /** @} */ // end of group } // namespace cudf diff --git a/cpp/src/groupby/sort/group_rank_scan.cu b/cpp/src/groupby/sort/group_rank_scan.cu index 5f4dda294fd..fb5302c1ca8 100644 --- a/cpp/src/groupby/sort/group_rank_scan.cu +++ b/cpp/src/groupby/sort/group_rank_scan.cu @@ -24,6 +24,11 @@ #include #include +#include "cudf/binaryop.hpp" +#include "cudf/column/column_device_view.cuh" +#include "cudf/table/table_device_view.cuh" +#include "cudf/table/table_view.hpp" +#include "thrust/logical.h" namespace cudf { namespace groupby { @@ -141,6 +146,140 @@ std::unique_ptr dense_rank_scan(column_view const& order_by, mr); } +template +void equality_row(table_view lhs, + table_view rhs, + mutable_column_view out, + rmm::cuda_stream_view stream) +{ + auto d_lhs = table_device_view::create(lhs); + auto d_rhs = table_device_view::create(rhs); + + row_equality_comparator comparator(*d_lhs, *d_rhs, true); + + thrust::tabulate( + rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator] __device__(size_type row_index) { return comparator(row_index, row_index); }); +} + +template +void nequal_row(table_view lhs, + table_view rhs, + mutable_column_view out, + rmm::cuda_stream_view stream) +{ + auto d_lhs = table_device_view::create(lhs); + auto d_rhs = table_device_view::create(rhs); + + row_equality_comparator comparator(*d_lhs, *d_rhs, true); + + thrust::tabulate( + rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator] __device__(size_type row_index) { return !comparator(row_index, row_index); }); +} + +void and_merge(table_view lhs, + table_view rhs, + mutable_column_view out, + binary_operator op, + rmm::cuda_stream_view stream) +{ + std::vector comp_views{}; + std::vector> child_comparisons{}; + std::for_each( + thrust::make_counting_iterator(0), + thrust::make_counting_iterator(lhs.num_columns()), + [&](auto child_index) { + auto res = binary_operation( + lhs.column(child_index), rhs.column(child_index), binary_operator::LESS, out.type()); + comp_views.push_back(res->view()); + child_comparisons.push_back(std::move(res)); + + }); + + + table_view comp_table{comp_views}; + auto const d_comp_table = table_device_view::create(comp_table); + + // merge + thrust::tabulate(rmm::exec_policy(stream), + out.begin(), + out.end(), + [d_comp_table = *d_comp_table] __device__(size_type row_index) { + return thrust::all_of(thrust::seq, + d_comp_table.begin(), + d_comp_table.end(), + [row_index] __device__(column_device_view col) { + return col.data()[row_index]; + // return col.element(row_index); + }); + }); +} + +template +void lt_row(table_view lhs, table_view rhs, mutable_column_view out, rmm::cuda_stream_view stream) +{ + auto d_lhs = table_device_view::create(lhs); + auto d_rhs = table_device_view::create(rhs); + + row_lexicographic_comparator comparator(*d_lhs, *d_rhs, nullptr, nullptr); + + thrust::tabulate( + rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator] __device__(size_type row_index) { return !comparator(row_index, row_index); }); +} + +std::unique_ptr struct_binary_operation2(column_view const& lhs, + column_view const& rhs, + binary_operator op, + data_type output_type, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) +{ + auto const lhs_superimposed = structs::detail::superimpose_parent_nulls(lhs); + auto const lhs_flattener = cudf::structs::detail::flatten_nested_columns( + table_view{{std::get<0>(lhs_superimposed)}}, + {}, + {}, + structs::detail::column_nullability::MATCH_INCOMING); + table_view lhs_flat = std::get<0>(lhs_flattener); + // auto const d_lhs_flat = table_device_view::create(lhs_flat, stream); + + auto const rhs_superimposed = structs::detail::superimpose_parent_nulls(rhs); + auto const rhs_flattener = cudf::structs::detail::flatten_nested_columns( + table_view{{std::get<0>(rhs_superimposed)}}, + {}, + {}, + structs::detail::column_nullability::MATCH_INCOMING); + table_view rhs_flat = std::get<0>(rhs_flattener); + // auto const d_rhs_flat = table_device_view::create(rhs_flat, stream); + + auto out = + cudf::detail::make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, mr); + auto out_view = out->mutable_view(); + + auto lhs_has_nulls = has_nested_nulls(lhs_flat); + auto rhs_has_nulls = has_nested_nulls(rhs_flat); + + switch (op) { + case binary_operator::EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, stream); break; + case binary_operator::NOT_EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, stream); break; + case binary_operator::LESS: lt_row(lhs_flat, rhs_flat, out_view, stream); break; + // case binary_operator::GREATER: break; + // case binary_operator::LESS_EQUAL: break; + case binary_operator::GREATER_EQUAL: lt_row(rhs_flat, lhs_flat, out_view, stream); break; + // case binary_operator::NULL_EQUALS: break; + default: CUDF_FAIL("Unsupported operator for these types"); + } + return out; +} } // namespace detail + } // namespace groupby } // namespace cudf diff --git a/cpp/src/groupby/sort/group_scan.hpp b/cpp/src/groupby/sort/group_scan.hpp index 82ef0e25380..731447894f9 100644 --- a/cpp/src/groupby/sort/group_scan.hpp +++ b/cpp/src/groupby/sort/group_scan.hpp @@ -23,6 +23,7 @@ #include #include +#include "cudf/binaryop.hpp" namespace cudf { namespace groupby { @@ -116,6 +117,13 @@ std::unique_ptr dense_rank_scan(column_view const& order_by, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr); +std::unique_ptr struct_binary_operation2( + column_view lhs, + column_view rhs, + binary_operator op, + data_type output_type, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); } // namespace detail } // namespace groupby } // namespace cudf diff --git a/cpp/src/structs/utilities.cpp b/cpp/src/structs/utilities.cpp index b84af73b681..f32c01c3ece 100644 --- a/cpp/src/structs/utilities.cpp +++ b/cpp/src/structs/utilities.cpp @@ -29,6 +29,7 @@ #include #include +#include "cudf/binaryop.hpp" namespace cudf { namespace structs { @@ -415,6 +416,19 @@ std::tuple> superimpose_paren std::move(ret_validity_buffers)); } +// std::unique_ptr struct_lexicographic_compare(column_view lhs, column_view rhs, data_type +// output_type, binary_operator op, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* +// mr) { + +// auto out = cudf::detail::make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, +// mr); + +// // superimpose +// // flatten + +// return out; +// } + } // namespace detail } // namespace structs } // namespace cudf diff --git a/cpp/src/structs/utilities.cu b/cpp/src/structs/utilities.cu new file mode 100644 index 00000000000..624371d6625 --- /dev/null +++ b/cpp/src/structs/utilities.cu @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2020-2021, 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. + */ + +#include +#include + +#include +#include +#include "cudf/binaryop.hpp" +#include "cudf/column/column_device_view.cuh" +#include "cudf/table/table_device_view.cuh" +#include "cudf/table/table_view.hpp" +#include "thrust/logical.h" + +namespace cudf { +namespace structs { +namespace detail { + +template +void equality_row(table_view lhs, + table_view rhs, + mutable_column_view out, + rmm::cuda_stream_view stream) +{ + auto d_lhs = table_device_view::create(lhs); + auto d_rhs = table_device_view::create(rhs); + + row_equality_comparator comparator(*d_lhs, *d_rhs, true); + + thrust::tabulate( + rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator] __device__(size_type row_index) { return comparator(row_index, row_index); }); +} + +template +void nequal_row(table_view lhs, + table_view rhs, + mutable_column_view out, + rmm::cuda_stream_view stream) +{ + auto d_lhs = table_device_view::create(lhs); + auto d_rhs = table_device_view::create(rhs); + + row_equality_comparator comparator(*d_lhs, *d_rhs, true); + + thrust::tabulate( + rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator] __device__(size_type row_index) { return !comparator(row_index, row_index); }); +} + +void and_merge(table_view lhs, + table_view rhs, + mutable_column_view out, + binary_operator op, + rmm::cuda_stream_view stream) +{ + std::vector comp_views{}; + std::vector> child_comparisons{}; + std::for_each( + thrust::make_counting_iterator(0), + thrust::make_counting_iterator(lhs.num_columns()), + [&](auto child_index) { + auto res = binary_operation( + lhs.column(child_index), rhs.column(child_index), binary_operator::LESS, out.type()); + comp_views.push_back(res->view()); + child_comparisons.push_back(std::move(res)); + }); + + + table_view comp_table{comp_views}; + auto const d_comp_table = table_device_view::create(comp_table); + + // merge + thrust::tabulate(rmm::exec_policy(stream), + out.begin(), + out.end(), + [d_comp_table = *d_comp_table] __device__(size_type row_index) { + return thrust::all_of(thrust::seq, + d_comp_table.begin(), + d_comp_table.end(), + [row_index] __device__(column_device_view col) { + return col.data()[row_index]; + // return col.element(row_index); + }); + }); +} + +template +void lt_row(table_view lhs, table_view rhs, mutable_column_view out, rmm::cuda_stream_view stream) +{ + auto d_lhs = table_device_view::create(lhs); + auto d_rhs = table_device_view::create(rhs); + + row_lexicographic_comparator comparator(*d_lhs, *d_rhs, nullptr, nullptr); + + thrust::tabulate( + rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator] __device__(size_type row_index) { return !comparator(row_index, row_index); }); +} + +std::unique_ptr struct_binary_operation(column_view const& lhs, + column_view const& rhs, + binary_operator op, + data_type output_type, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) +{ + auto const lhs_superimposed = superimpose_parent_nulls(lhs); + auto const lhs_flattener = flatten_nested_columns( + table_view{{std::get<0>(lhs_superimposed)}}, {}, {}, column_nullability::MATCH_INCOMING); + table_view lhs_flat = std::get<0>(lhs_flattener); + // auto const d_lhs_flat = table_device_view::create(lhs_flat, stream); + + auto const rhs_superimposed = superimpose_parent_nulls(rhs); + auto const rhs_flattener = flatten_nested_columns( + table_view{{std::get<0>(rhs_superimposed)}}, {}, {}, column_nullability::MATCH_INCOMING); + table_view rhs_flat = std::get<0>(rhs_flattener); + // auto const d_rhs_flat = table_device_view::create(rhs_flat, stream); + + auto out = + cudf::detail::make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, mr); + auto out_view = out->mutable_view(); + + auto lhs_has_nulls = has_nested_nulls(lhs_flat); + auto rhs_has_nulls = has_nested_nulls(rhs_flat); + + switch (op) { + case binary_operator::EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, stream); break; + case binary_operator::NOT_EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, stream); break; + case binary_operator::LESS: lt_row(lhs_flat, rhs_flat, out_view, stream); break; + // case binary_operator::GREATER: break; + // case binary_operator::LESS_EQUAL: break; + case binary_operator::GREATER_EQUAL: lt_row(rhs_flat, lhs_flat, out_view, stream); break; + // case binary_operator::NULL_EQUALS: break; + default: CUDF_FAIL("Unsupported operator for these types"); + } + return out; +} + +} // namespace detail +} // namespace structs +} // namespace cudf + +// binary_op_compare() { +// type_dispatcher() +// } diff --git a/cpp/src/structs/utilities.hpp b/cpp/src/structs/utilities.hpp index 24b80b58669..298ec95b58b 100644 --- a/cpp/src/structs/utilities.hpp +++ b/cpp/src/structs/utilities.hpp @@ -20,6 +20,7 @@ #include #include +#include "cudf/binaryop.hpp" namespace cudf { namespace structs { @@ -156,6 +157,14 @@ std::tuple> superimpose_paren rmm::cuda_stream_view stream = rmm::cuda_stream_default, rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); +std::unique_ptr struct_binary_operation( + column_view lhs, + column_view rhs, + binary_operator op, + data_type output_type, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + } // namespace detail } // namespace structs } // namespace cudf diff --git a/cpp/tests/structs/utilities_tests.cpp b/cpp/tests/structs/utilities_tests.cpp index 08b40b22aa4..024e7f0d3ce 100644 --- a/cpp/tests/structs/utilities_tests.cpp +++ b/cpp/tests/structs/utilities_tests.cpp @@ -16,6 +16,7 @@ #include +#include #include #include #include @@ -28,6 +29,9 @@ #include #include #include +#include +#include "cudf/binaryop.hpp" +#include "groupby/sort/group_scan.hpp" namespace cudf::test { @@ -504,4 +508,45 @@ TYPED_TEST(TypedSuperimposeTest, NestedStruct_Sliced) CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(output, expected_sliced_structs); } +template +struct TypedBinopStructCompare : StructUtilitiesTest { +}; + +TYPED_TEST_SUITE(TypedBinopStructCompare, int32_t); +TYPED_TEST(TypedBinopStructCompare, binopcompare) +{ + // Test with a sliced STRUCT column. + // Ensure that superimpose_parent_nulls() produces the right results, even when the input is + // sliced. + + using T = TypeParam; + + auto col1 = fixed_width_column_wrapper{{0, 0, 7, 7, 7, 5, 4, 4, 4, 9, 9, 9}, null_at(5)}; + auto col2 = fixed_width_column_wrapper{{0, 0, 7, 7, 7, 5, 4, 4, 4, 9, 9, 9}, null_at(5)}; + auto strings1 = strings_column_wrapper{ + {"0a", "0a", "2a", "2a", "3b", "5", "6c", "6c", "6c", "9", "9", "10d"}, null_at(8)}; + auto strings2 = strings_column_wrapper{ + {"0a", "0a", "2a", "2a", "3b", "5", "6c", "6c", "6c", "9", "9", "10d"}, null_at(8)}; + + std::vector> struct_columns; + struct_columns.push_back(col1.release()); + struct_columns.push_back(strings1.release()); + auto struct_col = + cudf::make_structs_column(12, std::move(struct_columns), 0, rmm::device_buffer{}); + auto const struct_nulls = + thrust::host_vector(std::vector{1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0}); + struct_col->set_null_mask( + cudf::test::detail::make_null_mask(struct_nulls.begin(), struct_nulls.end())); + + auto lhs = struct_col->view(); + auto rhs = struct_col->view(); + binary_operator bin_op = binary_operator::EQUAL; + data_type dt = cudf::data_type(cudf::type_id::BOOL8); + // auto res = cudf::structs::detail::struct_binary_operation(struct_col->view(), + // struct_col->view(), binary_operator::EQUAL, cudf::data_type(cudf::type_id::BOOL8)); + auto res = cudf::groupby::detail::struct_binary_operation2(lhs, rhs, bin_op, dt); + // auto res = cudf::structs::detail::struct_binary_operation();//lhs, rhs, bin_op, dt, + // rmm::cuda_stream_default, rmm::mr::get_current_device_resource()); +} + } // namespace cudf::test From a865fe094e4ba84e3a142979898ce0d81c3459ce Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Thu, 14 Oct 2021 16:57:35 -0700 Subject: [PATCH 02/54] vector-vector nested struct comparison --- cpp/src/groupby/sort/group_rank_scan.cu | 139 ------------- cpp/src/groupby/sort/group_scan.hpp | 8 - cpp/src/structs/utilities.cu | 262 +++++++++++++++--------- cpp/src/structs/utilities.cuh | 210 +++++++++++++++++++ cpp/src/structs/utilities.hpp | 4 +- cpp/tests/structs/utilities_tests.cpp | 261 ++++++++++++++++++++--- 6 files changed, 608 insertions(+), 276 deletions(-) create mode 100644 cpp/src/structs/utilities.cuh diff --git a/cpp/src/groupby/sort/group_rank_scan.cu b/cpp/src/groupby/sort/group_rank_scan.cu index fb5302c1ca8..5f4dda294fd 100644 --- a/cpp/src/groupby/sort/group_rank_scan.cu +++ b/cpp/src/groupby/sort/group_rank_scan.cu @@ -24,11 +24,6 @@ #include #include -#include "cudf/binaryop.hpp" -#include "cudf/column/column_device_view.cuh" -#include "cudf/table/table_device_view.cuh" -#include "cudf/table/table_view.hpp" -#include "thrust/logical.h" namespace cudf { namespace groupby { @@ -146,140 +141,6 @@ std::unique_ptr dense_rank_scan(column_view const& order_by, mr); } -template -void equality_row(table_view lhs, - table_view rhs, - mutable_column_view out, - rmm::cuda_stream_view stream) -{ - auto d_lhs = table_device_view::create(lhs); - auto d_rhs = table_device_view::create(rhs); - - row_equality_comparator comparator(*d_lhs, *d_rhs, true); - - thrust::tabulate( - rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator] __device__(size_type row_index) { return comparator(row_index, row_index); }); -} - -template -void nequal_row(table_view lhs, - table_view rhs, - mutable_column_view out, - rmm::cuda_stream_view stream) -{ - auto d_lhs = table_device_view::create(lhs); - auto d_rhs = table_device_view::create(rhs); - - row_equality_comparator comparator(*d_lhs, *d_rhs, true); - - thrust::tabulate( - rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator] __device__(size_type row_index) { return !comparator(row_index, row_index); }); -} - -void and_merge(table_view lhs, - table_view rhs, - mutable_column_view out, - binary_operator op, - rmm::cuda_stream_view stream) -{ - std::vector comp_views{}; - std::vector> child_comparisons{}; - std::for_each( - thrust::make_counting_iterator(0), - thrust::make_counting_iterator(lhs.num_columns()), - [&](auto child_index) { - auto res = binary_operation( - lhs.column(child_index), rhs.column(child_index), binary_operator::LESS, out.type()); - comp_views.push_back(res->view()); - child_comparisons.push_back(std::move(res)); - - }); - - - table_view comp_table{comp_views}; - auto const d_comp_table = table_device_view::create(comp_table); - - // merge - thrust::tabulate(rmm::exec_policy(stream), - out.begin(), - out.end(), - [d_comp_table = *d_comp_table] __device__(size_type row_index) { - return thrust::all_of(thrust::seq, - d_comp_table.begin(), - d_comp_table.end(), - [row_index] __device__(column_device_view col) { - return col.data()[row_index]; - // return col.element(row_index); - }); - }); -} - -template -void lt_row(table_view lhs, table_view rhs, mutable_column_view out, rmm::cuda_stream_view stream) -{ - auto d_lhs = table_device_view::create(lhs); - auto d_rhs = table_device_view::create(rhs); - - row_lexicographic_comparator comparator(*d_lhs, *d_rhs, nullptr, nullptr); - - thrust::tabulate( - rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator] __device__(size_type row_index) { return !comparator(row_index, row_index); }); -} - -std::unique_ptr struct_binary_operation2(column_view const& lhs, - column_view const& rhs, - binary_operator op, - data_type output_type, - rmm::cuda_stream_view stream, - rmm::mr::device_memory_resource* mr) -{ - auto const lhs_superimposed = structs::detail::superimpose_parent_nulls(lhs); - auto const lhs_flattener = cudf::structs::detail::flatten_nested_columns( - table_view{{std::get<0>(lhs_superimposed)}}, - {}, - {}, - structs::detail::column_nullability::MATCH_INCOMING); - table_view lhs_flat = std::get<0>(lhs_flattener); - // auto const d_lhs_flat = table_device_view::create(lhs_flat, stream); - - auto const rhs_superimposed = structs::detail::superimpose_parent_nulls(rhs); - auto const rhs_flattener = cudf::structs::detail::flatten_nested_columns( - table_view{{std::get<0>(rhs_superimposed)}}, - {}, - {}, - structs::detail::column_nullability::MATCH_INCOMING); - table_view rhs_flat = std::get<0>(rhs_flattener); - // auto const d_rhs_flat = table_device_view::create(rhs_flat, stream); - - auto out = - cudf::detail::make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, mr); - auto out_view = out->mutable_view(); - - auto lhs_has_nulls = has_nested_nulls(lhs_flat); - auto rhs_has_nulls = has_nested_nulls(rhs_flat); - - switch (op) { - case binary_operator::EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, stream); break; - case binary_operator::NOT_EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, stream); break; - case binary_operator::LESS: lt_row(lhs_flat, rhs_flat, out_view, stream); break; - // case binary_operator::GREATER: break; - // case binary_operator::LESS_EQUAL: break; - case binary_operator::GREATER_EQUAL: lt_row(rhs_flat, lhs_flat, out_view, stream); break; - // case binary_operator::NULL_EQUALS: break; - default: CUDF_FAIL("Unsupported operator for these types"); - } - return out; -} } // namespace detail - } // namespace groupby } // namespace cudf diff --git a/cpp/src/groupby/sort/group_scan.hpp b/cpp/src/groupby/sort/group_scan.hpp index 731447894f9..82ef0e25380 100644 --- a/cpp/src/groupby/sort/group_scan.hpp +++ b/cpp/src/groupby/sort/group_scan.hpp @@ -23,7 +23,6 @@ #include #include -#include "cudf/binaryop.hpp" namespace cudf { namespace groupby { @@ -117,13 +116,6 @@ std::unique_ptr dense_rank_scan(column_view const& order_by, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr); -std::unique_ptr struct_binary_operation2( - column_view lhs, - column_view rhs, - binary_operator op, - data_type output_type, - rmm::cuda_stream_view stream = rmm::cuda_stream_default, - rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); } // namespace detail } // namespace groupby } // namespace cudf diff --git a/cpp/src/structs/utilities.cu b/cpp/src/structs/utilities.cu index 624371d6625..16af72bb271 100644 --- a/cpp/src/structs/utilities.cu +++ b/cpp/src/structs/utilities.cu @@ -17,105 +17,192 @@ #include #include +#include #include #include #include "cudf/binaryop.hpp" #include "cudf/column/column_device_view.cuh" #include "cudf/table/table_device_view.cuh" #include "cudf/table/table_view.hpp" +#include "cudf/types.hpp" +#include "cudf/utilities/traits.hpp" +#include "cudf/utilities/type_dispatcher.hpp" #include "thrust/logical.h" namespace cudf { namespace structs { namespace detail { -template -void equality_row(table_view lhs, - table_view rhs, +struct StructCompFunctor { + template + void equality_row(table_device_view lhs, + table_device_view rhs, + mutable_column_view out, + rmm::cuda_stream_view stream) + { + row_equality_comparator comparator(lhs, rhs, true); + auto d_out = mutable_column_device_view::create(out); + + thrust::tabulate(rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator, d_out = *d_out] __device__(size_type row_index) { + return d_out.is_valid(row_index) && comparator(row_index, row_index); + }); + } + + template + void nequal_row(table_device_view lhs, + table_device_view rhs, mutable_column_view out, rmm::cuda_stream_view stream) -{ - auto d_lhs = table_device_view::create(lhs); - auto d_rhs = table_device_view::create(rhs); - - row_equality_comparator comparator(*d_lhs, *d_rhs, true); - - thrust::tabulate( - rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator] __device__(size_type row_index) { return comparator(row_index, row_index); }); -} + { + row_equality_comparator comparator(lhs, rhs, true); + auto d_out = mutable_column_device_view::create(out); + + thrust::tabulate(rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator, d_out = *d_out] __device__(size_type row_index) { + return d_out.is_valid(row_index) && !comparator(row_index, row_index); + }); + } -template -void nequal_row(table_view lhs, - table_view rhs, - mutable_column_view out, - rmm::cuda_stream_view stream) -{ - auto d_lhs = table_device_view::create(lhs); - auto d_rhs = table_device_view::create(rhs); + template + void lt_row(table_device_view lhs, + table_device_view rhs, + mutable_column_view out, + rmm::cuda_stream_view stream) + { + row_lexicographic_comparator comparator(lhs, rhs, nullptr, nullptr); + auto d_out = mutable_column_device_view::create(out); + + thrust::tabulate(rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator, d_out = *d_out] __device__(size_type row_index) { + return d_out.is_valid(row_index) && comparator(row_index, row_index); + }); + } - row_equality_comparator comparator(*d_lhs, *d_rhs, true); + template + void gte_row(table_device_view lhs, + table_device_view rhs, + mutable_column_view out, + rmm::cuda_stream_view stream) + { + row_lexicographic_comparator comparator(lhs, rhs, nullptr, nullptr); + auto d_out = mutable_column_device_view::create(out); + + thrust::tabulate(rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator, d_out = *d_out] __device__(size_type row_index) { + return d_out.is_valid(row_index) && !comparator(row_index, row_index); + }); + } - thrust::tabulate( - rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator] __device__(size_type row_index) { return !comparator(row_index, row_index); }); -} + template + void gt_row(table_device_view lhs, + table_device_view rhs, + mutable_column_view out, + rmm::cuda_stream_view stream) + { + std::vector op_modifier{}; + std::vector norder{}; + std::for_each(thrust::counting_iterator(0), + thrust::counting_iterator(lhs.num_columns()), + [&](auto child_ind) { + op_modifier.push_back(order::DESCENDING); + norder.push_back(null_order::BEFORE); + }); + + auto const op_modifier_dv = cudf::detail::make_device_uvector_async(op_modifier, stream); + auto comparator = row_lexicographic_comparator(lhs, rhs, op_modifier_dv.data()); + auto d_out = mutable_column_device_view::create(out); + + thrust::tabulate(rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator, d_out = *d_out] __device__(size_type row_index) { + return d_out.is_valid(row_index) && comparator(row_index, row_index); + }); + } -void and_merge(table_view lhs, - table_view rhs, + template + void lte_row(table_device_view lhs, + table_device_view rhs, mutable_column_view out, - binary_operator op, rmm::cuda_stream_view stream) -{ - std::vector comp_views{}; - std::vector> child_comparisons{}; - std::for_each( - thrust::make_counting_iterator(0), - thrust::make_counting_iterator(lhs.num_columns()), - [&](auto child_index) { - auto res = binary_operation( - lhs.column(child_index), rhs.column(child_index), binary_operator::LESS, out.type()); - comp_views.push_back(res->view()); - child_comparisons.push_back(std::move(res)); - }); - - - table_view comp_table{comp_views}; - auto const d_comp_table = table_device_view::create(comp_table); - - // merge - thrust::tabulate(rmm::exec_policy(stream), - out.begin(), - out.end(), - [d_comp_table = *d_comp_table] __device__(size_type row_index) { - return thrust::all_of(thrust::seq, - d_comp_table.begin(), - d_comp_table.end(), - [row_index] __device__(column_device_view col) { - return col.data()[row_index]; - // return col.element(row_index); - }); - }); -} - -template -void lt_row(table_view lhs, table_view rhs, mutable_column_view out, rmm::cuda_stream_view stream) -{ - auto d_lhs = table_device_view::create(lhs); - auto d_rhs = table_device_view::create(rhs); + { + std::vector op_modifier{}; + std::vector norder{}; + std::for_each(thrust::counting_iterator(0), + thrust::counting_iterator(lhs.num_columns()), + [&](auto child_ind) { + op_modifier.push_back(order::DESCENDING); + norder.push_back(null_order::BEFORE); + }); + + auto const op_modifier_dv = cudf::detail::make_device_uvector_async(op_modifier, stream); + auto comparator = row_lexicographic_comparator(lhs, rhs, op_modifier_dv.data()); + auto d_out = mutable_column_device_view::create(out); + + thrust::tabulate(rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator, d_out = *d_out] __device__(size_type row_index) { + return d_out.is_valid(row_index) && !comparator(row_index, row_index); + }); + } - row_lexicographic_comparator comparator(*d_lhs, *d_rhs, nullptr, nullptr); + template ()>* = nullptr> + void __host__ operator()(table_view const& lhs, + table_view const& rhs, + mutable_column_view& out, + binary_operator op, + rmm::cuda_stream_view stream) + { + bool const has_nulls = has_nested_nulls(lhs) || has_nested_nulls(rhs); + + auto d_lhs = table_device_view::create(lhs); + auto d_rhs = table_device_view::create(rhs); + + if (has_nulls) { + switch (op) { + case binary_operator::EQUAL: equality_row(*d_lhs, *d_rhs, out, stream); break; + case binary_operator::NOT_EQUAL: nequal_row(*d_lhs, *d_rhs, out, stream); break; + case binary_operator::LESS: lt_row(*d_lhs, *d_rhs, out, stream); break; + case binary_operator::GREATER: gt_row(*d_lhs, *d_rhs, out, stream); break; + case binary_operator::LESS_EQUAL: lte_row(*d_lhs, *d_rhs, out, stream); break; + case binary_operator::GREATER_EQUAL: gte_row(*d_lhs, *d_rhs, out, stream); break; + // case binary_operator::NULL_EQUALS: break; + default: CUDF_FAIL("Unsupported operator for these types"); + } + } else { + switch (op) { + case binary_operator::EQUAL: equality_row(*d_lhs, *d_rhs, out, stream); break; + case binary_operator::NOT_EQUAL: nequal_row(*d_lhs, *d_rhs, out, stream); break; + case binary_operator::LESS: lt_row(*d_lhs, *d_rhs, out, stream); break; + case binary_operator::GREATER: gt_row(*d_lhs, *d_rhs, out, stream); break; + case binary_operator::LESS_EQUAL: lte_row(*d_lhs, *d_rhs, out, stream); break; + case binary_operator::GREATER_EQUAL: gte_row(*d_lhs, *d_rhs, out, stream); break; + // case binary_operator::NULL_EQUALS: break; + default: CUDF_FAIL("Unsupported operator for these types"); + } + } + } - thrust::tabulate( - rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator] __device__(size_type row_index) { return !comparator(row_index, row_index); }); -} + template ()>* = nullptr> + void __host__ operator()(table_view const& lhs, + table_view const& rhs, + mutable_column_view& out, + binary_operator op, + rmm::cuda_stream_view stream) + { + CUDF_FAIL("unsupported output type"); + } +}; std::unique_ptr struct_binary_operation(column_view const& lhs, column_view const& rhs, @@ -128,38 +215,21 @@ std::unique_ptr struct_binary_operation(column_view const& lhs, auto const lhs_flattener = flatten_nested_columns( table_view{{std::get<0>(lhs_superimposed)}}, {}, {}, column_nullability::MATCH_INCOMING); table_view lhs_flat = std::get<0>(lhs_flattener); - // auto const d_lhs_flat = table_device_view::create(lhs_flat, stream); auto const rhs_superimposed = superimpose_parent_nulls(rhs); auto const rhs_flattener = flatten_nested_columns( table_view{{std::get<0>(rhs_superimposed)}}, {}, {}, column_nullability::MATCH_INCOMING); table_view rhs_flat = std::get<0>(rhs_flattener); - // auto const d_rhs_flat = table_device_view::create(rhs_flat, stream); auto out = cudf::detail::make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, mr); auto out_view = out->mutable_view(); - auto lhs_has_nulls = has_nested_nulls(lhs_flat); - auto rhs_has_nulls = has_nested_nulls(rhs_flat); - - switch (op) { - case binary_operator::EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, stream); break; - case binary_operator::NOT_EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, stream); break; - case binary_operator::LESS: lt_row(lhs_flat, rhs_flat, out_view, stream); break; - // case binary_operator::GREATER: break; - // case binary_operator::LESS_EQUAL: break; - case binary_operator::GREATER_EQUAL: lt_row(rhs_flat, lhs_flat, out_view, stream); break; - // case binary_operator::NULL_EQUALS: break; - default: CUDF_FAIL("Unsupported operator for these types"); - } + type_dispatcher(out_view.type(), StructCompFunctor{}, lhs_flat, rhs_flat, out_view, op, stream); + return out; } } // namespace detail } // namespace structs } // namespace cudf - -// binary_op_compare() { -// type_dispatcher() -// } diff --git a/cpp/src/structs/utilities.cuh b/cpp/src/structs/utilities.cuh new file mode 100644 index 00000000000..cc50ed0c201 --- /dev/null +++ b/cpp/src/structs/utilities.cuh @@ -0,0 +1,210 @@ +// /* +// * Copyright (c) 2020-2021, 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. +// */ + +// #include +// #include + +// #include +// #include +// #include "cudf/binaryop.hpp" +// #include "cudf/column/column_device_view.cuh" +// #include "cudf/table/table_device_view.cuh" +// #include "cudf/table/table_view.hpp" +// #include "cudf/types.hpp" +// #include "thrust/logical.h" + +// namespace cudf { +// namespace structs { +// namespace detail { + +// template +// void equality_row(table_view lhs, +// table_view rhs, +// mutable_column_view out, +// rmm::cuda_stream_view stream) +// { +// auto d_lhs = table_device_view::create(lhs); +// auto d_rhs = table_device_view::create(rhs); + +// row_equality_comparator comparator(*d_lhs, *d_rhs, true); + +// thrust::tabulate( +// rmm::exec_policy(stream), +// out.begin(), +// out.end(), +// [comparator] __device__(size_type row_index) { return comparator(row_index, row_index); }); +// } + +// template +// void nequal_row(table_view lhs, +// table_view rhs, +// mutable_column_view out, +// rmm::cuda_stream_view stream) +// { +// auto d_lhs = table_device_view::create(lhs); +// auto d_rhs = table_device_view::create(rhs); + +// row_equality_comparator comparator(*d_lhs, *d_rhs, true); + +// thrust::tabulate( +// rmm::exec_policy(stream), +// out.begin(), +// out.end(), +// [comparator] __device__(size_type row_index) { return !comparator(row_index, row_index); }); +// } + +// template +// void and_merge(table_view lhs, +// table_view rhs, +// mutable_column_view out, +// binary_operator op, +// rmm::cuda_stream_view stream) +// { +// std::vector comp_views{}; +// std::vector> child_comparisons{}; +// std::for_each( +// thrust::make_counting_iterator(0), +// thrust::make_counting_iterator(lhs.num_columns()), +// [&](auto child_index) { +// auto res = binary_operation( +// lhs.column(child_index), rhs.column(child_index), op, out.type()); +// comp_views.push_back(res->view()); +// child_comparisons.push_back(std::move(res)); +// }); + +// table_view comp_table{comp_views}; +// auto const d_comp_table = table_device_view::create(comp_table); + +// // merge +// thrust::tabulate(rmm::exec_policy(stream), +// out.begin(), +// out.end(), +// [d_comp_table = *d_comp_table] __device__(size_type row_index) { +// return thrust::all_of(thrust::seq, +// d_comp_table.begin(), +// d_comp_table.end(), +// [row_index] __device__(column_device_view col) { +// return col.data()[row_index]; +// }); +// }); +// } + +// template +// void lt_row(table_view lhs, table_view rhs, mutable_column_view out, rmm::cuda_stream_view +// stream) +// { +// auto d_lhs = table_device_view::create(lhs); +// auto d_rhs = table_device_view::create(rhs); + +// row_lexicographic_comparator comparator(*d_lhs, *d_rhs, nullptr, nullptr); + +// thrust::tabulate( +// rmm::exec_policy(stream), +// out.begin(), +// out.end(), +// [comparator] __device__(size_type row_index) { return comparator(row_index, row_index); }); +// } + +// template +// void gt_row(table_view lhs, table_view rhs, mutable_column_view out, rmm::cuda_stream_view +// stream) +// { +// auto d_lhs = table_device_view::create(lhs); +// auto d_rhs = table_device_view::create(rhs); + +// std::vector op_modifier{}; +// // std::vector norder{}; +// std::for_each(thrust::counting_iterator(0), +// thrust::counting_iterator(lhs.num_columns()), +// [&](auto child_ind) { +// op_modifier.push_back(order::DESCENDING); +// // norder.push_back(null_order::BEFORE); +// }); +// // auto comparator = row_lexicographic_comparator(*d_lhs, *d_rhs, +// op_modifier.data(), norder.data()); auto comparator = +// row_lexicographic_comparator(*d_lhs, *d_rhs, op_modifier.data(), nullptr); + +// comparator(0, 0); +// thrust::tabulate( +// rmm::exec_policy(stream), +// out.begin(), +// out.end(), +// [comparator] __device__(size_type row_index) { return comparator(row_index, row_index);}); +// } + +// template +// std::unique_ptr struct_binary_operation( +// column_view const& lhs, +// column_view const& rhs, +// binary_operator op, +// data_type output_type, +// rmm::cuda_stream_view stream = rmm::cuda_stream_default, +// rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()) +// { +// auto const lhs_superimposed = superimpose_parent_nulls(lhs); +// auto const lhs_flattener = flatten_nested_columns( +// table_view{{std::get<0>(lhs_superimposed)}}, {}, {}, column_nullability::MATCH_INCOMING); +// table_view lhs_flat = std::get<0>(lhs_flattener); +// // auto const d_lhs_flat = table_device_view::create(lhs_flat, stream); + +// auto const rhs_superimposed = superimpose_parent_nulls(rhs); +// auto const rhs_flattener = flatten_nested_columns( +// table_view{{std::get<0>(rhs_superimposed)}}, {}, {}, column_nullability::MATCH_INCOMING); +// table_view rhs_flat = std::get<0>(rhs_flattener); +// // auto const d_rhs_flat = table_device_view::create(rhs_flat, stream); + +// auto out = cudf::detail::make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, +// mr); auto out_view = out->mutable_view(); + +// auto const lhs_has_nulls = has_nested_nulls(lhs_flat); +// auto const rhs_has_nulls = has_nested_nulls(rhs_flat); +// bool const has_nulls = lhs_has_nulls || rhs_has_nulls; + +// if(has_nulls){ +// switch (op) { +// case binary_operator::EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, stream); +// break; case binary_operator::NOT_EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, +// stream); break; case binary_operator::LESS: lt_row(lhs_flat, rhs_flat, out_view, +// stream); break; case binary_operator::GREATER: gt_row(lhs_flat, rhs_flat, +// out_view, stream); break; case binary_operator::LESS_EQUAL: gt_row(rhs_flat, +// lhs_flat, out_view, stream); break; case binary_operator::GREATER_EQUAL: lt_row(rhs_flat, lhs_flat, out_view, stream); break; +// // case binary_operator::NULL_EQUALS: break; +// default: CUDF_FAIL("Unsupported operator for these types"); +// } +// } else { +// switch (op) { +// case binary_operator::EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, stream); +// break; case binary_operator::NOT_EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, +// stream); break; case binary_operator::LESS: lt_row(lhs_flat, rhs_flat, out_view, +// stream); break; case binary_operator::GREATER: gt_row(lhs_flat, rhs_flat, +// out_view, stream); break; case binary_operator::LESS_EQUAL: gt_row(rhs_flat, +// lhs_flat, out_view, stream); break; case binary_operator::GREATER_EQUAL: lt_row(rhs_flat, lhs_flat, out_view, stream); break; +// // case binary_operator::NULL_EQUALS: break; +// default: CUDF_FAIL("Unsupported operator for these types"); +// } +// } +// return out; +// } + +// } // namespace detail +// } // namespace structs +// } // namespace cudf + +// // binary_op_compare() { +// // type_dispatcher() +// // } diff --git a/cpp/src/structs/utilities.hpp b/cpp/src/structs/utilities.hpp index 298ec95b58b..8b2cfa19b3b 100644 --- a/cpp/src/structs/utilities.hpp +++ b/cpp/src/structs/utilities.hpp @@ -158,8 +158,8 @@ std::tuple> superimpose_paren rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); std::unique_ptr struct_binary_operation( - column_view lhs, - column_view rhs, + column_view const& lhs, + column_view const& rhs, binary_operator op, data_type output_type, rmm::cuda_stream_view stream = rmm::cuda_stream_default, diff --git a/cpp/tests/structs/utilities_tests.cpp b/cpp/tests/structs/utilities_tests.cpp index 024e7f0d3ce..1a0a4540a05 100644 --- a/cpp/tests/structs/utilities_tests.cpp +++ b/cpp/tests/structs/utilities_tests.cpp @@ -512,41 +512,240 @@ template struct TypedBinopStructCompare : StructUtilitiesTest { }; -TYPED_TEST_SUITE(TypedBinopStructCompare, int32_t); -TYPED_TEST(TypedBinopStructCompare, binopcompare) +TYPED_TEST_SUITE(TypedBinopStructCompare, cudf::test::NumericTypes); +TYPED_TEST(TypedBinopStructCompare, binopcompare_out_type) { - // Test with a sliced STRUCT column. - // Ensure that superimpose_parent_nulls() produces the right results, even when the input is - // sliced. + using T = TypeParam; + + auto col1 = fixed_width_column_wrapper{26, 0, 14, 116, 89, 62, 63, 0, 121}; + auto col2 = fixed_width_column_wrapper{117, 34, 23, 29, 2, 37, 63, 0, 121}; + + auto strings1 = strings_column_wrapper{"0a", "1c", "2d", "3b", "5c", "6", "7d", "9g", "0h"}; + auto strings2 = strings_column_wrapper{"0b", "0c", "2d", "3a", "4c", "6", "8e", "9f", "0h"}; + + std::vector> lhs_columns; + lhs_columns.push_back(col1.release()); + lhs_columns.push_back(strings1.release()); + auto lhs_col = cudf::make_structs_column(9, std::move(lhs_columns), 0, rmm::device_buffer{}); + std::vector> rhs_columns; + rhs_columns.push_back(col2.release()); + rhs_columns.push_back(strings2.release()); + auto rhs_col = cudf::make_structs_column(9, std::move(rhs_columns), 0, rmm::device_buffer{}); + + auto lhs = lhs_col->view(); + auto rhs = rhs_col->view(); + auto dt = cudf::data_type(cudf::type_to_id()); + + auto res_eq = + cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::EQUAL, dt); + auto res_neq = + cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); + auto res_lt = cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::LESS, dt); + auto res_gteq = + cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::GREATER_EQUAL, dt); + auto res_gt = + cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::GREATER, dt); + auto res_lteq = + cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::LESS_EQUAL, dt); + + auto expected_eq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 1}; + auto expected_neq = fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 0}; + auto expected_lt = fixed_width_column_wrapper{1, 1, 1, 0, 0, 0, 1, 0, 0}; + auto expected_gteq = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 1}; + auto expected_gt = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 0}; + auto expected_lteq = fixed_width_column_wrapper{1, 1, 1, 0, 0, 0, 1, 0, 1}; + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); +} +TYPED_TEST(TypedBinopStructCompare, binopcompare_with_nulls) +{ + using T = TypeParam; + + auto col1 = fixed_width_column_wrapper{ + {26, 0, 14, 116, 89, 62, 63, 0, 121, 26, 0, 14, 116, 89, 62, 63, 0, 121, 1, 1, 1}, + {0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1}}; + auto col2 = fixed_width_column_wrapper{ + {117, 34, 23, 29, 2, 37, 63, 0, 121, 117, 34, 23, 29, 2, 37, 63, 0, 121, 1, 1, 1}, + {1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1}}; + + auto strings1 = + strings_column_wrapper{{"0b", "", "1c", "2a", "", "5d", "6e", "8f", "", "0a", "1c", + "2d", "3b", "5c", "6", "7d", "9g", "0h", "1f", "2g", "3h"}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1}}; + auto strings2 = + strings_column_wrapper{{"0a", "", "1d", "2a", "3c", "4", "7d", "9", "", "0b", "0c", + "2d", "3a", "4c", "6", "8e", "9f", "0h", "1f", "2g", "3h"}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1}}; + + std::vector> lhs_columns; + lhs_columns.push_back(col1.release()); + lhs_columns.push_back(strings1.release()); + auto lhs_col = cudf::make_structs_column(21, std::move(lhs_columns), 0, rmm::device_buffer{}); + auto const lhs_nulls = thrust::host_vector( + std::vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}); + lhs_col->set_null_mask(cudf::test::detail::make_null_mask(lhs_nulls.begin(), lhs_nulls.end())); + + std::vector> rhs_columns; + rhs_columns.push_back(col2.release()); + rhs_columns.push_back(strings2.release()); + auto rhs_col = cudf::make_structs_column(21, std::move(rhs_columns), 0, rmm::device_buffer{}); + auto const rhs_nulls = thrust::host_vector( + std::vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}); + rhs_col->set_null_mask(cudf::test::detail::make_null_mask(rhs_nulls.begin(), rhs_nulls.end())); + + auto lhs = lhs_col->view(); + auto rhs = rhs_col->view(); + data_type dt = cudf::data_type(cudf::type_id::BOOL8); + + auto res_eq = + cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::EQUAL, dt); + auto res_neq = + cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); + auto res_lt = cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::LESS, dt); + auto res_gteq = + cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::GREATER_EQUAL, dt); + auto res_gt = + cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::GREATER, dt); + auto res_lteq = + cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::LESS_EQUAL, dt); + + // c1 vs c2 lt, gt, eq, lt, gt, eq, lt, gt, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq + // s1 vs s2 gt, eq, lt, eq, lt, gt, lt, gt, eq, gt, lt, eq, gt, lt, eq, gt, lt, eq, eq, eq, eq + // lt, gt, lt, lt, gt, gt, lt, gt, eq, gt, lt, eq, gt, lt, eq, gt, lt, eq, nu, nu, nu + + auto expected_eq = fixed_width_column_wrapper{ + {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + auto expected_neq = fixed_width_column_wrapper{ + {1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + auto expected_lt = fixed_width_column_wrapper{ + {1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + auto expected_gteq = fixed_width_column_wrapper{ + {0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + auto expected_gt = fixed_width_column_wrapper{ + {0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + auto expected_lteq = fixed_width_column_wrapper{ + {1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); +} + +TYPED_TEST(TypedBinopStructCompare, binopcompare_nested_structs) +{ using T = TypeParam; - auto col1 = fixed_width_column_wrapper{{0, 0, 7, 7, 7, 5, 4, 4, 4, 9, 9, 9}, null_at(5)}; - auto col2 = fixed_width_column_wrapper{{0, 0, 7, 7, 7, 5, 4, 4, 4, 9, 9, 9}, null_at(5)}; - auto strings1 = strings_column_wrapper{ - {"0a", "0a", "2a", "2a", "3b", "5", "6c", "6c", "6c", "9", "9", "10d"}, null_at(8)}; - auto strings2 = strings_column_wrapper{ - {"0a", "0a", "2a", "2a", "3b", "5", "6c", "6c", "6c", "9", "9", "10d"}, null_at(8)}; - - std::vector> struct_columns; - struct_columns.push_back(col1.release()); - struct_columns.push_back(strings1.release()); - auto struct_col = - cudf::make_structs_column(12, std::move(struct_columns), 0, rmm::device_buffer{}); - auto const struct_nulls = - thrust::host_vector(std::vector{1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0}); - struct_col->set_null_mask( - cudf::test::detail::make_null_mask(struct_nulls.begin(), struct_nulls.end())); - - auto lhs = struct_col->view(); - auto rhs = struct_col->view(); - binary_operator bin_op = binary_operator::EQUAL; - data_type dt = cudf::data_type(cudf::type_id::BOOL8); - // auto res = cudf::structs::detail::struct_binary_operation(struct_col->view(), - // struct_col->view(), binary_operator::EQUAL, cudf::data_type(cudf::type_id::BOOL8)); - auto res = cudf::groupby::detail::struct_binary_operation2(lhs, rhs, bin_op, dt); - // auto res = cudf::structs::detail::struct_binary_operation();//lhs, rhs, bin_op, dt, - // rmm::cuda_stream_default, rmm::mr::get_current_device_resource()); + auto col1 = fixed_width_column_wrapper{ + 104, 40, 105, 1, 86, 128, 25, 47, 39, 117, 125, 92, 101, 59, 69, 48, 36, 50}; + auto col2 = fixed_width_column_wrapper{ + {104, 40, 105, 1, 86, 128, 25, 47, 39, 117, 125, 92, 101, 59, 69, 48, 36, 50}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}; + auto col3 = fixed_width_column_wrapper{ + {26, 0, 14, 116, 89, 62, 63, 0, 121, 26, 0, 14, 116, 89, 62, 63, 0, 121}, + {0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + auto col4 = fixed_width_column_wrapper{ + {117, 34, 23, 29, 2, 37, 63, 0, 121, 117, 34, 23, 29, 2, 37, 63, 0, 121}, + {1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + + auto strings1 = strings_column_wrapper{{"0b", + "", + "1c", + "2a", + "", + "5d", + "6e", + "8f", + "", + "0a", + "1c", + "2d", + "3b", + "5c", + "6", + "7d", + "9g", + "0h"}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0}}; + auto strings2 = strings_column_wrapper{{"0a", + "", + "1d", + "2a", + "3c", + "4", + "7d", + "9", + "", + "0b", + "0c", + "2d", + "3a", + "4c", + "6", + "8e", + "9f", + "0h"}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0}}; + + auto struct_col1 = structs_column_wrapper{col3, strings1}; + auto nested_col1 = structs_column_wrapper{col1, struct_col1}.release(); + auto struct_col2 = structs_column_wrapper{col4, strings2}; + auto nested_col2 = structs_column_wrapper{col2, struct_col2}.release(); + + data_type dt = cudf::data_type(cudf::type_id::BOOL8); + + auto res_eq = cudf::structs::detail::struct_binary_operation( + *nested_col1, *nested_col2, binary_operator::EQUAL, dt); + auto res_neq = cudf::structs::detail::struct_binary_operation( + *nested_col1, *nested_col2, binary_operator::NOT_EQUAL, dt); + auto res_lt = cudf::structs::detail::struct_binary_operation( + *nested_col1, *nested_col2, binary_operator::LESS, dt); + auto res_gteq = cudf::structs::detail::struct_binary_operation( + *nested_col1, *nested_col2, binary_operator::GREATER_EQUAL, dt); + auto res_gt = cudf::structs::detail::struct_binary_operation( + *nested_col1, *nested_col2, binary_operator::GREATER, dt); + auto res_lteq = cudf::structs::detail::struct_binary_operation( + *nested_col1, *nested_col2, binary_operator::LESS_EQUAL, dt); + + auto expected_eq = + fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1}; + auto expected_neq = + fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0}; + auto expected_lt = + fixed_width_column_wrapper{1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0}; + auto expected_gteq = + fixed_width_column_wrapper{0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1}; + auto expected_gt = + fixed_width_column_wrapper{0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0}; + auto expected_lteq = + fixed_width_column_wrapper{1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1}; + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); } } // namespace cudf::test From ce4440c56da2272e3ef523ebb9cdc25ac1ebb314 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Fri, 15 Oct 2021 17:53:44 -0700 Subject: [PATCH 03/54] cleanup and simplify core code --- cpp/src/structs/utilities.cpp | 19 +- cpp/src/structs/utilities.cu | 287 +++++++++++--------------- cpp/src/structs/utilities.cuh | 210 ------------------- cpp/src/structs/utilities.hpp | 37 +++- cpp/tests/structs/utilities_tests.cpp | 46 ++--- 5 files changed, 183 insertions(+), 416 deletions(-) delete mode 100644 cpp/src/structs/utilities.cuh diff --git a/cpp/src/structs/utilities.cpp b/cpp/src/structs/utilities.cpp index f32c01c3ece..74d7132d81a 100644 --- a/cpp/src/structs/utilities.cpp +++ b/cpp/src/structs/utilities.cpp @@ -416,18 +416,13 @@ std::tuple> superimpose_paren std::move(ret_validity_buffers)); } -// std::unique_ptr struct_lexicographic_compare(column_view lhs, column_view rhs, data_type -// output_type, binary_operator op, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* -// mr) { - -// auto out = cudf::detail::make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, -// mr); - -// // superimpose -// // flatten - -// return out; -// } +bool contains_struct_nulls(column_view const& struct_col) +{ + return (struct_col.type().id() == type_id::STRUCT && struct_col.has_nulls()) || + std::all_of(struct_col.child_begin(), struct_col.child_end(), [](auto const& child) { + return contains_struct_nulls(child); + }); +} } // namespace detail } // namespace structs diff --git a/cpp/src/structs/utilities.cu b/cpp/src/structs/utilities.cu index 16af72bb271..0cc51ebfecf 100644 --- a/cpp/src/structs/utilities.cu +++ b/cpp/src/structs/utilities.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, NVIDIA CORPORATION. + * Copyright (c) 2021, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,146 +14,73 @@ * limitations under the License. */ +#include +#include #include +#include #include +#include +#include +#include +#include -#include #include + #include -#include "cudf/binaryop.hpp" -#include "cudf/column/column_device_view.cuh" -#include "cudf/table/table_device_view.cuh" -#include "cudf/table/table_view.hpp" -#include "cudf/types.hpp" -#include "cudf/utilities/traits.hpp" -#include "cudf/utilities/type_dispatcher.hpp" -#include "thrust/logical.h" namespace cudf { namespace structs { namespace detail { -struct StructCompFunctor { - template - void equality_row(table_device_view lhs, - table_device_view rhs, - mutable_column_view out, - rmm::cuda_stream_view stream) - { - row_equality_comparator comparator(lhs, rhs, true); - auto d_out = mutable_column_device_view::create(out); - - thrust::tabulate(rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator, d_out = *d_out] __device__(size_type row_index) { - return d_out.is_valid(row_index) && comparator(row_index, row_index); - }); - } - - template - void nequal_row(table_device_view lhs, - table_device_view rhs, - mutable_column_view out, - rmm::cuda_stream_view stream) - { - row_equality_comparator comparator(lhs, rhs, true); - auto d_out = mutable_column_device_view::create(out); - - thrust::tabulate(rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator, d_out = *d_out] __device__(size_type row_index) { - return d_out.is_valid(row_index) && !comparator(row_index, row_index); - }); - } - - template - void lt_row(table_device_view lhs, - table_device_view rhs, - mutable_column_view out, - rmm::cuda_stream_view stream) - { - row_lexicographic_comparator comparator(lhs, rhs, nullptr, nullptr); - auto d_out = mutable_column_device_view::create(out); - - thrust::tabulate(rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator, d_out = *d_out] __device__(size_type row_index) { - return d_out.is_valid(row_index) && comparator(row_index, row_index); - }); - } - - template - void gte_row(table_device_view lhs, - table_device_view rhs, - mutable_column_view out, - rmm::cuda_stream_view stream) +template +struct StructComparatorFunctor { + template + void negate_result(mutable_column_view out, compare_op comparator, rmm::cuda_stream_view stream) { - row_lexicographic_comparator comparator(lhs, rhs, nullptr, nullptr); - auto d_out = mutable_column_device_view::create(out); - - thrust::tabulate(rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator, d_out = *d_out] __device__(size_type row_index) { - return d_out.is_valid(row_index) && !comparator(row_index, row_index); - }); + if (out.has_nulls()) { + auto d_out = mutable_column_device_view::create(out); + thrust::tabulate(rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator, d_out = *d_out] __device__(size_type row_index) { + return d_out.is_valid_nocheck(row_index) && + !comparator(row_index, row_index); + }); + } else { + thrust::tabulate( + rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator] __device__(size_type row_index) { return !comparator(row_index, row_index); }); + } } - template - void gt_row(table_device_view lhs, - table_device_view rhs, - mutable_column_view out, - rmm::cuda_stream_view stream) + template + void direct_result(mutable_column_view out, compare_op comparator, rmm::cuda_stream_view stream) { - std::vector op_modifier{}; - std::vector norder{}; - std::for_each(thrust::counting_iterator(0), - thrust::counting_iterator(lhs.num_columns()), - [&](auto child_ind) { - op_modifier.push_back(order::DESCENDING); - norder.push_back(null_order::BEFORE); - }); - - auto const op_modifier_dv = cudf::detail::make_device_uvector_async(op_modifier, stream); - auto comparator = row_lexicographic_comparator(lhs, rhs, op_modifier_dv.data()); - auto d_out = mutable_column_device_view::create(out); - - thrust::tabulate(rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator, d_out = *d_out] __device__(size_type row_index) { - return d_out.is_valid(row_index) && comparator(row_index, row_index); - }); + if (out.has_nulls()) { + auto d_out = mutable_column_device_view::create(out); + thrust::tabulate(rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator, d_out = *d_out] __device__(size_type row_index) { + return d_out.is_valid_nocheck(row_index) && + comparator(row_index, row_index); + }); + } else { + thrust::tabulate( + rmm::exec_policy(stream), + out.begin(), + out.end(), + [comparator] __device__(size_type row_index) { return comparator(row_index, row_index); }); + } } - template - void lte_row(table_device_view lhs, - table_device_view rhs, - mutable_column_view out, - rmm::cuda_stream_view stream) + rmm::device_uvector get_descending_orders(uint32_t const num_columns, + rmm::cuda_stream_view stream) { - std::vector op_modifier{}; - std::vector norder{}; - std::for_each(thrust::counting_iterator(0), - thrust::counting_iterator(lhs.num_columns()), - [&](auto child_ind) { - op_modifier.push_back(order::DESCENDING); - norder.push_back(null_order::BEFORE); - }); - - auto const op_modifier_dv = cudf::detail::make_device_uvector_async(op_modifier, stream); - auto comparator = row_lexicographic_comparator(lhs, rhs, op_modifier_dv.data()); - auto d_out = mutable_column_device_view::create(out); - - thrust::tabulate(rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator, d_out = *d_out] __device__(size_type row_index) { - return d_out.is_valid(row_index) && !comparator(row_index, row_index); - }); + std::vector op_modifier(num_columns, order::DESCENDING); + return cudf::detail::make_device_uvector_async(op_modifier, stream); } template ()>* = nullptr> @@ -163,33 +90,42 @@ struct StructCompFunctor { binary_operator op, rmm::cuda_stream_view stream) { - bool const has_nulls = has_nested_nulls(lhs) || has_nested_nulls(rhs); - auto d_lhs = table_device_view::create(lhs); auto d_rhs = table_device_view::create(rhs); - if (has_nulls) { - switch (op) { - case binary_operator::EQUAL: equality_row(*d_lhs, *d_rhs, out, stream); break; - case binary_operator::NOT_EQUAL: nequal_row(*d_lhs, *d_rhs, out, stream); break; - case binary_operator::LESS: lt_row(*d_lhs, *d_rhs, out, stream); break; - case binary_operator::GREATER: gt_row(*d_lhs, *d_rhs, out, stream); break; - case binary_operator::LESS_EQUAL: lte_row(*d_lhs, *d_rhs, out, stream); break; - case binary_operator::GREATER_EQUAL: gte_row(*d_lhs, *d_rhs, out, stream); break; - // case binary_operator::NULL_EQUALS: break; - default: CUDF_FAIL("Unsupported operator for these types"); - } - } else { - switch (op) { - case binary_operator::EQUAL: equality_row(*d_lhs, *d_rhs, out, stream); break; - case binary_operator::NOT_EQUAL: nequal_row(*d_lhs, *d_rhs, out, stream); break; - case binary_operator::LESS: lt_row(*d_lhs, *d_rhs, out, stream); break; - case binary_operator::GREATER: gt_row(*d_lhs, *d_rhs, out, stream); break; - case binary_operator::LESS_EQUAL: lte_row(*d_lhs, *d_rhs, out, stream); break; - case binary_operator::GREATER_EQUAL: gte_row(*d_lhs, *d_rhs, out, stream); break; - // case binary_operator::NULL_EQUALS: break; - default: CUDF_FAIL("Unsupported operator for these types"); - } + switch (op) { + case binary_operator::EQUAL: + direct_result>( + out, row_equality_comparator{*d_lhs, *d_rhs, true}, stream); + break; + case binary_operator::NOT_EQUAL: + negate_result>( + out, row_equality_comparator{*d_lhs, *d_rhs, true}, stream); + break; + case binary_operator::LESS: + direct_result>( + out, row_lexicographic_comparator{*d_lhs, *d_rhs}, stream); + break; + case binary_operator::GREATER: + direct_result>( + out, + row_lexicographic_comparator{ + *d_lhs, *d_rhs, get_descending_orders(lhs.num_columns(), stream).data()}, + stream); + break; + case binary_operator::LESS_EQUAL: + negate_result>( + out, + row_lexicographic_comparator{ + *d_lhs, *d_rhs, get_descending_orders(lhs.num_columns(), stream).data()}, + stream); + break; + case binary_operator::GREATER_EQUAL: + negate_result>( + out, row_lexicographic_comparator{*d_lhs, *d_rhs}, stream); + break; + // case binary_operator::NULL_EQUALS: break; + default: CUDF_FAIL("Unsupported operator for these types"); } } @@ -204,30 +140,49 @@ struct StructCompFunctor { } }; -std::unique_ptr struct_binary_operation(column_view const& lhs, - column_view const& rhs, - binary_operator op, - data_type output_type, - rmm::cuda_stream_view stream, - rmm::mr::device_memory_resource* mr) +std::unique_ptr struct_binary_op(column_view const& lhs, + column_view const& rhs, + binary_operator op, + data_type output_type, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) +{ + auto out = make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, mr); + auto out_view = out->mutable_view(); + struct_binary_operation(out_view, lhs, rhs, op, stream); + return out; +} + +void struct_binary_operation(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + binary_operator op, + rmm::cuda_stream_view stream) { + bool const has_struct_nulls = contains_struct_nulls(lhs) || contains_struct_nulls(rhs); auto const lhs_superimposed = superimpose_parent_nulls(lhs); + auto const rhs_superimposed = superimpose_parent_nulls(rhs); auto const lhs_flattener = flatten_nested_columns( - table_view{{std::get<0>(lhs_superimposed)}}, {}, {}, column_nullability::MATCH_INCOMING); - table_view lhs_flat = std::get<0>(lhs_flattener); + table_view{{std::get<0>(lhs_superimposed)}}, + {}, + {}, + has_struct_nulls ? column_nullability::FORCE : column_nullability::MATCH_INCOMING); + auto const rhs_flattener = flatten_nested_columns( + table_view{{std::get<0>(rhs_superimposed)}}, + {}, + {}, + has_struct_nulls ? column_nullability::FORCE : column_nullability::MATCH_INCOMING); - auto const rhs_superimposed = superimpose_parent_nulls(rhs); - auto const rhs_flattener = flatten_nested_columns( - table_view{{std::get<0>(rhs_superimposed)}}, {}, {}, column_nullability::MATCH_INCOMING); + table_view lhs_flat = std::get<0>(lhs_flattener); table_view rhs_flat = std::get<0>(rhs_flattener); - auto out = - cudf::detail::make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, mr); - auto out_view = out->mutable_view(); - - type_dispatcher(out_view.type(), StructCompFunctor{}, lhs_flat, rhs_flat, out_view, op, stream); - - return out; + if (has_nested_nulls(lhs_flat) || has_nested_nulls(rhs_flat)) { + type_dispatcher( + out.type(), StructComparatorFunctor{}, lhs_flat, rhs_flat, out, op, stream); + } else { + type_dispatcher( + out.type(), StructComparatorFunctor{}, lhs_flat, rhs_flat, out, op, stream); + } } } // namespace detail diff --git a/cpp/src/structs/utilities.cuh b/cpp/src/structs/utilities.cuh deleted file mode 100644 index cc50ed0c201..00000000000 --- a/cpp/src/structs/utilities.cuh +++ /dev/null @@ -1,210 +0,0 @@ -// /* -// * Copyright (c) 2020-2021, 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. -// */ - -// #include -// #include - -// #include -// #include -// #include "cudf/binaryop.hpp" -// #include "cudf/column/column_device_view.cuh" -// #include "cudf/table/table_device_view.cuh" -// #include "cudf/table/table_view.hpp" -// #include "cudf/types.hpp" -// #include "thrust/logical.h" - -// namespace cudf { -// namespace structs { -// namespace detail { - -// template -// void equality_row(table_view lhs, -// table_view rhs, -// mutable_column_view out, -// rmm::cuda_stream_view stream) -// { -// auto d_lhs = table_device_view::create(lhs); -// auto d_rhs = table_device_view::create(rhs); - -// row_equality_comparator comparator(*d_lhs, *d_rhs, true); - -// thrust::tabulate( -// rmm::exec_policy(stream), -// out.begin(), -// out.end(), -// [comparator] __device__(size_type row_index) { return comparator(row_index, row_index); }); -// } - -// template -// void nequal_row(table_view lhs, -// table_view rhs, -// mutable_column_view out, -// rmm::cuda_stream_view stream) -// { -// auto d_lhs = table_device_view::create(lhs); -// auto d_rhs = table_device_view::create(rhs); - -// row_equality_comparator comparator(*d_lhs, *d_rhs, true); - -// thrust::tabulate( -// rmm::exec_policy(stream), -// out.begin(), -// out.end(), -// [comparator] __device__(size_type row_index) { return !comparator(row_index, row_index); }); -// } - -// template -// void and_merge(table_view lhs, -// table_view rhs, -// mutable_column_view out, -// binary_operator op, -// rmm::cuda_stream_view stream) -// { -// std::vector comp_views{}; -// std::vector> child_comparisons{}; -// std::for_each( -// thrust::make_counting_iterator(0), -// thrust::make_counting_iterator(lhs.num_columns()), -// [&](auto child_index) { -// auto res = binary_operation( -// lhs.column(child_index), rhs.column(child_index), op, out.type()); -// comp_views.push_back(res->view()); -// child_comparisons.push_back(std::move(res)); -// }); - -// table_view comp_table{comp_views}; -// auto const d_comp_table = table_device_view::create(comp_table); - -// // merge -// thrust::tabulate(rmm::exec_policy(stream), -// out.begin(), -// out.end(), -// [d_comp_table = *d_comp_table] __device__(size_type row_index) { -// return thrust::all_of(thrust::seq, -// d_comp_table.begin(), -// d_comp_table.end(), -// [row_index] __device__(column_device_view col) { -// return col.data()[row_index]; -// }); -// }); -// } - -// template -// void lt_row(table_view lhs, table_view rhs, mutable_column_view out, rmm::cuda_stream_view -// stream) -// { -// auto d_lhs = table_device_view::create(lhs); -// auto d_rhs = table_device_view::create(rhs); - -// row_lexicographic_comparator comparator(*d_lhs, *d_rhs, nullptr, nullptr); - -// thrust::tabulate( -// rmm::exec_policy(stream), -// out.begin(), -// out.end(), -// [comparator] __device__(size_type row_index) { return comparator(row_index, row_index); }); -// } - -// template -// void gt_row(table_view lhs, table_view rhs, mutable_column_view out, rmm::cuda_stream_view -// stream) -// { -// auto d_lhs = table_device_view::create(lhs); -// auto d_rhs = table_device_view::create(rhs); - -// std::vector op_modifier{}; -// // std::vector norder{}; -// std::for_each(thrust::counting_iterator(0), -// thrust::counting_iterator(lhs.num_columns()), -// [&](auto child_ind) { -// op_modifier.push_back(order::DESCENDING); -// // norder.push_back(null_order::BEFORE); -// }); -// // auto comparator = row_lexicographic_comparator(*d_lhs, *d_rhs, -// op_modifier.data(), norder.data()); auto comparator = -// row_lexicographic_comparator(*d_lhs, *d_rhs, op_modifier.data(), nullptr); - -// comparator(0, 0); -// thrust::tabulate( -// rmm::exec_policy(stream), -// out.begin(), -// out.end(), -// [comparator] __device__(size_type row_index) { return comparator(row_index, row_index);}); -// } - -// template -// std::unique_ptr struct_binary_operation( -// column_view const& lhs, -// column_view const& rhs, -// binary_operator op, -// data_type output_type, -// rmm::cuda_stream_view stream = rmm::cuda_stream_default, -// rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()) -// { -// auto const lhs_superimposed = superimpose_parent_nulls(lhs); -// auto const lhs_flattener = flatten_nested_columns( -// table_view{{std::get<0>(lhs_superimposed)}}, {}, {}, column_nullability::MATCH_INCOMING); -// table_view lhs_flat = std::get<0>(lhs_flattener); -// // auto const d_lhs_flat = table_device_view::create(lhs_flat, stream); - -// auto const rhs_superimposed = superimpose_parent_nulls(rhs); -// auto const rhs_flattener = flatten_nested_columns( -// table_view{{std::get<0>(rhs_superimposed)}}, {}, {}, column_nullability::MATCH_INCOMING); -// table_view rhs_flat = std::get<0>(rhs_flattener); -// // auto const d_rhs_flat = table_device_view::create(rhs_flat, stream); - -// auto out = cudf::detail::make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, -// mr); auto out_view = out->mutable_view(); - -// auto const lhs_has_nulls = has_nested_nulls(lhs_flat); -// auto const rhs_has_nulls = has_nested_nulls(rhs_flat); -// bool const has_nulls = lhs_has_nulls || rhs_has_nulls; - -// if(has_nulls){ -// switch (op) { -// case binary_operator::EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, stream); -// break; case binary_operator::NOT_EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, -// stream); break; case binary_operator::LESS: lt_row(lhs_flat, rhs_flat, out_view, -// stream); break; case binary_operator::GREATER: gt_row(lhs_flat, rhs_flat, -// out_view, stream); break; case binary_operator::LESS_EQUAL: gt_row(rhs_flat, -// lhs_flat, out_view, stream); break; case binary_operator::GREATER_EQUAL: lt_row(rhs_flat, lhs_flat, out_view, stream); break; -// // case binary_operator::NULL_EQUALS: break; -// default: CUDF_FAIL("Unsupported operator for these types"); -// } -// } else { -// switch (op) { -// case binary_operator::EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, stream); -// break; case binary_operator::NOT_EQUAL: and_merge(lhs_flat, rhs_flat, out_view, op, -// stream); break; case binary_operator::LESS: lt_row(lhs_flat, rhs_flat, out_view, -// stream); break; case binary_operator::GREATER: gt_row(lhs_flat, rhs_flat, -// out_view, stream); break; case binary_operator::LESS_EQUAL: gt_row(rhs_flat, -// lhs_flat, out_view, stream); break; case binary_operator::GREATER_EQUAL: lt_row(rhs_flat, lhs_flat, out_view, stream); break; -// // case binary_operator::NULL_EQUALS: break; -// default: CUDF_FAIL("Unsupported operator for these types"); -// } -// } -// return out; -// } - -// } // namespace detail -// } // namespace structs -// } // namespace cudf - -// // binary_op_compare() { -// // type_dispatcher() -// // } diff --git a/cpp/src/structs/utilities.hpp b/cpp/src/structs/utilities.hpp index 8b2cfa19b3b..496b65da539 100644 --- a/cpp/src/structs/utilities.hpp +++ b/cpp/src/structs/utilities.hpp @@ -15,12 +15,12 @@ */ #pragma once +#include #include #include #include #include -#include "cudf/binaryop.hpp" namespace cudf { namespace structs { @@ -157,7 +157,26 @@ std::tuple> superimpose_paren rmm::cuda_stream_view stream = rmm::cuda_stream_default, rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); -std::unique_ptr struct_binary_operation( +/** + * @brief + * + * @param struct_col + * @return true + * @return false + */ +bool contains_struct_nulls(column_view const& struct_col); + +/** + * @brief + * + * @param lhs + * @param rhs + * @param output_type + * @param stream + * @param mr + * @return std::unique_ptr + */ +std::unique_ptr struct_binary_op( column_view const& lhs, column_view const& rhs, binary_operator op, @@ -165,6 +184,20 @@ std::unique_ptr struct_binary_operation( rmm::cuda_stream_view stream = rmm::cuda_stream_default, rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); +/** + * @brief + * + * @param out + * @param lhs + * @param rhs + * @param stream + */ +void struct_binary_operation(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + binary_operator op, + rmm::cuda_stream_view stream); + } // namespace detail } // namespace structs } // namespace cudf diff --git a/cpp/tests/structs/utilities_tests.cpp b/cpp/tests/structs/utilities_tests.cpp index 1a0a4540a05..8c6e328db21 100644 --- a/cpp/tests/structs/utilities_tests.cpp +++ b/cpp/tests/structs/utilities_tests.cpp @@ -536,17 +536,14 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_out_type) auto rhs = rhs_col->view(); auto dt = cudf::data_type(cudf::type_to_id()); - auto res_eq = - cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::EQUAL, dt); - auto res_neq = - cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); - auto res_lt = cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::LESS, dt); + auto res_eq = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::EQUAL, dt); + auto res_neq = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::NOT_EQUAL, dt); + auto res_lt = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::LESS, dt); auto res_gteq = - cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::GREATER_EQUAL, dt); - auto res_gt = - cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::GREATER, dt); + cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::GREATER_EQUAL, dt); + auto res_gt = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::GREATER, dt); auto res_lteq = - cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::LESS_EQUAL, dt); + cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::LESS_EQUAL, dt); auto expected_eq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 1}; auto expected_neq = fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 0}; @@ -605,17 +602,14 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_with_nulls) auto rhs = rhs_col->view(); data_type dt = cudf::data_type(cudf::type_id::BOOL8); - auto res_eq = - cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::EQUAL, dt); - auto res_neq = - cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); - auto res_lt = cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::LESS, dt); + auto res_eq = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::EQUAL, dt); + auto res_neq = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::NOT_EQUAL, dt); + auto res_lt = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::LESS, dt); auto res_gteq = - cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::GREATER_EQUAL, dt); - auto res_gt = - cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::GREATER, dt); + cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::GREATER_EQUAL, dt); + auto res_gt = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::GREATER, dt); auto res_lteq = - cudf::structs::detail::struct_binary_operation(lhs, rhs, binary_operator::LESS_EQUAL, dt); + cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::LESS_EQUAL, dt); // c1 vs c2 lt, gt, eq, lt, gt, eq, lt, gt, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq // s1 vs s2 gt, eq, lt, eq, lt, gt, lt, gt, eq, gt, lt, eq, gt, lt, eq, gt, lt, eq, eq, eq, eq @@ -712,17 +706,17 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_nested_structs) data_type dt = cudf::data_type(cudf::type_id::BOOL8); - auto res_eq = cudf::structs::detail::struct_binary_operation( - *nested_col1, *nested_col2, binary_operator::EQUAL, dt); - auto res_neq = cudf::structs::detail::struct_binary_operation( + auto res_eq = + cudf::structs::detail::struct_binary_op(*nested_col1, *nested_col2, binary_operator::EQUAL, dt); + auto res_neq = cudf::structs::detail::struct_binary_op( *nested_col1, *nested_col2, binary_operator::NOT_EQUAL, dt); - auto res_lt = cudf::structs::detail::struct_binary_operation( - *nested_col1, *nested_col2, binary_operator::LESS, dt); - auto res_gteq = cudf::structs::detail::struct_binary_operation( + auto res_lt = + cudf::structs::detail::struct_binary_op(*nested_col1, *nested_col2, binary_operator::LESS, dt); + auto res_gteq = cudf::structs::detail::struct_binary_op( *nested_col1, *nested_col2, binary_operator::GREATER_EQUAL, dt); - auto res_gt = cudf::structs::detail::struct_binary_operation( + auto res_gt = cudf::structs::detail::struct_binary_op( *nested_col1, *nested_col2, binary_operator::GREATER, dt); - auto res_lteq = cudf::structs::detail::struct_binary_operation( + auto res_lteq = cudf::structs::detail::struct_binary_op( *nested_col1, *nested_col2, binary_operator::LESS_EQUAL, dt); auto expected_eq = From 1472c5ffaea25a4c93f63150c79319484671cc0c Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Tue, 19 Oct 2021 17:30:30 -0700 Subject: [PATCH 04/54] remove type dispatch and other code cleanup --- cpp/src/binaryop/compiled/binary_ops.cu | 40 ++++-- cpp/src/binaryop/compiled/util.cpp | 28 ++++ cpp/src/structs/utilities.cu | 165 ++++++++---------------- cpp/tests/structs/utilities_tests.cpp | 36 +++--- 4 files changed, 128 insertions(+), 141 deletions(-) diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index 7b0139a0082..616296cd2cc 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -26,6 +26,8 @@ #include #include +#include + namespace cudf { namespace binops { namespace compiled { @@ -351,10 +353,14 @@ void binary_operation(mutable_column_view& out, binary_operator op, rmm::cuda_stream_view stream) { - auto lhsd = column_device_view::create(lhs, stream); - auto rhsd = column_device_view::create(rhs, stream); - auto outd = mutable_column_device_view::create(out, stream); - operator_dispatcher(*outd, *lhsd, *rhsd, false, false, op, stream); + if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { + structs::detail::struct_binary_operation(out, lhs, rhs, op, stream); + } else { + auto lhsd = column_device_view::create(lhs, stream); + auto rhsd = column_device_view::create(rhs, stream); + auto outd = mutable_column_device_view::create(out, stream); + operator_dispatcher(*outd, *lhsd, *rhsd, false, false, op, stream); + } } // scalar_vector void binary_operation(mutable_column_view& out, @@ -363,10 +369,15 @@ void binary_operation(mutable_column_view& out, binary_operator op, rmm::cuda_stream_view stream) { - auto [lhsd, aux] = scalar_to_column_device_view(lhs, stream); - auto rhsd = column_device_view::create(rhs, stream); - auto outd = mutable_column_device_view::create(out, stream); - operator_dispatcher(*outd, *lhsd, *rhsd, true, false, op, stream); + if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { + auto lhs_col = make_column_from_scalar(lhs, rhs.size(), stream); + structs::detail::struct_binary_operation(out, lhs_col->view(), rhs, op, stream); + } else { + auto [lhsd, aux] = scalar_to_column_device_view(lhs, stream); + auto rhsd = column_device_view::create(rhs, stream); + auto outd = mutable_column_device_view::create(out, stream); + operator_dispatcher(*outd, *lhsd, *rhsd, true, false, op, stream); + } } // vector_scalar void binary_operation(mutable_column_view& out, @@ -375,10 +386,15 @@ void binary_operation(mutable_column_view& out, binary_operator op, rmm::cuda_stream_view stream) { - auto lhsd = column_device_view::create(lhs, stream); - auto [rhsd, aux] = scalar_to_column_device_view(rhs, stream); - auto outd = mutable_column_device_view::create(out, stream); - operator_dispatcher(*outd, *lhsd, *rhsd, false, true, op, stream); + if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { + auto rhs_col = make_column_from_scalar(rhs, lhs.size(), stream); + structs::detail::struct_binary_operation(out, lhs, rhs_col->view(), op, stream); + } else { + auto lhsd = column_device_view::create(lhs, stream); + auto [rhsd, aux] = scalar_to_column_device_view(rhs, stream); + auto outd = mutable_column_device_view::create(out, stream); + operator_dispatcher(*outd, *lhsd, *rhsd, false, true, op, stream); + } } } // namespace compiled diff --git a/cpp/src/binaryop/compiled/util.cpp b/cpp/src/binaryop/compiled/util.cpp index f89941a3d68..95421f15608 100644 --- a/cpp/src/binaryop/compiled/util.cpp +++ b/cpp/src/binaryop/compiled/util.cpp @@ -18,6 +18,8 @@ #include #include +#include +#include #include #include @@ -181,6 +183,32 @@ std::optional get_common_type(data_type out, data_type lhs, data_type bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_operator op) { + if (lhs.id() == type_id::STRUCT && rhs.id() == type_id::STRUCT) { + return op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL || + op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || + op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL; + } return double_type_dispatcher(lhs, rhs, is_supported_operation_functor{}, out, op); } + +bool is_supported_struct_operation(data_type out, + column_view const& lhs, + column_view const& rhs, + binary_operator op) +{ + if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { + return lhs.num_children() == rhs.num_children() && + (op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL || + op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || + op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL) && + std::all_of(thrust::counting_iterator(0), + thrust::counting_iterator(lhs.num_children()), + [&](size_type i) { + return is_supported_struct_operation(out, lhs.child(i), rhs.child(i), op); + }); + + } else { + return is_supported_operation(out, lhs.type(), rhs.type(), op); + } +} } // namespace cudf::binops::compiled diff --git a/cpp/src/structs/utilities.cu b/cpp/src/structs/utilities.cu index 0cc51ebfecf..126911ba99c 100644 --- a/cpp/src/structs/utilities.cu +++ b/cpp/src/structs/utilities.cu @@ -31,114 +31,38 @@ namespace cudf { namespace structs { namespace detail { +namespace { +rmm::device_uvector get_orders(binary_operator op, + uint32_t const num_columns, + rmm::cuda_stream_view stream) +{ + std::vector op_modifier( + num_columns, + (op == binary_operator::LESS || op == binary_operator::GREATER_EQUAL) ? order::ASCENDING + : order::DESCENDING); + return cudf::detail::make_device_uvector_async(op_modifier, stream); +} -template -struct StructComparatorFunctor { - template - void negate_result(mutable_column_view out, compare_op comparator, rmm::cuda_stream_view stream) - { - if (out.has_nulls()) { - auto d_out = mutable_column_device_view::create(out); - thrust::tabulate(rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator, d_out = *d_out] __device__(size_type row_index) { - return d_out.is_valid_nocheck(row_index) && - !comparator(row_index, row_index); - }); - } else { - thrust::tabulate( - rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator] __device__(size_type row_index) { return !comparator(row_index, row_index); }); - } - } - - template - void direct_result(mutable_column_view out, compare_op comparator, rmm::cuda_stream_view stream) - { - if (out.has_nulls()) { - auto d_out = mutable_column_device_view::create(out); - thrust::tabulate(rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator, d_out = *d_out] __device__(size_type row_index) { - return d_out.is_valid_nocheck(row_index) && - comparator(row_index, row_index); - }); - } else { - thrust::tabulate( - rmm::exec_policy(stream), - out.begin(), - out.end(), - [comparator] __device__(size_type row_index) { return comparator(row_index, row_index); }); - } - } - - rmm::device_uvector get_descending_orders(uint32_t const num_columns, - rmm::cuda_stream_view stream) - { - std::vector op_modifier(num_columns, order::DESCENDING); - return cudf::detail::make_device_uvector_async(op_modifier, stream); - } - - template ()>* = nullptr> - void __host__ operator()(table_view const& lhs, - table_view const& rhs, - mutable_column_view& out, - binary_operator op, - rmm::cuda_stream_view stream) - { - auto d_lhs = table_device_view::create(lhs); - auto d_rhs = table_device_view::create(rhs); +template +void struct_compare_tabulation(mutable_column_view& out, + comparator compare, + binary_operator op, + rmm::cuda_stream_view stream) +{ + auto d_out = mutable_column_device_view::create(out, stream); - switch (op) { - case binary_operator::EQUAL: - direct_result>( - out, row_equality_comparator{*d_lhs, *d_rhs, true}, stream); - break; - case binary_operator::NOT_EQUAL: - negate_result>( - out, row_equality_comparator{*d_lhs, *d_rhs, true}, stream); - break; - case binary_operator::LESS: - direct_result>( - out, row_lexicographic_comparator{*d_lhs, *d_rhs}, stream); - break; - case binary_operator::GREATER: - direct_result>( - out, - row_lexicographic_comparator{ - *d_lhs, *d_rhs, get_descending_orders(lhs.num_columns(), stream).data()}, - stream); - break; - case binary_operator::LESS_EQUAL: - negate_result>( - out, - row_lexicographic_comparator{ - *d_lhs, *d_rhs, get_descending_orders(lhs.num_columns(), stream).data()}, - stream); - break; - case binary_operator::GREATER_EQUAL: - negate_result>( - out, row_lexicographic_comparator{*d_lhs, *d_rhs}, stream); - break; - // case binary_operator::NULL_EQUALS: break; - default: CUDF_FAIL("Unsupported operator for these types"); - } - } + (op == binary_operator::EQUAL || op == binary_operator::LESS || op == binary_operator::GREATER) + ? thrust::tabulate(rmm::exec_policy(stream), + d_out->begin(), + d_out->end(), + [compare] __device__(auto i) { return compare(i, i); }) + : thrust::tabulate(rmm::exec_policy(stream), + d_out->begin(), + d_out->end(), + [compare] __device__(auto i) { return not compare(i, i); }); +} - template ()>* = nullptr> - void __host__ operator()(table_view const& lhs, - table_view const& rhs, - mutable_column_view& out, - binary_operator op, - rmm::cuda_stream_view stream) - { - CUDF_FAIL("unsupported output type"); - } -}; +} // namespace std::unique_ptr struct_binary_op(column_view const& lhs, column_view const& rhs, @@ -150,6 +74,7 @@ std::unique_ptr struct_binary_op(column_view const& lhs, auto out = make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, mr); auto out_view = out->mutable_view(); struct_binary_operation(out_view, lhs, rhs, op, stream); + return out; } @@ -176,12 +101,32 @@ void struct_binary_operation(mutable_column_view& out, table_view lhs_flat = std::get<0>(lhs_flattener); table_view rhs_flat = std::get<0>(rhs_flattener); - if (has_nested_nulls(lhs_flat) || has_nested_nulls(rhs_flat)) { - type_dispatcher( - out.type(), StructComparatorFunctor{}, lhs_flat, rhs_flat, out, op, stream); + auto d_lhs = table_device_view::create(lhs_flat); + auto d_rhs = table_device_view::create(rhs_flat); + bool has_nulls = has_nested_nulls(lhs_flat) || has_nested_nulls(rhs_flat); + + if (op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL) { + if (has_nulls) { + auto equal = row_equality_comparator{*d_lhs, *d_rhs, true}; + struct_compare_tabulation(out, equal, op, stream); + } else { + auto equal = row_equality_comparator{*d_lhs, *d_rhs, true}; + struct_compare_tabulation(out, equal, op, stream); + } + } else if (op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || + op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL) { + if (has_nulls) { + auto compare = row_lexicographic_comparator{ + *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}; + struct_compare_tabulation(out, compare, op, stream); + } else { + auto compare = row_lexicographic_comparator{ + *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}; + struct_compare_tabulation(out, compare, op, stream); + } + // } else if (op == binary_operator::NULL_EQUALS) { } else { - type_dispatcher( - out.type(), StructComparatorFunctor{}, lhs_flat, rhs_flat, out, op, stream); + CUDF_FAIL("Unsupported operator for these types"); } } diff --git a/cpp/tests/structs/utilities_tests.cpp b/cpp/tests/structs/utilities_tests.cpp index 8c6e328db21..77a30dc59b0 100644 --- a/cpp/tests/structs/utilities_tests.cpp +++ b/cpp/tests/structs/utilities_tests.cpp @@ -30,9 +30,9 @@ #include #include #include -#include "cudf/binaryop.hpp" -#include "groupby/sort/group_scan.hpp" +// #include "binary_op/compiled/binary_ops.hpp" +#include namespace cudf::test { /** @@ -512,13 +512,15 @@ template struct TypedBinopStructCompare : StructUtilitiesTest { }; -TYPED_TEST_SUITE(TypedBinopStructCompare, cudf::test::NumericTypes); -TYPED_TEST(TypedBinopStructCompare, binopcompare_out_type) +using NumericTypesNotBool = + cudf::test::Concat; +TYPED_TEST_SUITE(TypedBinopStructCompare, NumericTypesNotBool); +TYPED_TEST(TypedBinopStructCompare, binopcompare_no_nulls) { using T = TypeParam; - auto col1 = fixed_width_column_wrapper{26, 0, 14, 116, 89, 62, 63, 0, 121}; - auto col2 = fixed_width_column_wrapper{117, 34, 23, 29, 2, 37, 63, 0, 121}; + auto col1 = fixed_width_column_wrapper{26, 0, 14, 116, 89, 62, 63, 0, 121}; + auto col2 = fixed_width_column_wrapper{117, 34, 23, 29, 2, 37, 63, 0, 121}; auto strings1 = strings_column_wrapper{"0a", "1c", "2d", "3b", "5c", "6", "7d", "9g", "0h"}; auto strings2 = strings_column_wrapper{"0b", "0c", "2d", "3a", "4c", "6", "8e", "9f", "0h"}; @@ -532,9 +534,9 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_out_type) rhs_columns.push_back(strings2.release()); auto rhs_col = cudf::make_structs_column(9, std::move(rhs_columns), 0, rmm::device_buffer{}); - auto lhs = lhs_col->view(); - auto rhs = rhs_col->view(); - auto dt = cudf::data_type(cudf::type_to_id()); + auto lhs = lhs_col->view(); + auto rhs = rhs_col->view(); + data_type dt = cudf::data_type(type_id::BOOL8); auto res_eq = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::EQUAL, dt); auto res_neq = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::NOT_EQUAL, dt); @@ -545,12 +547,12 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_out_type) auto res_lteq = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::LESS_EQUAL, dt); - auto expected_eq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 1}; - auto expected_neq = fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 0}; - auto expected_lt = fixed_width_column_wrapper{1, 1, 1, 0, 0, 0, 1, 0, 0}; - auto expected_gteq = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 1}; - auto expected_gt = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 0}; - auto expected_lteq = fixed_width_column_wrapper{1, 1, 1, 0, 0, 0, 1, 0, 1}; + auto expected_eq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 1}; + auto expected_neq = fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 0}; + auto expected_lt = fixed_width_column_wrapper{1, 1, 1, 0, 0, 0, 1, 0, 0}; + auto expected_gteq = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 1}; + auto expected_gt = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 0}; + auto expected_lteq = fixed_width_column_wrapper{1, 1, 1, 0, 0, 0, 1, 0, 1}; CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); @@ -611,10 +613,6 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_with_nulls) auto res_lteq = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::LESS_EQUAL, dt); - // c1 vs c2 lt, gt, eq, lt, gt, eq, lt, gt, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq - // s1 vs s2 gt, eq, lt, eq, lt, gt, lt, gt, eq, gt, lt, eq, gt, lt, eq, gt, lt, eq, eq, eq, eq - // lt, gt, lt, lt, gt, gt, lt, gt, eq, gt, lt, eq, gt, lt, eq, gt, lt, eq, nu, nu, nu - auto expected_eq = fixed_width_column_wrapper{ {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; From 4a31fb62df2635c9a4f9d3fa1629b7fc9c0fa027 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Wed, 20 Oct 2021 00:30:01 -0700 Subject: [PATCH 05/54] move struct comparison to compiled binops code --- cpp/CMakeLists.txt | 1 - cpp/src/binaryop/compiled/binary_ops.cu | 109 +++++++++- cpp/src/binaryop/compiled/binary_ops.hpp | 32 +++ cpp/src/structs/utilities.cpp | 1 - cpp/src/structs/utilities.cu | 135 ------------ cpp/src/structs/utilities.hpp | 32 --- cpp/tests/CMakeLists.txt | 1 + cpp/tests/binaryop/binop-struct-test.cpp | 259 +++++++++++++++++++++++ cpp/tests/structs/utilities_tests.cpp | 236 --------------------- 9 files changed, 398 insertions(+), 408 deletions(-) delete mode 100644 cpp/src/structs/utilities.cu create mode 100644 cpp/tests/binaryop/binop-struct-test.cpp diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 066e4fb115d..079db9d144b 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -415,7 +415,6 @@ add_library(cudf src/structs/structs_column_factories.cu src/structs/structs_column_view.cpp src/structs/utilities.cpp - src/structs/utilities.cu src/table/table.cpp src/table/table_device_view.cu src/table/table_view.cpp diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index 616296cd2cc..cad13ebae46 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -19,8 +19,12 @@ #include #include +#include #include #include +#include +#include +#include #include #include @@ -241,8 +245,107 @@ struct null_considering_binop { } }; +rmm::device_uvector get_orders(binary_operator op, + uint32_t const num_columns, + rmm::cuda_stream_view stream) +{ + std::vector op_modifier( + num_columns, + (op == binary_operator::LESS || op == binary_operator::GREATER_EQUAL) ? order::ASCENDING + : order::DESCENDING); + return cudf::detail::make_device_uvector_async(op_modifier, stream); +} + +template +void struct_compare_tabulation(mutable_column_view& out, + comparator compare, + binary_operator op, + rmm::cuda_stream_view stream) +{ + auto d_out = mutable_column_device_view::create(out, stream); + + (op == binary_operator::EQUAL || op == binary_operator::LESS || op == binary_operator::GREATER) + ? thrust::tabulate(rmm::exec_policy(stream), + d_out->begin(), + d_out->end(), + [compare] __device__(auto i) { return compare(i, i); }) + : thrust::tabulate(rmm::exec_policy(stream), + d_out->begin(), + d_out->end(), + [compare] __device__(auto i) { return not compare(i, i); }); +} + } // namespace +std::unique_ptr struct_binary_op(column_view const& lhs, + column_view const& rhs, + binary_operator op, + data_type output_type, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) +{ + auto out = make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, mr); + auto out_view = out->mutable_view(); + struct_binary_operation(out_view, lhs, rhs, op, stream); + + return out; +} + +void struct_binary_operation(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + binary_operator op, + rmm::cuda_stream_view stream) +{ + bool const has_struct_nulls = + structs::detail::contains_struct_nulls(lhs) || structs::detail::contains_struct_nulls(rhs); + auto const lhs_superimposed = structs::detail::superimpose_parent_nulls(lhs); + auto const rhs_superimposed = structs::detail::superimpose_parent_nulls(rhs); + auto const lhs_flattener = structs::detail::flatten_nested_columns( + table_view{{std::get<0>(lhs_superimposed)}}, + {}, + {}, + has_struct_nulls ? structs::detail::column_nullability::FORCE + : structs::detail::column_nullability::MATCH_INCOMING); + auto const rhs_flattener = structs::detail::flatten_nested_columns( + table_view{{std::get<0>(rhs_superimposed)}}, + {}, + {}, + has_struct_nulls ? structs::detail::column_nullability::FORCE + : structs::detail::column_nullability::MATCH_INCOMING); + + table_view lhs_flat = std::get<0>(lhs_flattener); + table_view rhs_flat = std::get<0>(rhs_flattener); + + auto d_lhs = table_device_view::create(lhs_flat); + auto d_rhs = table_device_view::create(rhs_flat); + bool has_nulls = has_nested_nulls(lhs_flat) || has_nested_nulls(rhs_flat); + + if (op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL) { + if (has_nulls) { + auto equal = row_equality_comparator{*d_lhs, *d_rhs, true}; + struct_compare_tabulation(out, equal, op, stream); + } else { + auto equal = row_equality_comparator{*d_lhs, *d_rhs, true}; + struct_compare_tabulation(out, equal, op, stream); + } + } else if (op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || + op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL) { + if (has_nulls) { + auto compare = row_lexicographic_comparator{ + *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}; + struct_compare_tabulation(out, compare, op, stream); + } else { + auto compare = row_lexicographic_comparator{ + *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}; + struct_compare_tabulation(out, compare, op, stream); + } + // } else if (op == binary_operator::NULL_EQUALS) { + } else { + CUDF_FAIL("Unsupported operator for these types"); + } +} + std::unique_ptr string_null_min_max(scalar const& lhs, column_view const& rhs, binary_operator op, @@ -354,7 +457,7 @@ void binary_operation(mutable_column_view& out, rmm::cuda_stream_view stream) { if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { - structs::detail::struct_binary_operation(out, lhs, rhs, op, stream); + struct_binary_operation(out, lhs, rhs, op, stream); } else { auto lhsd = column_device_view::create(lhs, stream); auto rhsd = column_device_view::create(rhs, stream); @@ -371,7 +474,7 @@ void binary_operation(mutable_column_view& out, { if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { auto lhs_col = make_column_from_scalar(lhs, rhs.size(), stream); - structs::detail::struct_binary_operation(out, lhs_col->view(), rhs, op, stream); + struct_binary_operation(out, lhs_col->view(), rhs, op, stream); } else { auto [lhsd, aux] = scalar_to_column_device_view(lhs, stream); auto rhsd = column_device_view::create(rhs, stream); @@ -388,7 +491,7 @@ void binary_operation(mutable_column_view& out, { if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { auto rhs_col = make_column_from_scalar(rhs, lhs.size(), stream); - structs::detail::struct_binary_operation(out, lhs, rhs_col->view(), op, stream); + struct_binary_operation(out, lhs, rhs_col->view(), op, stream); } else { auto lhsd = column_device_view::create(lhs, stream); auto [rhsd, aux] = scalar_to_column_device_view(rhs, stream); diff --git a/cpp/src/binaryop/compiled/binary_ops.hpp b/cpp/src/binaryop/compiled/binary_ops.hpp index cf3a6025847..517f4bad755 100644 --- a/cpp/src/binaryop/compiled/binary_ops.hpp +++ b/cpp/src/binaryop/compiled/binary_ops.hpp @@ -215,6 +215,38 @@ void dispatch_equality_op(mutable_column_device_view& outd, bool is_rhs_scalar, binary_operator op, rmm::cuda_stream_view stream); + +/** + * @brief + * + * @param lhs + * @param rhs + * @param output_type + * @param stream + * @param mr + * @return std::unique_ptr + */ +std::unique_ptr struct_binary_op( + column_view const& lhs, + column_view const& rhs, + binary_operator op, + data_type output_type, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @brief binary op functionality for structs, limited to comparison binops + * + * @param out + * @param lhs + * @param rhs + * @param stream + */ +void struct_binary_operation(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + binary_operator op, + rmm::cuda_stream_view stream); } // namespace compiled } // namespace binops } // namespace cudf diff --git a/cpp/src/structs/utilities.cpp b/cpp/src/structs/utilities.cpp index 74d7132d81a..67b0cbc92d3 100644 --- a/cpp/src/structs/utilities.cpp +++ b/cpp/src/structs/utilities.cpp @@ -29,7 +29,6 @@ #include #include -#include "cudf/binaryop.hpp" namespace cudf { namespace structs { diff --git a/cpp/src/structs/utilities.cu b/cpp/src/structs/utilities.cu deleted file mode 100644 index 126911ba99c..00000000000 --- a/cpp/src/structs/utilities.cu +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2021, 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. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -namespace cudf { -namespace structs { -namespace detail { -namespace { -rmm::device_uvector get_orders(binary_operator op, - uint32_t const num_columns, - rmm::cuda_stream_view stream) -{ - std::vector op_modifier( - num_columns, - (op == binary_operator::LESS || op == binary_operator::GREATER_EQUAL) ? order::ASCENDING - : order::DESCENDING); - return cudf::detail::make_device_uvector_async(op_modifier, stream); -} - -template -void struct_compare_tabulation(mutable_column_view& out, - comparator compare, - binary_operator op, - rmm::cuda_stream_view stream) -{ - auto d_out = mutable_column_device_view::create(out, stream); - - (op == binary_operator::EQUAL || op == binary_operator::LESS || op == binary_operator::GREATER) - ? thrust::tabulate(rmm::exec_policy(stream), - d_out->begin(), - d_out->end(), - [compare] __device__(auto i) { return compare(i, i); }) - : thrust::tabulate(rmm::exec_policy(stream), - d_out->begin(), - d_out->end(), - [compare] __device__(auto i) { return not compare(i, i); }); -} - -} // namespace - -std::unique_ptr struct_binary_op(column_view const& lhs, - column_view const& rhs, - binary_operator op, - data_type output_type, - rmm::cuda_stream_view stream, - rmm::mr::device_memory_resource* mr) -{ - auto out = make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, mr); - auto out_view = out->mutable_view(); - struct_binary_operation(out_view, lhs, rhs, op, stream); - - return out; -} - -void struct_binary_operation(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - binary_operator op, - rmm::cuda_stream_view stream) -{ - bool const has_struct_nulls = contains_struct_nulls(lhs) || contains_struct_nulls(rhs); - auto const lhs_superimposed = superimpose_parent_nulls(lhs); - auto const rhs_superimposed = superimpose_parent_nulls(rhs); - auto const lhs_flattener = flatten_nested_columns( - table_view{{std::get<0>(lhs_superimposed)}}, - {}, - {}, - has_struct_nulls ? column_nullability::FORCE : column_nullability::MATCH_INCOMING); - auto const rhs_flattener = flatten_nested_columns( - table_view{{std::get<0>(rhs_superimposed)}}, - {}, - {}, - has_struct_nulls ? column_nullability::FORCE : column_nullability::MATCH_INCOMING); - - table_view lhs_flat = std::get<0>(lhs_flattener); - table_view rhs_flat = std::get<0>(rhs_flattener); - - auto d_lhs = table_device_view::create(lhs_flat); - auto d_rhs = table_device_view::create(rhs_flat); - bool has_nulls = has_nested_nulls(lhs_flat) || has_nested_nulls(rhs_flat); - - if (op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL) { - if (has_nulls) { - auto equal = row_equality_comparator{*d_lhs, *d_rhs, true}; - struct_compare_tabulation(out, equal, op, stream); - } else { - auto equal = row_equality_comparator{*d_lhs, *d_rhs, true}; - struct_compare_tabulation(out, equal, op, stream); - } - } else if (op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || - op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL) { - if (has_nulls) { - auto compare = row_lexicographic_comparator{ - *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}; - struct_compare_tabulation(out, compare, op, stream); - } else { - auto compare = row_lexicographic_comparator{ - *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}; - struct_compare_tabulation(out, compare, op, stream); - } - // } else if (op == binary_operator::NULL_EQUALS) { - } else { - CUDF_FAIL("Unsupported operator for these types"); - } -} - -} // namespace detail -} // namespace structs -} // namespace cudf diff --git a/cpp/src/structs/utilities.hpp b/cpp/src/structs/utilities.hpp index 496b65da539..f41555221b2 100644 --- a/cpp/src/structs/utilities.hpp +++ b/cpp/src/structs/utilities.hpp @@ -166,38 +166,6 @@ std::tuple> superimpose_paren */ bool contains_struct_nulls(column_view const& struct_col); -/** - * @brief - * - * @param lhs - * @param rhs - * @param output_type - * @param stream - * @param mr - * @return std::unique_ptr - */ -std::unique_ptr struct_binary_op( - column_view const& lhs, - column_view const& rhs, - binary_operator op, - data_type output_type, - rmm::cuda_stream_view stream = rmm::cuda_stream_default, - rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); - -/** - * @brief - * - * @param out - * @param lhs - * @param rhs - * @param stream - */ -void struct_binary_operation(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - binary_operator op, - rmm::cuda_stream_view stream); - } // namespace detail } // namespace structs } // namespace cudf diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index d9553d463ab..a849e2ada44 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -169,6 +169,7 @@ ConfigureTest(BINARY_TEST binaryop/binop-compiled-test.cpp binaryop/binop-compiled-fixed_point-test.cpp binaryop/binop-generic-ptx-test.cpp + binaryop/binop-struct-test.cpp ) ################################################################################################### diff --git a/cpp/tests/binaryop/binop-struct-test.cpp b/cpp/tests/binaryop/binop-struct-test.cpp new file mode 100644 index 00000000000..f181d995e78 --- /dev/null +++ b/cpp/tests/binaryop/binop-struct-test.cpp @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2021, 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. + */ + +#include + +#include +#include +#include +#include + +#include + +namespace cudf::test { +template +struct TypedBinopStructCompare : BaseFixture { +}; + +using NumericTypesNotBool = + cudf::test::Concat; +TYPED_TEST_SUITE(TypedBinopStructCompare, NumericTypesNotBool); +TYPED_TEST(TypedBinopStructCompare, binopcompare_no_nulls) +{ + using T = TypeParam; + + auto col1 = fixed_width_column_wrapper{26, 0, 14, 116, 89, 62, 63, 0, 121}; + auto col2 = fixed_width_column_wrapper{117, 34, 23, 29, 2, 37, 63, 0, 121}; + + auto strings1 = strings_column_wrapper{"0a", "1c", "2d", "3b", "5c", "6", "7d", "9g", "0h"}; + auto strings2 = strings_column_wrapper{"0b", "0c", "2d", "3a", "4c", "6", "8e", "9f", "0h"}; + + std::vector> lhs_columns; + lhs_columns.push_back(col1.release()); + lhs_columns.push_back(strings1.release()); + auto lhs_col = cudf::make_structs_column(9, std::move(lhs_columns), 0, rmm::device_buffer{}); + std::vector> rhs_columns; + rhs_columns.push_back(col2.release()); + rhs_columns.push_back(strings2.release()); + auto rhs_col = cudf::make_structs_column(9, std::move(rhs_columns), 0, rmm::device_buffer{}); + + auto lhs = lhs_col->view(); + auto rhs = rhs_col->view(); + data_type dt = cudf::data_type(type_id::BOOL8); + + auto res_eq = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::EQUAL, dt); + auto res_neq = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::NOT_EQUAL, dt); + auto res_lt = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::LESS, dt); + auto res_gteq = + cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::GREATER_EQUAL, dt); + auto res_gt = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::GREATER, dt); + auto res_lteq = + cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::LESS_EQUAL, dt); + + auto expected_eq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 1}; + auto expected_neq = fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 0}; + auto expected_lt = fixed_width_column_wrapper{1, 1, 1, 0, 0, 0, 1, 0, 0}; + auto expected_gteq = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 1}; + auto expected_gt = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 0}; + auto expected_lteq = fixed_width_column_wrapper{1, 1, 1, 0, 0, 0, 1, 0, 1}; + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); +} + +TYPED_TEST(TypedBinopStructCompare, binopcompare_with_nulls) +{ + using T = TypeParam; + + auto col1 = fixed_width_column_wrapper{ + {26, 0, 14, 116, 89, 62, 63, 0, 121, 26, 0, 14, 116, 89, 62, 63, 0, 121, 1, 1, 1}, + {0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1}}; + auto col2 = fixed_width_column_wrapper{ + {117, 34, 23, 29, 2, 37, 63, 0, 121, 117, 34, 23, 29, 2, 37, 63, 0, 121, 1, 1, 1}, + {1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1}}; + + auto strings1 = + strings_column_wrapper{{"0b", "", "1c", "2a", "", "5d", "6e", "8f", "", "0a", "1c", + "2d", "3b", "5c", "6", "7d", "9g", "0h", "1f", "2g", "3h"}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1}}; + auto strings2 = + strings_column_wrapper{{"0a", "", "1d", "2a", "3c", "4", "7d", "9", "", "0b", "0c", + "2d", "3a", "4c", "6", "8e", "9f", "0h", "1f", "2g", "3h"}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1}}; + + std::vector> lhs_columns; + lhs_columns.push_back(col1.release()); + lhs_columns.push_back(strings1.release()); + auto lhs_col = cudf::make_structs_column(21, std::move(lhs_columns), 0, rmm::device_buffer{}); + auto const lhs_nulls = thrust::host_vector( + std::vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}); + lhs_col->set_null_mask(cudf::test::detail::make_null_mask(lhs_nulls.begin(), lhs_nulls.end())); + + std::vector> rhs_columns; + rhs_columns.push_back(col2.release()); + rhs_columns.push_back(strings2.release()); + auto rhs_col = cudf::make_structs_column(21, std::move(rhs_columns), 0, rmm::device_buffer{}); + auto const rhs_nulls = thrust::host_vector( + std::vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}); + rhs_col->set_null_mask(cudf::test::detail::make_null_mask(rhs_nulls.begin(), rhs_nulls.end())); + + auto lhs = lhs_col->view(); + auto rhs = rhs_col->view(); + data_type dt = cudf::data_type(cudf::type_id::BOOL8); + + auto res_eq = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::EQUAL, dt); + auto res_neq = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::NOT_EQUAL, dt); + auto res_lt = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::LESS, dt); + auto res_gteq = + cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::GREATER_EQUAL, dt); + auto res_gt = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::GREATER, dt); + auto res_lteq = + cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::LESS_EQUAL, dt); + + auto expected_eq = fixed_width_column_wrapper{ + {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + auto expected_neq = fixed_width_column_wrapper{ + {1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + auto expected_lt = fixed_width_column_wrapper{ + {1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + auto expected_gteq = fixed_width_column_wrapper{ + {0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + auto expected_gt = fixed_width_column_wrapper{ + {0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + auto expected_lteq = fixed_width_column_wrapper{ + {1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); +} + +TYPED_TEST(TypedBinopStructCompare, binopcompare_nested_structs) +{ + using T = TypeParam; + + auto col1 = fixed_width_column_wrapper{ + 104, 40, 105, 1, 86, 128, 25, 47, 39, 117, 125, 92, 101, 59, 69, 48, 36, 50}; + auto col2 = fixed_width_column_wrapper{ + {104, 40, 105, 1, 86, 128, 25, 47, 39, 117, 125, 92, 101, 59, 69, 48, 36, 50}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}; + auto col3 = fixed_width_column_wrapper{ + {26, 0, 14, 116, 89, 62, 63, 0, 121, 26, 0, 14, 116, 89, 62, 63, 0, 121}, + {0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + auto col4 = fixed_width_column_wrapper{ + {117, 34, 23, 29, 2, 37, 63, 0, 121, 117, 34, 23, 29, 2, 37, 63, 0, 121}, + {1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + + auto strings1 = strings_column_wrapper{{"0b", + "", + "1c", + "2a", + "", + "5d", + "6e", + "8f", + "", + "0a", + "1c", + "2d", + "3b", + "5c", + "6", + "7d", + "9g", + "0h"}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0}}; + auto strings2 = strings_column_wrapper{{"0a", + "", + "1d", + "2a", + "3c", + "4", + "7d", + "9", + "", + "0b", + "0c", + "2d", + "3a", + "4c", + "6", + "8e", + "9f", + "0h"}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0}}; + + auto struct_col1 = structs_column_wrapper{col3, strings1}; + auto nested_col1 = structs_column_wrapper{col1, struct_col1}.release(); + auto struct_col2 = structs_column_wrapper{col4, strings2}; + auto nested_col2 = structs_column_wrapper{col2, struct_col2}.release(); + + data_type dt = cudf::data_type(cudf::type_id::BOOL8); + + auto res_eq = cudf::binops::compiled::struct_binary_op( + *nested_col1, *nested_col2, binary_operator::EQUAL, dt); + auto res_neq = cudf::binops::compiled::struct_binary_op( + *nested_col1, *nested_col2, binary_operator::NOT_EQUAL, dt); + auto res_lt = + cudf::binops::compiled::struct_binary_op(*nested_col1, *nested_col2, binary_operator::LESS, dt); + auto res_gteq = cudf::binops::compiled::struct_binary_op( + *nested_col1, *nested_col2, binary_operator::GREATER_EQUAL, dt); + auto res_gt = cudf::binops::compiled::struct_binary_op( + *nested_col1, *nested_col2, binary_operator::GREATER, dt); + auto res_lteq = cudf::binops::compiled::struct_binary_op( + *nested_col1, *nested_col2, binary_operator::LESS_EQUAL, dt); + + auto expected_eq = + fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1}; + auto expected_neq = + fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0}; + auto expected_lt = + fixed_width_column_wrapper{1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0}; + auto expected_gteq = + fixed_width_column_wrapper{0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1}; + auto expected_gt = + fixed_width_column_wrapper{0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0}; + auto expected_lteq = + fixed_width_column_wrapper{1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1}; + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); +} + +} // namespace cudf::test diff --git a/cpp/tests/structs/utilities_tests.cpp b/cpp/tests/structs/utilities_tests.cpp index 77a30dc59b0..08b40b22aa4 100644 --- a/cpp/tests/structs/utilities_tests.cpp +++ b/cpp/tests/structs/utilities_tests.cpp @@ -16,7 +16,6 @@ #include -#include #include #include #include @@ -29,10 +28,7 @@ #include #include #include -#include -// #include "binary_op/compiled/binary_ops.hpp" -#include namespace cudf::test { /** @@ -508,236 +504,4 @@ TYPED_TEST(TypedSuperimposeTest, NestedStruct_Sliced) CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(output, expected_sliced_structs); } -template -struct TypedBinopStructCompare : StructUtilitiesTest { -}; - -using NumericTypesNotBool = - cudf::test::Concat; -TYPED_TEST_SUITE(TypedBinopStructCompare, NumericTypesNotBool); -TYPED_TEST(TypedBinopStructCompare, binopcompare_no_nulls) -{ - using T = TypeParam; - - auto col1 = fixed_width_column_wrapper{26, 0, 14, 116, 89, 62, 63, 0, 121}; - auto col2 = fixed_width_column_wrapper{117, 34, 23, 29, 2, 37, 63, 0, 121}; - - auto strings1 = strings_column_wrapper{"0a", "1c", "2d", "3b", "5c", "6", "7d", "9g", "0h"}; - auto strings2 = strings_column_wrapper{"0b", "0c", "2d", "3a", "4c", "6", "8e", "9f", "0h"}; - - std::vector> lhs_columns; - lhs_columns.push_back(col1.release()); - lhs_columns.push_back(strings1.release()); - auto lhs_col = cudf::make_structs_column(9, std::move(lhs_columns), 0, rmm::device_buffer{}); - std::vector> rhs_columns; - rhs_columns.push_back(col2.release()); - rhs_columns.push_back(strings2.release()); - auto rhs_col = cudf::make_structs_column(9, std::move(rhs_columns), 0, rmm::device_buffer{}); - - auto lhs = lhs_col->view(); - auto rhs = rhs_col->view(); - data_type dt = cudf::data_type(type_id::BOOL8); - - auto res_eq = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::EQUAL, dt); - auto res_neq = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::NOT_EQUAL, dt); - auto res_lt = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::LESS, dt); - auto res_gteq = - cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::GREATER_EQUAL, dt); - auto res_gt = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::GREATER, dt); - auto res_lteq = - cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::LESS_EQUAL, dt); - - auto expected_eq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 1}; - auto expected_neq = fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 0}; - auto expected_lt = fixed_width_column_wrapper{1, 1, 1, 0, 0, 0, 1, 0, 0}; - auto expected_gteq = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 1}; - auto expected_gt = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 0}; - auto expected_lteq = fixed_width_column_wrapper{1, 1, 1, 0, 0, 0, 1, 0, 1}; - - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); - - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); - - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); -} - -TYPED_TEST(TypedBinopStructCompare, binopcompare_with_nulls) -{ - using T = TypeParam; - - auto col1 = fixed_width_column_wrapper{ - {26, 0, 14, 116, 89, 62, 63, 0, 121, 26, 0, 14, 116, 89, 62, 63, 0, 121, 1, 1, 1}, - {0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1}}; - auto col2 = fixed_width_column_wrapper{ - {117, 34, 23, 29, 2, 37, 63, 0, 121, 117, 34, 23, 29, 2, 37, 63, 0, 121, 1, 1, 1}, - {1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1}}; - - auto strings1 = - strings_column_wrapper{{"0b", "", "1c", "2a", "", "5d", "6e", "8f", "", "0a", "1c", - "2d", "3b", "5c", "6", "7d", "9g", "0h", "1f", "2g", "3h"}, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1}}; - auto strings2 = - strings_column_wrapper{{"0a", "", "1d", "2a", "3c", "4", "7d", "9", "", "0b", "0c", - "2d", "3a", "4c", "6", "8e", "9f", "0h", "1f", "2g", "3h"}, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1}}; - - std::vector> lhs_columns; - lhs_columns.push_back(col1.release()); - lhs_columns.push_back(strings1.release()); - auto lhs_col = cudf::make_structs_column(21, std::move(lhs_columns), 0, rmm::device_buffer{}); - auto const lhs_nulls = thrust::host_vector( - std::vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}); - lhs_col->set_null_mask(cudf::test::detail::make_null_mask(lhs_nulls.begin(), lhs_nulls.end())); - - std::vector> rhs_columns; - rhs_columns.push_back(col2.release()); - rhs_columns.push_back(strings2.release()); - auto rhs_col = cudf::make_structs_column(21, std::move(rhs_columns), 0, rmm::device_buffer{}); - auto const rhs_nulls = thrust::host_vector( - std::vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}); - rhs_col->set_null_mask(cudf::test::detail::make_null_mask(rhs_nulls.begin(), rhs_nulls.end())); - - auto lhs = lhs_col->view(); - auto rhs = rhs_col->view(); - data_type dt = cudf::data_type(cudf::type_id::BOOL8); - - auto res_eq = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::EQUAL, dt); - auto res_neq = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::NOT_EQUAL, dt); - auto res_lt = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::LESS, dt); - auto res_gteq = - cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::GREATER_EQUAL, dt); - auto res_gt = cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::GREATER, dt); - auto res_lteq = - cudf::structs::detail::struct_binary_op(lhs, rhs, binary_operator::LESS_EQUAL, dt); - - auto expected_eq = fixed_width_column_wrapper{ - {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1}, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; - auto expected_neq = fixed_width_column_wrapper{ - {1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0}, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; - auto expected_lt = fixed_width_column_wrapper{ - {1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1}, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; - auto expected_gteq = fixed_width_column_wrapper{ - {0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0}, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; - auto expected_gt = fixed_width_column_wrapper{ - {0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0}, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; - auto expected_lteq = fixed_width_column_wrapper{ - {1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1}, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; - - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); - - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); - - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); -} - -TYPED_TEST(TypedBinopStructCompare, binopcompare_nested_structs) -{ - using T = TypeParam; - - auto col1 = fixed_width_column_wrapper{ - 104, 40, 105, 1, 86, 128, 25, 47, 39, 117, 125, 92, 101, 59, 69, 48, 36, 50}; - auto col2 = fixed_width_column_wrapper{ - {104, 40, 105, 1, 86, 128, 25, 47, 39, 117, 125, 92, 101, 59, 69, 48, 36, 50}, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}; - auto col3 = fixed_width_column_wrapper{ - {26, 0, 14, 116, 89, 62, 63, 0, 121, 26, 0, 14, 116, 89, 62, 63, 0, 121}, - {0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; - auto col4 = fixed_width_column_wrapper{ - {117, 34, 23, 29, 2, 37, 63, 0, 121, 117, 34, 23, 29, 2, 37, 63, 0, 121}, - {1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; - - auto strings1 = strings_column_wrapper{{"0b", - "", - "1c", - "2a", - "", - "5d", - "6e", - "8f", - "", - "0a", - "1c", - "2d", - "3b", - "5c", - "6", - "7d", - "9g", - "0h"}, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0}}; - auto strings2 = strings_column_wrapper{{"0a", - "", - "1d", - "2a", - "3c", - "4", - "7d", - "9", - "", - "0b", - "0c", - "2d", - "3a", - "4c", - "6", - "8e", - "9f", - "0h"}, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0}}; - - auto struct_col1 = structs_column_wrapper{col3, strings1}; - auto nested_col1 = structs_column_wrapper{col1, struct_col1}.release(); - auto struct_col2 = structs_column_wrapper{col4, strings2}; - auto nested_col2 = structs_column_wrapper{col2, struct_col2}.release(); - - data_type dt = cudf::data_type(cudf::type_id::BOOL8); - - auto res_eq = - cudf::structs::detail::struct_binary_op(*nested_col1, *nested_col2, binary_operator::EQUAL, dt); - auto res_neq = cudf::structs::detail::struct_binary_op( - *nested_col1, *nested_col2, binary_operator::NOT_EQUAL, dt); - auto res_lt = - cudf::structs::detail::struct_binary_op(*nested_col1, *nested_col2, binary_operator::LESS, dt); - auto res_gteq = cudf::structs::detail::struct_binary_op( - *nested_col1, *nested_col2, binary_operator::GREATER_EQUAL, dt); - auto res_gt = cudf::structs::detail::struct_binary_op( - *nested_col1, *nested_col2, binary_operator::GREATER, dt); - auto res_lteq = cudf::structs::detail::struct_binary_op( - *nested_col1, *nested_col2, binary_operator::LESS_EQUAL, dt); - - auto expected_eq = - fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1}; - auto expected_neq = - fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0}; - auto expected_lt = - fixed_width_column_wrapper{1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0}; - auto expected_gteq = - fixed_width_column_wrapper{0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1}; - auto expected_gt = - fixed_width_column_wrapper{0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0}; - auto expected_lteq = - fixed_width_column_wrapper{1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1}; - - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); - - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); - - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); -} - } // namespace cudf::test From ce2d727909923ebcaed93d3676c20f7512d91bb7 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Thu, 21 Oct 2021 14:36:46 -0700 Subject: [PATCH 06/54] improved testing, type checks, and skipped null value calculations --- cpp/include/cudf/binaryop.hpp | 11 - cpp/src/binaryop/compiled/binary_ops.cu | 86 ++++--- cpp/src/binaryop/compiled/binary_ops.hpp | 46 ++-- cpp/src/binaryop/compiled/util.cpp | 14 +- cpp/src/structs/utilities.cpp | 6 +- cpp/src/structs/utilities.hpp | 16 +- cpp/tests/binaryop/binop-struct-test.cpp | 274 ++++++++++++++++------- 7 files changed, 271 insertions(+), 182 deletions(-) diff --git a/cpp/include/cudf/binaryop.hpp b/cpp/include/cudf/binaryop.hpp index 1e267be233a..fe548a36cf0 100644 --- a/cpp/include/cudf/binaryop.hpp +++ b/cpp/include/cudf/binaryop.hpp @@ -74,7 +74,6 @@ enum class binary_operator : int32_t { ///< ptx code INVALID_BINARY ///< invalid operation }; - /** * @brief Performs a binary operation between a scalar and a column. * @@ -289,15 +288,5 @@ std::unique_ptr binary_operation( data_type output_type, rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); } // namespace jit -namespace detail { - -std::unique_ptr make_fixed_width_column_for_output( - column_view const& lhs, - column_view const& rhs, - binary_operator op, - data_type output_type, - rmm::cuda_stream_view stream = rmm::cuda_stream_default, - rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); -} // namespace detail /** @} */ // end of group } // namespace cudf diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index cad13ebae46..9dc77c14dd8 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -256,39 +257,26 @@ rmm::device_uvector get_orders(binary_operator op, return cudf::detail::make_device_uvector_async(op_modifier, stream); } -template +template void struct_compare_tabulation(mutable_column_view& out, - comparator compare, + Comparator compare, binary_operator op, + OptionalOutIter optional_iter, rmm::cuda_stream_view stream) { - auto d_out = mutable_column_device_view::create(out, stream); - (op == binary_operator::EQUAL || op == binary_operator::LESS || op == binary_operator::GREATER) ? thrust::tabulate(rmm::exec_policy(stream), - d_out->begin(), - d_out->end(), - [compare] __device__(auto i) { return compare(i, i); }) + out.begin(), + out.end(), + [optional_iter, compare] __device__(size_type i) { + return optional_iter[i].has_value() and compare(i, i); + }) : thrust::tabulate(rmm::exec_policy(stream), - d_out->begin(), - d_out->end(), - [compare] __device__(auto i) { return not compare(i, i); }); -} - -} // namespace - -std::unique_ptr struct_binary_op(column_view const& lhs, - column_view const& rhs, - binary_operator op, - data_type output_type, - rmm::cuda_stream_view stream, - rmm::mr::device_memory_resource* mr) -{ - auto out = make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, mr); - auto out_view = out->mutable_view(); - struct_binary_operation(out_view, lhs, rhs, op, stream); - - return out; + out.begin(), + out.end(), + [optional_iter, compare] __device__(size_type i) { + return optional_iter[i].has_value() and not compare(i, i); + }); } void struct_binary_operation(mutable_column_view& out, @@ -317,28 +305,45 @@ void struct_binary_operation(mutable_column_view& out, table_view lhs_flat = std::get<0>(lhs_flattener); table_view rhs_flat = std::get<0>(rhs_flattener); + auto d_out = column_device_view::create(out, stream); auto d_lhs = table_device_view::create(lhs_flat); auto d_rhs = table_device_view::create(rhs_flat); bool has_nulls = has_nested_nulls(lhs_flat) || has_nested_nulls(rhs_flat); if (op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL) { if (has_nulls) { - auto equal = row_equality_comparator{*d_lhs, *d_rhs, true}; - struct_compare_tabulation(out, equal, op, stream); + auto out_iter = cudf::detail::make_optional_iterator( + *d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); + struct_compare_tabulation( + out, row_equality_comparator{*d_lhs, *d_rhs, true}, op, out_iter, stream); } else { - auto equal = row_equality_comparator{*d_lhs, *d_rhs, true}; - struct_compare_tabulation(out, equal, op, stream); + auto out_iter = cudf::detail::make_optional_iterator( + *d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); + struct_compare_tabulation( + out, row_equality_comparator{*d_lhs, *d_rhs, true}, op, out_iter, stream); } } else if (op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL) { if (has_nulls) { - auto compare = row_lexicographic_comparator{ - *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}; - struct_compare_tabulation(out, compare, op, stream); + auto out_iter = cudf::detail::make_optional_iterator( + *d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); + struct_compare_tabulation( + out, + row_lexicographic_comparator{ + *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}, + op, + out_iter, + stream); } else { - auto compare = row_lexicographic_comparator{ - *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}; - struct_compare_tabulation(out, compare, op, stream); + auto out_iter = cudf::detail::make_optional_iterator( + *d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); + struct_compare_tabulation( + out, + row_lexicographic_comparator{ + *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}, + op, + out_iter, + stream); } // } else if (op == binary_operator::NULL_EQUALS) { } else { @@ -346,6 +351,8 @@ void struct_binary_operation(mutable_column_view& out, } } +} // namespace + std::unique_ptr string_null_min_max(scalar const& lhs, column_view const& rhs, binary_operator op, @@ -457,6 +464,8 @@ void binary_operation(mutable_column_view& out, rmm::cuda_stream_view stream) { if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { + CUDF_EXPECTS(struct_children_support_operation(out.type(), lhs, rhs, op), + "Unsupported operator for these types"); struct_binary_operation(out, lhs, rhs, op, stream); } else { auto lhsd = column_device_view::create(lhs, stream); @@ -474,6 +483,8 @@ void binary_operation(mutable_column_view& out, { if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { auto lhs_col = make_column_from_scalar(lhs, rhs.size(), stream); + CUDF_EXPECTS(struct_children_support_operation(out.type(), lhs_col->view(), rhs, op), + "Unsupported operator for these types"); struct_binary_operation(out, lhs_col->view(), rhs, op, stream); } else { auto [lhsd, aux] = scalar_to_column_device_view(lhs, stream); @@ -491,6 +502,9 @@ void binary_operation(mutable_column_view& out, { if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { auto rhs_col = make_column_from_scalar(rhs, lhs.size(), stream); + CUDF_EXPECTS(struct_children_support_operation(out.type(), lhs, rhs_col->view(), op), + "Unsupported operator for these types"); + struct_binary_operation(out, lhs, rhs_col->view(), op, stream); } else { auto lhsd = column_device_view::create(lhs, stream); diff --git a/cpp/src/binaryop/compiled/binary_ops.hpp b/cpp/src/binaryop/compiled/binary_ops.hpp index 517f4bad755..d5da504f185 100644 --- a/cpp/src/binaryop/compiled/binary_ops.hpp +++ b/cpp/src/binaryop/compiled/binary_ops.hpp @@ -169,6 +169,20 @@ std::optional get_common_type(data_type out, data_type lhs, data_type */ bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_operator op); +/** + * @brief Check if input binary operation is supported for the given input and output types. + * + * @param out output type of the binary operation + * @param lhs left column of the binary operation + * @param rhs right column of the binary operation + * @param op binary operator enum. + * @return true if given binary operator supports given input and output types. + */ +bool struct_children_support_operation(data_type out, + column_view const& lhs, + column_view const& rhs, + binary_operator op); + // Defined in individual .cu files. /** * @brief Deploys single type or double type dispatcher that runs binary operation on each element @@ -215,38 +229,6 @@ void dispatch_equality_op(mutable_column_device_view& outd, bool is_rhs_scalar, binary_operator op, rmm::cuda_stream_view stream); - -/** - * @brief - * - * @param lhs - * @param rhs - * @param output_type - * @param stream - * @param mr - * @return std::unique_ptr - */ -std::unique_ptr struct_binary_op( - column_view const& lhs, - column_view const& rhs, - binary_operator op, - data_type output_type, - rmm::cuda_stream_view stream = rmm::cuda_stream_default, - rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); - -/** - * @brief binary op functionality for structs, limited to comparison binops - * - * @param out - * @param lhs - * @param rhs - * @param stream - */ -void struct_binary_operation(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - binary_operator op, - rmm::cuda_stream_view stream); } // namespace compiled } // namespace binops } // namespace cudf diff --git a/cpp/src/binaryop/compiled/util.cpp b/cpp/src/binaryop/compiled/util.cpp index 95421f15608..6111de931c3 100644 --- a/cpp/src/binaryop/compiled/util.cpp +++ b/cpp/src/binaryop/compiled/util.cpp @@ -191,20 +191,18 @@ bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_ return double_type_dispatcher(lhs, rhs, is_supported_operation_functor{}, out, op); } -bool is_supported_struct_operation(data_type out, - column_view const& lhs, - column_view const& rhs, - binary_operator op) +bool struct_children_support_operation(data_type out, + column_view const& lhs, + column_view const& rhs, + binary_operator op) { if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { return lhs.num_children() == rhs.num_children() && - (op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL || - op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || - op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL) && std::all_of(thrust::counting_iterator(0), thrust::counting_iterator(lhs.num_children()), [&](size_type i) { - return is_supported_struct_operation(out, lhs.child(i), rhs.child(i), op); + return struct_children_support_operation( + out, lhs.child(i), rhs.child(i), op); }); } else { diff --git a/cpp/src/structs/utilities.cpp b/cpp/src/structs/utilities.cpp index 67b0cbc92d3..17fbacfdcef 100644 --- a/cpp/src/structs/utilities.cpp +++ b/cpp/src/structs/utilities.cpp @@ -415,10 +415,10 @@ std::tuple> superimpose_paren std::move(ret_validity_buffers)); } -bool contains_struct_nulls(column_view const& struct_col) +bool contains_struct_nulls(column_view const& col) { - return (struct_col.type().id() == type_id::STRUCT && struct_col.has_nulls()) || - std::all_of(struct_col.child_begin(), struct_col.child_end(), [](auto const& child) { + return (col.type().id() == type_id::STRUCT && col.has_nulls()) || + std::all_of(col.child_begin(), col.child_end(), [](auto const& child) { return contains_struct_nulls(child); }); } diff --git a/cpp/src/structs/utilities.hpp b/cpp/src/structs/utilities.hpp index f41555221b2..4842c9ecb73 100644 --- a/cpp/src/structs/utilities.hpp +++ b/cpp/src/structs/utilities.hpp @@ -15,7 +15,6 @@ */ #pragma once -#include #include #include #include @@ -158,13 +157,18 @@ std::tuple> superimpose_paren rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); /** - * @brief + * @brief Checks if column or any of its children are struct columns with structs that are null. * - * @param struct_col - * @return true - * @return false + * This function searchings for structs that are null and differentiates between them and structs + * containing null values. Struct nulls add a column to the table result of the flatten column + * utility. The existence of struct nulls necessitates the use of column_nullability::FORCE when + * flattening the column for comparison. + * + * @param col Column to check for structs containing nulls + * @return true If the column is or contains a struct column with struct nulls + * @return false If the column is not a struct column or does not contain struct nulls */ -bool contains_struct_nulls(column_view const& struct_col); +bool contains_struct_nulls(column_view const& col); } // namespace detail } // namespace structs diff --git a/cpp/tests/binaryop/binop-struct-test.cpp b/cpp/tests/binaryop/binop-struct-test.cpp index f181d995e78..634f8dd7a7e 100644 --- a/cpp/tests/binaryop/binop-struct-test.cpp +++ b/cpp/tests/binaryop/binop-struct-test.cpp @@ -16,12 +16,15 @@ #include +#include #include #include #include #include #include +#include "cudf/binaryop.hpp" +#include "cudf/types.hpp" namespace cudf::test { template @@ -54,30 +57,27 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_no_nulls) auto rhs = rhs_col->view(); data_type dt = cudf::data_type(type_id::BOOL8); - auto res_eq = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::EQUAL, dt); - auto res_neq = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::NOT_EQUAL, dt); - auto res_lt = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::LESS, dt); - auto res_gteq = - cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::GREATER_EQUAL, dt); - auto res_gt = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::GREATER, dt); - auto res_lteq = - cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::LESS_EQUAL, dt); + auto res_eq = binary_operation(lhs, rhs, binary_operator::EQUAL, dt); + auto res_neq = binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); + auto res_lt = binary_operation(lhs, rhs, binary_operator::LESS, dt); + auto res_lteq = binary_operation(lhs, rhs, binary_operator::LESS_EQUAL, dt); + auto res_gt = binary_operation(lhs, rhs, binary_operator::GREATER, dt); + auto res_gteq = binary_operation(lhs, rhs, binary_operator::GREATER_EQUAL, dt); auto expected_eq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 1}; auto expected_neq = fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 0}; auto expected_lt = fixed_width_column_wrapper{1, 1, 1, 0, 0, 0, 1, 0, 0}; - auto expected_gteq = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 1}; - auto expected_gt = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 0}; auto expected_lteq = fixed_width_column_wrapper{1, 1, 1, 0, 0, 0, 1, 0, 1}; + auto expected_gt = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 0}; + auto expected_gteq = fixed_width_column_wrapper{0, 0, 0, 1, 1, 1, 0, 1, 1}; CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); - - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); } TYPED_TEST(TypedBinopStructCompare, binopcompare_with_nulls) @@ -120,14 +120,12 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_with_nulls) auto rhs = rhs_col->view(); data_type dt = cudf::data_type(cudf::type_id::BOOL8); - auto res_eq = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::EQUAL, dt); - auto res_neq = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::NOT_EQUAL, dt); - auto res_lt = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::LESS, dt); - auto res_gteq = - cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::GREATER_EQUAL, dt); - auto res_gt = cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::GREATER, dt); - auto res_lteq = - cudf::binops::compiled::struct_binary_op(lhs, rhs, binary_operator::LESS_EQUAL, dt); + auto res_eq = binary_operation(lhs, rhs, binary_operator::EQUAL, dt); + auto res_neq = binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); + auto res_lt = binary_operation(lhs, rhs, binary_operator::LESS, dt); + auto res_lteq = binary_operation(lhs, rhs, binary_operator::LESS_EQUAL, dt); + auto res_gt = binary_operation(lhs, rhs, binary_operator::GREATER, dt); + auto res_gteq = binary_operation(lhs, rhs, binary_operator::GREATER_EQUAL, dt); auto expected_eq = fixed_width_column_wrapper{ {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1}, @@ -138,24 +136,23 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_with_nulls) auto expected_lt = fixed_width_column_wrapper{ {1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; - auto expected_gteq = fixed_width_column_wrapper{ - {0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0}, + auto expected_lteq = fixed_width_column_wrapper{ + {1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; auto expected_gt = fixed_width_column_wrapper{ {0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; - auto expected_lteq = fixed_width_column_wrapper{ - {1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1}, + auto expected_gteq = fixed_width_column_wrapper{ + {0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); - - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); } TYPED_TEST(TypedBinopStructCompare, binopcompare_nested_structs) @@ -174,64 +171,60 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_nested_structs) {117, 34, 23, 29, 2, 37, 63, 0, 121, 117, 34, 23, 29, 2, 37, 63, 0, 121}, {1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; - auto strings1 = strings_column_wrapper{{"0b", - "", - "1c", - "2a", - "", - "5d", - "6e", - "8f", - "", - "0a", - "1c", - "2d", - "3b", - "5c", - "6", - "7d", - "9g", - "0h"}, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0}}; - auto strings2 = strings_column_wrapper{{"0a", - "", - "1d", - "2a", - "3c", - "4", - "7d", - "9", - "", - "0b", - "0c", - "2d", - "3a", - "4c", - "6", - "8e", - "9f", - "0h"}, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0}}; - - auto struct_col1 = structs_column_wrapper{col3, strings1}; + auto s1 = strings_column_wrapper{{"0b", + "", + "1c", + "2a", + "", + "5d", + "6e", + "8f", + "", + "0a", + "1c", + "2d", + "3b", + "5c", + "6", + "7d", + "9g", + "0h"}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0}}; + auto s2 = strings_column_wrapper{{"0a", + "", + "1d", + "2a", + "3c", + "4", + "7d", + "9", + "", + "0b", + "0c", + "2d", + "3a", + "4c", + "6", + "8e", + "9f", + "0h"}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0}}; + + auto struct_col1 = structs_column_wrapper{col3, s1}; auto nested_col1 = structs_column_wrapper{col1, struct_col1}.release(); - auto struct_col2 = structs_column_wrapper{col4, strings2}; + auto struct_col2 = structs_column_wrapper{col4, s2}; auto nested_col2 = structs_column_wrapper{col2, struct_col2}.release(); + auto lhs = nested_col1->view(); + auto rhs = nested_col2->view(); data_type dt = cudf::data_type(cudf::type_id::BOOL8); - auto res_eq = cudf::binops::compiled::struct_binary_op( - *nested_col1, *nested_col2, binary_operator::EQUAL, dt); - auto res_neq = cudf::binops::compiled::struct_binary_op( - *nested_col1, *nested_col2, binary_operator::NOT_EQUAL, dt); - auto res_lt = - cudf::binops::compiled::struct_binary_op(*nested_col1, *nested_col2, binary_operator::LESS, dt); - auto res_gteq = cudf::binops::compiled::struct_binary_op( - *nested_col1, *nested_col2, binary_operator::GREATER_EQUAL, dt); - auto res_gt = cudf::binops::compiled::struct_binary_op( - *nested_col1, *nested_col2, binary_operator::GREATER, dt); - auto res_lteq = cudf::binops::compiled::struct_binary_op( - *nested_col1, *nested_col2, binary_operator::LESS_EQUAL, dt); + auto res_eq = binary_operation(lhs, rhs, binary_operator::EQUAL, dt); + auto res_neq = binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); + auto res_lt = binary_operation(lhs, rhs, binary_operator::LESS, dt); + auto res_lteq = binary_operation(lhs, rhs, binary_operator::LESS_EQUAL, dt); + auto res_gt = binary_operation(lhs, rhs, binary_operator::GREATER, dt); + auto res_gteq = binary_operation(lhs, rhs, binary_operator::GREATER_EQUAL, dt); auto expected_eq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1}; @@ -239,21 +232,130 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_nested_structs) fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0}; auto expected_lt = fixed_width_column_wrapper{1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0}; - auto expected_gteq = - fixed_width_column_wrapper{0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1}; - auto expected_gt = - fixed_width_column_wrapper{0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0}; auto expected_lteq = fixed_width_column_wrapper{1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1}; + auto expected_gt = + fixed_width_column_wrapper{0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0}; + auto expected_gteq = + fixed_width_column_wrapper{0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1}; CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); +} - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); +TYPED_TEST(TypedBinopStructCompare, binopcompare_scalars) +{ + using T = TypeParam; + + auto col1 = + fixed_width_column_wrapper{40, 105, 68, 25, 86, 68, 25, 127, 68, 68, 68, 68, 68, 68, 68}; + auto col2 = + fixed_width_column_wrapper{{26, 0, 14, 116, 89, 62, 63, 0, 121, 5, 115, 18, 0, 88, 18}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0}}; + + auto s1 = strings_column_wrapper{ + {"6S", "5G", "4a", "5G", "", "5Z", "5e", "9a", "5G", "5", "5Gs", "5G", "", "5G2", "5G"}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + + auto struct_col1 = structs_column_wrapper{col2, s1}; + auto nested_col1 = structs_column_wrapper{col1, struct_col1}.release(); + auto col_val = nested_col1->view(); + + cudf::test::fixed_width_column_wrapper col3{68}; + cudf::test::fixed_width_column_wrapper col4{{18}, {0}}; + auto strings2 = strings_column_wrapper{"5G"}; + auto struct_col2 = structs_column_wrapper{col4, strings2}; + cudf::table_view tbl({col3, struct_col2}); + cudf::struct_scalar struct_val(tbl); + data_type dt = cudf::data_type(cudf::type_id::BOOL8); + + auto res_eq = binary_operation(col_val, struct_val, binary_operator::EQUAL, dt); + auto res_neq = binary_operation(col_val, struct_val, binary_operator::NOT_EQUAL, dt); + auto res_lt = binary_operation(col_val, struct_val, binary_operator::LESS, dt); + auto res_gt = binary_operation(col_val, struct_val, binary_operator::GREATER, dt); + auto res_gteq = binary_operation(col_val, struct_val, binary_operator::GREATER_EQUAL, dt); + auto res_lteq = binary_operation(col_val, struct_val, binary_operator::LESS_EQUAL, dt); + + auto expected_eq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}; + auto expected_neq = fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1}; + auto expected_lt = fixed_width_column_wrapper{1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1}; + auto expected_lteq = + fixed_width_column_wrapper{1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1}; + auto expected_gt = fixed_width_column_wrapper{0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0}; + auto expected_gteq = + fixed_width_column_wrapper{0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0}; + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); +} + +struct BinopStructCompareFailures : public cudf::test::BaseFixture { + void attempt_struct_binop(binary_operator op, + data_type dt = cudf::data_type(cudf::type_id::BOOL8)) + { + auto col = fixed_width_column_wrapper{0, 89, 121}; + auto struct_col = structs_column_wrapper{col}; + binary_operation(struct_col, struct_col, op, dt); + } +}; + +TEST_F(BinopStructCompareFailures, binopcompare_lists) +{ + auto list_col = lists_column_wrapper{{0, 0}, {127, 3, 55}, {7, 3}}; + auto struct_col = structs_column_wrapper{list_col}; + auto dt = cudf::data_type(cudf::type_id::BOOL8); + + EXPECT_THROW(binary_operation(struct_col, struct_col, binary_operator::EQUAL, dt), + cudf::logic_error); + EXPECT_THROW(binary_operation(struct_col, struct_col, binary_operator::NOT_EQUAL, dt), + cudf::logic_error); + EXPECT_THROW(binary_operation(struct_col, struct_col, binary_operator::LESS, dt), + cudf::logic_error); + EXPECT_THROW(binary_operation(struct_col, struct_col, binary_operator::GREATER, dt), + cudf::logic_error); + EXPECT_THROW(binary_operation(struct_col, struct_col, binary_operator::GREATER_EQUAL, dt), + cudf::logic_error); + EXPECT_THROW(binary_operation(struct_col, struct_col, binary_operator::LESS_EQUAL, dt), + cudf::logic_error); +} + +TEST_F(BinopStructCompareFailures, binopcompare_unsupported_ops) +{ + EXPECT_THROW(attempt_struct_binop(binary_operator::ADD), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::SUB), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::MUL), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::DIV), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::TRUE_DIV), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::FLOOR_DIV), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::MOD), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::PMOD), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::PYMOD), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::POW), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::LOG_BASE), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::ATAN2), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::SHIFT_LEFT), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::SHIFT_RIGHT), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::SHIFT_RIGHT_UNSIGNED), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::BITWISE_AND), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::BITWISE_OR), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::BITWISE_XOR), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::LOGICAL_AND), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::LOGICAL_OR), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::NULL_EQUALS), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::NULL_MAX), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::NULL_MIN), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::GENERIC_BINARY), cudf::logic_error); + EXPECT_THROW(attempt_struct_binop(binary_operator::INVALID_BINARY), cudf::logic_error); } } // namespace cudf::test From 10c95f9f6f44fb8acaf68ae96f6d94e563fb7d43 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Thu, 21 Oct 2021 14:53:15 -0700 Subject: [PATCH 07/54] cleanup --- cpp/src/binaryop/compiled/binary_ops.hpp | 4 ++-- cpp/tests/binaryop/binop-struct-test.cpp | 10 +--------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/cpp/src/binaryop/compiled/binary_ops.hpp b/cpp/src/binaryop/compiled/binary_ops.hpp index d5da504f185..030983af37a 100644 --- a/cpp/src/binaryop/compiled/binary_ops.hpp +++ b/cpp/src/binaryop/compiled/binary_ops.hpp @@ -164,7 +164,7 @@ std::optional get_common_type(data_type out, data_type lhs, data_type * @param out output type of the binary operation * @param lhs first operand type of the binary operation * @param rhs second operand type of the binary operation - * @param op binary operator enum. + * @param op binary operator enum * @return true if given binary operator supports given input and output types. */ bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_operator op); @@ -175,7 +175,7 @@ bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_ * @param out output type of the binary operation * @param lhs left column of the binary operation * @param rhs right column of the binary operation - * @param op binary operator enum. + * @param op binary operator enum * @return true if given binary operator supports given input and output types. */ bool struct_children_support_operation(data_type out, diff --git a/cpp/tests/binaryop/binop-struct-test.cpp b/cpp/tests/binaryop/binop-struct-test.cpp index 634f8dd7a7e..f9a0d8dcccb 100644 --- a/cpp/tests/binaryop/binop-struct-test.cpp +++ b/cpp/tests/binaryop/binop-struct-test.cpp @@ -16,16 +16,10 @@ #include -#include #include #include -#include #include -#include -#include "cudf/binaryop.hpp" -#include "cudf/types.hpp" - namespace cudf::test { template struct TypedBinopStructCompare : BaseFixture { @@ -257,11 +251,9 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_scalars) auto col2 = fixed_width_column_wrapper{{26, 0, 14, 116, 89, 62, 63, 0, 121, 5, 115, 18, 0, 88, 18}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0}}; - auto s1 = strings_column_wrapper{ {"6S", "5G", "4a", "5G", "", "5Z", "5e", "9a", "5G", "5", "5Gs", "5G", "", "5G2", "5G"}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; - auto struct_col1 = structs_column_wrapper{col2, s1}; auto nested_col1 = structs_column_wrapper{col1, struct_col1}.release(); auto col_val = nested_col1->view(); @@ -303,7 +295,7 @@ struct BinopStructCompareFailures : public cudf::test::BaseFixture { void attempt_struct_binop(binary_operator op, data_type dt = cudf::data_type(cudf::type_id::BOOL8)) { - auto col = fixed_width_column_wrapper{0, 89, 121}; + auto col = fixed_width_column_wrapper{0, 89, 121}; auto struct_col = structs_column_wrapper{col}; binary_operation(struct_col, struct_col, op, dt); } From b6fa590abcd3d3fe06d563a09e00f79a1f788b36 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Thu, 21 Oct 2021 16:07:33 -0700 Subject: [PATCH 08/54] fix upmerge issues --- cpp/src/binaryop/compiled/binary_ops.cu | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index 9dc77c14dd8..14ff01b25d9 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -31,7 +31,7 @@ #include #include -#include +#include namespace cudf { namespace binops { @@ -302,8 +302,8 @@ void struct_binary_operation(mutable_column_view& out, has_struct_nulls ? structs::detail::column_nullability::FORCE : structs::detail::column_nullability::MATCH_INCOMING); - table_view lhs_flat = std::get<0>(lhs_flattener); - table_view rhs_flat = std::get<0>(rhs_flattener); + auto lhs_flat = lhs_flattener.flattened_columns(); + auto rhs_flat = rhs_flattener.flattened_columns(); auto d_out = column_device_view::create(out, stream); auto d_lhs = table_device_view::create(lhs_flat); From d64c1f9963c60f81c49c30e8f249c7a8c9dc6c90 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Fri, 22 Oct 2021 12:58:29 -0700 Subject: [PATCH 09/54] fix logic and improve documentation --- cpp/include/cudf/detail/structs/utilities.hpp | 14 +++++++------- cpp/src/binaryop/compiled/binary_ops.cu | 6 +++--- cpp/src/binaryop/compiled/binary_ops.hpp | 17 +++++++++++------ cpp/src/binaryop/compiled/util.cpp | 11 +++++------ cpp/src/structs/utilities.cpp | 2 +- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/cpp/include/cudf/detail/structs/utilities.hpp b/cpp/include/cudf/detail/structs/utilities.hpp index 4f1d2f3bbff..a13bc910576 100644 --- a/cpp/include/cudf/detail/structs/utilities.hpp +++ b/cpp/include/cudf/detail/structs/utilities.hpp @@ -249,14 +249,14 @@ std::tuple> superimpose_parent /** * @brief Checks if column or any of its children are struct columns with structs that are null. * - * This function searchings for structs that are null and differentiates between them and structs - * containing null values. Struct nulls add a column to the table result of the flatten column - * utility. The existence of struct nulls necessitates the use of column_nullability::FORCE when - * flattening the column for comparison. + * This function searches for structs that are null -- differentiating between structs that are null + * and structs containing null values. Null structs add a column to the result of the flatten column + * utility and necessitates column_nullability::FORCE when flattening the column for comparison + * operations. * - * @param col Column to check for structs containing nulls - * @return true If the column is or contains a struct column with struct nulls - * @return false If the column is not a struct column or does not contain struct nulls + * @param col Column to check for null structs + * @return true If the column is or contains a struct column with null structs + * @return false If the column is not a struct column or does not contain null structs */ bool contains_struct_nulls(column_view const& col); } // namespace detail diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index 14ff01b25d9..d67a7592355 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -464,7 +464,7 @@ void binary_operation(mutable_column_view& out, rmm::cuda_stream_view stream) { if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { - CUDF_EXPECTS(struct_children_support_operation(out.type(), lhs, rhs, op), + CUDF_EXPECTS(is_supported_struct_operation(out.type(), lhs, rhs, op), "Unsupported operator for these types"); struct_binary_operation(out, lhs, rhs, op, stream); } else { @@ -483,7 +483,7 @@ void binary_operation(mutable_column_view& out, { if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { auto lhs_col = make_column_from_scalar(lhs, rhs.size(), stream); - CUDF_EXPECTS(struct_children_support_operation(out.type(), lhs_col->view(), rhs, op), + CUDF_EXPECTS(is_supported_struct_operation(out.type(), lhs_col->view(), rhs, op), "Unsupported operator for these types"); struct_binary_operation(out, lhs_col->view(), rhs, op, stream); } else { @@ -502,7 +502,7 @@ void binary_operation(mutable_column_view& out, { if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { auto rhs_col = make_column_from_scalar(rhs, lhs.size(), stream); - CUDF_EXPECTS(struct_children_support_operation(out.type(), lhs, rhs_col->view(), op), + CUDF_EXPECTS(is_supported_struct_operation(out.type(), lhs, rhs_col->view(), op), "Unsupported operator for these types"); struct_binary_operation(out, lhs, rhs_col->view(), op, stream); diff --git a/cpp/src/binaryop/compiled/binary_ops.hpp b/cpp/src/binaryop/compiled/binary_ops.hpp index 2c8c0a0b51d..38b842003c5 100644 --- a/cpp/src/binaryop/compiled/binary_ops.hpp +++ b/cpp/src/binaryop/compiled/binary_ops.hpp @@ -173,18 +173,23 @@ std::optional get_common_type(data_type out, data_type lhs, data_type bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_operator op); /** - * @brief Check if input binary operation is supported for the given input and output types. + * @brief Check if input binary operation is supported for the given input columns and output types. + * + * If the left and right columns are struct columns, recursively checks if the input columns have + * the same number of children and the corresponding child columns are supported for the specified + * operation and output type. If either input column is not a struct, returns the result of + * is_supported_operation for the input column types. * * @param out output type of the binary operation * @param lhs left column of the binary operation * @param rhs right column of the binary operation * @param op binary operator enum - * @return true if given binary operator supports given input and output types. + * @return true if given binary operator supports given input columns and output types. */ -bool struct_children_support_operation(data_type out, - column_view const& lhs, - column_view const& rhs, - binary_operator op); +bool is_supported_struct_operation(data_type out, + column_view const& lhs, + column_view const& rhs, + binary_operator op); // Defined in individual .cu files. /** diff --git a/cpp/src/binaryop/compiled/util.cpp b/cpp/src/binaryop/compiled/util.cpp index 6111de931c3..09e91fadaf1 100644 --- a/cpp/src/binaryop/compiled/util.cpp +++ b/cpp/src/binaryop/compiled/util.cpp @@ -191,18 +191,17 @@ bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_ return double_type_dispatcher(lhs, rhs, is_supported_operation_functor{}, out, op); } -bool struct_children_support_operation(data_type out, - column_view const& lhs, - column_view const& rhs, - binary_operator op) +bool is_supported_struct_operation(data_type out, + column_view const& lhs, + column_view const& rhs, + binary_operator op) { if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { return lhs.num_children() == rhs.num_children() && std::all_of(thrust::counting_iterator(0), thrust::counting_iterator(lhs.num_children()), [&](size_type i) { - return struct_children_support_operation( - out, lhs.child(i), rhs.child(i), op); + return is_supported_struct_operation(out, lhs.child(i), rhs.child(i), op); }); } else { diff --git a/cpp/src/structs/utilities.cpp b/cpp/src/structs/utilities.cpp index ae33570072c..aedec154faf 100644 --- a/cpp/src/structs/utilities.cpp +++ b/cpp/src/structs/utilities.cpp @@ -440,7 +440,7 @@ std::tuple> superimpose_parent bool contains_struct_nulls(column_view const& col) { return (col.type().id() == type_id::STRUCT && col.has_nulls()) || - std::all_of(col.child_begin(), col.child_end(), [](auto const& child) { + std::any_of(col.child_begin(), col.child_end(), [](auto const& child) { return contains_struct_nulls(child); }); } From 57900da96b23885188150c8da91a1a4ae683925b Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Fri, 22 Oct 2021 16:11:16 -0700 Subject: [PATCH 10/54] clean up logic for nulls --- cpp/src/binaryop/compiled/binary_ops.cu | 57 ++++++++++--------------- 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index d67a7592355..65d40fbf20e 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -305,47 +305,36 @@ void struct_binary_operation(mutable_column_view& out, auto lhs_flat = lhs_flattener.flattened_columns(); auto rhs_flat = rhs_flattener.flattened_columns(); - auto d_out = column_device_view::create(out, stream); auto d_lhs = table_device_view::create(lhs_flat); auto d_rhs = table_device_view::create(rhs_flat); bool has_nulls = has_nested_nulls(lhs_flat) || has_nested_nulls(rhs_flat); + auto d_out = column_device_view::create(out, stream); + auto out_iter = + cudf::detail::make_optional_iterator(*d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); + if (op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL) { - if (has_nulls) { - auto out_iter = cudf::detail::make_optional_iterator( - *d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); - struct_compare_tabulation( - out, row_equality_comparator{*d_lhs, *d_rhs, true}, op, out_iter, stream); - } else { - auto out_iter = cudf::detail::make_optional_iterator( - *d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); - struct_compare_tabulation( - out, row_equality_comparator{*d_lhs, *d_rhs, true}, op, out_iter, stream); - } + has_nulls ? struct_compare_tabulation( + out, row_equality_comparator{*d_lhs, *d_rhs, true}, op, out_iter, stream) + : struct_compare_tabulation( + out, row_equality_comparator{*d_lhs, *d_rhs, true}, op, out_iter, stream); } else if (op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL) { - if (has_nulls) { - auto out_iter = cudf::detail::make_optional_iterator( - *d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); - struct_compare_tabulation( - out, - row_lexicographic_comparator{ - *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}, - op, - out_iter, - stream); - } else { - auto out_iter = cudf::detail::make_optional_iterator( - *d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); - struct_compare_tabulation( - out, - row_lexicographic_comparator{ - *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}, - op, - out_iter, - stream); - } - // } else if (op == binary_operator::NULL_EQUALS) { + has_nulls ? struct_compare_tabulation( + out, + row_lexicographic_comparator{ + *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}, + op, + out_iter, + stream) + : struct_compare_tabulation( + out, + row_lexicographic_comparator{ + *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}, + op, + out_iter, + stream); + // } else if (op == binary_operator::NULL_EQUALS) { } else { CUDF_FAIL("Unsupported operator for these types"); } From f170149cd70ec428e00c8f7030a62fb3fb4261aa Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Fri, 22 Oct 2021 16:52:07 -0700 Subject: [PATCH 11/54] remove unecessary call to superimpose parent nulls --- cpp/src/binaryop/compiled/binary_ops.cu | 50 +++++++++++-------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index 65d40fbf20e..86aa5a2ba00 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -287,31 +287,25 @@ void struct_binary_operation(mutable_column_view& out, { bool const has_struct_nulls = structs::detail::contains_struct_nulls(lhs) || structs::detail::contains_struct_nulls(rhs); - auto const lhs_superimposed = structs::detail::superimpose_parent_nulls(lhs); - auto const rhs_superimposed = structs::detail::superimpose_parent_nulls(rhs); - auto const lhs_flattener = structs::detail::flatten_nested_columns( - table_view{{std::get<0>(lhs_superimposed)}}, + auto const lhs_flattened = structs::detail::flatten_nested_columns( + table_view{{lhs}}, {}, {}, has_struct_nulls ? structs::detail::column_nullability::FORCE - : structs::detail::column_nullability::MATCH_INCOMING); - auto const rhs_flattener = structs::detail::flatten_nested_columns( - table_view{{std::get<0>(rhs_superimposed)}}, + : structs::detail::column_nullability::MATCH_INCOMING); + auto const rhs_flattened = structs::detail::flatten_nested_columns( + table_view{{rhs}}, {}, {}, has_struct_nulls ? structs::detail::column_nullability::FORCE : structs::detail::column_nullability::MATCH_INCOMING); - auto lhs_flat = lhs_flattener.flattened_columns(); - auto rhs_flat = rhs_flattener.flattened_columns(); - - auto d_lhs = table_device_view::create(lhs_flat); - auto d_rhs = table_device_view::create(rhs_flat); - bool has_nulls = has_nested_nulls(lhs_flat) || has_nested_nulls(rhs_flat); - + auto d_lhs = table_device_view::create(lhs_flattened); + auto d_rhs = table_device_view::create(rhs_flattened); auto d_out = column_device_view::create(out, stream); auto out_iter = cudf::detail::make_optional_iterator(*d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); + bool has_nulls = has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened); if (op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL) { has_nulls ? struct_compare_tabulation( @@ -320,20 +314,20 @@ void struct_binary_operation(mutable_column_view& out, out, row_equality_comparator{*d_lhs, *d_rhs, true}, op, out_iter, stream); } else if (op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL) { - has_nulls ? struct_compare_tabulation( - out, - row_lexicographic_comparator{ - *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}, - op, - out_iter, - stream) - : struct_compare_tabulation( - out, - row_lexicographic_comparator{ - *d_lhs, *d_rhs, get_orders(op, lhs_flat.num_columns(), stream).data()}, - op, - out_iter, - stream); + auto const num_columns = lhs_flattened.flattened_columns().num_columns(); + has_nulls + ? struct_compare_tabulation(out, + row_lexicographic_comparator{ + *d_lhs, *d_rhs, get_orders(op, num_columns, stream).data()}, + op, + out_iter, + stream) + : struct_compare_tabulation(out, + row_lexicographic_comparator{ + *d_lhs, *d_rhs, get_orders(op, num_columns, stream).data()}, + op, + out_iter, + stream); // } else if (op == binary_operator::NULL_EQUALS) { } else { CUDF_FAIL("Unsupported operator for these types"); From de129a115d3c63d89e316b788e2adf9d67c3f587 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Tue, 26 Oct 2021 17:21:31 -0700 Subject: [PATCH 12/54] PR fixes --- cpp/include/cudf/detail/structs/utilities.hpp | 19 +++++++++++ cpp/src/binaryop/compiled/binary_ops.cu | 10 +++--- cpp/src/binaryop/compiled/util.cpp | 32 +++++++++---------- cpp/src/structs/utilities.cpp | 11 +++---- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/cpp/include/cudf/detail/structs/utilities.hpp b/cpp/include/cudf/detail/structs/utilities.hpp index a13bc910576..c18cb483280 100644 --- a/cpp/include/cudf/detail/structs/utilities.hpp +++ b/cpp/include/cudf/detail/structs/utilities.hpp @@ -15,6 +15,7 @@ */ #pragma once +#include #include #include #include @@ -259,6 +260,24 @@ std::tuple> superimpose_parent * @return false If the column is not a struct column or does not contain null structs */ bool contains_struct_nulls(column_view const& col); + +/** + * @brief Check whether the specified column is of type `STRUCT`. + * + * @param col Column whose type is checked + * @return true If input is a struct column + * @return false If input is not a struct column + */ +bool is_struct(column_view const& col); + +/** + * @brief Check whether the specified scalar is of type `STRUCT`. + * + * @param scalar_value scalar whose type is checked + * @return true If input is a struct scalar + * @return false If input is not a struct scalar + */ +bool is_struct(scalar const& scalar_value); } // namespace detail } // namespace structs } // namespace cudf diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index 86aa5a2ba00..502b5657ddd 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -31,8 +32,6 @@ #include #include -#include - namespace cudf { namespace binops { namespace compiled { @@ -328,7 +327,6 @@ void struct_binary_operation(mutable_column_view& out, op, out_iter, stream); - // } else if (op == binary_operator::NULL_EQUALS) { } else { CUDF_FAIL("Unsupported operator for these types"); } @@ -446,7 +444,7 @@ void binary_operation(mutable_column_view& out, binary_operator op, rmm::cuda_stream_view stream) { - if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { + if (structs::detail::is_struct(lhs) && structs::detail::is_struct(rhs)) { CUDF_EXPECTS(is_supported_struct_operation(out.type(), lhs, rhs, op), "Unsupported operator for these types"); struct_binary_operation(out, lhs, rhs, op, stream); @@ -464,7 +462,7 @@ void binary_operation(mutable_column_view& out, binary_operator op, rmm::cuda_stream_view stream) { - if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { + if (structs::detail::is_struct(lhs) && structs::detail::is_struct(rhs)) { auto lhs_col = make_column_from_scalar(lhs, rhs.size(), stream); CUDF_EXPECTS(is_supported_struct_operation(out.type(), lhs_col->view(), rhs, op), "Unsupported operator for these types"); @@ -483,7 +481,7 @@ void binary_operation(mutable_column_view& out, binary_operator op, rmm::cuda_stream_view stream) { - if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { + if (structs::detail::is_struct(lhs) && structs::detail::is_struct(rhs)) { auto rhs_col = make_column_from_scalar(rhs, lhs.size(), stream); CUDF_EXPECTS(is_supported_struct_operation(out.type(), lhs, rhs_col->view(), op), "Unsupported operator for these types"); diff --git a/cpp/src/binaryop/compiled/util.cpp b/cpp/src/binaryop/compiled/util.cpp index 09e91fadaf1..702e77aaadb 100644 --- a/cpp/src/binaryop/compiled/util.cpp +++ b/cpp/src/binaryop/compiled/util.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -183,12 +184,11 @@ std::optional get_common_type(data_type out, data_type lhs, data_type bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_operator op) { - if (lhs.id() == type_id::STRUCT && rhs.id() == type_id::STRUCT) { - return op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL || - op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || - op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL; - } - return double_type_dispatcher(lhs, rhs, is_supported_operation_functor{}, out, op); + return lhs.id() == type_id::STRUCT && rhs.id() == type_id::STRUCT + ? op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL || + op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || + op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL + : double_type_dispatcher(lhs, rhs, is_supported_operation_functor{}, out, op); } bool is_supported_struct_operation(data_type out, @@ -196,16 +196,14 @@ bool is_supported_struct_operation(data_type out, column_view const& rhs, binary_operator op) { - if (lhs.type().id() == type_id::STRUCT && rhs.type().id() == type_id::STRUCT) { - return lhs.num_children() == rhs.num_children() && - std::all_of(thrust::counting_iterator(0), - thrust::counting_iterator(lhs.num_children()), - [&](size_type i) { - return is_supported_struct_operation(out, lhs.child(i), rhs.child(i), op); - }); - - } else { - return is_supported_operation(out, lhs.type(), rhs.type(), op); - } + return structs::detail::is_struct(lhs) && structs::detail::is_struct(rhs) + ? lhs.num_children() == rhs.num_children() && + std::all_of(thrust::counting_iterator(0), + thrust::counting_iterator(lhs.num_children()), + [&](size_type i) { + return is_supported_struct_operation( + out, lhs.child(i), rhs.child(i), op); + }) + : is_supported_operation(out, lhs.type(), rhs.type(), op); } } // namespace cudf::binops::compiled diff --git a/cpp/src/structs/utilities.cpp b/cpp/src/structs/utilities.cpp index aedec154faf..43d0300156a 100644 --- a/cpp/src/structs/utilities.cpp +++ b/cpp/src/structs/utilities.cpp @@ -70,12 +70,9 @@ std::vector> extract_ordered_struct_children( return result; } -namespace { -/** - * @brief Check whether the specified column is of type `STRUCT`. - */ -bool is_struct(cudf::column_view const& col) { return col.type().id() == type_id::STRUCT; } -} // namespace +bool is_struct(column_view const& col) { return col.type().id() == type_id::STRUCT; } + +bool is_struct(scalar const& scalar_value) { return scalar_value.type().id() == type_id::STRUCT; } bool is_or_has_nested_lists(cudf::column_view const& col) { @@ -439,7 +436,7 @@ std::tuple> superimpose_parent bool contains_struct_nulls(column_view const& col) { - return (col.type().id() == type_id::STRUCT && col.has_nulls()) || + return (is_struct(col) && col.has_nulls()) || std::any_of(col.child_begin(), col.child_end(), [](auto const& child) { return contains_struct_nulls(child); }); From b6321922aa8f633aa30c88ab88fa7de0bc5db2ff Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Wed, 27 Oct 2021 02:00:38 -0700 Subject: [PATCH 13/54] pr fixes --- cpp/src/structs/utilities.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/src/structs/utilities.cpp b/cpp/src/structs/utilities.cpp index 43d0300156a..4768fcb88c7 100644 --- a/cpp/src/structs/utilities.cpp +++ b/cpp/src/structs/utilities.cpp @@ -199,7 +199,8 @@ flattened_table flatten_nested_columns(table_view const& input, std::vector const& null_precedence, column_nullability nullability) { - auto const has_struct = std::any_of(input.begin(), input.end(), is_struct); + auto const has_struct = + std::any_of(input.begin(), input.end(), [](auto const& col) { return is_struct(col); }); if (not has_struct) { return flattened_table{input, column_order, null_precedence, {}, {}}; } return table_flattener{input, column_order, null_precedence, nullability}(); @@ -280,7 +281,8 @@ std::unique_ptr unflatten_nested_columns(std::unique_ptr Date: Wed, 3 Nov 2021 03:01:25 -0700 Subject: [PATCH 14/54] restructure struct binop code and other pr fixes --- cpp/include/cudf/detail/structs/utilities.hpp | 23 +- cpp/include/cudf/utilities/traits.hpp | 41 ++++ cpp/src/binaryop/compiled/ATan2.cu | 6 +- cpp/src/binaryop/compiled/Add.cu | 6 +- cpp/src/binaryop/compiled/BitwiseAnd.cu | 6 +- cpp/src/binaryop/compiled/BitwiseOr.cu | 6 +- cpp/src/binaryop/compiled/BitwiseXor.cu | 6 +- cpp/src/binaryop/compiled/Div.cu | 6 +- cpp/src/binaryop/compiled/FloorDiv.cu | 6 +- cpp/src/binaryop/compiled/Greater.cu | 21 +- cpp/src/binaryop/compiled/GreaterEqual.cu | 21 +- cpp/src/binaryop/compiled/Less.cu | 21 +- cpp/src/binaryop/compiled/LessEqual.cu | 21 +- cpp/src/binaryop/compiled/LogBase.cu | 6 +- cpp/src/binaryop/compiled/LogicalAnd.cu | 6 +- cpp/src/binaryop/compiled/LogicalOr.cu | 6 +- cpp/src/binaryop/compiled/Mod.cu | 6 +- cpp/src/binaryop/compiled/Mul.cu | 6 +- cpp/src/binaryop/compiled/NullMax.cu | 6 +- cpp/src/binaryop/compiled/NullMin.cu | 6 +- cpp/src/binaryop/compiled/PMod.cu | 6 +- cpp/src/binaryop/compiled/Pow.cu | 6 +- cpp/src/binaryop/compiled/PyMod.cu | 6 +- cpp/src/binaryop/compiled/ShiftLeft.cu | 6 +- cpp/src/binaryop/compiled/ShiftRight.cu | 6 +- .../binaryop/compiled/ShiftRightUnsigned.cu | 6 +- cpp/src/binaryop/compiled/Sub.cu | 6 +- cpp/src/binaryop/compiled/TrueDiv.cu | 6 +- cpp/src/binaryop/compiled/binary_ops.cu | 218 ++++++------------ cpp/src/binaryop/compiled/binary_ops.cuh | 39 +++- cpp/src/binaryop/compiled/binary_ops.hpp | 21 +- cpp/src/binaryop/compiled/equality_ops.cu | 71 +++++- .../binaryop/compiled/struct_binary_ops.cuh | 58 +++++ cpp/src/binaryop/compiled/util.cpp | 25 +- cpp/src/structs/utilities.cpp | 21 +- 35 files changed, 421 insertions(+), 312 deletions(-) create mode 100644 cpp/src/binaryop/compiled/struct_binary_ops.cuh diff --git a/cpp/include/cudf/detail/structs/utilities.hpp b/cpp/include/cudf/detail/structs/utilities.hpp index c18cb483280..5c4cdd027ab 100644 --- a/cpp/include/cudf/detail/structs/utilities.hpp +++ b/cpp/include/cudf/detail/structs/utilities.hpp @@ -15,7 +15,6 @@ */ #pragma once -#include #include #include #include @@ -248,7 +247,7 @@ std::tuple> superimpose_parent rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); /** - * @brief Checks if column or any of its children are struct columns with structs that are null. + * @brief Checks if a column or any of its children is a struct column with structs that are null. * * This function searches for structs that are null -- differentiating between structs that are null * and structs containing null values. Null structs add a column to the result of the flatten column @@ -259,25 +258,7 @@ std::tuple> superimpose_parent * @return true If the column is or contains a struct column with null structs * @return false If the column is not a struct column or does not contain null structs */ -bool contains_struct_nulls(column_view const& col); - -/** - * @brief Check whether the specified column is of type `STRUCT`. - * - * @param col Column whose type is checked - * @return true If input is a struct column - * @return false If input is not a struct column - */ -bool is_struct(column_view const& col); - -/** - * @brief Check whether the specified scalar is of type `STRUCT`. - * - * @param scalar_value scalar whose type is checked - * @return true If input is a struct scalar - * @return false If input is not a struct scalar - */ -bool is_struct(scalar const& scalar_value); +bool contains_null_structs(column_view const& col); } // namespace detail } // namespace structs } // namespace cudf diff --git a/cpp/include/cudf/utilities/traits.hpp b/cpp/include/cudf/utilities/traits.hpp index 40a833112e1..2341ae4d670 100644 --- a/cpp/include/cudf/utilities/traits.hpp +++ b/cpp/include/cudf/utilities/traits.hpp @@ -673,6 +673,47 @@ constexpr inline bool is_nested(data_type type) return cudf::type_dispatcher(type, is_nested_impl{}); } +/** + * @brief Indicates whether `T` is a struct type. + * + * "Nested" types are distinct from compound types in that they + * can have an arbitrarily deep list of descendants of the same + * type. Strings are not a nested type, but lists are. + * + * @param T The type to verify + * @return true T is a nested type + * @return false T is not a nested type + */ +template +constexpr inline bool is_struct() +{ + return std::is_same_v; +} + +struct is_struct_impl { + template + constexpr bool operator()() + { + return is_struct(); + } +}; + +/** + * @brief Indicates whether `type` is a nested type + * + * "Nested" types are distinct from compound types in that they + * can have an arbitrarily deep list of descendants of the same + * type. Strings are not a nested type, but lists are. + * + * @param type The `data_type` to verify + * @return true `type` is a nested type + * @return false `type` is not a nested type + */ +constexpr inline bool is_struct(data_type type) +{ + return cudf::type_dispatcher(type, is_struct_impl{}); +} + template struct is_bit_castable_to_impl { template ()>* = nullptr> diff --git a/cpp/src/binaryop/compiled/ATan2.cu b/cpp/src/binaryop/compiled/ATan2.cu index 8e5cbf57f55..e13756773b0 100644 --- a/cpp/src/binaryop/compiled/ATan2.cu +++ b/cpp/src/binaryop/compiled/ATan2.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/Add.cu b/cpp/src/binaryop/compiled/Add.cu index 4cd2ced66f4..94f1eca0354 100644 --- a/cpp/src/binaryop/compiled/Add.cu +++ b/cpp/src/binaryop/compiled/Add.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/BitwiseAnd.cu b/cpp/src/binaryop/compiled/BitwiseAnd.cu index 6abac2bd197..d6cdd205977 100644 --- a/cpp/src/binaryop/compiled/BitwiseAnd.cu +++ b/cpp/src/binaryop/compiled/BitwiseAnd.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/BitwiseOr.cu b/cpp/src/binaryop/compiled/BitwiseOr.cu index 6d523cbf1d1..712a5cf40a7 100644 --- a/cpp/src/binaryop/compiled/BitwiseOr.cu +++ b/cpp/src/binaryop/compiled/BitwiseOr.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/BitwiseXor.cu b/cpp/src/binaryop/compiled/BitwiseXor.cu index 45175681574..4d40a8a2ed6 100644 --- a/cpp/src/binaryop/compiled/BitwiseXor.cu +++ b/cpp/src/binaryop/compiled/BitwiseXor.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/Div.cu b/cpp/src/binaryop/compiled/Div.cu index 7cc895ecd06..0cb5cdc90bb 100644 --- a/cpp/src/binaryop/compiled/Div.cu +++ b/cpp/src/binaryop/compiled/Div.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/FloorDiv.cu b/cpp/src/binaryop/compiled/FloorDiv.cu index 99ea2706b86..66a156ded88 100644 --- a/cpp/src/binaryop/compiled/FloorDiv.cu +++ b/cpp/src/binaryop/compiled/FloorDiv.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/Greater.cu b/cpp/src/binaryop/compiled/Greater.cu index 679e029b5fc..209b7c23f4a 100644 --- a/cpp/src/binaryop/compiled/Greater.cu +++ b/cpp/src/binaryop/compiled/Greater.cu @@ -15,12 +15,21 @@ */ #include "binary_ops.cuh" +#include "struct_binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view); +template <> +void apply_binary_op(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + rmm::cuda_stream_view stream) +{ + is_struct(lhs.type()) && is_struct(rhs.type()) + ? detail::struct_lexicographic_compare( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, false, stream) + : detail::apply_unnested_binary_op( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); } +} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/GreaterEqual.cu b/cpp/src/binaryop/compiled/GreaterEqual.cu index 23b0c6aaa0d..e7d50d4713c 100644 --- a/cpp/src/binaryop/compiled/GreaterEqual.cu +++ b/cpp/src/binaryop/compiled/GreaterEqual.cu @@ -15,12 +15,21 @@ */ #include "binary_ops.cuh" +#include "struct_binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view); +template <> +void apply_binary_op(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + rmm::cuda_stream_view stream) +{ + is_struct(lhs.type()) && is_struct(rhs.type()) + ? detail::struct_lexicographic_compare( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, true, stream) + : detail::apply_unnested_binary_op( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); } +} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/Less.cu b/cpp/src/binaryop/compiled/Less.cu index 7ab5dfe3478..e45921162ac 100644 --- a/cpp/src/binaryop/compiled/Less.cu +++ b/cpp/src/binaryop/compiled/Less.cu @@ -15,12 +15,21 @@ */ #include "binary_ops.cuh" +#include "struct_binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view); +template <> +void apply_binary_op(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + rmm::cuda_stream_view stream) +{ + is_struct(lhs.type()) && is_struct(rhs.type()) + ? detail::struct_lexicographic_compare( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream) + : detail::apply_unnested_binary_op( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); } +} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/LessEqual.cu b/cpp/src/binaryop/compiled/LessEqual.cu index 983c50c9575..534ba4e0acf 100644 --- a/cpp/src/binaryop/compiled/LessEqual.cu +++ b/cpp/src/binaryop/compiled/LessEqual.cu @@ -15,12 +15,21 @@ */ #include "binary_ops.cuh" +#include "struct_binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view); +template <> +void apply_binary_op(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + rmm::cuda_stream_view stream) +{ + is_struct(lhs.type()) && is_struct(rhs.type()) + ? detail::struct_lexicographic_compare( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, true, stream) + : detail::apply_unnested_binary_op( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); } +} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/LogBase.cu b/cpp/src/binaryop/compiled/LogBase.cu index bdc709b86bf..dd9131f5f88 100644 --- a/cpp/src/binaryop/compiled/LogBase.cu +++ b/cpp/src/binaryop/compiled/LogBase.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/LogicalAnd.cu b/cpp/src/binaryop/compiled/LogicalAnd.cu index 08112fadfff..ae2e7de0782 100644 --- a/cpp/src/binaryop/compiled/LogicalAnd.cu +++ b/cpp/src/binaryop/compiled/LogicalAnd.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/LogicalOr.cu b/cpp/src/binaryop/compiled/LogicalOr.cu index bc400afd4cd..c6981a8ba0c 100644 --- a/cpp/src/binaryop/compiled/LogicalOr.cu +++ b/cpp/src/binaryop/compiled/LogicalOr.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/Mod.cu b/cpp/src/binaryop/compiled/Mod.cu index 0b82c09c8a6..706113503e7 100644 --- a/cpp/src/binaryop/compiled/Mod.cu +++ b/cpp/src/binaryop/compiled/Mod.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/Mul.cu b/cpp/src/binaryop/compiled/Mul.cu index 15394245259..a6010fd5c17 100644 --- a/cpp/src/binaryop/compiled/Mul.cu +++ b/cpp/src/binaryop/compiled/Mul.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/NullMax.cu b/cpp/src/binaryop/compiled/NullMax.cu index 78a44041cba..792cfbfca2f 100644 --- a/cpp/src/binaryop/compiled/NullMax.cu +++ b/cpp/src/binaryop/compiled/NullMax.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/NullMin.cu b/cpp/src/binaryop/compiled/NullMin.cu index 629ab600fd7..f413dadc23c 100644 --- a/cpp/src/binaryop/compiled/NullMin.cu +++ b/cpp/src/binaryop/compiled/NullMin.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/PMod.cu b/cpp/src/binaryop/compiled/PMod.cu index 36902c0ed10..faa1337b1bc 100644 --- a/cpp/src/binaryop/compiled/PMod.cu +++ b/cpp/src/binaryop/compiled/PMod.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/Pow.cu b/cpp/src/binaryop/compiled/Pow.cu index c6f897ee18d..9ccd5a02d0b 100644 --- a/cpp/src/binaryop/compiled/Pow.cu +++ b/cpp/src/binaryop/compiled/Pow.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/PyMod.cu b/cpp/src/binaryop/compiled/PyMod.cu index b05dcd8e7bc..8260cd51b28 100644 --- a/cpp/src/binaryop/compiled/PyMod.cu +++ b/cpp/src/binaryop/compiled/PyMod.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/ShiftLeft.cu b/cpp/src/binaryop/compiled/ShiftLeft.cu index 6cc950b2d50..100bcf93a2d 100644 --- a/cpp/src/binaryop/compiled/ShiftLeft.cu +++ b/cpp/src/binaryop/compiled/ShiftLeft.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/ShiftRight.cu b/cpp/src/binaryop/compiled/ShiftRight.cu index 1ddd7100a73..7c9b3c6194d 100644 --- a/cpp/src/binaryop/compiled/ShiftRight.cu +++ b/cpp/src/binaryop/compiled/ShiftRight.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu index a87b4b9f9ac..f539dda7f66 100644 --- a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu +++ b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/Sub.cu b/cpp/src/binaryop/compiled/Sub.cu index e0cf47c1310..3b93bd63d2b 100644 --- a/cpp/src/binaryop/compiled/Sub.cu +++ b/cpp/src/binaryop/compiled/Sub.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/TrueDiv.cu b/cpp/src/binaryop/compiled/TrueDiv.cu index d8f1d956340..c72e34e415c 100644 --- a/cpp/src/binaryop/compiled/TrueDiv.cu +++ b/cpp/src/binaryop/compiled/TrueDiv.cu @@ -17,9 +17,9 @@ #include "binary_ops.cuh" namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index 502b5657ddd..7195474092e 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -16,17 +16,16 @@ #include "binary_ops.hpp" #include "operation.cuh" +#include "struct_binary_ops.cuh" #include #include -#include #include #include #include #include #include #include -#include #include #include @@ -38,25 +37,30 @@ namespace compiled { namespace { /** - * @brief Converts scalar to column_device_view with single element. + * @brief Converts scalar to column_view with single element. * - * @return pair with column_device_view and column containing any auxilary data to create - * column_view from scalar + * @return pair with column_view and column containing any auxilary data to create column_view from + * scalar */ -struct scalar_as_column_device_view { - using return_type = typename std::pair>; +struct scalar_as_column_view { + using return_type = typename std::pair>; template ())>* = nullptr> - return_type operator()(scalar const& s, - rmm::cuda_stream_view stream, - rmm::mr::device_memory_resource*) + return_type operator()(scalar const& s, rmm::cuda_stream_view, rmm::mr::device_memory_resource*) { auto& h_scalar_type_view = static_cast&>(const_cast(s)); auto col_v = column_view(s.type(), 1, h_scalar_type_view.data(), (bitmask_type const*)s.validity_data()); - return std::pair{column_device_view::create(col_v, stream), std::unique_ptr(nullptr)}; + return std::pair{col_v, std::unique_ptr(nullptr)}; + } + template ())>* = nullptr> + return_type operator()(scalar const& s, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) + { + auto col = make_column_from_scalar(s, 1, stream, mr); + return std::pair{col->view(), std::move(col)}; } - template ())>* = nullptr> + template () and !is_struct())>* = nullptr> return_type operator()(scalar const&, rmm::cuda_stream_view, rmm::mr::device_memory_resource*) { CUDF_FAIL("Unsupported type"); @@ -64,10 +68,8 @@ struct scalar_as_column_device_view { }; // specialization for cudf::string_view template <> -scalar_as_column_device_view::return_type -scalar_as_column_device_view::operator()(scalar const& s, - rmm::cuda_stream_view stream, - rmm::mr::device_memory_resource* mr) +scalar_as_column_view::return_type scalar_as_column_view::operator()( + scalar const& s, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { using T = cudf::string_view; auto& h_scalar_type_view = static_cast&>(const_cast(s)); @@ -88,24 +90,24 @@ scalar_as_column_device_view::operator()(scalar const& s, cudf::UNKNOWN_NULL_COUNT, 0, {offsets_column->view(), chars_column_v}); - return std::pair{column_device_view::create(col_v, stream), std::move(offsets_column)}; + return std::pair{col_v, std::move(offsets_column)}; } /** - * @brief Converts scalar to column_device_view with single element. + * @brief Converts scalar to column_view with single element. * * @param scal scalar to convert * @param stream CUDA stream used for device memory operations and kernel launches. * @param mr Device memory resource used to allocate the returned column's device memory - * @return pair with column_device_view and column containing any auxilary data to create + * @return pair with column_view and column containing any auxilary data to create * column_view from scalar */ -auto scalar_to_column_device_view( +auto scalar_to_column_view( scalar const& scal, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()) { - return type_dispatcher(scal.type(), scalar_as_column_device_view{}, scal, stream, mr); + return type_dispatcher(scal.type(), scalar_as_column_view{}, scal, stream, mr); } // This functor does the actual comparison between string column value and a scalar string @@ -245,93 +247,6 @@ struct null_considering_binop { } }; -rmm::device_uvector get_orders(binary_operator op, - uint32_t const num_columns, - rmm::cuda_stream_view stream) -{ - std::vector op_modifier( - num_columns, - (op == binary_operator::LESS || op == binary_operator::GREATER_EQUAL) ? order::ASCENDING - : order::DESCENDING); - return cudf::detail::make_device_uvector_async(op_modifier, stream); -} - -template -void struct_compare_tabulation(mutable_column_view& out, - Comparator compare, - binary_operator op, - OptionalOutIter optional_iter, - rmm::cuda_stream_view stream) -{ - (op == binary_operator::EQUAL || op == binary_operator::LESS || op == binary_operator::GREATER) - ? thrust::tabulate(rmm::exec_policy(stream), - out.begin(), - out.end(), - [optional_iter, compare] __device__(size_type i) { - return optional_iter[i].has_value() and compare(i, i); - }) - : thrust::tabulate(rmm::exec_policy(stream), - out.begin(), - out.end(), - [optional_iter, compare] __device__(size_type i) { - return optional_iter[i].has_value() and not compare(i, i); - }); -} - -void struct_binary_operation(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - binary_operator op, - rmm::cuda_stream_view stream) -{ - bool const has_struct_nulls = - structs::detail::contains_struct_nulls(lhs) || structs::detail::contains_struct_nulls(rhs); - auto const lhs_flattened = structs::detail::flatten_nested_columns( - table_view{{lhs}}, - {}, - {}, - has_struct_nulls ? structs::detail::column_nullability::FORCE - : structs::detail::column_nullability::MATCH_INCOMING); - auto const rhs_flattened = structs::detail::flatten_nested_columns( - table_view{{rhs}}, - {}, - {}, - has_struct_nulls ? structs::detail::column_nullability::FORCE - : structs::detail::column_nullability::MATCH_INCOMING); - - auto d_lhs = table_device_view::create(lhs_flattened); - auto d_rhs = table_device_view::create(rhs_flattened); - auto d_out = column_device_view::create(out, stream); - auto out_iter = - cudf::detail::make_optional_iterator(*d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); - bool has_nulls = has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened); - - if (op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL) { - has_nulls ? struct_compare_tabulation( - out, row_equality_comparator{*d_lhs, *d_rhs, true}, op, out_iter, stream) - : struct_compare_tabulation( - out, row_equality_comparator{*d_lhs, *d_rhs, true}, op, out_iter, stream); - } else if (op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || - op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL) { - auto const num_columns = lhs_flattened.flattened_columns().num_columns(); - has_nulls - ? struct_compare_tabulation(out, - row_lexicographic_comparator{ - *d_lhs, *d_rhs, get_orders(op, num_columns, stream).data()}, - op, - out_iter, - stream) - : struct_compare_tabulation(out, - row_lexicographic_comparator{ - *d_lhs, *d_rhs, get_orders(op, num_columns, stream).data()}, - op, - out_iter, - stream); - } else { - CUDF_FAIL("Unsupported operator for these types"); - } -} - } // namespace std::unique_ptr string_null_min_max(scalar const& lhs, @@ -388,9 +303,9 @@ std::unique_ptr string_null_min_max(column_view const& lhs, *lhs_device_view, *rhs_device_view, op, output_type, lhs.size(), stream, mr); } -void operator_dispatcher(mutable_column_device_view& out, - column_device_view const& lhs, - column_device_view const& rhs, +void operator_dispatcher(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, bool is_lhs_scalar, bool is_rhs_scalar, binary_operator op, @@ -444,16 +359,7 @@ void binary_operation(mutable_column_view& out, binary_operator op, rmm::cuda_stream_view stream) { - if (structs::detail::is_struct(lhs) && structs::detail::is_struct(rhs)) { - CUDF_EXPECTS(is_supported_struct_operation(out.type(), lhs, rhs, op), - "Unsupported operator for these types"); - struct_binary_operation(out, lhs, rhs, op, stream); - } else { - auto lhsd = column_device_view::create(lhs, stream); - auto rhsd = column_device_view::create(rhs, stream); - auto outd = mutable_column_device_view::create(out, stream); - operator_dispatcher(*outd, *lhsd, *rhsd, false, false, op, stream); - } + operator_dispatcher(out, lhs, rhs, false, false, op, stream); } // scalar_vector void binary_operation(mutable_column_view& out, @@ -462,17 +368,8 @@ void binary_operation(mutable_column_view& out, binary_operator op, rmm::cuda_stream_view stream) { - if (structs::detail::is_struct(lhs) && structs::detail::is_struct(rhs)) { - auto lhs_col = make_column_from_scalar(lhs, rhs.size(), stream); - CUDF_EXPECTS(is_supported_struct_operation(out.type(), lhs_col->view(), rhs, op), - "Unsupported operator for these types"); - struct_binary_operation(out, lhs_col->view(), rhs, op, stream); - } else { - auto [lhsd, aux] = scalar_to_column_device_view(lhs, stream); - auto rhsd = column_device_view::create(rhs, stream); - auto outd = mutable_column_device_view::create(out, stream); - operator_dispatcher(*outd, *lhsd, *rhsd, true, false, op, stream); - } + auto [lhsv, aux] = scalar_to_column_view(lhs, stream); + operator_dispatcher(out, lhsv, rhs, true, false, op, stream); } // vector_scalar void binary_operation(mutable_column_view& out, @@ -481,20 +378,51 @@ void binary_operation(mutable_column_view& out, binary_operator op, rmm::cuda_stream_view stream) { - if (structs::detail::is_struct(lhs) && structs::detail::is_struct(rhs)) { - auto rhs_col = make_column_from_scalar(rhs, lhs.size(), stream); - CUDF_EXPECTS(is_supported_struct_operation(out.type(), lhs, rhs_col->view(), op), - "Unsupported operator for these types"); - - struct_binary_operation(out, lhs, rhs_col->view(), op, stream); - } else { - auto lhsd = column_device_view::create(lhs, stream); - auto [rhsd, aux] = scalar_to_column_device_view(rhs, stream); - auto outd = mutable_column_device_view::create(out, stream); - operator_dispatcher(*outd, *lhsd, *rhsd, false, true, op, stream); - } + auto [rhsv, aux] = scalar_to_column_view(rhs, stream); + operator_dispatcher(out, lhs, rhsv, false, true, op, stream); } +namespace detail { +void struct_lexicographic_compare(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + order op_order, + bool flip_output, + rmm::cuda_stream_view stream) +{ + if (!is_supported_operation(out.type(), lhs, rhs, binary_operator::LESS_EQUAL)) + CUDF_FAIL("Unsupported operator for these types"); + auto const nullability = + structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) + ? structs::detail::column_nullability::FORCE + : structs::detail::column_nullability::MATCH_INCOMING; + auto const lhs_flattened = + structs::detail::flatten_nested_columns(table_view{{lhs}}, {}, {}, nullability); + auto const rhs_flattened = + structs::detail::flatten_nested_columns(table_view{{rhs}}, {}, {}, nullability); + + auto d_lhs = table_device_view::create(lhs_flattened); + auto d_rhs = table_device_view::create(rhs_flattened); + auto compare_orders = + cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); + + has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened) + ? struct_compare(out, + row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}, + is_lhs_scalar, + is_rhs_scalar, + flip_output, + stream) + : struct_compare(out, + row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}, + is_lhs_scalar, + is_rhs_scalar, + flip_output, + stream); +} +} // namespace detail } // namespace compiled } // namespace binops } // namespace cudf diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 84147fc9220..6239b22f85d 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -20,6 +20,7 @@ #include "operation.cuh" #include +#include #include #include @@ -252,21 +253,41 @@ void for_each(rmm::cuda_stream_view stream, cudf::size_type size, Functor f) for_each_kernel<<>>(size, std::forward(f)); } +namespace detail { template -void apply_binary_op(mutable_column_device_view& outd, - column_device_view const& lhsd, - column_device_view const& rhsd, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view stream) +void apply_unnested_binary_op(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + rmm::cuda_stream_view stream) { - auto common_dtype = get_common_type(outd.type(), lhsd.type(), rhsd.type()); + auto common_dtype = get_common_type(out.type(), lhs.type(), rhs.type()); + auto lhsd = column_device_view::create(lhs, stream); + auto rhsd = column_device_view::create(rhs, stream); + auto outd = mutable_column_device_view::create(out, stream); // Create binop functor instance auto binop_func = device_type_dispatcher{ - outd, lhsd, rhsd, is_lhs_scalar, is_rhs_scalar, common_dtype}; + *outd, *lhsd, *rhsd, is_lhs_scalar, is_rhs_scalar, common_dtype}; // Execute it on every element - for_each(stream, outd.size(), binop_func); + for_each(stream, out.size(), binop_func); +} +} // namespace detail + +template +void apply_binary_op(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + rmm::cuda_stream_view stream) +{ + if (is_struct(lhs.type()) && is_struct(rhs.type())) { + CUDF_FAIL("Unsupported operator for these types"); + } + detail::apply_unnested_binary_op( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); } } // namespace compiled diff --git a/cpp/src/binaryop/compiled/binary_ops.hpp b/cpp/src/binaryop/compiled/binary_ops.hpp index 38b842003c5..b36a0ed1e5e 100644 --- a/cpp/src/binaryop/compiled/binary_ops.hpp +++ b/cpp/src/binaryop/compiled/binary_ops.hpp @@ -22,6 +22,7 @@ #include #include +#include "cudf/column/column_view.hpp" namespace cudf { // Forward declarations @@ -186,10 +187,10 @@ bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_ * @param op binary operator enum * @return true if given binary operator supports given input columns and output types. */ -bool is_supported_struct_operation(data_type out, - column_view const& lhs, - column_view const& rhs, - binary_operator op); +bool is_supported_operation(data_type out, + column_view const& lhs, + column_view const& rhs, + binary_operator op); // Defined in individual .cu files. /** @@ -207,9 +208,9 @@ bool is_supported_struct_operation(data_type out, * @param stream CUDA stream used for device memory operations */ template -void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view stream); @@ -230,9 +231,9 @@ void apply_binary_op(mutable_column_device_view&, * @param op comparison binary operator * @param stream CUDA stream used for device memory operations */ -void dispatch_equality_op(mutable_column_device_view& outd, - column_device_view const& lhsd, - column_device_view const& rhsd, +void dispatch_equality_op(mutable_column_view& outd, + column_view const& lhsd, + column_view const& rhsd, bool is_lhs_scalar, bool is_rhs_scalar, binary_operator op, diff --git a/cpp/src/binaryop/compiled/equality_ops.cu b/cpp/src/binaryop/compiled/equality_ops.cu index feee310716a..209a1d57db8 100644 --- a/cpp/src/binaryop/compiled/equality_ops.cu +++ b/cpp/src/binaryop/compiled/equality_ops.cu @@ -15,24 +15,70 @@ */ #include "binary_ops.cuh" +#include "struct_binary_ops.cuh" + +#include +#include namespace cudf::binops::compiled { -void dispatch_equality_op(mutable_column_device_view& outd, - column_device_view const& lhsd, - column_device_view const& rhsd, +void dispatch_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, rmm::cuda_stream_view stream) { - auto common_dtype = get_common_type(outd.type(), lhsd.type(), rhsd.type()); + if (is_struct(lhs.type()) && is_struct(rhs.type())) { + if (!is_supported_operation(out.type(), lhs, rhs, op)) + CUDF_FAIL("Unsupported operator for these types"); + + auto const nullability = + structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) + ? structs::detail::column_nullability::FORCE + : structs::detail::column_nullability::MATCH_INCOMING; + auto const lhs_flattened = + structs::detail::flatten_nested_columns(table_view{{lhs}}, {}, {}, nullability); + auto const rhs_flattened = + structs::detail::flatten_nested_columns(table_view{{rhs}}, {}, {}, nullability); + auto d_lhs = table_device_view::create(lhs_flattened); + auto d_rhs = table_device_view::create(rhs_flattened); - // Execute it on every element - for_each( - stream, - outd.size(), - [op, outd, lhsd, rhsd, is_lhs_scalar, is_rhs_scalar, common_dtype] __device__(size_type i) { - // clang-format off + switch (op) { + case binary_operator::EQUAL: + case binary_operator::NOT_EQUAL: + has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened) + ? detail::struct_compare(out, + row_equality_comparator{*d_lhs, *d_rhs, true}, + is_lhs_scalar, + is_rhs_scalar, + op == binary_operator::NOT_EQUAL, + stream) + : detail::struct_compare(out, + row_equality_comparator{*d_lhs, *d_rhs, true}, + is_lhs_scalar, + is_rhs_scalar, + op == binary_operator::NOT_EQUAL, + stream); + break; + default: CUDF_FAIL("Unsupported operator for these types"); + } + } else { + auto common_dtype = get_common_type(out.type(), lhs.type(), rhs.type()); + auto lhsd = column_device_view::create(lhs, stream); + auto rhsd = column_device_view::create(rhs, stream); + auto outd = mutable_column_device_view::create(out, stream); + // Execute it on every element + for_each(stream, + out.size(), + [op, + outd = *outd, + lhsd = *lhsd, + rhsd = *rhsd, + is_lhs_scalar, + is_rhs_scalar, + common_dtype] __device__(size_type i) { + // clang-format off // Similar enabled template types should go together (better performance) switch (op) { case binary_operator::EQUAL: device_type_dispatcher{outd, lhsd, rhsd, is_lhs_scalar, is_rhs_scalar, common_dtype}(i); break; @@ -40,7 +86,8 @@ void dispatch_equality_op(mutable_column_device_view& outd, case binary_operator::NULL_EQUALS: device_type_dispatcher{outd, lhsd, rhsd, is_lhs_scalar, is_rhs_scalar, common_dtype}(i); break; default:; } - // clang-format on - }); + // clang-format on + }); + } } } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cuh b/cpp/src/binaryop/compiled/struct_binary_ops.cuh new file mode 100644 index 00000000000..b91dd763664 --- /dev/null +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cuh @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021, 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 +#include +#include + +#include +#include + +namespace cudf::binops::compiled::detail { +template +void struct_compare(mutable_column_view& out, + Comparator compare, + bool is_lhs_scalar, + bool is_rhs_scalar, + bool flip_output, + rmm::cuda_stream_view stream) +{ + auto d_out = column_device_view::create(out, stream); + auto optional_iter = + cudf::detail::make_optional_iterator(*d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); + thrust::tabulate( + rmm::exec_policy(stream), + out.begin(), + out.end(), + [optional_iter, is_lhs_scalar, is_rhs_scalar, flip_output, compare] __device__(size_type i) { + auto lhs = is_lhs_scalar ? 0 : i; + auto rhs = is_rhs_scalar ? 0 : i; + return optional_iter[i].has_value() and + (flip_output ? not compare(lhs, rhs) : compare(lhs, rhs)); + }); +} + +void struct_lexicographic_compare(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); +} // namespace cudf::binops::compiled::detail diff --git a/cpp/src/binaryop/compiled/util.cpp b/cpp/src/binaryop/compiled/util.cpp index 702e77aaadb..16089bae893 100644 --- a/cpp/src/binaryop/compiled/util.cpp +++ b/cpp/src/binaryop/compiled/util.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -184,25 +183,23 @@ std::optional get_common_type(data_type out, data_type lhs, data_type bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_operator op) { - return lhs.id() == type_id::STRUCT && rhs.id() == type_id::STRUCT - ? op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL || - op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || - op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL - : double_type_dispatcher(lhs, rhs, is_supported_operation_functor{}, out, op); + return double_type_dispatcher(lhs, rhs, is_supported_operation_functor{}, out, op) || + (is_struct(lhs) && is_struct(rhs) && op != binary_operator::GENERIC_BINARY && + op != binary_operator::INVALID_BINARY); } -bool is_supported_struct_operation(data_type out, - column_view const& lhs, - column_view const& rhs, - binary_operator op) +bool is_supported_operation(data_type out, + column_view const& lhs, + column_view const& rhs, + binary_operator op) { - return structs::detail::is_struct(lhs) && structs::detail::is_struct(rhs) - ? lhs.num_children() == rhs.num_children() && + return is_struct(lhs.type()) && is_struct(rhs.type()) + ? (lhs.num_children() == rhs.num_children() || lhs.num_children() == 1 || + rhs.num_children() == 1) && std::all_of(thrust::counting_iterator(0), thrust::counting_iterator(lhs.num_children()), [&](size_type i) { - return is_supported_struct_operation( - out, lhs.child(i), rhs.child(i), op); + return is_supported_operation(out, lhs.child(i), rhs.child(i), op); }) : is_supported_operation(out, lhs.type(), rhs.type(), op); } diff --git a/cpp/src/structs/utilities.cpp b/cpp/src/structs/utilities.cpp index 4768fcb88c7..ad989bb5ae4 100644 --- a/cpp/src/structs/utilities.cpp +++ b/cpp/src/structs/utilities.cpp @@ -70,9 +70,12 @@ std::vector> extract_ordered_struct_children( return result; } -bool is_struct(column_view const& col) { return col.type().id() == type_id::STRUCT; } - -bool is_struct(scalar const& scalar_value) { return scalar_value.type().id() == type_id::STRUCT; } +namespace { +/** + * @brief Check whether the specified column is of type `STRUCT`. + */ +bool is_struct(cudf::column_view const& col) { return col.type().id() == type_id::STRUCT; } +} // namespace bool is_or_has_nested_lists(cudf::column_view const& col) { @@ -199,8 +202,7 @@ flattened_table flatten_nested_columns(table_view const& input, std::vector const& null_precedence, column_nullability nullability) { - auto const has_struct = - std::any_of(input.begin(), input.end(), [](auto const& col) { return is_struct(col); }); + auto const has_struct = std::any_of(input.begin(), input.end(), is_struct); if (not has_struct) { return flattened_table{input, column_order, null_precedence, {}, {}}; } return table_flattener{input, column_order, null_precedence, nullability}(); @@ -281,8 +283,7 @@ std::unique_ptr unflatten_nested_columns(std::unique_ptr> superimpose_parent return {table_view{superimposed_columns}, std::move(superimposed_nullmasks)}; } -bool contains_struct_nulls(column_view const& col) +bool contains_null_structs(column_view const& col) { return (is_struct(col) && col.has_nulls()) || - std::any_of(col.child_begin(), col.child_end(), [](auto const& child) { - return contains_struct_nulls(child); - }); + std::any_of(col.child_begin(), col.child_end(), contains_null_structs); } } // namespace detail From 1d6263e176e488e2629e80239cddcccba9013a57 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Tue, 9 Nov 2021 15:36:08 -0800 Subject: [PATCH 15/54] full paths for includes --- cpp/include/cudf/utilities/traits.hpp | 18 +++++------------- cpp/src/binaryop/compiled/ATan2.cu | 2 +- cpp/src/binaryop/compiled/Add.cu | 2 +- cpp/src/binaryop/compiled/BitwiseAnd.cu | 2 +- cpp/src/binaryop/compiled/BitwiseOr.cu | 2 +- cpp/src/binaryop/compiled/BitwiseXor.cu | 2 +- cpp/src/binaryop/compiled/Div.cu | 2 +- cpp/src/binaryop/compiled/FloorDiv.cu | 2 +- cpp/src/binaryop/compiled/Greater.cu | 4 ++-- cpp/src/binaryop/compiled/GreaterEqual.cu | 4 ++-- cpp/src/binaryop/compiled/Less.cu | 4 ++-- cpp/src/binaryop/compiled/LessEqual.cu | 4 ++-- cpp/src/binaryop/compiled/LogBase.cu | 2 +- cpp/src/binaryop/compiled/LogicalAnd.cu | 2 +- cpp/src/binaryop/compiled/LogicalOr.cu | 2 +- cpp/src/binaryop/compiled/Mod.cu | 2 +- cpp/src/binaryop/compiled/Mul.cu | 2 +- cpp/src/binaryop/compiled/NullMax.cu | 2 +- cpp/src/binaryop/compiled/NullMin.cu | 2 +- cpp/src/binaryop/compiled/PMod.cu | 2 +- cpp/src/binaryop/compiled/Pow.cu | 2 +- cpp/src/binaryop/compiled/PyMod.cu | 2 +- cpp/src/binaryop/compiled/ShiftLeft.cu | 2 +- cpp/src/binaryop/compiled/ShiftRight.cu | 2 +- .../binaryop/compiled/ShiftRightUnsigned.cu | 2 +- cpp/src/binaryop/compiled/Sub.cu | 2 +- cpp/src/binaryop/compiled/TrueDiv.cu | 2 +- cpp/src/binaryop/compiled/binary_ops.cu | 6 +++--- cpp/src/binaryop/compiled/binary_ops.cuh | 4 ++-- cpp/src/binaryop/compiled/binary_ops.hpp | 1 - cpp/src/binaryop/compiled/equality_ops.cu | 4 ++-- cpp/src/binaryop/compiled/util.cpp | 2 +- 32 files changed, 43 insertions(+), 52 deletions(-) diff --git a/cpp/include/cudf/utilities/traits.hpp b/cpp/include/cudf/utilities/traits.hpp index 2341ae4d670..d6c28692dec 100644 --- a/cpp/include/cudf/utilities/traits.hpp +++ b/cpp/include/cudf/utilities/traits.hpp @@ -676,13 +676,9 @@ constexpr inline bool is_nested(data_type type) /** * @brief Indicates whether `T` is a struct type. * - * "Nested" types are distinct from compound types in that they - * can have an arbitrarily deep list of descendants of the same - * type. Strings are not a nested type, but lists are. - * * @param T The type to verify - * @return true T is a nested type - * @return false T is not a nested type + * @return true T is a struct type + * @return false T is not a struct type */ template constexpr inline bool is_struct() @@ -699,15 +695,11 @@ struct is_struct_impl { }; /** - * @brief Indicates whether `type` is a nested type - * - * "Nested" types are distinct from compound types in that they - * can have an arbitrarily deep list of descendants of the same - * type. Strings are not a nested type, but lists are. + * @brief Indicates whether `type` is a struct type. * * @param type The `data_type` to verify - * @return true `type` is a nested type - * @return false `type` is not a nested type + * @return true `type` is a struct type + * @return false `type` is not a struct type */ constexpr inline bool is_struct(data_type type) { diff --git a/cpp/src/binaryop/compiled/ATan2.cu b/cpp/src/binaryop/compiled/ATan2.cu index e13756773b0..51df4048006 100644 --- a/cpp/src/binaryop/compiled/ATan2.cu +++ b/cpp/src/binaryop/compiled/ATan2.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Add.cu b/cpp/src/binaryop/compiled/Add.cu index 94f1eca0354..500333d32c3 100644 --- a/cpp/src/binaryop/compiled/Add.cu +++ b/cpp/src/binaryop/compiled/Add.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/BitwiseAnd.cu b/cpp/src/binaryop/compiled/BitwiseAnd.cu index d6cdd205977..071490cbd3e 100644 --- a/cpp/src/binaryop/compiled/BitwiseAnd.cu +++ b/cpp/src/binaryop/compiled/BitwiseAnd.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/BitwiseOr.cu b/cpp/src/binaryop/compiled/BitwiseOr.cu index 712a5cf40a7..b531d13f608 100644 --- a/cpp/src/binaryop/compiled/BitwiseOr.cu +++ b/cpp/src/binaryop/compiled/BitwiseOr.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/BitwiseXor.cu b/cpp/src/binaryop/compiled/BitwiseXor.cu index 4d40a8a2ed6..2a8ee0fd0c9 100644 --- a/cpp/src/binaryop/compiled/BitwiseXor.cu +++ b/cpp/src/binaryop/compiled/BitwiseXor.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Div.cu b/cpp/src/binaryop/compiled/Div.cu index 0cb5cdc90bb..4816e5891ac 100644 --- a/cpp/src/binaryop/compiled/Div.cu +++ b/cpp/src/binaryop/compiled/Div.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/FloorDiv.cu b/cpp/src/binaryop/compiled/FloorDiv.cu index 66a156ded88..bb892ab12e2 100644 --- a/cpp/src/binaryop/compiled/FloorDiv.cu +++ b/cpp/src/binaryop/compiled/FloorDiv.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Greater.cu b/cpp/src/binaryop/compiled/Greater.cu index 209b7c23f4a..fc7442b7f2e 100644 --- a/cpp/src/binaryop/compiled/Greater.cu +++ b/cpp/src/binaryop/compiled/Greater.cu @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "binary_ops.cuh" -#include "struct_binary_ops.cuh" +#include +#include namespace cudf::binops::compiled { template <> diff --git a/cpp/src/binaryop/compiled/GreaterEqual.cu b/cpp/src/binaryop/compiled/GreaterEqual.cu index e7d50d4713c..e1fbfd704f0 100644 --- a/cpp/src/binaryop/compiled/GreaterEqual.cu +++ b/cpp/src/binaryop/compiled/GreaterEqual.cu @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "binary_ops.cuh" -#include "struct_binary_ops.cuh" +#include +#include namespace cudf::binops::compiled { template <> diff --git a/cpp/src/binaryop/compiled/Less.cu b/cpp/src/binaryop/compiled/Less.cu index e45921162ac..1e45d38edaa 100644 --- a/cpp/src/binaryop/compiled/Less.cu +++ b/cpp/src/binaryop/compiled/Less.cu @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "binary_ops.cuh" -#include "struct_binary_ops.cuh" +#include +#include namespace cudf::binops::compiled { template <> diff --git a/cpp/src/binaryop/compiled/LessEqual.cu b/cpp/src/binaryop/compiled/LessEqual.cu index 534ba4e0acf..b1ef9be6044 100644 --- a/cpp/src/binaryop/compiled/LessEqual.cu +++ b/cpp/src/binaryop/compiled/LessEqual.cu @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "binary_ops.cuh" -#include "struct_binary_ops.cuh" +#include +#include namespace cudf::binops::compiled { template <> diff --git a/cpp/src/binaryop/compiled/LogBase.cu b/cpp/src/binaryop/compiled/LogBase.cu index dd9131f5f88..8c070ded7b0 100644 --- a/cpp/src/binaryop/compiled/LogBase.cu +++ b/cpp/src/binaryop/compiled/LogBase.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/LogicalAnd.cu b/cpp/src/binaryop/compiled/LogicalAnd.cu index ae2e7de0782..0f1e59a1462 100644 --- a/cpp/src/binaryop/compiled/LogicalAnd.cu +++ b/cpp/src/binaryop/compiled/LogicalAnd.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/LogicalOr.cu b/cpp/src/binaryop/compiled/LogicalOr.cu index c6981a8ba0c..2a43a46f0c1 100644 --- a/cpp/src/binaryop/compiled/LogicalOr.cu +++ b/cpp/src/binaryop/compiled/LogicalOr.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Mod.cu b/cpp/src/binaryop/compiled/Mod.cu index 706113503e7..d08127514e3 100644 --- a/cpp/src/binaryop/compiled/Mod.cu +++ b/cpp/src/binaryop/compiled/Mod.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Mul.cu b/cpp/src/binaryop/compiled/Mul.cu index a6010fd5c17..5384d0a62bc 100644 --- a/cpp/src/binaryop/compiled/Mul.cu +++ b/cpp/src/binaryop/compiled/Mul.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/NullMax.cu b/cpp/src/binaryop/compiled/NullMax.cu index 792cfbfca2f..914796663c8 100644 --- a/cpp/src/binaryop/compiled/NullMax.cu +++ b/cpp/src/binaryop/compiled/NullMax.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/NullMin.cu b/cpp/src/binaryop/compiled/NullMin.cu index f413dadc23c..0e3120c849f 100644 --- a/cpp/src/binaryop/compiled/NullMin.cu +++ b/cpp/src/binaryop/compiled/NullMin.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/PMod.cu b/cpp/src/binaryop/compiled/PMod.cu index faa1337b1bc..be71f0d4425 100644 --- a/cpp/src/binaryop/compiled/PMod.cu +++ b/cpp/src/binaryop/compiled/PMod.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Pow.cu b/cpp/src/binaryop/compiled/Pow.cu index 9ccd5a02d0b..92c44fe880a 100644 --- a/cpp/src/binaryop/compiled/Pow.cu +++ b/cpp/src/binaryop/compiled/Pow.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/PyMod.cu b/cpp/src/binaryop/compiled/PyMod.cu index 8260cd51b28..f9a9007c507 100644 --- a/cpp/src/binaryop/compiled/PyMod.cu +++ b/cpp/src/binaryop/compiled/PyMod.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/ShiftLeft.cu b/cpp/src/binaryop/compiled/ShiftLeft.cu index 100bcf93a2d..fd865452cb3 100644 --- a/cpp/src/binaryop/compiled/ShiftLeft.cu +++ b/cpp/src/binaryop/compiled/ShiftLeft.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/ShiftRight.cu b/cpp/src/binaryop/compiled/ShiftRight.cu index 7c9b3c6194d..d411306337c 100644 --- a/cpp/src/binaryop/compiled/ShiftRight.cu +++ b/cpp/src/binaryop/compiled/ShiftRight.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu index f539dda7f66..3eb22081626 100644 --- a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu +++ b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Sub.cu b/cpp/src/binaryop/compiled/Sub.cu index 3b93bd63d2b..2765edb53a0 100644 --- a/cpp/src/binaryop/compiled/Sub.cu +++ b/cpp/src/binaryop/compiled/Sub.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/TrueDiv.cu b/cpp/src/binaryop/compiled/TrueDiv.cu index c72e34e415c..8203c5df891 100644 --- a/cpp/src/binaryop/compiled/TrueDiv.cu +++ b/cpp/src/binaryop/compiled/TrueDiv.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index 7195474092e..93665b68f7d 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -14,9 +14,9 @@ * limitations under the License. */ -#include "binary_ops.hpp" -#include "operation.cuh" -#include "struct_binary_ops.cuh" +#include +#include +#include #include #include diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 6239b22f85d..6bb67a78939 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -16,8 +16,8 @@ #pragma once -#include "binary_ops.hpp" -#include "operation.cuh" +#include +#include #include #include diff --git a/cpp/src/binaryop/compiled/binary_ops.hpp b/cpp/src/binaryop/compiled/binary_ops.hpp index b36a0ed1e5e..f146afdc0a8 100644 --- a/cpp/src/binaryop/compiled/binary_ops.hpp +++ b/cpp/src/binaryop/compiled/binary_ops.hpp @@ -22,7 +22,6 @@ #include #include -#include "cudf/column/column_view.hpp" namespace cudf { // Forward declarations diff --git a/cpp/src/binaryop/compiled/equality_ops.cu b/cpp/src/binaryop/compiled/equality_ops.cu index 209a1d57db8..a62a34c84e2 100644 --- a/cpp/src/binaryop/compiled/equality_ops.cu +++ b/cpp/src/binaryop/compiled/equality_ops.cu @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "binary_ops.cuh" -#include "struct_binary_ops.cuh" +#include +#include #include #include diff --git a/cpp/src/binaryop/compiled/util.cpp b/cpp/src/binaryop/compiled/util.cpp index 16089bae893..e85bd302c66 100644 --- a/cpp/src/binaryop/compiled/util.cpp +++ b/cpp/src/binaryop/compiled/util.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "operation.cuh" +#include #include #include From 48d0355cad2445899844eb519244cd7b5c2c5c20 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Wed, 10 Nov 2021 19:59:49 -0800 Subject: [PATCH 16/54] move to new TU and remove common code --- cpp/CMakeLists.txt | 1 + cpp/src/binaryop/compiled/binary_ops.cu | 44 +------------- cpp/src/binaryop/compiled/equality_ops.cu | 19 +++--- .../binaryop/compiled/struct_binary_ops.cu | 59 +++++++++++++++++++ 4 files changed, 69 insertions(+), 54 deletions(-) create mode 100644 cpp/src/binaryop/compiled/struct_binary_ops.cu diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index cf7b5be0e3e..2b441d474cc 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -197,6 +197,7 @@ add_library( src/binaryop/compiled/ShiftLeft.cu src/binaryop/compiled/ShiftRight.cu src/binaryop/compiled/ShiftRightUnsigned.cu + src/binaryop/compiled/struct_binary_ops.cu src/binaryop/compiled/Sub.cu src/binaryop/compiled/TrueDiv.cu src/binaryop/compiled/util.cpp diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index 93665b68f7d..a76d2d0dd9f 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -311,6 +311,8 @@ void operator_dispatcher(mutable_column_view& out, binary_operator op, rmm::cuda_stream_view stream) { + if (!is_supported_operation(out.type(), lhs, rhs, binary_operator::LESS_EQUAL)) + CUDF_FAIL("Unsupported operator for these types"); // clang-format off switch (op) { case binary_operator::ADD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; @@ -381,48 +383,6 @@ void binary_operation(mutable_column_view& out, auto [rhsv, aux] = scalar_to_column_view(rhs, stream); operator_dispatcher(out, lhs, rhsv, false, true, op, stream); } - -namespace detail { -void struct_lexicographic_compare(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream) -{ - if (!is_supported_operation(out.type(), lhs, rhs, binary_operator::LESS_EQUAL)) - CUDF_FAIL("Unsupported operator for these types"); - auto const nullability = - structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) - ? structs::detail::column_nullability::FORCE - : structs::detail::column_nullability::MATCH_INCOMING; - auto const lhs_flattened = - structs::detail::flatten_nested_columns(table_view{{lhs}}, {}, {}, nullability); - auto const rhs_flattened = - structs::detail::flatten_nested_columns(table_view{{rhs}}, {}, {}, nullability); - - auto d_lhs = table_device_view::create(lhs_flattened); - auto d_rhs = table_device_view::create(rhs_flattened); - auto compare_orders = - cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); - - has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened) - ? struct_compare(out, - row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}, - is_lhs_scalar, - is_rhs_scalar, - flip_output, - stream) - : struct_compare(out, - row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}, - is_lhs_scalar, - is_rhs_scalar, - flip_output, - stream); -} -} // namespace detail } // namespace compiled } // namespace binops } // namespace cudf diff --git a/cpp/src/binaryop/compiled/equality_ops.cu b/cpp/src/binaryop/compiled/equality_ops.cu index a62a34c84e2..b56234b270f 100644 --- a/cpp/src/binaryop/compiled/equality_ops.cu +++ b/cpp/src/binaryop/compiled/equality_ops.cu @@ -44,22 +44,17 @@ void dispatch_equality_op(mutable_column_view& out, auto d_lhs = table_device_view::create(lhs_flattened); auto d_rhs = table_device_view::create(rhs_flattened); + auto const do_compare = [&](auto const& comp) { + detail::struct_compare( + out, comp, is_lhs_scalar, is_rhs_scalar, op == binary_operator::NOT_EQUAL, stream); + }; switch (op) { case binary_operator::EQUAL: case binary_operator::NOT_EQUAL: + has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened) - ? detail::struct_compare(out, - row_equality_comparator{*d_lhs, *d_rhs, true}, - is_lhs_scalar, - is_rhs_scalar, - op == binary_operator::NOT_EQUAL, - stream) - : detail::struct_compare(out, - row_equality_comparator{*d_lhs, *d_rhs, true}, - is_lhs_scalar, - is_rhs_scalar, - op == binary_operator::NOT_EQUAL, - stream); + ? do_compare(row_equality_comparator{*d_lhs, *d_rhs}) + : do_compare(row_equality_comparator{*d_lhs, *d_rhs}); break; default: CUDF_FAIL("Unsupported operator for these types"); } diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cu b/cpp/src/binaryop/compiled/struct_binary_ops.cu new file mode 100644 index 00000000000..553d89e7f11 --- /dev/null +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cu @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021, 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. + */ + +// #include +#include +// #include +// #include +#include +#include +#include + +namespace cudf::binops::compiled::detail { +// namespace { + +// } +void struct_lexicographic_compare(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + order op_order, + bool flip_output, + rmm::cuda_stream_view stream) +{ + auto const nullability = + structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) + ? structs::detail::column_nullability::FORCE + : structs::detail::column_nullability::MATCH_INCOMING; + auto const lhs_flattened = + structs::detail::flatten_nested_columns(table_view{{lhs}}, {}, {}, nullability); + auto const rhs_flattened = + structs::detail::flatten_nested_columns(table_view{{rhs}}, {}, {}, nullability); + + auto d_lhs = table_device_view::create(lhs_flattened); + auto d_rhs = table_device_view::create(rhs_flattened); + auto compare_orders = + cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); + + auto const do_compare = [&](auto const& comp) { + struct_compare(out, comp, is_lhs_scalar, is_rhs_scalar, flip_output, stream); + }; + has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened) + ? do_compare(row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}) + : do_compare(row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}); +} +} // namespace cudf::binops::compiled::detail \ No newline at end of file From 6cf0e169e81964001d58af246481664d1eb7d295 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Thu, 11 Nov 2021 10:50:51 -0800 Subject: [PATCH 17/54] fix logic errors and push down struct branching --- cpp/src/binaryop/compiled/Greater.cu | 7 +-- cpp/src/binaryop/compiled/GreaterEqual.cu | 7 +-- cpp/src/binaryop/compiled/Less.cu | 7 +-- cpp/src/binaryop/compiled/LessEqual.cu | 7 +-- cpp/src/binaryop/compiled/binary_ops.cu | 7 +-- cpp/src/binaryop/compiled/binary_ops.cuh | 9 ++- cpp/src/binaryop/compiled/equality_ops.cu | 4 -- .../binaryop/compiled/struct_binary_ops.cu | 59 ------------------- .../binaryop/compiled/struct_binary_ops.cuh | 50 ++++++++++++---- 9 files changed, 53 insertions(+), 104 deletions(-) delete mode 100644 cpp/src/binaryop/compiled/struct_binary_ops.cu diff --git a/cpp/src/binaryop/compiled/Greater.cu b/cpp/src/binaryop/compiled/Greater.cu index fc7442b7f2e..90c59ea0f91 100644 --- a/cpp/src/binaryop/compiled/Greater.cu +++ b/cpp/src/binaryop/compiled/Greater.cu @@ -26,10 +26,7 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream) { - is_struct(lhs.type()) && is_struct(rhs.type()) - ? detail::struct_lexicographic_compare( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, false, stream) - : detail::apply_unnested_binary_op( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); + detail::apply_struct_lexicographic_binop( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, false, stream); } } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/GreaterEqual.cu b/cpp/src/binaryop/compiled/GreaterEqual.cu index e1fbfd704f0..1afc175661c 100644 --- a/cpp/src/binaryop/compiled/GreaterEqual.cu +++ b/cpp/src/binaryop/compiled/GreaterEqual.cu @@ -26,10 +26,7 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream) { - is_struct(lhs.type()) && is_struct(rhs.type()) - ? detail::struct_lexicographic_compare( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, true, stream) - : detail::apply_unnested_binary_op( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); + detail::apply_struct_lexicographic_binop( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, true, stream); } } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/Less.cu b/cpp/src/binaryop/compiled/Less.cu index 1e45d38edaa..4a914f8462a 100644 --- a/cpp/src/binaryop/compiled/Less.cu +++ b/cpp/src/binaryop/compiled/Less.cu @@ -26,10 +26,7 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream) { - is_struct(lhs.type()) && is_struct(rhs.type()) - ? detail::struct_lexicographic_compare( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream) - : detail::apply_unnested_binary_op( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); + detail::apply_struct_lexicographic_binop( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); } } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/LessEqual.cu b/cpp/src/binaryop/compiled/LessEqual.cu index b1ef9be6044..85389b31985 100644 --- a/cpp/src/binaryop/compiled/LessEqual.cu +++ b/cpp/src/binaryop/compiled/LessEqual.cu @@ -26,10 +26,7 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream) { - is_struct(lhs.type()) && is_struct(rhs.type()) - ? detail::struct_lexicographic_compare( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, true, stream) - : detail::apply_unnested_binary_op( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); + detail::apply_struct_lexicographic_binop( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, true, stream); } } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index a76d2d0dd9f..d4341acd901 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -16,16 +16,11 @@ #include #include -#include #include #include -#include -#include #include #include -#include -#include #include #include @@ -311,7 +306,7 @@ void operator_dispatcher(mutable_column_view& out, binary_operator op, rmm::cuda_stream_view stream) { - if (!is_supported_operation(out.type(), lhs, rhs, binary_operator::LESS_EQUAL)) + if (!is_supported_operation(out.type(), lhs, rhs, op)) CUDF_FAIL("Unsupported operator for these types"); // clang-format off switch (op) { diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 6bb67a78939..17ceb863c1c 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -283,11 +283,10 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream) { - if (is_struct(lhs.type()) && is_struct(rhs.type())) { - CUDF_FAIL("Unsupported operator for these types"); - } - detail::apply_unnested_binary_op( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); + is_struct(lhs.type()) && is_struct(rhs.type()) + ? CUDF_FAIL("Unsupported operator for these types") + : detail::apply_unnested_binary_op( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); } } // namespace compiled diff --git a/cpp/src/binaryop/compiled/equality_ops.cu b/cpp/src/binaryop/compiled/equality_ops.cu index b56234b270f..cec761f28c9 100644 --- a/cpp/src/binaryop/compiled/equality_ops.cu +++ b/cpp/src/binaryop/compiled/equality_ops.cu @@ -30,9 +30,6 @@ void dispatch_equality_op(mutable_column_view& out, rmm::cuda_stream_view stream) { if (is_struct(lhs.type()) && is_struct(rhs.type())) { - if (!is_supported_operation(out.type(), lhs, rhs, op)) - CUDF_FAIL("Unsupported operator for these types"); - auto const nullability = structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) ? structs::detail::column_nullability::FORCE @@ -51,7 +48,6 @@ void dispatch_equality_op(mutable_column_view& out, switch (op) { case binary_operator::EQUAL: case binary_operator::NOT_EQUAL: - has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened) ? do_compare(row_equality_comparator{*d_lhs, *d_rhs}) : do_compare(row_equality_comparator{*d_lhs, *d_rhs}); diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cu b/cpp/src/binaryop/compiled/struct_binary_ops.cu deleted file mode 100644 index 553d89e7f11..00000000000 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cu +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2021, 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. - */ - -// #include -#include -// #include -// #include -#include -#include -#include - -namespace cudf::binops::compiled::detail { -// namespace { - -// } -void struct_lexicographic_compare(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream) -{ - auto const nullability = - structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) - ? structs::detail::column_nullability::FORCE - : structs::detail::column_nullability::MATCH_INCOMING; - auto const lhs_flattened = - structs::detail::flatten_nested_columns(table_view{{lhs}}, {}, {}, nullability); - auto const rhs_flattened = - structs::detail::flatten_nested_columns(table_view{{rhs}}, {}, {}, nullability); - - auto d_lhs = table_device_view::create(lhs_flattened); - auto d_rhs = table_device_view::create(rhs_flattened); - auto compare_orders = - cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); - - auto const do_compare = [&](auto const& comp) { - struct_compare(out, comp, is_lhs_scalar, is_rhs_scalar, flip_output, stream); - }; - has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened) - ? do_compare(row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}) - : do_compare(row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}); -} -} // namespace cudf::binops::compiled::detail \ No newline at end of file diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cuh b/cpp/src/binaryop/compiled/struct_binary_ops.cuh index b91dd763664..e0f1892d920 100644 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cuh +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cuh @@ -16,9 +16,12 @@ #pragma once -#include -#include +#include + #include +#include +#include +#include #include #include @@ -47,12 +50,39 @@ void struct_compare(mutable_column_view& out, }); } -void struct_lexicographic_compare(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); +template +void apply_struct_lexicographic_binop(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + order op_order, + bool flip_output, + rmm::cuda_stream_view stream) +{ + if (is_struct(lhs.type()) && is_struct(rhs.type())) { + auto const nullability = + structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) + ? structs::detail::column_nullability::FORCE + : structs::detail::column_nullability::MATCH_INCOMING; + auto const lhs_flattened = + structs::detail::flatten_nested_columns(table_view{{lhs}}, {}, {}, nullability); + auto const rhs_flattened = + structs::detail::flatten_nested_columns(table_view{{rhs}}, {}, {}, nullability); + + auto d_lhs = table_device_view::create(lhs_flattened); + auto d_rhs = table_device_view::create(rhs_flattened); + auto compare_orders = + cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); + + auto const do_compare = [&](auto const& comp) { + struct_compare(out, comp, is_lhs_scalar, is_rhs_scalar, flip_output, stream); + }; + has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened) + ? do_compare(row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}) + : do_compare(row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}); + } else { + apply_unnested_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); + } +} } // namespace cudf::binops::compiled::detail From 9ec2acfed165b9e0cd2452ffaa8260239e702bb8 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Thu, 11 Nov 2021 10:52:41 -0800 Subject: [PATCH 18/54] remove deleted file from CMakeLists --- cpp/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 2b441d474cc..cf7b5be0e3e 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -197,7 +197,6 @@ add_library( src/binaryop/compiled/ShiftLeft.cu src/binaryop/compiled/ShiftRight.cu src/binaryop/compiled/ShiftRightUnsigned.cu - src/binaryop/compiled/struct_binary_ops.cu src/binaryop/compiled/Sub.cu src/binaryop/compiled/TrueDiv.cu src/binaryop/compiled/util.cpp From 3016abfbf4ca186c739dc94c2d4981a0206ce454 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Thu, 11 Nov 2021 12:13:33 -0800 Subject: [PATCH 19/54] Naming and comment fixes --- cpp/include/cudf/detail/structs/utilities.hpp | 4 ++-- cpp/include/cudf/utilities/traits.hpp | 6 ++---- cpp/src/binaryop/compiled/Greater.cu | 2 +- cpp/src/binaryop/compiled/GreaterEqual.cu | 2 +- cpp/src/binaryop/compiled/Less.cu | 2 +- cpp/src/binaryop/compiled/LessEqual.cu | 2 +- cpp/src/binaryop/compiled/struct_binary_ops.cuh | 16 ++++++++-------- 7 files changed, 16 insertions(+), 18 deletions(-) diff --git a/cpp/include/cudf/detail/structs/utilities.hpp b/cpp/include/cudf/detail/structs/utilities.hpp index 5c4cdd027ab..64604a94f0e 100644 --- a/cpp/include/cudf/detail/structs/utilities.hpp +++ b/cpp/include/cudf/detail/structs/utilities.hpp @@ -255,8 +255,8 @@ std::tuple> superimpose_parent * operations. * * @param col Column to check for null structs - * @return true If the column is or contains a struct column with null structs - * @return false If the column is not a struct column or does not contain null structs + * @return A boolean indicating if the column is or contains a struct column that contains a null + * struct. */ bool contains_null_structs(column_view const& col); } // namespace detail diff --git a/cpp/include/cudf/utilities/traits.hpp b/cpp/include/cudf/utilities/traits.hpp index d6c28692dec..74b8f9a1fb6 100644 --- a/cpp/include/cudf/utilities/traits.hpp +++ b/cpp/include/cudf/utilities/traits.hpp @@ -677,8 +677,7 @@ constexpr inline bool is_nested(data_type type) * @brief Indicates whether `T` is a struct type. * * @param T The type to verify - * @return true T is a struct type - * @return false T is not a struct type + * @return A boolean indicating if T is a struct type */ template constexpr inline bool is_struct() @@ -698,8 +697,7 @@ struct is_struct_impl { * @brief Indicates whether `type` is a struct type. * * @param type The `data_type` to verify - * @return true `type` is a struct type - * @return false `type` is not a struct type + * @return A boolean indicating if `type` is a struct type */ constexpr inline bool is_struct(data_type type) { diff --git a/cpp/src/binaryop/compiled/Greater.cu b/cpp/src/binaryop/compiled/Greater.cu index 90c59ea0f91..345cf71e80e 100644 --- a/cpp/src/binaryop/compiled/Greater.cu +++ b/cpp/src/binaryop/compiled/Greater.cu @@ -26,7 +26,7 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream) { - detail::apply_struct_lexicographic_binop( + detail::generate_binop_result( out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, false, stream); } } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/GreaterEqual.cu b/cpp/src/binaryop/compiled/GreaterEqual.cu index 1afc175661c..ee374a0a5e3 100644 --- a/cpp/src/binaryop/compiled/GreaterEqual.cu +++ b/cpp/src/binaryop/compiled/GreaterEqual.cu @@ -26,7 +26,7 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream) { - detail::apply_struct_lexicographic_binop( + detail::generate_binop_result( out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, true, stream); } } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/Less.cu b/cpp/src/binaryop/compiled/Less.cu index 4a914f8462a..805a4c6d787 100644 --- a/cpp/src/binaryop/compiled/Less.cu +++ b/cpp/src/binaryop/compiled/Less.cu @@ -26,7 +26,7 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream) { - detail::apply_struct_lexicographic_binop( + detail::generate_binop_result( out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); } } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/LessEqual.cu b/cpp/src/binaryop/compiled/LessEqual.cu index 85389b31985..30b93495c34 100644 --- a/cpp/src/binaryop/compiled/LessEqual.cu +++ b/cpp/src/binaryop/compiled/LessEqual.cu @@ -26,7 +26,7 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream) { - detail::apply_struct_lexicographic_binop( + detail::generate_binop_result( out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, true, stream); } } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cuh b/cpp/src/binaryop/compiled/struct_binary_ops.cuh index e0f1892d920..b87a9147d3f 100644 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cuh +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cuh @@ -51,14 +51,14 @@ void struct_compare(mutable_column_view& out, } template -void apply_struct_lexicographic_binop(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream) +void generate_binop_result(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + order op_order, + bool flip_output, + rmm::cuda_stream_view stream) { if (is_struct(lhs.type()) && is_struct(rhs.type())) { auto const nullability = From b2a7973862c6331a94767861b1a0265da9b2d9e5 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Thu, 11 Nov 2021 13:20:17 -0800 Subject: [PATCH 20/54] naming --- cpp/src/binaryop/compiled/Greater.cu | 2 +- cpp/src/binaryop/compiled/GreaterEqual.cu | 2 +- cpp/src/binaryop/compiled/Less.cu | 2 +- cpp/src/binaryop/compiled/LessEqual.cu | 2 +- cpp/src/binaryop/compiled/struct_binary_ops.cuh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cpp/src/binaryop/compiled/Greater.cu b/cpp/src/binaryop/compiled/Greater.cu index 345cf71e80e..f4f9be42930 100644 --- a/cpp/src/binaryop/compiled/Greater.cu +++ b/cpp/src/binaryop/compiled/Greater.cu @@ -26,7 +26,7 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream) { - detail::generate_binop_result( + detail::apply_binary_op_impl( out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, false, stream); } } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/GreaterEqual.cu b/cpp/src/binaryop/compiled/GreaterEqual.cu index ee374a0a5e3..e7852fbf7d6 100644 --- a/cpp/src/binaryop/compiled/GreaterEqual.cu +++ b/cpp/src/binaryop/compiled/GreaterEqual.cu @@ -26,7 +26,7 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream) { - detail::generate_binop_result( + detail::apply_binary_op_impl( out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, true, stream); } } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/Less.cu b/cpp/src/binaryop/compiled/Less.cu index 805a4c6d787..3f9d3e660e1 100644 --- a/cpp/src/binaryop/compiled/Less.cu +++ b/cpp/src/binaryop/compiled/Less.cu @@ -26,7 +26,7 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream) { - detail::generate_binop_result( + detail::apply_binary_op_impl( out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); } } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/LessEqual.cu b/cpp/src/binaryop/compiled/LessEqual.cu index 30b93495c34..4c0a068b7bd 100644 --- a/cpp/src/binaryop/compiled/LessEqual.cu +++ b/cpp/src/binaryop/compiled/LessEqual.cu @@ -26,7 +26,7 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream) { - detail::generate_binop_result( + detail::apply_binary_op_impl( out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, true, stream); } } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cuh b/cpp/src/binaryop/compiled/struct_binary_ops.cuh index b87a9147d3f..424f3ed5d86 100644 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cuh +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cuh @@ -51,7 +51,7 @@ void struct_compare(mutable_column_view& out, } template -void generate_binop_result(mutable_column_view& out, +void apply_binary_op_impl(mutable_column_view& out, column_view const& lhs, column_view const& rhs, bool is_lhs_scalar, From 191da69edf3b19025f0d40d507e48a7aba3b6f50 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Thu, 11 Nov 2021 13:32:17 -0800 Subject: [PATCH 21/54] style formatting --- cpp/src/binaryop/compiled/struct_binary_ops.cuh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cuh b/cpp/src/binaryop/compiled/struct_binary_ops.cuh index 424f3ed5d86..b6b45e4441d 100644 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cuh +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cuh @@ -52,13 +52,13 @@ void struct_compare(mutable_column_view& out, template void apply_binary_op_impl(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream) + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + order op_order, + bool flip_output, + rmm::cuda_stream_view stream) { if (is_struct(lhs.type()) && is_struct(rhs.type())) { auto const nullability = From 2cf2b28618172519b21e3c14ef584ea75bca1fc4 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Fri, 12 Nov 2021 14:01:38 -0800 Subject: [PATCH 22/54] merge apply_binary_op and _impl implementation --- cpp/src/binaryop/compiled/ATan2.cu | 4 +- cpp/src/binaryop/compiled/Add.cu | 4 +- cpp/src/binaryop/compiled/BitwiseAnd.cu | 4 +- cpp/src/binaryop/compiled/BitwiseOr.cu | 4 +- cpp/src/binaryop/compiled/BitwiseXor.cu | 4 +- cpp/src/binaryop/compiled/Div.cu | 4 +- cpp/src/binaryop/compiled/FloorDiv.cu | 4 +- cpp/src/binaryop/compiled/Greater.cu | 20 +++--- cpp/src/binaryop/compiled/GreaterEqual.cu | 20 +++--- cpp/src/binaryop/compiled/Less.cu | 20 +++--- cpp/src/binaryop/compiled/LessEqual.cu | 20 +++--- cpp/src/binaryop/compiled/LogBase.cu | 4 +- cpp/src/binaryop/compiled/LogicalAnd.cu | 4 +- cpp/src/binaryop/compiled/LogicalOr.cu | 4 +- cpp/src/binaryop/compiled/Mod.cu | 4 +- cpp/src/binaryop/compiled/Mul.cu | 4 +- cpp/src/binaryop/compiled/NullMax.cu | 4 +- cpp/src/binaryop/compiled/NullMin.cu | 4 +- cpp/src/binaryop/compiled/PMod.cu | 4 +- cpp/src/binaryop/compiled/Pow.cu | 4 +- cpp/src/binaryop/compiled/PyMod.cu | 4 +- cpp/src/binaryop/compiled/ShiftLeft.cu | 4 +- cpp/src/binaryop/compiled/ShiftRight.cu | 4 +- .../binaryop/compiled/ShiftRightUnsigned.cu | 4 +- cpp/src/binaryop/compiled/Sub.cu | 4 +- cpp/src/binaryop/compiled/TrueDiv.cu | 4 +- cpp/src/binaryop/compiled/binary_ops.cu | 52 +++++++-------- cpp/src/binaryop/compiled/binary_ops.cuh | 66 +++++++++++-------- cpp/src/binaryop/compiled/binary_ops.hpp | 16 +++-- .../binaryop/compiled/struct_binary_ops.cuh | 40 ----------- cpp/src/binaryop/compiled/util.cpp | 6 +- 31 files changed, 178 insertions(+), 170 deletions(-) diff --git a/cpp/src/binaryop/compiled/ATan2.cu b/cpp/src/binaryop/compiled/ATan2.cu index 51df4048006..42edabcf944 100644 --- a/cpp/src/binaryop/compiled/ATan2.cu +++ b/cpp/src/binaryop/compiled/ATan2.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/Add.cu b/cpp/src/binaryop/compiled/Add.cu index 500333d32c3..d44e09b58b6 100644 --- a/cpp/src/binaryop/compiled/Add.cu +++ b/cpp/src/binaryop/compiled/Add.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/BitwiseAnd.cu b/cpp/src/binaryop/compiled/BitwiseAnd.cu index 071490cbd3e..01b1e7098ca 100644 --- a/cpp/src/binaryop/compiled/BitwiseAnd.cu +++ b/cpp/src/binaryop/compiled/BitwiseAnd.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/BitwiseOr.cu b/cpp/src/binaryop/compiled/BitwiseOr.cu index b531d13f608..7094b2b069f 100644 --- a/cpp/src/binaryop/compiled/BitwiseOr.cu +++ b/cpp/src/binaryop/compiled/BitwiseOr.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/BitwiseXor.cu b/cpp/src/binaryop/compiled/BitwiseXor.cu index 2a8ee0fd0c9..e9f6c90ff8a 100644 --- a/cpp/src/binaryop/compiled/BitwiseXor.cu +++ b/cpp/src/binaryop/compiled/BitwiseXor.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/Div.cu b/cpp/src/binaryop/compiled/Div.cu index 4816e5891ac..a3e01b4735d 100644 --- a/cpp/src/binaryop/compiled/Div.cu +++ b/cpp/src/binaryop/compiled/Div.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/FloorDiv.cu b/cpp/src/binaryop/compiled/FloorDiv.cu index bb892ab12e2..3f6c9e12459 100644 --- a/cpp/src/binaryop/compiled/FloorDiv.cu +++ b/cpp/src/binaryop/compiled/FloorDiv.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/Greater.cu b/cpp/src/binaryop/compiled/Greater.cu index f4f9be42930..1d6ca4badef 100644 --- a/cpp/src/binaryop/compiled/Greater.cu +++ b/cpp/src/binaryop/compiled/Greater.cu @@ -15,18 +15,14 @@ */ #include -#include namespace cudf::binops::compiled { -template <> -void apply_binary_op(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view stream) -{ - detail::apply_binary_op_impl( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, false, stream); +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, + bool is_lhs_scalar, + bool is_rhs_scalar, + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } -} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/GreaterEqual.cu b/cpp/src/binaryop/compiled/GreaterEqual.cu index e7852fbf7d6..5a0e04791ad 100644 --- a/cpp/src/binaryop/compiled/GreaterEqual.cu +++ b/cpp/src/binaryop/compiled/GreaterEqual.cu @@ -15,18 +15,14 @@ */ #include -#include namespace cudf::binops::compiled { -template <> -void apply_binary_op(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view stream) -{ - detail::apply_binary_op_impl( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, true, stream); +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, + bool is_lhs_scalar, + bool is_rhs_scalar, + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } -} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/Less.cu b/cpp/src/binaryop/compiled/Less.cu index 3f9d3e660e1..bbbd46c6f69 100644 --- a/cpp/src/binaryop/compiled/Less.cu +++ b/cpp/src/binaryop/compiled/Less.cu @@ -15,18 +15,14 @@ */ #include -#include namespace cudf::binops::compiled { -template <> -void apply_binary_op(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view stream) -{ - detail::apply_binary_op_impl( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, + bool is_lhs_scalar, + bool is_rhs_scalar, + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } -} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/LessEqual.cu b/cpp/src/binaryop/compiled/LessEqual.cu index 4c0a068b7bd..a7c1986f3fe 100644 --- a/cpp/src/binaryop/compiled/LessEqual.cu +++ b/cpp/src/binaryop/compiled/LessEqual.cu @@ -15,18 +15,14 @@ */ #include -#include namespace cudf::binops::compiled { -template <> -void apply_binary_op(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view stream) -{ - detail::apply_binary_op_impl( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, true, stream); +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, + bool is_lhs_scalar, + bool is_rhs_scalar, + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } -} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/LogBase.cu b/cpp/src/binaryop/compiled/LogBase.cu index 8c070ded7b0..86a04401bc5 100644 --- a/cpp/src/binaryop/compiled/LogBase.cu +++ b/cpp/src/binaryop/compiled/LogBase.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/LogicalAnd.cu b/cpp/src/binaryop/compiled/LogicalAnd.cu index 0f1e59a1462..537890e563c 100644 --- a/cpp/src/binaryop/compiled/LogicalAnd.cu +++ b/cpp/src/binaryop/compiled/LogicalAnd.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/LogicalOr.cu b/cpp/src/binaryop/compiled/LogicalOr.cu index 2a43a46f0c1..162cba32002 100644 --- a/cpp/src/binaryop/compiled/LogicalOr.cu +++ b/cpp/src/binaryop/compiled/LogicalOr.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/Mod.cu b/cpp/src/binaryop/compiled/Mod.cu index d08127514e3..60101b6c959 100644 --- a/cpp/src/binaryop/compiled/Mod.cu +++ b/cpp/src/binaryop/compiled/Mod.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/Mul.cu b/cpp/src/binaryop/compiled/Mul.cu index 5384d0a62bc..aa41cead374 100644 --- a/cpp/src/binaryop/compiled/Mul.cu +++ b/cpp/src/binaryop/compiled/Mul.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/NullMax.cu b/cpp/src/binaryop/compiled/NullMax.cu index 914796663c8..410b3c7c697 100644 --- a/cpp/src/binaryop/compiled/NullMax.cu +++ b/cpp/src/binaryop/compiled/NullMax.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/NullMin.cu b/cpp/src/binaryop/compiled/NullMin.cu index 0e3120c849f..48b1063e323 100644 --- a/cpp/src/binaryop/compiled/NullMin.cu +++ b/cpp/src/binaryop/compiled/NullMin.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/PMod.cu b/cpp/src/binaryop/compiled/PMod.cu index be71f0d4425..da821f401b2 100644 --- a/cpp/src/binaryop/compiled/PMod.cu +++ b/cpp/src/binaryop/compiled/PMod.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/Pow.cu b/cpp/src/binaryop/compiled/Pow.cu index 92c44fe880a..9cc0a94081d 100644 --- a/cpp/src/binaryop/compiled/Pow.cu +++ b/cpp/src/binaryop/compiled/Pow.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/PyMod.cu b/cpp/src/binaryop/compiled/PyMod.cu index f9a9007c507..18bbe60b6f3 100644 --- a/cpp/src/binaryop/compiled/PyMod.cu +++ b/cpp/src/binaryop/compiled/PyMod.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/ShiftLeft.cu b/cpp/src/binaryop/compiled/ShiftLeft.cu index fd865452cb3..81b96854da2 100644 --- a/cpp/src/binaryop/compiled/ShiftLeft.cu +++ b/cpp/src/binaryop/compiled/ShiftLeft.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/ShiftRight.cu b/cpp/src/binaryop/compiled/ShiftRight.cu index d411306337c..8d5a6f5490b 100644 --- a/cpp/src/binaryop/compiled/ShiftRight.cu +++ b/cpp/src/binaryop/compiled/ShiftRight.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu index 3eb22081626..61e87eb1f36 100644 --- a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu +++ b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/Sub.cu b/cpp/src/binaryop/compiled/Sub.cu index 2765edb53a0..91f7875d582 100644 --- a/cpp/src/binaryop/compiled/Sub.cu +++ b/cpp/src/binaryop/compiled/Sub.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/TrueDiv.cu b/cpp/src/binaryop/compiled/TrueDiv.cu index 8203c5df891..344d3647dd1 100644 --- a/cpp/src/binaryop/compiled/TrueDiv.cu +++ b/cpp/src/binaryop/compiled/TrueDiv.cu @@ -22,5 +22,7 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - rmm::cuda_stream_view); + order op_order, + bool flip_output, + rmm::cuda_stream_view stream); } diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index d4341acd901..8a8c7179958 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -310,40 +310,40 @@ void operator_dispatcher(mutable_column_view& out, CUDF_FAIL("Unsupported operator for these types"); // clang-format off switch (op) { -case binary_operator::ADD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::SUB: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::MUL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::TRUE_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::FLOOR_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::MOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::PYMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::POW: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::ADD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::SUB: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::MUL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::TRUE_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::FLOOR_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::MOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::PYMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::POW: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; case binary_operator::EQUAL: case binary_operator::NOT_EQUAL: case binary_operator::NULL_EQUALS: if(out.type().id() != type_id::BOOL8) CUDF_FAIL("Output type of Comparison operator should be bool type"); dispatch_equality_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::LESS: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::GREATER: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::LESS_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::GREATER_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::BITWISE_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::BITWISE_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::BITWISE_XOR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::LOGICAL_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::LOGICAL_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::LESS: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::GREATER: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, false, stream); break; +case binary_operator::LESS_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, true, stream); break; +case binary_operator::GREATER_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, true, stream); break; +case binary_operator::BITWISE_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::BITWISE_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::BITWISE_XOR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::LOGICAL_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::LOGICAL_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; /* case binary_operator::GENERIC_BINARY: // Cannot be compiled, should be called by jit::binary_operation */ -case binary_operator::SHIFT_LEFT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::SHIFT_RIGHT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::SHIFT_RIGHT_UNSIGNED: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::LOG_BASE: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::ATAN2: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::PMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::NULL_MAX: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::NULL_MIN: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::SHIFT_LEFT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::SHIFT_RIGHT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::SHIFT_RIGHT_UNSIGNED: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::LOG_BASE: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::ATAN2: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::PMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::NULL_MAX: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::NULL_MIN: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; default:; } // clang-format on diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 17ceb863c1c..87e803411c6 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -18,10 +18,14 @@ #include #include +#include #include #include +#include #include +#include +#include #include #include @@ -253,42 +257,50 @@ void for_each(rmm::cuda_stream_view stream, cudf::size_type size, Functor f) for_each_kernel<<>>(size, std::forward(f)); } -namespace detail { -template -void apply_unnested_binary_op(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view stream) -{ - auto common_dtype = get_common_type(out.type(), lhs.type(), rhs.type()); - - auto lhsd = column_device_view::create(lhs, stream); - auto rhsd = column_device_view::create(rhs, stream); - auto outd = mutable_column_device_view::create(out, stream); - // Create binop functor instance - auto binop_func = device_type_dispatcher{ - *outd, *lhsd, *rhsd, is_lhs_scalar, is_rhs_scalar, common_dtype}; - // Execute it on every element - for_each(stream, out.size(), binop_func); -} -} // namespace detail - template void apply_binary_op(mutable_column_view& out, column_view const& lhs, column_view const& rhs, bool is_lhs_scalar, bool is_rhs_scalar, + order op_order, + bool flip_output, rmm::cuda_stream_view stream) { - is_struct(lhs.type()) && is_struct(rhs.type()) - ? CUDF_FAIL("Unsupported operator for these types") - : detail::apply_unnested_binary_op( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); -} + if (is_struct(lhs.type()) && is_struct(rhs.type())) { + auto const nullability = + structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) + ? structs::detail::column_nullability::FORCE + : structs::detail::column_nullability::MATCH_INCOMING; + auto const lhs_flattened = + structs::detail::flatten_nested_columns(table_view{{lhs}}, {}, {}, nullability); + auto const rhs_flattened = + structs::detail::flatten_nested_columns(table_view{{rhs}}, {}, {}, nullability); + + auto d_lhs = table_device_view::create(lhs_flattened); + auto d_rhs = table_device_view::create(rhs_flattened); + auto compare_orders = + cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); + + auto const do_compare = [&](auto const& comp) { + detail::struct_compare(out, comp, is_lhs_scalar, is_rhs_scalar, flip_output, stream); + }; + has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened) + ? do_compare(row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}) + : do_compare(row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}); + } else { + auto common_dtype = get_common_type(out.type(), lhs.type(), rhs.type()); + auto lhsd = column_device_view::create(lhs, stream); + auto rhsd = column_device_view::create(rhs, stream); + auto outd = mutable_column_device_view::create(out, stream); + // Create binop functor instance + auto binop_func = device_type_dispatcher{ + *outd, *lhsd, *rhsd, is_lhs_scalar, is_rhs_scalar, common_dtype}; + // Execute it on every element + for_each(stream, out.size(), binop_func); + } +} } // namespace compiled } // namespace binops } // namespace cudf diff --git a/cpp/src/binaryop/compiled/binary_ops.hpp b/cpp/src/binaryop/compiled/binary_ops.hpp index f146afdc0a8..823b3b7f94f 100644 --- a/cpp/src/binaryop/compiled/binary_ops.hpp +++ b/cpp/src/binaryop/compiled/binary_ops.hpp @@ -204,18 +204,24 @@ bool is_supported_operation(data_type out, * @param rhsd device view of right operand column * @param is_lhs_scalar true if @p lhsd is a single element column representing a scalar * @param is_rhs_scalar true if @p rhsd is a single element column representing a scalar + * @param op_order order for row_lexicographic_comparator and only used by struct binary comparison + * operations + * @param flip_output true for or-equal comparison ops. Flips row_lexicographic_comparator results + * and only used by struct binary comparison operations * @param stream CUDA stream used for device memory operations */ template -void apply_binary_op(mutable_column_view&, - column_view const&, - column_view const&, +void apply_binary_op(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, bool is_lhs_scalar, bool is_rhs_scalar, + order op_order, + bool flip_output, rmm::cuda_stream_view stream); /** - * @brief Deploys single type or double type dispatcher that runs equality operation on each element - * of @p lhsd and @p rhsd columns. + * @brief Deploys single type or double type dispatcher that runs equality operation on each + * element of @p lhsd and @p rhsd columns. * * Comparison operators are EQUAL, NOT_EQUAL, NULL_EQUALS. * @p outd type is boolean. diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cuh b/cpp/src/binaryop/compiled/struct_binary_ops.cuh index b6b45e4441d..3ec58f95f98 100644 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cuh +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cuh @@ -16,11 +16,7 @@ #pragma once -#include - #include -#include -#include #include #include @@ -49,40 +45,4 @@ void struct_compare(mutable_column_view& out, (flip_output ? not compare(lhs, rhs) : compare(lhs, rhs)); }); } - -template -void apply_binary_op_impl(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream) -{ - if (is_struct(lhs.type()) && is_struct(rhs.type())) { - auto const nullability = - structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) - ? structs::detail::column_nullability::FORCE - : structs::detail::column_nullability::MATCH_INCOMING; - auto const lhs_flattened = - structs::detail::flatten_nested_columns(table_view{{lhs}}, {}, {}, nullability); - auto const rhs_flattened = - structs::detail::flatten_nested_columns(table_view{{rhs}}, {}, {}, nullability); - - auto d_lhs = table_device_view::create(lhs_flattened); - auto d_rhs = table_device_view::create(rhs_flattened); - auto compare_orders = - cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); - - auto const do_compare = [&](auto const& comp) { - struct_compare(out, comp, is_lhs_scalar, is_rhs_scalar, flip_output, stream); - }; - has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened) - ? do_compare(row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}) - : do_compare(row_lexicographic_comparator{*d_lhs, *d_rhs, compare_orders.data()}); - } else { - apply_unnested_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); - } -} } // namespace cudf::binops::compiled::detail diff --git a/cpp/src/binaryop/compiled/util.cpp b/cpp/src/binaryop/compiled/util.cpp index e85bd302c66..483c9b3b50e 100644 --- a/cpp/src/binaryop/compiled/util.cpp +++ b/cpp/src/binaryop/compiled/util.cpp @@ -184,8 +184,10 @@ std::optional get_common_type(data_type out, data_type lhs, data_type bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_operator op) { return double_type_dispatcher(lhs, rhs, is_supported_operation_functor{}, out, op) || - (is_struct(lhs) && is_struct(rhs) && op != binary_operator::GENERIC_BINARY && - op != binary_operator::INVALID_BINARY); + (is_struct(lhs) && is_struct(rhs) && + (op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL || + op == binary_operator::LESS || op == binary_operator::LESS_EQUAL || + op == binary_operator::GREATER || op == binary_operator::GREATER_EQUAL)); } bool is_supported_operation(data_type out, From 2b634c42a2b753739402e37d8ea00112bda40d04 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Fri, 12 Nov 2021 16:47:09 -0800 Subject: [PATCH 23/54] all apply_binary_op calls call apply_binary_op_impl --- cpp/src/binaryop/compiled/ATan2.cu | 4 +- cpp/src/binaryop/compiled/Add.cu | 4 +- cpp/src/binaryop/compiled/BitwiseAnd.cu | 4 +- cpp/src/binaryop/compiled/BitwiseOr.cu | 4 +- cpp/src/binaryop/compiled/BitwiseXor.cu | 4 +- cpp/src/binaryop/compiled/Div.cu | 4 +- cpp/src/binaryop/compiled/FloorDiv.cu | 4 +- cpp/src/binaryop/compiled/Greater.cu | 19 ++++--- cpp/src/binaryop/compiled/GreaterEqual.cu | 19 ++++--- cpp/src/binaryop/compiled/Less.cu | 4 +- cpp/src/binaryop/compiled/LessEqual.cu | 19 ++++--- cpp/src/binaryop/compiled/LogBase.cu | 4 +- cpp/src/binaryop/compiled/LogicalAnd.cu | 4 +- cpp/src/binaryop/compiled/LogicalOr.cu | 4 +- cpp/src/binaryop/compiled/Mod.cu | 4 +- cpp/src/binaryop/compiled/Mul.cu | 4 +- cpp/src/binaryop/compiled/NullMax.cu | 4 +- cpp/src/binaryop/compiled/NullMin.cu | 4 +- cpp/src/binaryop/compiled/PMod.cu | 4 +- cpp/src/binaryop/compiled/Pow.cu | 4 +- cpp/src/binaryop/compiled/PyMod.cu | 4 +- cpp/src/binaryop/compiled/ShiftLeft.cu | 4 +- cpp/src/binaryop/compiled/ShiftRight.cu | 4 +- .../binaryop/compiled/ShiftRightUnsigned.cu | 4 +- cpp/src/binaryop/compiled/Sub.cu | 4 +- cpp/src/binaryop/compiled/TrueDiv.cu | 4 +- cpp/src/binaryop/compiled/binary_ops.cu | 52 +++++++++---------- cpp/src/binaryop/compiled/binary_ops.cuh | 30 ++++++++--- cpp/src/binaryop/compiled/binary_ops.hpp | 6 --- 29 files changed, 104 insertions(+), 133 deletions(-) diff --git a/cpp/src/binaryop/compiled/ATan2.cu b/cpp/src/binaryop/compiled/ATan2.cu index 42edabcf944..51df4048006 100644 --- a/cpp/src/binaryop/compiled/ATan2.cu +++ b/cpp/src/binaryop/compiled/ATan2.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Add.cu b/cpp/src/binaryop/compiled/Add.cu index d44e09b58b6..500333d32c3 100644 --- a/cpp/src/binaryop/compiled/Add.cu +++ b/cpp/src/binaryop/compiled/Add.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/BitwiseAnd.cu b/cpp/src/binaryop/compiled/BitwiseAnd.cu index 01b1e7098ca..071490cbd3e 100644 --- a/cpp/src/binaryop/compiled/BitwiseAnd.cu +++ b/cpp/src/binaryop/compiled/BitwiseAnd.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/BitwiseOr.cu b/cpp/src/binaryop/compiled/BitwiseOr.cu index 7094b2b069f..b531d13f608 100644 --- a/cpp/src/binaryop/compiled/BitwiseOr.cu +++ b/cpp/src/binaryop/compiled/BitwiseOr.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/BitwiseXor.cu b/cpp/src/binaryop/compiled/BitwiseXor.cu index e9f6c90ff8a..2a8ee0fd0c9 100644 --- a/cpp/src/binaryop/compiled/BitwiseXor.cu +++ b/cpp/src/binaryop/compiled/BitwiseXor.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Div.cu b/cpp/src/binaryop/compiled/Div.cu index a3e01b4735d..4816e5891ac 100644 --- a/cpp/src/binaryop/compiled/Div.cu +++ b/cpp/src/binaryop/compiled/Div.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/FloorDiv.cu b/cpp/src/binaryop/compiled/FloorDiv.cu index 3f6c9e12459..bb892ab12e2 100644 --- a/cpp/src/binaryop/compiled/FloorDiv.cu +++ b/cpp/src/binaryop/compiled/FloorDiv.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Greater.cu b/cpp/src/binaryop/compiled/Greater.cu index 1d6ca4badef..216b41a0ebc 100644 --- a/cpp/src/binaryop/compiled/Greater.cu +++ b/cpp/src/binaryop/compiled/Greater.cu @@ -17,12 +17,15 @@ #include namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_view&, - column_view const&, - column_view const&, - bool is_lhs_scalar, - bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); +template <> +void apply_binary_op(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + rmm::cuda_stream_view stream) +{ + detail::apply_binary_op_impl( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, false, stream); } +} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/GreaterEqual.cu b/cpp/src/binaryop/compiled/GreaterEqual.cu index 5a0e04791ad..498fc208743 100644 --- a/cpp/src/binaryop/compiled/GreaterEqual.cu +++ b/cpp/src/binaryop/compiled/GreaterEqual.cu @@ -17,12 +17,15 @@ #include namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_view&, - column_view const&, - column_view const&, - bool is_lhs_scalar, - bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); +template <> +void apply_binary_op(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + rmm::cuda_stream_view stream) +{ + detail::apply_binary_op_impl( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, true, stream); } +} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/Less.cu b/cpp/src/binaryop/compiled/Less.cu index bbbd46c6f69..561ed9fab0b 100644 --- a/cpp/src/binaryop/compiled/Less.cu +++ b/cpp/src/binaryop/compiled/Less.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/LessEqual.cu b/cpp/src/binaryop/compiled/LessEqual.cu index a7c1986f3fe..326f08072b1 100644 --- a/cpp/src/binaryop/compiled/LessEqual.cu +++ b/cpp/src/binaryop/compiled/LessEqual.cu @@ -17,12 +17,15 @@ #include namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_view&, - column_view const&, - column_view const&, - bool is_lhs_scalar, - bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); +template <> +void apply_binary_op(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + rmm::cuda_stream_view stream) +{ + detail::apply_binary_op_impl( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, true, stream); } +} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/LogBase.cu b/cpp/src/binaryop/compiled/LogBase.cu index 86a04401bc5..8c070ded7b0 100644 --- a/cpp/src/binaryop/compiled/LogBase.cu +++ b/cpp/src/binaryop/compiled/LogBase.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/LogicalAnd.cu b/cpp/src/binaryop/compiled/LogicalAnd.cu index 537890e563c..0f1e59a1462 100644 --- a/cpp/src/binaryop/compiled/LogicalAnd.cu +++ b/cpp/src/binaryop/compiled/LogicalAnd.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/LogicalOr.cu b/cpp/src/binaryop/compiled/LogicalOr.cu index 162cba32002..2a43a46f0c1 100644 --- a/cpp/src/binaryop/compiled/LogicalOr.cu +++ b/cpp/src/binaryop/compiled/LogicalOr.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Mod.cu b/cpp/src/binaryop/compiled/Mod.cu index 60101b6c959..d08127514e3 100644 --- a/cpp/src/binaryop/compiled/Mod.cu +++ b/cpp/src/binaryop/compiled/Mod.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Mul.cu b/cpp/src/binaryop/compiled/Mul.cu index aa41cead374..5384d0a62bc 100644 --- a/cpp/src/binaryop/compiled/Mul.cu +++ b/cpp/src/binaryop/compiled/Mul.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/NullMax.cu b/cpp/src/binaryop/compiled/NullMax.cu index 410b3c7c697..914796663c8 100644 --- a/cpp/src/binaryop/compiled/NullMax.cu +++ b/cpp/src/binaryop/compiled/NullMax.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/NullMin.cu b/cpp/src/binaryop/compiled/NullMin.cu index 48b1063e323..0e3120c849f 100644 --- a/cpp/src/binaryop/compiled/NullMin.cu +++ b/cpp/src/binaryop/compiled/NullMin.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/PMod.cu b/cpp/src/binaryop/compiled/PMod.cu index da821f401b2..be71f0d4425 100644 --- a/cpp/src/binaryop/compiled/PMod.cu +++ b/cpp/src/binaryop/compiled/PMod.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Pow.cu b/cpp/src/binaryop/compiled/Pow.cu index 9cc0a94081d..92c44fe880a 100644 --- a/cpp/src/binaryop/compiled/Pow.cu +++ b/cpp/src/binaryop/compiled/Pow.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/PyMod.cu b/cpp/src/binaryop/compiled/PyMod.cu index 18bbe60b6f3..f9a9007c507 100644 --- a/cpp/src/binaryop/compiled/PyMod.cu +++ b/cpp/src/binaryop/compiled/PyMod.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/ShiftLeft.cu b/cpp/src/binaryop/compiled/ShiftLeft.cu index 81b96854da2..fd865452cb3 100644 --- a/cpp/src/binaryop/compiled/ShiftLeft.cu +++ b/cpp/src/binaryop/compiled/ShiftLeft.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/ShiftRight.cu b/cpp/src/binaryop/compiled/ShiftRight.cu index 8d5a6f5490b..d411306337c 100644 --- a/cpp/src/binaryop/compiled/ShiftRight.cu +++ b/cpp/src/binaryop/compiled/ShiftRight.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu index 61e87eb1f36..3eb22081626 100644 --- a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu +++ b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Sub.cu b/cpp/src/binaryop/compiled/Sub.cu index 91f7875d582..2765edb53a0 100644 --- a/cpp/src/binaryop/compiled/Sub.cu +++ b/cpp/src/binaryop/compiled/Sub.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/TrueDiv.cu b/cpp/src/binaryop/compiled/TrueDiv.cu index 344d3647dd1..8203c5df891 100644 --- a/cpp/src/binaryop/compiled/TrueDiv.cu +++ b/cpp/src/binaryop/compiled/TrueDiv.cu @@ -22,7 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream); + rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index 8a8c7179958..d4341acd901 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -310,40 +310,40 @@ void operator_dispatcher(mutable_column_view& out, CUDF_FAIL("Unsupported operator for these types"); // clang-format off switch (op) { -case binary_operator::ADD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::SUB: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::MUL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::TRUE_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::FLOOR_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::MOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::PYMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::POW: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::ADD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::SUB: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::MUL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::TRUE_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::FLOOR_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::MOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::PYMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::POW: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; case binary_operator::EQUAL: case binary_operator::NOT_EQUAL: case binary_operator::NULL_EQUALS: if(out.type().id() != type_id::BOOL8) CUDF_FAIL("Output type of Comparison operator should be bool type"); dispatch_equality_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::LESS: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::GREATER: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, false, stream); break; -case binary_operator::LESS_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, true, stream); break; -case binary_operator::GREATER_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, true, stream); break; -case binary_operator::BITWISE_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::BITWISE_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::BITWISE_XOR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::LOGICAL_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::LOGICAL_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::LESS: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::GREATER: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::LESS_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::GREATER_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::BITWISE_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::BITWISE_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::BITWISE_XOR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::LOGICAL_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::LOGICAL_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; /* case binary_operator::GENERIC_BINARY: // Cannot be compiled, should be called by jit::binary_operation */ -case binary_operator::SHIFT_LEFT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::SHIFT_RIGHT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::SHIFT_RIGHT_UNSIGNED: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::LOG_BASE: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::ATAN2: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::PMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::NULL_MAX: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; -case binary_operator::NULL_MIN: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); break; +case binary_operator::SHIFT_LEFT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::SHIFT_RIGHT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::SHIFT_RIGHT_UNSIGNED: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::LOG_BASE: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::ATAN2: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::PMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::NULL_MAX: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::NULL_MIN: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; default:; } // clang-format on diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 87e803411c6..3baf3684192 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -257,15 +257,16 @@ void for_each(rmm::cuda_stream_view stream, cudf::size_type size, Functor f) for_each_kernel<<>>(size, std::forward(f)); } +namespace detail { template -void apply_binary_op(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream) +void apply_binary_op_impl(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + order op_order, + bool flip_output, + rmm::cuda_stream_view stream) { if (is_struct(lhs.type()) && is_struct(rhs.type())) { auto const nullability = @@ -301,6 +302,19 @@ void apply_binary_op(mutable_column_view& out, for_each(stream, out.size(), binop_func); } } +} // namespace detail + +template +void apply_binary_op(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + rmm::cuda_stream_view stream) +{ + detail::apply_binary_op_impl( + out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); +} } // namespace compiled } // namespace binops } // namespace cudf diff --git a/cpp/src/binaryop/compiled/binary_ops.hpp b/cpp/src/binaryop/compiled/binary_ops.hpp index 823b3b7f94f..85448a2de34 100644 --- a/cpp/src/binaryop/compiled/binary_ops.hpp +++ b/cpp/src/binaryop/compiled/binary_ops.hpp @@ -204,10 +204,6 @@ bool is_supported_operation(data_type out, * @param rhsd device view of right operand column * @param is_lhs_scalar true if @p lhsd is a single element column representing a scalar * @param is_rhs_scalar true if @p rhsd is a single element column representing a scalar - * @param op_order order for row_lexicographic_comparator and only used by struct binary comparison - * operations - * @param flip_output true for or-equal comparison ops. Flips row_lexicographic_comparator results - * and only used by struct binary comparison operations * @param stream CUDA stream used for device memory operations */ template @@ -216,8 +212,6 @@ void apply_binary_op(mutable_column_view& out, column_view const& rhs, bool is_lhs_scalar, bool is_rhs_scalar, - order op_order, - bool flip_output, rmm::cuda_stream_view stream); /** * @brief Deploys single type or double type dispatcher that runs equality operation on each From 19f1afbc37f8a52c4be64d34bd643760ccd757d4 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 22 Nov 2021 16:02:45 -0800 Subject: [PATCH 24/54] common code path --- cpp/src/binaryop/compiled/ATan2.cu | 1 + cpp/src/binaryop/compiled/Add.cu | 1 + cpp/src/binaryop/compiled/BitwiseAnd.cu | 1 + cpp/src/binaryop/compiled/BitwiseOr.cu | 1 + cpp/src/binaryop/compiled/BitwiseXor.cu | 1 + cpp/src/binaryop/compiled/Div.cu | 1 + cpp/src/binaryop/compiled/FloorDiv.cu | 1 + cpp/src/binaryop/compiled/Greater.cu | 18 +++---- cpp/src/binaryop/compiled/GreaterEqual.cu | 18 +++---- cpp/src/binaryop/compiled/Less.cu | 1 + cpp/src/binaryop/compiled/LessEqual.cu | 18 +++---- cpp/src/binaryop/compiled/LogBase.cu | 1 + cpp/src/binaryop/compiled/LogicalAnd.cu | 1 + cpp/src/binaryop/compiled/LogicalOr.cu | 1 + cpp/src/binaryop/compiled/Mod.cu | 1 + cpp/src/binaryop/compiled/Mul.cu | 1 + cpp/src/binaryop/compiled/NullMax.cu | 1 + cpp/src/binaryop/compiled/NullMin.cu | 1 + cpp/src/binaryop/compiled/PMod.cu | 1 + cpp/src/binaryop/compiled/Pow.cu | 1 + cpp/src/binaryop/compiled/PyMod.cu | 1 + cpp/src/binaryop/compiled/ShiftLeft.cu | 1 + cpp/src/binaryop/compiled/ShiftRight.cu | 1 + .../binaryop/compiled/ShiftRightUnsigned.cu | 1 + cpp/src/binaryop/compiled/Sub.cu | 1 + cpp/src/binaryop/compiled/TrueDiv.cu | 1 + cpp/src/binaryop/compiled/binary_ops.cu | 52 +++++++++---------- cpp/src/binaryop/compiled/binary_ops.cuh | 33 ++++-------- cpp/src/binaryop/compiled/binary_ops.hpp | 1 + 29 files changed, 82 insertions(+), 81 deletions(-) diff --git a/cpp/src/binaryop/compiled/ATan2.cu b/cpp/src/binaryop/compiled/ATan2.cu index 51df4048006..163e8ec7a38 100644 --- a/cpp/src/binaryop/compiled/ATan2.cu +++ b/cpp/src/binaryop/compiled/ATan2.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Add.cu b/cpp/src/binaryop/compiled/Add.cu index 500333d32c3..6eea65b5c29 100644 --- a/cpp/src/binaryop/compiled/Add.cu +++ b/cpp/src/binaryop/compiled/Add.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/BitwiseAnd.cu b/cpp/src/binaryop/compiled/BitwiseAnd.cu index 071490cbd3e..7d8a5d8d51c 100644 --- a/cpp/src/binaryop/compiled/BitwiseAnd.cu +++ b/cpp/src/binaryop/compiled/BitwiseAnd.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/BitwiseOr.cu b/cpp/src/binaryop/compiled/BitwiseOr.cu index b531d13f608..90c8565785e 100644 --- a/cpp/src/binaryop/compiled/BitwiseOr.cu +++ b/cpp/src/binaryop/compiled/BitwiseOr.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/BitwiseXor.cu b/cpp/src/binaryop/compiled/BitwiseXor.cu index 2a8ee0fd0c9..d8ba9db77fb 100644 --- a/cpp/src/binaryop/compiled/BitwiseXor.cu +++ b/cpp/src/binaryop/compiled/BitwiseXor.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Div.cu b/cpp/src/binaryop/compiled/Div.cu index 4816e5891ac..a7f3aaf13a8 100644 --- a/cpp/src/binaryop/compiled/Div.cu +++ b/cpp/src/binaryop/compiled/Div.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/FloorDiv.cu b/cpp/src/binaryop/compiled/FloorDiv.cu index bb892ab12e2..67e533b9547 100644 --- a/cpp/src/binaryop/compiled/FloorDiv.cu +++ b/cpp/src/binaryop/compiled/FloorDiv.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Greater.cu b/cpp/src/binaryop/compiled/Greater.cu index 216b41a0ebc..97ac2b3e7e8 100644 --- a/cpp/src/binaryop/compiled/Greater.cu +++ b/cpp/src/binaryop/compiled/Greater.cu @@ -17,15 +17,11 @@ #include namespace cudf::binops::compiled { -template <> -void apply_binary_op(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view stream) -{ - detail::apply_binary_op_impl( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, false, stream); +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, + bool is_lhs_scalar, + bool is_rhs_scalar, + binary_operator op, + rmm::cuda_stream_view); } -} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/GreaterEqual.cu b/cpp/src/binaryop/compiled/GreaterEqual.cu index 498fc208743..47d3d59826f 100644 --- a/cpp/src/binaryop/compiled/GreaterEqual.cu +++ b/cpp/src/binaryop/compiled/GreaterEqual.cu @@ -17,15 +17,11 @@ #include namespace cudf::binops::compiled { -template <> -void apply_binary_op(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view stream) -{ - detail::apply_binary_op_impl( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, true, stream); +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, + bool is_lhs_scalar, + bool is_rhs_scalar, + binary_operator op, + rmm::cuda_stream_view); } -} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/Less.cu b/cpp/src/binaryop/compiled/Less.cu index 561ed9fab0b..0942d9e1a24 100644 --- a/cpp/src/binaryop/compiled/Less.cu +++ b/cpp/src/binaryop/compiled/Less.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/LessEqual.cu b/cpp/src/binaryop/compiled/LessEqual.cu index 326f08072b1..743ad5f24bd 100644 --- a/cpp/src/binaryop/compiled/LessEqual.cu +++ b/cpp/src/binaryop/compiled/LessEqual.cu @@ -17,15 +17,11 @@ #include namespace cudf::binops::compiled { -template <> -void apply_binary_op(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view stream) -{ - detail::apply_binary_op_impl( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::DESCENDING, true, stream); +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, + bool is_lhs_scalar, + bool is_rhs_scalar, + binary_operator op, + rmm::cuda_stream_view); } -} // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/LogBase.cu b/cpp/src/binaryop/compiled/LogBase.cu index 8c070ded7b0..2cf5f8a61e0 100644 --- a/cpp/src/binaryop/compiled/LogBase.cu +++ b/cpp/src/binaryop/compiled/LogBase.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/LogicalAnd.cu b/cpp/src/binaryop/compiled/LogicalAnd.cu index 0f1e59a1462..7f4fb44d8cb 100644 --- a/cpp/src/binaryop/compiled/LogicalAnd.cu +++ b/cpp/src/binaryop/compiled/LogicalAnd.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/LogicalOr.cu b/cpp/src/binaryop/compiled/LogicalOr.cu index 2a43a46f0c1..3613d11fa0e 100644 --- a/cpp/src/binaryop/compiled/LogicalOr.cu +++ b/cpp/src/binaryop/compiled/LogicalOr.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Mod.cu b/cpp/src/binaryop/compiled/Mod.cu index d08127514e3..1854ec21121 100644 --- a/cpp/src/binaryop/compiled/Mod.cu +++ b/cpp/src/binaryop/compiled/Mod.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Mul.cu b/cpp/src/binaryop/compiled/Mul.cu index 5384d0a62bc..58f7d91dcb3 100644 --- a/cpp/src/binaryop/compiled/Mul.cu +++ b/cpp/src/binaryop/compiled/Mul.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/NullMax.cu b/cpp/src/binaryop/compiled/NullMax.cu index 914796663c8..c32e5d55b90 100644 --- a/cpp/src/binaryop/compiled/NullMax.cu +++ b/cpp/src/binaryop/compiled/NullMax.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/NullMin.cu b/cpp/src/binaryop/compiled/NullMin.cu index 0e3120c849f..b653039695a 100644 --- a/cpp/src/binaryop/compiled/NullMin.cu +++ b/cpp/src/binaryop/compiled/NullMin.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/PMod.cu b/cpp/src/binaryop/compiled/PMod.cu index be71f0d4425..bd99bcf8d7d 100644 --- a/cpp/src/binaryop/compiled/PMod.cu +++ b/cpp/src/binaryop/compiled/PMod.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Pow.cu b/cpp/src/binaryop/compiled/Pow.cu index 92c44fe880a..cdf60e47aef 100644 --- a/cpp/src/binaryop/compiled/Pow.cu +++ b/cpp/src/binaryop/compiled/Pow.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/PyMod.cu b/cpp/src/binaryop/compiled/PyMod.cu index f9a9007c507..5bf0e72449f 100644 --- a/cpp/src/binaryop/compiled/PyMod.cu +++ b/cpp/src/binaryop/compiled/PyMod.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/ShiftLeft.cu b/cpp/src/binaryop/compiled/ShiftLeft.cu index fd865452cb3..8a6eeeef817 100644 --- a/cpp/src/binaryop/compiled/ShiftLeft.cu +++ b/cpp/src/binaryop/compiled/ShiftLeft.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/ShiftRight.cu b/cpp/src/binaryop/compiled/ShiftRight.cu index d411306337c..f993940d696 100644 --- a/cpp/src/binaryop/compiled/ShiftRight.cu +++ b/cpp/src/binaryop/compiled/ShiftRight.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu index 3eb22081626..845ad76e6d4 100644 --- a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu +++ b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Sub.cu b/cpp/src/binaryop/compiled/Sub.cu index 2765edb53a0..4d10826a732 100644 --- a/cpp/src/binaryop/compiled/Sub.cu +++ b/cpp/src/binaryop/compiled/Sub.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/TrueDiv.cu b/cpp/src/binaryop/compiled/TrueDiv.cu index 8203c5df891..12d8162e151 100644 --- a/cpp/src/binaryop/compiled/TrueDiv.cu +++ b/cpp/src/binaryop/compiled/TrueDiv.cu @@ -22,5 +22,6 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index d4341acd901..3d1bf6ea5ca 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -310,40 +310,40 @@ void operator_dispatcher(mutable_column_view& out, CUDF_FAIL("Unsupported operator for these types"); // clang-format off switch (op) { -case binary_operator::ADD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::SUB: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::MUL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::TRUE_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::FLOOR_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::MOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::PYMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::POW: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::ADD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::SUB: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::MUL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::TRUE_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::FLOOR_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::MOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::PYMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::POW: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; case binary_operator::EQUAL: case binary_operator::NOT_EQUAL: case binary_operator::NULL_EQUALS: if(out.type().id() != type_id::BOOL8) CUDF_FAIL("Output type of Comparison operator should be bool type"); dispatch_equality_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::LESS: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::GREATER: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::LESS_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::GREATER_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::BITWISE_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::BITWISE_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::BITWISE_XOR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::LOGICAL_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::LOGICAL_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::LESS: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::GREATER: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::LESS_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::GREATER_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::BITWISE_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::BITWISE_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::BITWISE_XOR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::LOGICAL_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::LOGICAL_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; /* case binary_operator::GENERIC_BINARY: // Cannot be compiled, should be called by jit::binary_operation */ -case binary_operator::SHIFT_LEFT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::SHIFT_RIGHT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::SHIFT_RIGHT_UNSIGNED: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::LOG_BASE: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::ATAN2: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::PMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::NULL_MAX: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; -case binary_operator::NULL_MIN: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::SHIFT_LEFT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::SHIFT_RIGHT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::SHIFT_RIGHT_UNSIGNED: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::LOG_BASE: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::ATAN2: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::PMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::NULL_MAX: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::NULL_MIN: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; default:; } // clang-format on diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 3baf3684192..5090be47e96 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -257,18 +257,20 @@ void for_each(rmm::cuda_stream_view stream, cudf::size_type size, Functor f) for_each_kernel<<>>(size, std::forward(f)); } -namespace detail { template -void apply_binary_op_impl(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - order op_order, - bool flip_output, - rmm::cuda_stream_view stream) +void apply_binary_op(mutable_column_view& out, + column_view const& lhs, + column_view const& rhs, + bool is_lhs_scalar, + bool is_rhs_scalar, + binary_operator op, + rmm::cuda_stream_view stream) { if (is_struct(lhs.type()) && is_struct(rhs.type())) { + auto op_order = (binary_operator::GREATER == op || binary_operator::LESS_EQUAL == op) + ? order::DESCENDING + : order::ASCENDING; + auto flip_output = (binary_operator::GREATER_EQUAL == op || binary_operator::LESS_EQUAL == op); auto const nullability = structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) ? structs::detail::column_nullability::FORCE @@ -302,19 +304,6 @@ void apply_binary_op_impl(mutable_column_view& out, for_each(stream, out.size(), binop_func); } } -} // namespace detail - -template -void apply_binary_op(mutable_column_view& out, - column_view const& lhs, - column_view const& rhs, - bool is_lhs_scalar, - bool is_rhs_scalar, - rmm::cuda_stream_view stream) -{ - detail::apply_binary_op_impl( - out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, order::ASCENDING, false, stream); -} } // namespace compiled } // namespace binops } // namespace cudf diff --git a/cpp/src/binaryop/compiled/binary_ops.hpp b/cpp/src/binaryop/compiled/binary_ops.hpp index 85448a2de34..6865a42415a 100644 --- a/cpp/src/binaryop/compiled/binary_ops.hpp +++ b/cpp/src/binaryop/compiled/binary_ops.hpp @@ -212,6 +212,7 @@ void apply_binary_op(mutable_column_view& out, column_view const& rhs, bool is_lhs_scalar, bool is_rhs_scalar, + binary_operator op, rmm::cuda_stream_view stream); /** * @brief Deploys single type or double type dispatcher that runs equality operation on each From f316a0aa3335c9a94081251255ce7aa3b11522cf Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Tue, 23 Nov 2021 13:42:25 -0800 Subject: [PATCH 25/54] explicit instantiation of struct_compare --- cpp/CMakeLists.txt | 1 + .../binaryop/compiled/struct_binary_ops.cu | 77 +++++++++++++++++++ .../binaryop/compiled/struct_binary_ops.cuh | 23 +----- 3 files changed, 79 insertions(+), 22 deletions(-) create mode 100644 cpp/src/binaryop/compiled/struct_binary_ops.cu diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index cf7b5be0e3e..e8f41296a01 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -172,6 +172,7 @@ add_library( src/ast/expressions.cpp src/binaryop/binaryop.cpp src/binaryop/compiled/binary_ops.cu + src/binaryop/compiled/struct_binary_ops.cu src/binaryop/compiled/Add.cu src/binaryop/compiled/ATan2.cu src/binaryop/compiled/BitwiseAnd.cu diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cu b/cpp/src/binaryop/compiled/struct_binary_ops.cu new file mode 100644 index 00000000000..aed13e130a5 --- /dev/null +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cu @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021, 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. + */ + +#include +#include + +#include +#include + +namespace cudf { +namespace binops::compiled::detail { +template +void struct_compare(mutable_column_view& out, + Comparator compare, + bool is_lhs_scalar, + bool is_rhs_scalar, + bool flip_output, + rmm::cuda_stream_view stream) +{ + auto d_out = column_device_view::create(out, stream); + auto optional_iter = + cudf::detail::make_optional_iterator(*d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); + thrust::tabulate( + rmm::exec_policy(stream), + out.begin(), + out.end(), + [optional_iter, is_lhs_scalar, is_rhs_scalar, flip_output, compare] __device__(size_type i) { + auto lhs = is_lhs_scalar ? 0 : i; + auto rhs = is_rhs_scalar ? 0 : i; + return optional_iter[i].has_value() and + (flip_output ? not compare(lhs, rhs) : compare(lhs, rhs)); + }); +} +} // namespace binops::compiled::detail + +template void binops::compiled::detail::struct_compare>( + mutable_column_view& out, + row_lexicographic_comparator compare, + bool is_lhs_scalar, + bool is_rhs_scalar, + bool flip_output, + rmm::cuda_stream_view stream); +template void binops::compiled::detail::struct_compare>( + mutable_column_view& out, + row_lexicographic_comparator compare, + bool is_lhs_scalar, + bool is_rhs_scalar, + bool flip_output, + rmm::cuda_stream_view stream); +template void binops::compiled::detail::struct_compare>( + mutable_column_view& out, + row_equality_comparator compare, + bool is_lhs_scalar, + bool is_rhs_scalar, + bool flip_output, + rmm::cuda_stream_view stream); +template void binops::compiled::detail::struct_compare>( + mutable_column_view& out, + row_equality_comparator compare, + bool is_lhs_scalar, + bool is_rhs_scalar, + bool flip_output, + rmm::cuda_stream_view stream); +} // namespace cudf diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cuh b/cpp/src/binaryop/compiled/struct_binary_ops.cuh index 3ec58f95f98..e62d30ebaba 100644 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cuh +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cuh @@ -16,12 +16,6 @@ #pragma once -#include -#include - -#include -#include - namespace cudf::binops::compiled::detail { template void struct_compare(mutable_column_view& out, @@ -29,20 +23,5 @@ void struct_compare(mutable_column_view& out, bool is_lhs_scalar, bool is_rhs_scalar, bool flip_output, - rmm::cuda_stream_view stream) -{ - auto d_out = column_device_view::create(out, stream); - auto optional_iter = - cudf::detail::make_optional_iterator(*d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); - thrust::tabulate( - rmm::exec_policy(stream), - out.begin(), - out.end(), - [optional_iter, is_lhs_scalar, is_rhs_scalar, flip_output, compare] __device__(size_type i) { - auto lhs = is_lhs_scalar ? 0 : i; - auto rhs = is_rhs_scalar ? 0 : i; - return optional_iter[i].has_value() and - (flip_output ? not compare(lhs, rhs) : compare(lhs, rhs)); - }); -} + rmm::cuda_stream_view stream); } // namespace cudf::binops::compiled::detail From 7f3624155e1123156283d9a0e80975526ef94a73 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 29 Nov 2021 13:34:25 -0800 Subject: [PATCH 26/54] streamline explicit instantiation --- .../binaryop/compiled/struct_binary_ops.cu | 36 +++++-------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cu b/cpp/src/binaryop/compiled/struct_binary_ops.cu index aed13e130a5..38f77217471 100644 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cu +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cu @@ -46,32 +46,12 @@ void struct_compare(mutable_column_view& out, } } // namespace binops::compiled::detail -template void binops::compiled::detail::struct_compare>( - mutable_column_view& out, - row_lexicographic_comparator compare, - bool is_lhs_scalar, - bool is_rhs_scalar, - bool flip_output, - rmm::cuda_stream_view stream); -template void binops::compiled::detail::struct_compare>( - mutable_column_view& out, - row_lexicographic_comparator compare, - bool is_lhs_scalar, - bool is_rhs_scalar, - bool flip_output, - rmm::cuda_stream_view stream); -template void binops::compiled::detail::struct_compare>( - mutable_column_view& out, - row_equality_comparator compare, - bool is_lhs_scalar, - bool is_rhs_scalar, - bool flip_output, - rmm::cuda_stream_view stream); -template void binops::compiled::detail::struct_compare>( - mutable_column_view& out, - row_equality_comparator compare, - bool is_lhs_scalar, - bool is_rhs_scalar, - bool flip_output, - rmm::cuda_stream_view stream); +#define INSTANTIATE_STRUCT_COMPARE(comp_op) \ + template void binops::compiled::detail::struct_compare( \ + mutable_column_view&, comp_op, bool, bool, bool, rmm::cuda_stream_view); + +INSTANTIATE_STRUCT_COMPARE(row_equality_comparator); +INSTANTIATE_STRUCT_COMPARE(row_equality_comparator); +INSTANTIATE_STRUCT_COMPARE(row_lexicographic_comparator); +INSTANTIATE_STRUCT_COMPARE(row_lexicographic_comparator); } // namespace cudf From 2abefd5a96943de2e67664116c9829546c7190e0 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Sun, 5 Dec 2021 13:28:36 -0800 Subject: [PATCH 27/54] remove op argument --- cpp/src/binaryop/compiled/ATan2.cu | 1 - cpp/src/binaryop/compiled/Add.cu | 1 - cpp/src/binaryop/compiled/BitwiseAnd.cu | 1 - cpp/src/binaryop/compiled/BitwiseOr.cu | 1 - cpp/src/binaryop/compiled/BitwiseXor.cu | 1 - cpp/src/binaryop/compiled/Div.cu | 1 - cpp/src/binaryop/compiled/FloorDiv.cu | 1 - cpp/src/binaryop/compiled/Greater.cu | 1 - cpp/src/binaryop/compiled/GreaterEqual.cu | 1 - cpp/src/binaryop/compiled/Less.cu | 1 - cpp/src/binaryop/compiled/LessEqual.cu | 1 - cpp/src/binaryop/compiled/LogBase.cu | 1 - cpp/src/binaryop/compiled/LogicalAnd.cu | 1 - cpp/src/binaryop/compiled/LogicalOr.cu | 1 - cpp/src/binaryop/compiled/Mod.cu | 1 - cpp/src/binaryop/compiled/Mul.cu | 1 - cpp/src/binaryop/compiled/NullMax.cu | 1 - cpp/src/binaryop/compiled/NullMin.cu | 1 - cpp/src/binaryop/compiled/PMod.cu | 1 - cpp/src/binaryop/compiled/Pow.cu | 1 - cpp/src/binaryop/compiled/PyMod.cu | 1 - cpp/src/binaryop/compiled/ShiftLeft.cu | 1 - cpp/src/binaryop/compiled/ShiftRight.cu | 1 - .../binaryop/compiled/ShiftRightUnsigned.cu | 1 - cpp/src/binaryop/compiled/Sub.cu | 1 - cpp/src/binaryop/compiled/TrueDiv.cu | 1 - cpp/src/binaryop/compiled/binary_ops.cu | 52 +++++++++---------- cpp/src/binaryop/compiled/binary_ops.cuh | 10 ++-- cpp/src/binaryop/compiled/binary_ops.hpp | 1 - 29 files changed, 32 insertions(+), 57 deletions(-) diff --git a/cpp/src/binaryop/compiled/ATan2.cu b/cpp/src/binaryop/compiled/ATan2.cu index 163e8ec7a38..51df4048006 100644 --- a/cpp/src/binaryop/compiled/ATan2.cu +++ b/cpp/src/binaryop/compiled/ATan2.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Add.cu b/cpp/src/binaryop/compiled/Add.cu index 6eea65b5c29..500333d32c3 100644 --- a/cpp/src/binaryop/compiled/Add.cu +++ b/cpp/src/binaryop/compiled/Add.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/BitwiseAnd.cu b/cpp/src/binaryop/compiled/BitwiseAnd.cu index 7d8a5d8d51c..071490cbd3e 100644 --- a/cpp/src/binaryop/compiled/BitwiseAnd.cu +++ b/cpp/src/binaryop/compiled/BitwiseAnd.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/BitwiseOr.cu b/cpp/src/binaryop/compiled/BitwiseOr.cu index 90c8565785e..b531d13f608 100644 --- a/cpp/src/binaryop/compiled/BitwiseOr.cu +++ b/cpp/src/binaryop/compiled/BitwiseOr.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/BitwiseXor.cu b/cpp/src/binaryop/compiled/BitwiseXor.cu index d8ba9db77fb..2a8ee0fd0c9 100644 --- a/cpp/src/binaryop/compiled/BitwiseXor.cu +++ b/cpp/src/binaryop/compiled/BitwiseXor.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Div.cu b/cpp/src/binaryop/compiled/Div.cu index a7f3aaf13a8..4816e5891ac 100644 --- a/cpp/src/binaryop/compiled/Div.cu +++ b/cpp/src/binaryop/compiled/Div.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/FloorDiv.cu b/cpp/src/binaryop/compiled/FloorDiv.cu index 67e533b9547..bb892ab12e2 100644 --- a/cpp/src/binaryop/compiled/FloorDiv.cu +++ b/cpp/src/binaryop/compiled/FloorDiv.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Greater.cu b/cpp/src/binaryop/compiled/Greater.cu index 97ac2b3e7e8..d657fd3d9fd 100644 --- a/cpp/src/binaryop/compiled/Greater.cu +++ b/cpp/src/binaryop/compiled/Greater.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/GreaterEqual.cu b/cpp/src/binaryop/compiled/GreaterEqual.cu index 47d3d59826f..d9f4325bc24 100644 --- a/cpp/src/binaryop/compiled/GreaterEqual.cu +++ b/cpp/src/binaryop/compiled/GreaterEqual.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Less.cu b/cpp/src/binaryop/compiled/Less.cu index 0942d9e1a24..561ed9fab0b 100644 --- a/cpp/src/binaryop/compiled/Less.cu +++ b/cpp/src/binaryop/compiled/Less.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/LessEqual.cu b/cpp/src/binaryop/compiled/LessEqual.cu index 743ad5f24bd..df63fa3576c 100644 --- a/cpp/src/binaryop/compiled/LessEqual.cu +++ b/cpp/src/binaryop/compiled/LessEqual.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/LogBase.cu b/cpp/src/binaryop/compiled/LogBase.cu index 2cf5f8a61e0..8c070ded7b0 100644 --- a/cpp/src/binaryop/compiled/LogBase.cu +++ b/cpp/src/binaryop/compiled/LogBase.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/LogicalAnd.cu b/cpp/src/binaryop/compiled/LogicalAnd.cu index 7f4fb44d8cb..0f1e59a1462 100644 --- a/cpp/src/binaryop/compiled/LogicalAnd.cu +++ b/cpp/src/binaryop/compiled/LogicalAnd.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/LogicalOr.cu b/cpp/src/binaryop/compiled/LogicalOr.cu index 3613d11fa0e..2a43a46f0c1 100644 --- a/cpp/src/binaryop/compiled/LogicalOr.cu +++ b/cpp/src/binaryop/compiled/LogicalOr.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Mod.cu b/cpp/src/binaryop/compiled/Mod.cu index 1854ec21121..d08127514e3 100644 --- a/cpp/src/binaryop/compiled/Mod.cu +++ b/cpp/src/binaryop/compiled/Mod.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Mul.cu b/cpp/src/binaryop/compiled/Mul.cu index 58f7d91dcb3..5384d0a62bc 100644 --- a/cpp/src/binaryop/compiled/Mul.cu +++ b/cpp/src/binaryop/compiled/Mul.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/NullMax.cu b/cpp/src/binaryop/compiled/NullMax.cu index c32e5d55b90..914796663c8 100644 --- a/cpp/src/binaryop/compiled/NullMax.cu +++ b/cpp/src/binaryop/compiled/NullMax.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/NullMin.cu b/cpp/src/binaryop/compiled/NullMin.cu index b653039695a..0e3120c849f 100644 --- a/cpp/src/binaryop/compiled/NullMin.cu +++ b/cpp/src/binaryop/compiled/NullMin.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } // namespace cudf::binops::compiled diff --git a/cpp/src/binaryop/compiled/PMod.cu b/cpp/src/binaryop/compiled/PMod.cu index bd99bcf8d7d..be71f0d4425 100644 --- a/cpp/src/binaryop/compiled/PMod.cu +++ b/cpp/src/binaryop/compiled/PMod.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Pow.cu b/cpp/src/binaryop/compiled/Pow.cu index cdf60e47aef..92c44fe880a 100644 --- a/cpp/src/binaryop/compiled/Pow.cu +++ b/cpp/src/binaryop/compiled/Pow.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/PyMod.cu b/cpp/src/binaryop/compiled/PyMod.cu index 5bf0e72449f..f9a9007c507 100644 --- a/cpp/src/binaryop/compiled/PyMod.cu +++ b/cpp/src/binaryop/compiled/PyMod.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/ShiftLeft.cu b/cpp/src/binaryop/compiled/ShiftLeft.cu index 8a6eeeef817..fd865452cb3 100644 --- a/cpp/src/binaryop/compiled/ShiftLeft.cu +++ b/cpp/src/binaryop/compiled/ShiftLeft.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/ShiftRight.cu b/cpp/src/binaryop/compiled/ShiftRight.cu index f993940d696..d411306337c 100644 --- a/cpp/src/binaryop/compiled/ShiftRight.cu +++ b/cpp/src/binaryop/compiled/ShiftRight.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu index 845ad76e6d4..3eb22081626 100644 --- a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu +++ b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/Sub.cu b/cpp/src/binaryop/compiled/Sub.cu index 4d10826a732..2765edb53a0 100644 --- a/cpp/src/binaryop/compiled/Sub.cu +++ b/cpp/src/binaryop/compiled/Sub.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/TrueDiv.cu b/cpp/src/binaryop/compiled/TrueDiv.cu index 12d8162e151..8203c5df891 100644 --- a/cpp/src/binaryop/compiled/TrueDiv.cu +++ b/cpp/src/binaryop/compiled/TrueDiv.cu @@ -22,6 +22,5 @@ template void apply_binary_op(mutable_column_view&, column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view); } diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index 3d1bf6ea5ca..d4341acd901 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -310,40 +310,40 @@ void operator_dispatcher(mutable_column_view& out, CUDF_FAIL("Unsupported operator for these types"); // clang-format off switch (op) { -case binary_operator::ADD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::SUB: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::MUL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::TRUE_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::FLOOR_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::MOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::PYMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::POW: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::ADD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::SUB: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::MUL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::TRUE_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::FLOOR_DIV: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::MOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::PYMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::POW: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; case binary_operator::EQUAL: case binary_operator::NOT_EQUAL: case binary_operator::NULL_EQUALS: if(out.type().id() != type_id::BOOL8) CUDF_FAIL("Output type of Comparison operator should be bool type"); dispatch_equality_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::LESS: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::GREATER: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::LESS_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::GREATER_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::BITWISE_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::BITWISE_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::BITWISE_XOR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::LOGICAL_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::LOGICAL_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::LESS: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::GREATER: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::LESS_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::GREATER_EQUAL: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::BITWISE_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::BITWISE_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::BITWISE_XOR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::LOGICAL_AND: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::LOGICAL_OR: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; /* case binary_operator::GENERIC_BINARY: // Cannot be compiled, should be called by jit::binary_operation */ -case binary_operator::SHIFT_LEFT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::SHIFT_RIGHT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::SHIFT_RIGHT_UNSIGNED: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::LOG_BASE: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::ATAN2: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::PMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::NULL_MAX: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; -case binary_operator::NULL_MIN: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, op, stream); break; +case binary_operator::SHIFT_LEFT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::SHIFT_RIGHT: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::SHIFT_RIGHT_UNSIGNED: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::LOG_BASE: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::ATAN2: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::PMOD: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::NULL_MAX: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; +case binary_operator::NULL_MIN: apply_binary_op(out, lhs, rhs, is_lhs_scalar, is_rhs_scalar, stream); break; default:; } // clang-format on diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 3a66a30850c..ef70e664534 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -256,21 +256,23 @@ void for_each(rmm::cuda_stream_view stream, cudf::size_type size, Functor f) const int grid_size = util::div_rounding_up_safe(size, 2 * block_size); for_each_kernel<<>>(size, std::forward(f)); } - +namespace detail { +template +inline constexpr bool is_any_v = std::disjunction...>::value; +} template void apply_binary_op(mutable_column_view& out, column_view const& lhs, column_view const& rhs, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view stream) { if (is_struct(lhs.type()) && is_struct(rhs.type())) { - auto op_order = (binary_operator::GREATER == op || binary_operator::LESS_EQUAL == op) + auto op_order = detail::is_any_v ? order::DESCENDING : order::ASCENDING; - auto flip_output = (binary_operator::GREATER_EQUAL == op || binary_operator::LESS_EQUAL == op); + auto flip_output = detail::is_any_v; auto const nullability = structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) ? structs::detail::column_nullability::FORCE diff --git a/cpp/src/binaryop/compiled/binary_ops.hpp b/cpp/src/binaryop/compiled/binary_ops.hpp index 6865a42415a..85448a2de34 100644 --- a/cpp/src/binaryop/compiled/binary_ops.hpp +++ b/cpp/src/binaryop/compiled/binary_ops.hpp @@ -212,7 +212,6 @@ void apply_binary_op(mutable_column_view& out, column_view const& rhs, bool is_lhs_scalar, bool is_rhs_scalar, - binary_operator op, rmm::cuda_stream_view stream); /** * @brief Deploys single type or double type dispatcher that runs equality operation on each From 8cc05e2ff5691edcc5f12ed6cec7a5cdf5333230 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 6 Dec 2021 07:26:32 -0800 Subject: [PATCH 28/54] documentation --- cpp/src/binaryop/compiled/struct_binary_ops.cuh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cuh b/cpp/src/binaryop/compiled/struct_binary_ops.cuh index e62d30ebaba..10bc367d8b6 100644 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cuh +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cuh @@ -17,6 +17,20 @@ #pragma once namespace cudf::binops::compiled::detail { +/** + * @brief Generates comparison results for each row in the output column. Supports scalar columns + * and negation of comparison results to mimic !=, <=, and >= operators. + * + * @tparam Comparator comparator type + * @param out mutable column view of output column + * @param compare initialized comparator function + * @param is_lhs_scalar true if @p compare has a single element column representing a scalar on its + * lhs + * @param is_rhs_scalar true if @p compare has a single element column representing a scalar on its + * rhs + * @param flip_output true if the comparison results should be negated + * @param stream CUDA stream used for device memory operations + */ template void struct_compare(mutable_column_view& out, Comparator compare, From 470acfec917592f752fa9bd67f9df4dd1eed22e9 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 6 Dec 2021 11:16:21 -0800 Subject: [PATCH 29/54] Fix upmerge errors --- cpp/include/cudf/table/row_operators.cuh | 2 +- cpp/src/binaryop/compiled/NullEquals.cu | 8 +++--- cpp/src/binaryop/compiled/binary_ops.cuh | 25 ++++++++++--------- cpp/src/binaryop/compiled/equality_ops.cu | 14 +++++------ .../binaryop/compiled/struct_binary_ops.cu | 8 +++--- 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/cpp/include/cudf/table/row_operators.cuh b/cpp/include/cudf/table/row_operators.cuh index 0f3ca073380..d7fef5e6389 100644 --- a/cpp/include/cudf/table/row_operators.cuh +++ b/cpp/include/cudf/table/row_operators.cuh @@ -233,7 +233,7 @@ class row_equality_comparator { row_equality_comparator(Nullate has_nulls, table_device_view lhs, table_device_view rhs, - null_equality nulls_are_equal = true) + null_equality nulls_are_equal = null_equality::EQUAL) : lhs{lhs}, rhs{rhs}, nulls{has_nulls}, nulls_are_equal{nulls_are_equal} { CUDF_EXPECTS(lhs.num_columns() == rhs.num_columns(), "Mismatched number of columns."); diff --git a/cpp/src/binaryop/compiled/NullEquals.cu b/cpp/src/binaryop/compiled/NullEquals.cu index 3fc76e804f7..7f4cf422cff 100644 --- a/cpp/src/binaryop/compiled/NullEquals.cu +++ b/cpp/src/binaryop/compiled/NullEquals.cu @@ -14,12 +14,12 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 5c3c607ecd3..c94703f8c80 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -303,16 +303,17 @@ void apply_binary_op(mutable_column_view& out, auto compare_orders = cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); - detail::struct_compare(out, - row_lexicographic_comparator{ - has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened), - *d_lhs, - *d_rhs, - compare_orders.data()}, - is_lhs_scalar, - is_rhs_scalar, - flip_output, - stream); + detail::struct_compare( + out, + row_lexicographic_comparator{ + nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, + *d_lhs, + *d_rhs, + compare_orders.data()}, + is_lhs_scalar, + is_rhs_scalar, + flip_output, + stream); } else { auto common_dtype = get_common_type(out.type(), lhs.type(), rhs.type()); @@ -323,13 +324,13 @@ void apply_binary_op(mutable_column_view& out, if (common_dtype) { // Execute it on every element for_each(stream, - outd.size(), + out.size(), binary_op_device_dispatcher{ *common_dtype, *outd, *lhsd, *rhsd, is_lhs_scalar, is_rhs_scalar}); } else { // Execute it on every element for_each(stream, - outd.size(), + out.size(), binary_op_double_device_dispatcher{ *outd, *lhsd, *rhsd, is_lhs_scalar, is_rhs_scalar}); } diff --git a/cpp/src/binaryop/compiled/equality_ops.cu b/cpp/src/binaryop/compiled/equality_ops.cu index dfa6f1d5ca5..91c41528314 100644 --- a/cpp/src/binaryop/compiled/equality_ops.cu +++ b/cpp/src/binaryop/compiled/equality_ops.cu @@ -19,8 +19,6 @@ #include #include -#include "cudf/binaryop.hpp" -#include "cudf/column/column_device_view.cuh" namespace cudf::binops::compiled { void dispatch_equality_op(mutable_column_view& out, @@ -47,7 +45,9 @@ void dispatch_equality_op(mutable_column_view& out, detail::struct_compare( out, row_equality_comparator{ - has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened), *d_lhs, *d_rhs}, + nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, + *d_lhs, + *d_rhs}, is_lhs_scalar, is_rhs_scalar, op == binary_operator::NOT_EQUAL, @@ -62,24 +62,24 @@ void dispatch_equality_op(mutable_column_view& out, if (common_dtype) { if (op == binary_operator::EQUAL) { for_each(stream, - outd.size(), + out.size(), binary_op_device_dispatcher{ *common_dtype, *outd, *lhsd, *rhsd, is_lhs_scalar, is_rhs_scalar}); } else if (op == binary_operator::NOT_EQUAL) { for_each(stream, - outd.size(), + out.size(), binary_op_device_dispatcher{ *common_dtype, *outd, *lhsd, *rhsd, is_lhs_scalar, is_rhs_scalar}); } } else { if (op == binary_operator::EQUAL) { for_each(stream, - outd.size(), + out.size(), binary_op_double_device_dispatcher{ *outd, *lhsd, *rhsd, is_lhs_scalar, is_rhs_scalar}); } else if (op == binary_operator::NOT_EQUAL) { for_each(stream, - outd.size(), + out.size(), binary_op_double_device_dispatcher{ *outd, *lhsd, *rhsd, is_lhs_scalar, is_rhs_scalar}); } diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cu b/cpp/src/binaryop/compiled/struct_binary_ops.cu index 38f77217471..f2adcc5008a 100644 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cu +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cu @@ -32,7 +32,7 @@ void struct_compare(mutable_column_view& out, { auto d_out = column_device_view::create(out, stream); auto optional_iter = - cudf::detail::make_optional_iterator(*d_out, contains_nulls::DYNAMIC{}, out.has_nulls()); + cudf::detail::make_optional_iterator(*d_out, nullate::DYNAMIC{out.has_nulls()}); thrust::tabulate( rmm::exec_policy(stream), out.begin(), @@ -50,8 +50,6 @@ void struct_compare(mutable_column_view& out, template void binops::compiled::detail::struct_compare( \ mutable_column_view&, comp_op, bool, bool, bool, rmm::cuda_stream_view); -INSTANTIATE_STRUCT_COMPARE(row_equality_comparator); -INSTANTIATE_STRUCT_COMPARE(row_equality_comparator); -INSTANTIATE_STRUCT_COMPARE(row_lexicographic_comparator); -INSTANTIATE_STRUCT_COMPARE(row_lexicographic_comparator); +INSTANTIATE_STRUCT_COMPARE(row_equality_comparator); +INSTANTIATE_STRUCT_COMPARE(row_lexicographic_comparator); } // namespace cudf From 2b7773918f9e895c568d6fa4e9ddafe22202eb7f Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Thu, 3 Feb 2022 17:13:48 -0800 Subject: [PATCH 30/54] fix new ops from upmerge --- cpp/src/binaryop/compiled/NullLogicalAnd.cu | 8 ++++---- cpp/src/binaryop/compiled/NullLogicalOr.cu | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cpp/src/binaryop/compiled/NullLogicalAnd.cu b/cpp/src/binaryop/compiled/NullLogicalAnd.cu index 48ae125bc93..f98bc46105f 100644 --- a/cpp/src/binaryop/compiled/NullLogicalAnd.cu +++ b/cpp/src/binaryop/compiled/NullLogicalAnd.cu @@ -14,12 +14,12 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); diff --git a/cpp/src/binaryop/compiled/NullLogicalOr.cu b/cpp/src/binaryop/compiled/NullLogicalOr.cu index e0ea95ac3ee..a0b1112175b 100644 --- a/cpp/src/binaryop/compiled/NullLogicalOr.cu +++ b/cpp/src/binaryop/compiled/NullLogicalOr.cu @@ -14,12 +14,12 @@ * limitations under the License. */ -#include "binary_ops.cuh" +#include namespace cudf::binops::compiled { -template void apply_binary_op(mutable_column_device_view&, - column_device_view const&, - column_device_view const&, +template void apply_binary_op(mutable_column_view&, + column_view const&, + column_view const&, bool is_lhs_scalar, bool is_rhs_scalar, rmm::cuda_stream_view); From de09cecbd3bedc20ad2109651c10a253cd6cb3e3 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Tue, 8 Feb 2022 15:28:47 -0800 Subject: [PATCH 31/54] Fix floating point nan handling in struct comparison binops --- cpp/include/cudf/table/row_operators.cuh | 72 +++++++++++++++++-- cpp/src/binaryop/compiled/binary_ops.cuh | 2 +- .../binaryop/compiled/struct_binary_ops.cu | 12 +++- cpp/tests/binaryop/binop-struct-test.cpp | 65 ++++++++++++++++- 4 files changed, 140 insertions(+), 11 deletions(-) diff --git a/cpp/include/cudf/table/row_operators.cuh b/cpp/include/cudf/table/row_operators.cuh index 10d4c894ea5..814a0decba7 100644 --- a/cpp/include/cudf/table/row_operators.cuh +++ b/cpp/include/cudf/table/row_operators.cuh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021, NVIDIA CORPORATION. + * Copyright (c) 2019-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. @@ -71,7 +71,7 @@ __device__ weak_ordering compare_elements(Element lhs, Element rhs) * @brief A specialization for floating-point `Element` type relational comparison * to derive the order of the elements with respect to `lhs`. * - * This Specialization handles `nan` in the following order: + * This specialization handles `nan` in the following order: * `[-Inf, -ve, 0, -0, +ve, +Inf, NaN, NaN, null] (for null_order::AFTER)` * `[null, -Inf, -ve, 0, -0, +ve, +Inf, NaN, NaN] (for null_order::BEFORE)` * @@ -94,6 +94,25 @@ __device__ weak_ordering relational_compare(Element lhs, Element rhs) return detail::compare_elements(lhs, rhs); } +/** + * @brief A specialization for floating-point `Element` type relational comparison + * to derive the order of the elements with respect to `lhs`. Returns specified weak_ordering if + * either value is `nan`, enabling IEEE 754 compliant comparison. + * + * This specialization allows `nan` values to be evaluated as not equal to any other value, while also not evaluating as greater or less than + * + * @param lhs first element + * @param rhs second element + * @param nan_result specifies what value should be returned if either element is `nan` + * @return Indicates the relationship between the elements in + * the `lhs` and `rhs` columns. + */ +template ::value>* = nullptr> +__device__ weak_ordering relational_compare(Element lhs, Element rhs, weak_ordering nan_result) +{ + return isnan(lhs) or isnan(rhs) ? nan_result : detail::compare_elements(lhs, rhs); +} + /** * @brief Compare the nulls according to null order. * @@ -120,11 +139,15 @@ inline __device__ auto null_compare(bool lhs_is_null, bool rhs_is_null, null_ord * * @param[in] lhs first element * @param[in] rhs second element + * @param[in] nan_result ignored, allows for configurable `nan` handling in the + * corresponding float enabled functions * @return Indicates the relationship between the elements in * the `lhs` and `rhs` columns. */ template ::value>* = nullptr> -__device__ weak_ordering relational_compare(Element lhs, Element rhs) +__device__ weak_ordering relational_compare(Element lhs, + Element rhs, + weak_ordering nan_result = weak_ordering::GREATER) { return detail::compare_elements(lhs, rhs); } @@ -318,9 +341,39 @@ class element_relational_comparator { rhs.element(rhs_element_index)); } + /** + * @brief Performs a relational comparison between the specified elements + * + * @param lhs_element_index The index of the first element + * @param rhs_element_index The index of the second element + * @param nan_result specifies what value should be returned if either element is `nan` + * @return Indicates the relationship between the elements in + * the `lhs` and `rhs` columns. + */ + template ()>* = nullptr> + __device__ weak_ordering operator()(size_type lhs_element_index, + size_type rhs_element_index, + weak_ordering nan_result) const noexcept + { + if (nulls) { + bool const lhs_is_null{lhs.is_null(lhs_element_index)}; + bool const rhs_is_null{rhs.is_null(rhs_element_index)}; + + if (lhs_is_null or rhs_is_null) { // at least one is null + return null_compare(lhs_is_null, rhs_is_null, null_precedence); + } + } + + return relational_compare( + lhs.element(lhs_element_index), rhs.element(rhs_element_index), nan_result); + } + template ()>* = nullptr> - __device__ weak_ordering operator()(size_type lhs_element_index, size_type rhs_element_index) + __device__ weak_ordering operator()(size_type lhs_element_index, + size_type rhs_element_index, + weak_ordering nan_result=weak_ordering::LESS) { cudf_assert(false && "Attempted to compare elements of uncomparable types."); return weak_ordering::LESS; @@ -348,7 +401,7 @@ class element_relational_comparator { * * @tparam Nullate A cudf::nullate type describing how to check for nulls. */ -template +template class row_lexicographic_comparator { public: /** @@ -404,9 +457,14 @@ class row_lexicographic_comparator { auto comparator = element_relational_comparator{_nulls, _lhs.column(i), _rhs.column(i), null_precedence}; - weak_ordering state = - cudf::type_dispatcher(_lhs.column(i).type(), comparator, lhs_index, rhs_index); + NanConfig && is_floating_point(_lhs.column(i).type()) + ? cudf::type_dispatcher(_lhs.column(i).type(), + comparator, + lhs_index, + rhs_index, + ascending ? weak_ordering::GREATER : weak_ordering::LESS) + : cudf::type_dispatcher(_lhs.column(i).type(), comparator, lhs_index, rhs_index); if (state == weak_ordering::EQUIVALENT) { continue; } diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 11c554077a0..e580e5433da 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -309,7 +309,7 @@ void apply_binary_op(mutable_column_view& out, detail::struct_compare( out, - row_lexicographic_comparator{ + row_lexicographic_comparator{ nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, *d_lhs, *d_rhs, diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cu b/cpp/src/binaryop/compiled/struct_binary_ops.cu index f2adcc5008a..36ef2506fca 100644 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cu +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. @@ -51,5 +51,13 @@ void struct_compare(mutable_column_view& out, mutable_column_view&, comp_op, bool, bool, bool, rmm::cuda_stream_view); INSTANTIATE_STRUCT_COMPARE(row_equality_comparator); -INSTANTIATE_STRUCT_COMPARE(row_lexicographic_comparator); +// INSTANTIATE_STRUCT_COMPARE does not work with the optional template argument +template void +binops::compiled::detail::struct_compare>( + mutable_column_view&, + row_lexicographic_comparator, + bool, + bool, + bool, + rmm::cuda_stream_view); } // namespace cudf diff --git a/cpp/tests/binaryop/binop-struct-test.cpp b/cpp/tests/binaryop/binop-struct-test.cpp index f9a0d8dcccb..4804f575c3d 100644 --- a/cpp/tests/binaryop/binop-struct-test.cpp +++ b/cpp/tests/binaryop/binop-struct-test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. @@ -291,6 +291,69 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_scalars) CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); } +struct BinopStructCompareNAN : public cudf::test::BaseFixture { +}; + +TEST_F(BinopStructCompareNAN, float_nans) +{ + cudf::test::fixed_width_column_wrapper lhs{ + -NAN, -NAN, -NAN, NAN, NAN, NAN, 1.0f, 0.0f, -54.3f}; + cudf::test::fixed_width_column_wrapper rhs{ + -32.5f, -NAN, NAN, -0.0f, -NAN, NAN, 111.0f, -NAN, NAN}; + + auto expected_eq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 0}; + auto expected_neq = fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 1}; + auto expected_lt = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 1, 0, 0}; + auto expected_lteq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 1, 0, 0}; + auto expected_gt = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 0}; + auto expected_gteq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 0}; + + data_type dt = cudf::data_type(cudf::type_id::BOOL8); + auto res_eq = binary_operation(lhs, rhs, binary_operator::EQUAL, dt); + auto res_neq = binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); + auto res_lt = binary_operation(lhs, rhs, binary_operator::LESS, dt); + auto res_gt = binary_operation(lhs, rhs, binary_operator::GREATER, dt); + auto res_gteq = binary_operation(lhs, rhs, binary_operator::GREATER_EQUAL, dt); + auto res_lteq = binary_operation(lhs, rhs, binary_operator::LESS_EQUAL, dt); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); +}; + +TEST_F(BinopStructCompareNAN, double_nans) +{ + cudf::test::fixed_width_column_wrapper lhs{ + -NAN, -NAN, -NAN, NAN, NAN, NAN, 1.0f, 0.0f, -54.3f}; + cudf::test::fixed_width_column_wrapper rhs{ + -32.5f, -NAN, NAN, -0.0f, -NAN, NAN, 111.0f, -NAN, NAN}; + + auto expected_eq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 0}; + auto expected_neq = fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 1}; + auto expected_lt = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 1, 0, 0}; + auto expected_lteq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 1, 0, 0}; + auto expected_gt = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 0}; + auto expected_gteq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 0}; + + data_type dt = cudf::data_type(cudf::type_id::BOOL8); + auto res_eq = binary_operation(lhs, rhs, binary_operator::EQUAL, dt); + auto res_neq = binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); + auto res_lt = binary_operation(lhs, rhs, binary_operator::LESS, dt); + auto res_gt = binary_operation(lhs, rhs, binary_operator::GREATER, dt); + auto res_gteq = binary_operation(lhs, rhs, binary_operator::GREATER_EQUAL, dt); + auto res_lteq = binary_operation(lhs, rhs, binary_operator::LESS_EQUAL, dt); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); +}; + struct BinopStructCompareFailures : public cudf::test::BaseFixture { void attempt_struct_binop(binary_operator op, data_type dt = cudf::data_type(cudf::type_id::BOOL8)) From 251d607cfc7d8026a5d43f4a78f241b89c3e62b8 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Tue, 8 Feb 2022 18:05:03 -0800 Subject: [PATCH 32/54] fix formatting --- cpp/include/cudf/table/row_operators.cuh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cpp/include/cudf/table/row_operators.cuh b/cpp/include/cudf/table/row_operators.cuh index 839028c0c88..e5bd3047eec 100644 --- a/cpp/include/cudf/table/row_operators.cuh +++ b/cpp/include/cudf/table/row_operators.cuh @@ -99,7 +99,8 @@ __device__ weak_ordering relational_compare(Element lhs, Element rhs) * to derive the order of the elements with respect to `lhs`. Returns specified weak_ordering if * either value is `nan`, enabling IEEE 754 compliant comparison. * - * This specialization allows `nan` values to be evaluated as not equal to any other value, while also not evaluating as greater or less than + * This specialization allows `nan` values to be evaluated as not equal to any other value, while + * also not evaluating as greater or less than * * @param lhs first element * @param rhs second element @@ -346,7 +347,7 @@ class element_relational_comparator { * * @param lhs_element_index The index of the first element * @param rhs_element_index The index of the second element - * @param nan_result specifies what value should be returned if either element is `nan` + * @param nan_result specifies what value should be returned if either element is `nan` * @return Indicates the relationship between the elements in * the `lhs` and `rhs` columns. */ @@ -373,7 +374,7 @@ class element_relational_comparator { std::enable_if_t()>* = nullptr> __device__ weak_ordering operator()(size_type lhs_element_index, size_type rhs_element_index, - weak_ordering nan_result=weak_ordering::LESS) + weak_ordering nan_result = weak_ordering::LESS) { cudf_assert(false && "Attempted to compare elements of uncomparable types."); return weak_ordering::LESS; From 703aaf8774610fe77060aba0bbec7e31c9a3d0ae Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 14 Feb 2022 15:46:30 -0800 Subject: [PATCH 33/54] fix copyright --- cpp/include/cudf/detail/structs/utilities.hpp | 2 +- cpp/include/cudf/utilities/traits.hpp | 2 +- cpp/src/binaryop/compiled/ATan2.cu | 2 +- cpp/src/binaryop/compiled/Add.cu | 2 +- cpp/src/binaryop/compiled/BitwiseAnd.cu | 2 +- cpp/src/binaryop/compiled/BitwiseOr.cu | 2 +- cpp/src/binaryop/compiled/BitwiseXor.cu | 2 +- cpp/src/binaryop/compiled/Div.cu | 2 +- cpp/src/binaryop/compiled/FloorDiv.cu | 2 +- cpp/src/binaryop/compiled/Greater.cu | 2 +- cpp/src/binaryop/compiled/GreaterEqual.cu | 2 +- cpp/src/binaryop/compiled/Less.cu | 2 +- cpp/src/binaryop/compiled/LessEqual.cu | 2 +- cpp/src/binaryop/compiled/LogBase.cu | 2 +- cpp/src/binaryop/compiled/LogicalAnd.cu | 2 +- cpp/src/binaryop/compiled/Mod.cu | 2 +- cpp/src/binaryop/compiled/Mul.cu | 2 +- cpp/src/binaryop/compiled/NullEquals.cu | 2 +- cpp/src/binaryop/compiled/NullMax.cu | 2 +- cpp/src/binaryop/compiled/NullMin.cu | 2 +- cpp/src/binaryop/compiled/PMod.cu | 2 +- cpp/src/binaryop/compiled/Pow.cu | 2 +- cpp/src/binaryop/compiled/PyMod.cu | 2 +- cpp/src/binaryop/compiled/ShiftLeft.cu | 2 +- cpp/src/binaryop/compiled/ShiftRight.cu | 2 +- cpp/src/binaryop/compiled/ShiftRightUnsigned.cu | 2 +- cpp/src/binaryop/compiled/Sub.cu | 2 +- cpp/src/binaryop/compiled/TrueDiv.cu | 2 +- cpp/src/binaryop/compiled/binary_ops.cuh | 2 +- cpp/src/binaryop/compiled/binary_ops.hpp | 2 +- cpp/src/binaryop/compiled/equality_ops.cu | 4 ++-- cpp/src/binaryop/compiled/struct_binary_ops.cuh | 2 +- cpp/src/structs/utilities.cpp | 2 +- 33 files changed, 34 insertions(+), 34 deletions(-) diff --git a/cpp/include/cudf/detail/structs/utilities.hpp b/cpp/include/cudf/detail/structs/utilities.hpp index fa33a9f0a99..45d4c3b5ae4 100644 --- a/cpp/include/cudf/detail/structs/utilities.hpp +++ b/cpp/include/cudf/detail/structs/utilities.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, NVIDIA CORPORATION. + * Copyright (c) 2020-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. diff --git a/cpp/include/cudf/utilities/traits.hpp b/cpp/include/cudf/utilities/traits.hpp index d6e1de9e2be..cdfe254a129 100644 --- a/cpp/include/cudf/utilities/traits.hpp +++ b/cpp/include/cudf/utilities/traits.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021, NVIDIA CORPORATION. + * Copyright (c) 2019-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. diff --git a/cpp/src/binaryop/compiled/ATan2.cu b/cpp/src/binaryop/compiled/ATan2.cu index 51df4048006..71f823ab95a 100644 --- a/cpp/src/binaryop/compiled/ATan2.cu +++ b/cpp/src/binaryop/compiled/ATan2.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/Add.cu b/cpp/src/binaryop/compiled/Add.cu index 500333d32c3..77a829e4886 100644 --- a/cpp/src/binaryop/compiled/Add.cu +++ b/cpp/src/binaryop/compiled/Add.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/BitwiseAnd.cu b/cpp/src/binaryop/compiled/BitwiseAnd.cu index 071490cbd3e..29880c563e6 100644 --- a/cpp/src/binaryop/compiled/BitwiseAnd.cu +++ b/cpp/src/binaryop/compiled/BitwiseAnd.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/BitwiseOr.cu b/cpp/src/binaryop/compiled/BitwiseOr.cu index b531d13f608..083df549e32 100644 --- a/cpp/src/binaryop/compiled/BitwiseOr.cu +++ b/cpp/src/binaryop/compiled/BitwiseOr.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/BitwiseXor.cu b/cpp/src/binaryop/compiled/BitwiseXor.cu index 2a8ee0fd0c9..2578906c8fc 100644 --- a/cpp/src/binaryop/compiled/BitwiseXor.cu +++ b/cpp/src/binaryop/compiled/BitwiseXor.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/Div.cu b/cpp/src/binaryop/compiled/Div.cu index 4816e5891ac..e329839466c 100644 --- a/cpp/src/binaryop/compiled/Div.cu +++ b/cpp/src/binaryop/compiled/Div.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/FloorDiv.cu b/cpp/src/binaryop/compiled/FloorDiv.cu index bb892ab12e2..20417a3b050 100644 --- a/cpp/src/binaryop/compiled/FloorDiv.cu +++ b/cpp/src/binaryop/compiled/FloorDiv.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/Greater.cu b/cpp/src/binaryop/compiled/Greater.cu index d657fd3d9fd..7f0d2533e00 100644 --- a/cpp/src/binaryop/compiled/Greater.cu +++ b/cpp/src/binaryop/compiled/Greater.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/GreaterEqual.cu b/cpp/src/binaryop/compiled/GreaterEqual.cu index d9f4325bc24..82422193c39 100644 --- a/cpp/src/binaryop/compiled/GreaterEqual.cu +++ b/cpp/src/binaryop/compiled/GreaterEqual.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/Less.cu b/cpp/src/binaryop/compiled/Less.cu index 561ed9fab0b..38883701305 100644 --- a/cpp/src/binaryop/compiled/Less.cu +++ b/cpp/src/binaryop/compiled/Less.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/LessEqual.cu b/cpp/src/binaryop/compiled/LessEqual.cu index df63fa3576c..d3252284537 100644 --- a/cpp/src/binaryop/compiled/LessEqual.cu +++ b/cpp/src/binaryop/compiled/LessEqual.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/LogBase.cu b/cpp/src/binaryop/compiled/LogBase.cu index 8c070ded7b0..bc6237b1e65 100644 --- a/cpp/src/binaryop/compiled/LogBase.cu +++ b/cpp/src/binaryop/compiled/LogBase.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/LogicalAnd.cu b/cpp/src/binaryop/compiled/LogicalAnd.cu index 0f1e59a1462..fd8ba0d1cd5 100644 --- a/cpp/src/binaryop/compiled/LogicalAnd.cu +++ b/cpp/src/binaryop/compiled/LogicalAnd.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/Mod.cu b/cpp/src/binaryop/compiled/Mod.cu index d08127514e3..9f60d353bdb 100644 --- a/cpp/src/binaryop/compiled/Mod.cu +++ b/cpp/src/binaryop/compiled/Mod.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/Mul.cu b/cpp/src/binaryop/compiled/Mul.cu index 5384d0a62bc..3fe4a3cb222 100644 --- a/cpp/src/binaryop/compiled/Mul.cu +++ b/cpp/src/binaryop/compiled/Mul.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/NullEquals.cu b/cpp/src/binaryop/compiled/NullEquals.cu index 7f4cf422cff..d5949e95775 100644 --- a/cpp/src/binaryop/compiled/NullEquals.cu +++ b/cpp/src/binaryop/compiled/NullEquals.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/NullMax.cu b/cpp/src/binaryop/compiled/NullMax.cu index 914796663c8..27dfc291e4c 100644 --- a/cpp/src/binaryop/compiled/NullMax.cu +++ b/cpp/src/binaryop/compiled/NullMax.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/NullMin.cu b/cpp/src/binaryop/compiled/NullMin.cu index 0e3120c849f..281a27d426a 100644 --- a/cpp/src/binaryop/compiled/NullMin.cu +++ b/cpp/src/binaryop/compiled/NullMin.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/PMod.cu b/cpp/src/binaryop/compiled/PMod.cu index be71f0d4425..f3a4a876864 100644 --- a/cpp/src/binaryop/compiled/PMod.cu +++ b/cpp/src/binaryop/compiled/PMod.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/Pow.cu b/cpp/src/binaryop/compiled/Pow.cu index 92c44fe880a..2abf88c404d 100644 --- a/cpp/src/binaryop/compiled/Pow.cu +++ b/cpp/src/binaryop/compiled/Pow.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/PyMod.cu b/cpp/src/binaryop/compiled/PyMod.cu index f9a9007c507..046505d4482 100644 --- a/cpp/src/binaryop/compiled/PyMod.cu +++ b/cpp/src/binaryop/compiled/PyMod.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/ShiftLeft.cu b/cpp/src/binaryop/compiled/ShiftLeft.cu index fd865452cb3..22734b3d3cb 100644 --- a/cpp/src/binaryop/compiled/ShiftLeft.cu +++ b/cpp/src/binaryop/compiled/ShiftLeft.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/ShiftRight.cu b/cpp/src/binaryop/compiled/ShiftRight.cu index d411306337c..c7b36002f79 100644 --- a/cpp/src/binaryop/compiled/ShiftRight.cu +++ b/cpp/src/binaryop/compiled/ShiftRight.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu index 3eb22081626..637ad6f189e 100644 --- a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu +++ b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/Sub.cu b/cpp/src/binaryop/compiled/Sub.cu index 2765edb53a0..5a528d472e4 100644 --- a/cpp/src/binaryop/compiled/Sub.cu +++ b/cpp/src/binaryop/compiled/Sub.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/TrueDiv.cu b/cpp/src/binaryop/compiled/TrueDiv.cu index 8203c5df891..87f83246d17 100644 --- a/cpp/src/binaryop/compiled/TrueDiv.cu +++ b/cpp/src/binaryop/compiled/TrueDiv.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index e580e5433da..9cf36ef974b 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -307,7 +307,7 @@ void apply_binary_op(mutable_column_view& out, auto compare_orders = cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); - detail::struct_compare( + detail::( out, row_lexicographic_comparator{ nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, diff --git a/cpp/src/binaryop/compiled/binary_ops.hpp b/cpp/src/binaryop/compiled/binary_ops.hpp index 85448a2de34..2faab761f60 100644 --- a/cpp/src/binaryop/compiled/binary_ops.hpp +++ b/cpp/src/binaryop/compiled/binary_ops.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, NVIDIA CORPORATION. + * Copyright (c) 2018-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. diff --git a/cpp/src/binaryop/compiled/equality_ops.cu b/cpp/src/binaryop/compiled/equality_ops.cu index 91c41528314..9f8ddd6f72c 100644 --- a/cpp/src/binaryop/compiled/equality_ops.cu +++ b/cpp/src/binaryop/compiled/equality_ops.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. @@ -42,7 +42,7 @@ void dispatch_equality_op(mutable_column_view& out, auto d_rhs = table_device_view::create(rhs_flattened); if (op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL) - detail::struct_compare( + detail::( out, row_equality_comparator{ nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cuh b/cpp/src/binaryop/compiled/struct_binary_ops.cuh index 10bc367d8b6..0655187ad17 100644 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cuh +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cuh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. diff --git a/cpp/src/structs/utilities.cpp b/cpp/src/structs/utilities.cpp index 9ea6fb099af..891a0887dcf 100644 --- a/cpp/src/structs/utilities.cpp +++ b/cpp/src/structs/utilities.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, NVIDIA CORPORATION. + * Copyright (c) 2020-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. From 43e451bbd513485a523552cf670040730ecb20ba Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 14 Feb 2022 15:47:58 -0800 Subject: [PATCH 34/54] fix accidently deletd function --- cpp/src/binaryop/compiled/equality_ops.cu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/binaryop/compiled/equality_ops.cu b/cpp/src/binaryop/compiled/equality_ops.cu index 9f8ddd6f72c..cf912cc3910 100644 --- a/cpp/src/binaryop/compiled/equality_ops.cu +++ b/cpp/src/binaryop/compiled/equality_ops.cu @@ -42,7 +42,7 @@ void dispatch_equality_op(mutable_column_view& out, auto d_rhs = table_device_view::create(rhs_flattened); if (op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL) - detail::( + detail::struct_compare( out, row_equality_comparator{ nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, From 9ec4a41e380a0f3170489c1ad5e6cf03260db2b9 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 14 Feb 2022 19:13:15 -0800 Subject: [PATCH 35/54] style fix --- cpp/src/binaryop/compiled/binary_ops.cuh | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 9cf36ef974b..2138084b598 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -307,17 +307,16 @@ void apply_binary_op(mutable_column_view& out, auto compare_orders = cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); - detail::( - out, - row_lexicographic_comparator{ - nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, - *d_lhs, - *d_rhs, - compare_orders.data()}, - is_lhs_scalar, - is_rhs_scalar, - flip_output, - stream); + detail::(out, + row_lexicographic_comparator{ + nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, + *d_lhs, + *d_rhs, + compare_orders.data()}, + is_lhs_scalar, + is_rhs_scalar, + flip_output, + stream); } else { auto common_dtype = get_common_type(out.type(), lhs.type(), rhs.type()); From 201a89b6d542f951add81a273937900aaf58f13a Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 14 Feb 2022 19:42:35 -0800 Subject: [PATCH 36/54] copyright fix --- cpp/src/binaryop/compiled/LogicalOr.cu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/binaryop/compiled/LogicalOr.cu b/cpp/src/binaryop/compiled/LogicalOr.cu index 2a43a46f0c1..7b8c1433a29 100644 --- a/cpp/src/binaryop/compiled/LogicalOr.cu +++ b/cpp/src/binaryop/compiled/LogicalOr.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. From 1bb1534ec916c7aa0af15106a4e492a1af93e69d Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Tue, 15 Feb 2022 14:01:18 -0800 Subject: [PATCH 37/54] fix cmake style --- cpp/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 6bb65f9498e..7ec0acf8143 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -167,8 +167,6 @@ add_library( src/ast/expression_parser.cpp src/ast/expressions.cpp src/binaryop/binaryop.cpp - src/binaryop/compiled/binary_ops.cu - src/binaryop/compiled/struct_binary_ops.cu src/binaryop/compiled/Add.cu src/binaryop/compiled/ATan2.cu src/binaryop/compiled/BitwiseAnd.cu @@ -199,6 +197,8 @@ add_library( src/binaryop/compiled/ShiftRightUnsigned.cu src/binaryop/compiled/Sub.cu src/binaryop/compiled/TrueDiv.cu + src/binaryop/compiled/binary_ops.cu + src/binaryop/compiled/struct_binary_ops.cu src/binaryop/compiled/util.cpp src/labeling/label_bins.cu src/bitmask/null_mask.cu From 6c6c8abf38a9b8fb93195bebec234e5b21e143ed Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Tue, 15 Feb 2022 16:34:32 -0800 Subject: [PATCH 38/54] re-add missing function name --- cpp/src/binaryop/compiled/binary_ops.cuh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 2138084b598..6121b0628ef 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -307,7 +307,7 @@ void apply_binary_op(mutable_column_view& out, auto compare_orders = cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); - detail::(out, + detail::struct_compare(out, row_lexicographic_comparator{ nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, *d_lhs, From 42e58aec6be4d81c3db0bb7556d626e0248f8813 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Tue, 15 Feb 2022 17:07:54 -0800 Subject: [PATCH 39/54] style fix --- cpp/src/binaryop/compiled/binary_ops.cuh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 6121b0628ef..e580e5433da 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -307,16 +307,17 @@ void apply_binary_op(mutable_column_view& out, auto compare_orders = cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); - detail::struct_compare(out, - row_lexicographic_comparator{ - nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, - *d_lhs, - *d_rhs, - compare_orders.data()}, - is_lhs_scalar, - is_rhs_scalar, - flip_output, - stream); + detail::struct_compare( + out, + row_lexicographic_comparator{ + nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, + *d_lhs, + *d_rhs, + compare_orders.data()}, + is_lhs_scalar, + is_rhs_scalar, + flip_output, + stream); } else { auto common_dtype = get_common_type(out.type(), lhs.type(), rhs.type()); From 475c89636ebdc810eba214e452ba4ee1c43f7aae Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Fri, 18 Feb 2022 16:37:46 -0800 Subject: [PATCH 40/54] Fix struct equality binop comparisons --- cpp/include/cudf/table/row_operators.cuh | 53 +++++++++----- cpp/src/binaryop/compiled/binary_ops.cuh | 14 ++-- cpp/src/binaryop/compiled/equality_ops.cu | 4 +- cpp/tests/binaryop/binop-struct-test.cpp | 88 ++++++++++++----------- 4 files changed, 94 insertions(+), 65 deletions(-) diff --git a/cpp/include/cudf/table/row_operators.cuh b/cpp/include/cudf/table/row_operators.cuh index e5bd3047eec..0ebcf2abba0 100644 --- a/cpp/include/cudf/table/row_operators.cuh +++ b/cpp/include/cudf/table/row_operators.cuh @@ -148,7 +148,7 @@ inline __device__ auto null_compare(bool lhs_is_null, bool rhs_is_null, null_ord template ::value>* = nullptr> __device__ weak_ordering relational_compare(Element lhs, Element rhs, - weak_ordering nan_result = weak_ordering::GREATER) + weak_ordering const nan_result = weak_ordering::GREATER) { return detail::compare_elements(lhs, rhs); } @@ -162,9 +162,11 @@ __device__ weak_ordering relational_compare(Element lhs, * @return `true` if `lhs` == `rhs` else `false`. */ template ::value>* = nullptr> -__device__ bool equality_compare(Element lhs, Element rhs) +__device__ bool equality_compare(Element lhs, + Element rhs, + nan_equality const nan_result = nan_equality::ALL_EQUAL) { - if (isnan(lhs) and isnan(rhs)) { return true; } + if (isnan(lhs) and isnan(rhs)) { return nan_result == nan_equality::ALL_EQUAL; } return lhs == rhs; } @@ -177,7 +179,9 @@ __device__ bool equality_compare(Element lhs, Element rhs) * @return `true` if `lhs` == `rhs` else `false`. */ template ::value>* = nullptr> -__device__ bool equality_compare(Element const lhs, Element const rhs) +__device__ bool equality_compare(Element const lhs, + Element const rhs, + nan_equality const nan_result = nan_equality::ALL_EQUAL) { return lhs == rhs; } @@ -205,8 +209,13 @@ class element_equality_comparator { element_equality_comparator(Nullate has_nulls, column_device_view lhs, column_device_view rhs, - null_equality nulls_are_equal = null_equality::EQUAL) - : lhs{lhs}, rhs{rhs}, nulls{has_nulls}, nulls_are_equal{nulls_are_equal} + null_equality nulls_are_equal = null_equality::EQUAL, + nan_equality nans_are_equal = nan_equality::ALL_EQUAL) + : lhs{lhs}, + rhs{rhs}, + nulls{has_nulls}, + nulls_are_equal{nulls_are_equal}, + nans_are_equal{nans_are_equal} { } @@ -233,7 +242,8 @@ class element_equality_comparator { } return equality_compare(lhs.element(lhs_element_index), - rhs.element(rhs_element_index)); + rhs.element(rhs_element_index), + nans_are_equal); } template @@ -257,8 +268,13 @@ class row_equality_comparator { row_equality_comparator(Nullate has_nulls, table_device_view lhs, table_device_view rhs, - null_equality nulls_are_equal = null_equality::EQUAL) - : lhs{lhs}, rhs{rhs}, nulls{has_nulls}, nulls_are_equal{nulls_are_equal} + null_equality nulls_are_equal = null_equality::EQUAL, + nan_equality nans_are_equal = nan_equality::ALL_EQUAL) + : lhs{lhs}, + rhs{rhs}, + nulls{has_nulls}, + nulls_are_equal{nulls_are_equal}, + nans_are_equal{nans_are_equal} { CUDF_EXPECTS(lhs.num_columns() == rhs.num_columns(), "Mismatched number of columns."); } @@ -266,10 +282,11 @@ class row_equality_comparator { __device__ bool operator()(size_type lhs_row_index, size_type rhs_row_index) const noexcept { auto equal_elements = [=](column_device_view l, column_device_view r) { - return cudf::type_dispatcher(l.type(), - element_equality_comparator{nulls, l, r, nulls_are_equal}, - lhs_row_index, - rhs_row_index); + return cudf::type_dispatcher( + l.type(), + element_equality_comparator{nulls, l, r, nulls_are_equal, nans_are_equal}, + lhs_row_index, + rhs_row_index); }; return thrust::equal(thrust::seq, lhs.begin(), lhs.end(), rhs.begin(), equal_elements); @@ -280,6 +297,7 @@ class row_equality_comparator { table_device_view rhs; Nullate nulls; null_equality nulls_are_equal; + nan_equality nans_are_equal; }; /** @@ -427,12 +445,14 @@ class row_lexicographic_comparator { table_device_view lhs, table_device_view rhs, order const* column_order = nullptr, - null_order const* null_precedence = nullptr) + null_order const* null_precedence = nullptr, + bool const accept_equality = false) : _lhs{lhs}, _rhs{rhs}, _nulls{has_nulls}, _column_order{column_order}, - _null_precedence{null_precedence} + _null_precedence{null_precedence}, + _accept_equality{accept_equality} { CUDF_EXPECTS(_lhs.num_columns() == _rhs.num_columns(), "Mismatched number of columns."); CUDF_EXPECTS(detail::is_relationally_comparable(_lhs, _rhs), @@ -471,7 +491,7 @@ class row_lexicographic_comparator { return state == (ascending ? weak_ordering::LESS : weak_ordering::GREATER); } - return false; + return _accept_equality; } private: @@ -480,6 +500,7 @@ class row_lexicographic_comparator { Nullate _nulls{}; null_order const* _null_precedence{}; order const* _column_order{}; + bool const _accept_equality; }; // class row_lexicographic_comparator /** diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index e580e5433da..bad4b9a82df 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -289,10 +289,10 @@ void apply_binary_op(mutable_column_view& out, rmm::cuda_stream_view stream) { if (is_struct(lhs.type()) && is_struct(rhs.type())) { - auto op_order = detail::is_any_v - ? order::DESCENDING - : order::ASCENDING; - auto flip_output = detail::is_any_v; + auto op_order = detail::is_any_v + ? order::DESCENDING + : order::ASCENDING; + auto accept_equality = detail::is_any_v; auto const nullability = structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) ? structs::detail::column_nullability::FORCE @@ -313,10 +313,12 @@ void apply_binary_op(mutable_column_view& out, nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, *d_lhs, *d_rhs, - compare_orders.data()}, + compare_orders.data(), + nullptr, + accept_equality}, is_lhs_scalar, is_rhs_scalar, - flip_output, + false, stream); } else { auto common_dtype = get_common_type(out.type(), lhs.type(), rhs.type()); diff --git a/cpp/src/binaryop/compiled/equality_ops.cu b/cpp/src/binaryop/compiled/equality_ops.cu index cf912cc3910..436fdc7fa90 100644 --- a/cpp/src/binaryop/compiled/equality_ops.cu +++ b/cpp/src/binaryop/compiled/equality_ops.cu @@ -47,7 +47,9 @@ void dispatch_equality_op(mutable_column_view& out, row_equality_comparator{ nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, *d_lhs, - *d_rhs}, + *d_rhs, + null_equality::EQUAL, + nan_equality::UNEQUAL}, is_lhs_scalar, is_rhs_scalar, op == binary_operator::NOT_EQUAL, diff --git a/cpp/tests/binaryop/binop-struct-test.cpp b/cpp/tests/binaryop/binop-struct-test.cpp index 4804f575c3d..5643fe28f52 100644 --- a/cpp/tests/binaryop/binop-struct-test.cpp +++ b/cpp/tests/binaryop/binop-struct-test.cpp @@ -300,28 +300,30 @@ TEST_F(BinopStructCompareNAN, float_nans) -NAN, -NAN, -NAN, NAN, NAN, NAN, 1.0f, 0.0f, -54.3f}; cudf::test::fixed_width_column_wrapper rhs{ -32.5f, -NAN, NAN, -0.0f, -NAN, NAN, 111.0f, -NAN, NAN}; + data_type dt = cudf::data_type(cudf::type_id::BOOL8); - auto expected_eq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 0}; - auto expected_neq = fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 1}; - auto expected_lt = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 1, 0, 0}; - auto expected_lteq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 1, 0, 0}; - auto expected_gt = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 0}; - auto expected_gteq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 0}; - - data_type dt = cudf::data_type(cudf::type_id::BOOL8); - auto res_eq = binary_operation(lhs, rhs, binary_operator::EQUAL, dt); - auto res_neq = binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); - auto res_lt = binary_operation(lhs, rhs, binary_operator::LESS, dt); - auto res_gt = binary_operation(lhs, rhs, binary_operator::GREATER, dt); - auto res_gteq = binary_operation(lhs, rhs, binary_operator::GREATER_EQUAL, dt); - auto res_lteq = binary_operation(lhs, rhs, binary_operator::LESS_EQUAL, dt); - - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); + auto expected_eq = binary_operation(lhs, rhs, binary_operator::EQUAL, dt); + auto expected_neq = binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); + auto expected_lt = binary_operation(lhs, rhs, binary_operator::LESS, dt); + auto expected_gt = binary_operation(lhs, rhs, binary_operator::GREATER, dt); + auto expected_gteq = binary_operation(lhs, rhs, binary_operator::GREATER_EQUAL, dt); + auto expected_lteq = binary_operation(lhs, rhs, binary_operator::LESS_EQUAL, dt); + + auto struct_lhs = structs_column_wrapper{lhs}; + auto struct_rhs = structs_column_wrapper{rhs}; + auto res_eq = binary_operation(struct_lhs, struct_rhs, binary_operator::EQUAL, dt); + auto res_neq = binary_operation(struct_lhs, struct_rhs, binary_operator::NOT_EQUAL, dt); + auto res_lt = binary_operation(struct_lhs, struct_rhs, binary_operator::LESS, dt); + auto res_gt = binary_operation(struct_lhs, struct_rhs, binary_operator::GREATER, dt); + auto res_gteq = binary_operation(struct_lhs, struct_rhs, binary_operator::GREATER_EQUAL, dt); + auto res_lteq = binary_operation(struct_lhs, struct_rhs, binary_operator::LESS_EQUAL, dt); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, *expected_eq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, *expected_neq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, *expected_lt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, *expected_lteq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, *expected_gt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, *expected_gteq); }; TEST_F(BinopStructCompareNAN, double_nans) @@ -330,28 +332,30 @@ TEST_F(BinopStructCompareNAN, double_nans) -NAN, -NAN, -NAN, NAN, NAN, NAN, 1.0f, 0.0f, -54.3f}; cudf::test::fixed_width_column_wrapper rhs{ -32.5f, -NAN, NAN, -0.0f, -NAN, NAN, 111.0f, -NAN, NAN}; + data_type dt = cudf::data_type(cudf::type_id::BOOL8); - auto expected_eq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 0}; - auto expected_neq = fixed_width_column_wrapper{1, 1, 1, 1, 1, 1, 1, 1, 1}; - auto expected_lt = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 1, 0, 0}; - auto expected_lteq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 1, 0, 0}; - auto expected_gt = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 0}; - auto expected_gteq = fixed_width_column_wrapper{0, 0, 0, 0, 0, 0, 0, 0, 0}; - - data_type dt = cudf::data_type(cudf::type_id::BOOL8); - auto res_eq = binary_operation(lhs, rhs, binary_operator::EQUAL, dt); - auto res_neq = binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); - auto res_lt = binary_operation(lhs, rhs, binary_operator::LESS, dt); - auto res_gt = binary_operation(lhs, rhs, binary_operator::GREATER, dt); - auto res_gteq = binary_operation(lhs, rhs, binary_operator::GREATER_EQUAL, dt); - auto res_lteq = binary_operation(lhs, rhs, binary_operator::LESS_EQUAL, dt); - - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, expected_gteq); + auto expected_eq = binary_operation(lhs, rhs, binary_operator::EQUAL, dt); + auto expected_neq = binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); + auto expected_lt = binary_operation(lhs, rhs, binary_operator::LESS, dt); + auto expected_gt = binary_operation(lhs, rhs, binary_operator::GREATER, dt); + auto expected_gteq = binary_operation(lhs, rhs, binary_operator::GREATER_EQUAL, dt); + auto expected_lteq = binary_operation(lhs, rhs, binary_operator::LESS_EQUAL, dt); + + auto struct_lhs = structs_column_wrapper{lhs}; + auto struct_rhs = structs_column_wrapper{rhs}; + auto res_eq = binary_operation(struct_lhs, struct_rhs, binary_operator::EQUAL, dt); + auto res_neq = binary_operation(struct_lhs, struct_rhs, binary_operator::NOT_EQUAL, dt); + auto res_lt = binary_operation(struct_lhs, struct_rhs, binary_operator::LESS, dt); + auto res_gt = binary_operation(struct_lhs, struct_rhs, binary_operator::GREATER, dt); + auto res_gteq = binary_operation(struct_lhs, struct_rhs, binary_operator::GREATER_EQUAL, dt); + auto res_lteq = binary_operation(struct_lhs, struct_rhs, binary_operator::LESS_EQUAL, dt); + + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, *expected_eq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, *expected_neq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, *expected_lt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, *expected_lteq); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, *expected_gt); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gteq, *expected_gteq); }; struct BinopStructCompareFailures : public cudf::test::BaseFixture { From 1dae04a3b428bd4cc933bb066a192e21c4ef556b Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 7 Mar 2022 15:53:12 -0800 Subject: [PATCH 41/54] PR reviews --- cpp/include/cudf/table/row_operators.cuh | 76 +++++++------------ cpp/src/binaryop/compiled/binary_ops.cu | 2 +- cpp/src/binaryop/compiled/equality_ops.cu | 4 +- .../binaryop/compiled/struct_binary_ops.cu | 17 +---- 4 files changed, 35 insertions(+), 64 deletions(-) diff --git a/cpp/include/cudf/table/row_operators.cuh b/cpp/include/cudf/table/row_operators.cuh index 0ebcf2abba0..a77ad8ac3da 100644 --- a/cpp/include/cudf/table/row_operators.cuh +++ b/cpp/include/cudf/table/row_operators.cuh @@ -318,19 +318,24 @@ class element_relational_comparator { * @param rhs The column containing the second element (may be the same as lhs) * @param has_nulls Indicates if either input column contains nulls. * @param null_precedence Indicates how null values are ordered with other values + * @param nan_result Default set to EQUIVALENT, which will produce results consitent with `nan == + * nan` and `nan > non_nan`. If not equivalent, it specifies what value should be returned if + * either element is nan. */ - __host__ __device__ element_relational_comparator(Nullate has_nulls, - column_device_view lhs, - column_device_view rhs, - null_order null_precedence) - : lhs{lhs}, rhs{rhs}, nulls{has_nulls}, null_precedence{null_precedence} + __host__ __device__ + element_relational_comparator(Nullate has_nulls, + column_device_view lhs, + column_device_view rhs, + null_order null_precedence, + weak_ordering nan_result = weak_ordering::EQUIVALENT) + : lhs{lhs}, rhs{rhs}, nulls{has_nulls}, null_precedence{null_precedence}, nan_result{nan_result} { } __host__ __device__ element_relational_comparator(Nullate has_nulls, column_device_view lhs, column_device_view rhs) - : lhs{lhs}, rhs{rhs}, nulls{has_nulls} + : lhs{lhs}, rhs{rhs}, nulls{has_nulls}, nan_result{weak_ordering::EQUIVALENT} { } @@ -355,44 +360,17 @@ class element_relational_comparator { return null_compare(lhs_is_null, rhs_is_null, null_precedence); } } - - return relational_compare(lhs.element(lhs_element_index), - rhs.element(rhs_element_index)); - } - - /** - * @brief Performs a relational comparison between the specified elements - * - * @param lhs_element_index The index of the first element - * @param rhs_element_index The index of the second element - * @param nan_result specifies what value should be returned if either element is `nan` - * @return Indicates the relationship between the elements in - * the `lhs` and `rhs` columns. - */ - template ()>* = nullptr> - __device__ weak_ordering operator()(size_type lhs_element_index, - size_type rhs_element_index, - weak_ordering nan_result) const noexcept - { - if (nulls) { - bool const lhs_is_null{lhs.is_null(lhs_element_index)}; - bool const rhs_is_null{rhs.is_null(rhs_element_index)}; - - if (lhs_is_null or rhs_is_null) { // at least one is null - return null_compare(lhs_is_null, rhs_is_null, null_precedence); - } - } - - return relational_compare( - lhs.element(lhs_element_index), rhs.element(rhs_element_index), nan_result); + return nan_result == weak_ordering::EQUIVALENT + ? relational_compare(lhs.element(lhs_element_index), + rhs.element(rhs_element_index)) + : relational_compare(lhs.element(lhs_element_index), + rhs.element(rhs_element_index), + nan_result); } template ()>* = nullptr> - __device__ weak_ordering operator()(size_type lhs_element_index, - size_type rhs_element_index, - weak_ordering nan_result = weak_ordering::LESS) + __device__ weak_ordering operator()(size_type lhs_element_index, size_type rhs_element_index) { cudf_assert(false && "Attempted to compare elements of uncomparable types."); return weak_ordering::LESS; @@ -403,6 +381,7 @@ class element_relational_comparator { column_device_view rhs; Nullate nulls; null_order null_precedence{}; + weak_ordering nan_result; }; /** @@ -477,15 +456,16 @@ class row_lexicographic_comparator { _null_precedence == nullptr ? null_order::BEFORE : _null_precedence[i]; auto comparator = - element_relational_comparator{_nulls, _lhs.column(i), _rhs.column(i), null_precedence}; + NanConfig + ? element_relational_comparator{_nulls, + _lhs.column(i), + _rhs.column(i), + null_precedence, + ascending ? weak_ordering::GREATER : weak_ordering::LESS} + : element_relational_comparator{ + _nulls, _lhs.column(i), _rhs.column(i), null_precedence, weak_ordering::EQUIVALENT}; weak_ordering state = - NanConfig && is_floating_point(_lhs.column(i).type()) - ? cudf::type_dispatcher(_lhs.column(i).type(), - comparator, - lhs_index, - rhs_index, - ascending ? weak_ordering::GREATER : weak_ordering::LESS) - : cudf::type_dispatcher(_lhs.column(i).type(), comparator, lhs_index, rhs_index); + cudf::type_dispatcher(_lhs.column(i).type(), comparator, lhs_index, rhs_index); if (state == weak_ordering::EQUIVALENT) { continue; } diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index ee09eabdfc6..b9db7a01d0e 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -38,7 +38,7 @@ namespace { * scalar */ struct scalar_as_column_view { - using return_type = typename std::pair>; + using return_type = typename std::pair>; template ())>* = nullptr> return_type operator()(scalar const& s, rmm::cuda_stream_view, rmm::mr::device_memory_resource*) { diff --git a/cpp/src/binaryop/compiled/equality_ops.cu b/cpp/src/binaryop/compiled/equality_ops.cu index 436fdc7fa90..22158b32f2a 100644 --- a/cpp/src/binaryop/compiled/equality_ops.cu +++ b/cpp/src/binaryop/compiled/equality_ops.cu @@ -29,6 +29,8 @@ void dispatch_equality_op(mutable_column_view& out, binary_operator op, rmm::cuda_stream_view stream) { + CUDF_EXPECTS(op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL, + "Unsupported operator for these types"); if (is_struct(lhs.type()) && is_struct(rhs.type())) { auto const nullability = structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) @@ -54,8 +56,6 @@ void dispatch_equality_op(mutable_column_view& out, is_rhs_scalar, op == binary_operator::NOT_EQUAL, stream); - else - CUDF_FAIL("Unsupported operator for these types"); } else { auto common_dtype = get_common_type(out.type(), lhs.type(), rhs.type()); auto outd = mutable_column_device_view::create(out, stream); diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cu b/cpp/src/binaryop/compiled/struct_binary_ops.cu index 36ef2506fca..fd657f82a83 100644 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cu +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cu @@ -46,18 +46,9 @@ void struct_compare(mutable_column_view& out, } } // namespace binops::compiled::detail -#define INSTANTIATE_STRUCT_COMPARE(comp_op) \ - template void binops::compiled::detail::struct_compare( \ - mutable_column_view&, comp_op, bool, bool, bool, rmm::cuda_stream_view); - +#define INSTANTIATE_STRUCT_COMPARE(...) \ + template void binops::compiled::detail::struct_compare<__VA_ARGS__>( \ + mutable_column_view&, __VA_ARGS__, bool, bool, bool, rmm::cuda_stream_view); INSTANTIATE_STRUCT_COMPARE(row_equality_comparator); -// INSTANTIATE_STRUCT_COMPARE does not work with the optional template argument -template void -binops::compiled::detail::struct_compare>( - mutable_column_view&, - row_lexicographic_comparator, - bool, - bool, - bool, - rmm::cuda_stream_view); +INSTANTIATE_STRUCT_COMPARE(row_lexicographic_comparator); } // namespace cudf From a35600d3963c725d2028857fb085cbbfcd2b3379 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Tue, 22 Mar 2022 14:05:04 -0700 Subject: [PATCH 42/54] refactor row comparison operators into common spaceship operator --- cpp/include/cudf/table/row_operators.cuh | 166 ++++++++++++++++-- cpp/src/binaryop/compiled/binary_ops.cuh | 47 +++-- .../binaryop/compiled/struct_binary_ops.cu | 2 + 3 files changed, 182 insertions(+), 33 deletions(-) diff --git a/cpp/include/cudf/table/row_operators.cuh b/cpp/include/cudf/table/row_operators.cuh index 7b0c2cf0954..f5fac353e88 100644 --- a/cpp/include/cudf/table/row_operators.cuh +++ b/cpp/include/cudf/table/row_operators.cuh @@ -16,6 +16,7 @@ #pragma once +#include #include #include #include @@ -386,12 +387,14 @@ class element_relational_comparator { }; /** - * @brief Computes whether one row is lexicographically *less* than another row. + * @brief Computes whether one row is lexicographically less, greater, or equivalent than another + * row. * * Lexicographic ordering is determined by: * - Two rows are compared element by element. * - The first mismatching element defines which row is lexicographically less * or greater than the other. + * - If the rows are compared without mismatched elements, the rows are equivalent * * Lexicographic ordering is exactly equivalent to doing an alphabetical sort of * two words, for example, `aac` would be *less* than (or precede) `abb`. The @@ -399,9 +402,11 @@ class element_relational_comparator { * `aac < abb`. * * @tparam Nullate A cudf::nullate type describing how to check for nulls. + * @tparam NanConfig default configuration nans are equal, if set to true triggers specialized IEEE + * 754 compliant nan handling */ template -class row_lexicographic_comparator { +class row_generic_comparator { public: /** * @brief Construct a function object for performing a lexicographic @@ -421,18 +426,16 @@ class row_lexicographic_comparator { * it is nullptr, then null precedence would be `null_order::BEFORE` for all * columns. */ - row_lexicographic_comparator(Nullate has_nulls, - table_device_view lhs, - table_device_view rhs, - order const* column_order = nullptr, - null_order const* null_precedence = nullptr, - bool const accept_equality = false) + row_generic_comparator(Nullate has_nulls, + table_device_view lhs, + table_device_view rhs, + order const* column_order = nullptr, + null_order const* null_precedence = nullptr) : _lhs{lhs}, _rhs{rhs}, _nulls{has_nulls}, _column_order{column_order}, - _null_precedence{null_precedence}, - _accept_equality{accept_equality} + _null_precedence{null_precedence} { CUDF_EXPECTS(_lhs.num_columns() == _rhs.num_columns(), "Mismatched number of columns."); CUDF_EXPECTS(detail::is_relationally_comparable(_lhs, _rhs), @@ -441,14 +444,14 @@ class row_lexicographic_comparator { /** * @brief Checks whether the row at `lhs_index` in the `lhs` table compares - * lexicographically less than the row at `rhs_index` in the `rhs` table. + * lexicographically less, greater, or equal to the row at `rhs_index` in the `rhs` table. * * @param lhs_index The index of row in the `lhs` table to examine * @param rhs_index The index of the row in the `rhs` table to examine * @return `true` if row from the `lhs` table compares less than row in the * `rhs` table */ - __device__ bool operator()(size_type lhs_index, size_type rhs_index) const noexcept + __device__ weak_ordering operator()(size_type lhs_index, size_type rhs_index) const noexcept { for (size_type i = 0; i < _lhs.num_columns(); ++i) { bool ascending = (_column_order == nullptr) or (_column_order[i] == order::ASCENDING); @@ -470,9 +473,11 @@ class row_lexicographic_comparator { if (state == weak_ordering::EQUIVALENT) { continue; } - return state == (ascending ? weak_ordering::LESS : weak_ordering::GREATER); + return ascending + ? state + : (state == weak_ordering::GREATER ? weak_ordering::LESS : weak_ordering::GREATER); } - return _accept_equality; + return weak_ordering::EQUIVALENT; } private: @@ -481,9 +486,140 @@ class row_lexicographic_comparator { Nullate _nulls{}; null_order const* _null_precedence{}; order const* _column_order{}; - bool const _accept_equality; +}; // class row_generic_comparator + +/** + * @brief Computes whether one row is lexicographically *less* than another row. + * + * Lexicographic ordering is determined by: + * - Two rows are compared element by element. + * - The first mismatching element defines which row is lexicographically less + * or greater than the other. + * + * Lexicographic ordering is exactly equivalent to doing an alphabetical sort of + * two words, for example, `aac` would be *less* than (or precede) `abb`. The + * second letter in both words is the first non-equal letter, and `a < b`, thus + * `aac < abb`. + * + * @tparam Nullate A cudf::nullate type describing how to check for nulls. + * @tparam NanConfig default configuration nans are equal, if set to true triggers specialized IEEE + * 754 compliant nan handling + */ +template +class row_lexicographic_comparator { + public: + /** + * @brief Construct a function object for performing a lexicographic + * comparison between the rows of two tables. + * + * @throws cudf::logic_error if `lhs.num_columns() != rhs.num_columns()` + * @throws cudf::logic_error if column types of `lhs` and `rhs` are not comparable. + * + * @param lhs The first table + * @param rhs The second table (may be the same table as `lhs`) + * @param has_nulls Indicates if either input table contains columns with nulls. + * @param column_order Optional, device array the same length as a row that + * indicates the desired ascending/descending order of each column in a row. + * If `nullptr`, it is assumed all columns are sorted in ascending order. + * @param null_precedence Optional, device array the same length as a row + * and indicates how null values compare to all other for every column. If + * it is nullptr, then null precedence would be `null_order::BEFORE` for all + * columns. + */ + row_lexicographic_comparator(Nullate has_nulls, + table_device_view lhs, + table_device_view rhs, + order const* column_order = nullptr, + null_order const* null_precedence = nullptr) + : comparator{has_nulls, lhs, rhs, column_order, null_precedence} + { + } + + /** + * @brief Checks whether the row at `lhs_index` in the `lhs` table compares + * lexicographically less than the row at `rhs_index` in the `rhs` table. + * + * @param lhs_index The index of row in the `lhs` table to examine + * @param rhs_index The index of the row in the `rhs` table to examine + * @return `true` if row from the `lhs` table compares less than row in the + * `rhs` table + */ + __device__ bool operator()(size_type lhs_index, size_type rhs_index) const noexcept + { + return comparator(lhs_index, rhs_index) == weak_ordering::LESS; + } + + private: + row_generic_comparator comparator; }; // class row_lexicographic_comparator +/** + * @brief Computes whether one row is lexicographically *less than or equal to* another row. + * + * Lexicographic ordering is determined by: + * - Two rows are compared element by element. + * - The first mismatching element defines which row is lexicographically less + * or greater than the other. + * - If the rows are compared without mismatched elements, the rows are equivalent + * + * Lexicographic ordering is exactly equivalent to doing an alphabetical sort of + * two words, for example, `aac` would be *less* than (or precede) `abb`. The + * second letter in both words is the first non-equal letter, and `a < b`, thus + * `aac < abb`. + * + * @tparam Nullate A cudf::nullate type describing how to check for nulls. + * @tparam NanConfig default configuration nans are equal, if set to true triggers specialized IEEE + * 754 compliant nan handling + */ +template +class row_lexicographic_or_equal_comparator { + public: + /** + * @brief Construct a function object for performing a lexicographic + * comparison between the rows of two tables. + * + * @throws cudf::logic_error if `lhs.num_columns() != rhs.num_columns()` + * @throws cudf::logic_error if column types of `lhs` and `rhs` are not comparable. + * + * @param lhs The first table + * @param rhs The second table (may be the same table as `lhs`) + * @param has_nulls Indicates if either input table contains columns with nulls. + * @param column_order Optional, device array the same length as a row that + * indicates the desired ascending/descending order of each column in a row. + * If `nullptr`, it is assumed all columns are sorted in ascending order. + * @param null_precedence Optional, device array the same length as a row + * and indicates how null values compare to all other for every column. If + * it is nullptr, then null precedence would be `null_order::BEFORE` for all + * columns. + */ + row_lexicographic_or_equal_comparator(Nullate has_nulls, + table_device_view lhs, + table_device_view rhs, + order const* column_order = nullptr, + null_order const* null_precedence = nullptr) + : comparator{has_nulls, lhs, rhs, column_order, null_precedence} + { + } + + /** + * @brief Checks whether the row at `lhs_index` in the `lhs` table compares + * lexicographically less than or equal to the row at `rhs_index` in the `rhs` table. + * + * @param lhs_index The index of row in the `lhs` table to examine + * @param rhs_index The index of the row in the `rhs` table to examine + * @return `true` if row from the `lhs` table compares less than or equal to the row in the `rhs` + * table + */ + __device__ bool operator()(size_type lhs_index, size_type rhs_index) const noexcept + { + weak_ordering result = comparator(lhs_index, rhs_index); + return result == weak_ordering::LESS || result == weak_ordering::EQUIVALENT; + } + + private: + row_generic_comparator comparator; +}; // class row_lexicographic_or_equal_comparator + /** * @brief Computes the hash value of an element in the given column. * diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index bad4b9a82df..6f2abb72415 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -289,10 +290,9 @@ void apply_binary_op(mutable_column_view& out, rmm::cuda_stream_view stream) { if (is_struct(lhs.type()) && is_struct(rhs.type())) { - auto op_order = detail::is_any_v - ? order::DESCENDING - : order::ASCENDING; - auto accept_equality = detail::is_any_v; + auto op_order = detail::is_any_v + ? order::DESCENDING + : order::ASCENDING; auto const nullability = structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) ? structs::detail::column_nullability::FORCE @@ -306,20 +306,31 @@ void apply_binary_op(mutable_column_view& out, auto d_rhs = table_device_view::create(rhs_flattened); auto compare_orders = cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); - - detail::struct_compare( - out, - row_lexicographic_comparator{ - nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, - *d_lhs, - *d_rhs, - compare_orders.data(), - nullptr, - accept_equality}, - is_lhs_scalar, - is_rhs_scalar, - false, - stream); + detail::is_any_v + ? detail::struct_compare( + out, + row_lexicographic_or_equal_comparator{ + nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, + *d_lhs, + *d_rhs, + compare_orders.data(), + nullptr}, + is_lhs_scalar, + is_rhs_scalar, + false, + stream) + : detail::struct_compare( + out, + row_lexicographic_comparator{ + nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, + *d_lhs, + *d_rhs, + compare_orders.data(), + nullptr}, + is_lhs_scalar, + is_rhs_scalar, + false, + stream); } else { auto common_dtype = get_common_type(out.type(), lhs.type(), rhs.type()); diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cu b/cpp/src/binaryop/compiled/struct_binary_ops.cu index fd657f82a83..649cf611c0e 100644 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cu +++ b/cpp/src/binaryop/compiled/struct_binary_ops.cu @@ -51,4 +51,6 @@ void struct_compare(mutable_column_view& out, mutable_column_view&, __VA_ARGS__, bool, bool, bool, rmm::cuda_stream_view); INSTANTIATE_STRUCT_COMPARE(row_equality_comparator); INSTANTIATE_STRUCT_COMPARE(row_lexicographic_comparator); +INSTANTIATE_STRUCT_COMPARE(row_lexicographic_or_equal_comparator); + } // namespace cudf From fcc1dd285b387f2c8f10060690978f0ba2b8b241 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Tue, 29 Mar 2022 14:47:15 -0700 Subject: [PATCH 43/54] first pass, test failures --- .../cudf/table/experimental/row_operators.cuh | 127 +++++++++++++++--- 1 file changed, 111 insertions(+), 16 deletions(-) diff --git a/cpp/include/cudf/table/experimental/row_operators.cuh b/cpp/include/cudf/table/experimental/row_operators.cuh index d305cfa66b5..1b4856ecbb1 100644 --- a/cpp/include/cudf/table/experimental/row_operators.cuh +++ b/cpp/include/cudf/table/experimental/row_operators.cuh @@ -16,6 +16,7 @@ #pragma once +#include #include #include #include @@ -78,10 +79,12 @@ namespace lexicographic { * * @tparam Nullate A cudf::nullate type describing how to check for nulls. */ -template -class device_row_comparator { - friend class self_comparator; - +template +class device_row_generic_comparator { + // private: + // friend class device_row_comparator; + // friend class template device_row_comparator; + public: /** * @brief Construct a function object for performing a lexicographic * comparison between the rows of two tables. @@ -98,7 +101,7 @@ class device_row_comparator { * values compare to all other for every column. If `nullopt`, then null precedence would be * `null_order::BEFORE` for all columns. */ - device_row_comparator( + device_row_generic_comparator( Nullate has_nulls, table_device_view lhs, table_device_view rhs, @@ -112,6 +115,7 @@ class device_row_comparator { _column_order{column_order}, _null_precedence{null_precedence} { + // CUDF_EXPECTS(_lhs.num_columns() == _rhs.num_columns(), "Mismatched number of columns."); } /** @@ -136,8 +140,14 @@ class device_row_comparator { column_device_view lhs, column_device_view rhs, null_order null_precedence = null_order::BEFORE, - int depth = 0) - : _lhs{lhs}, _rhs{rhs}, _nulls{has_nulls}, _null_precedence{null_precedence}, _depth{depth} + int depth = 0, + weak_ordering nan_result = weak_ordering::EQUIVALENT) + : _lhs{lhs}, + _rhs{rhs}, + _nulls{has_nulls}, + _null_precedence{null_precedence}, + _depth{depth}, + _nan_result{nan_result} { } @@ -164,8 +174,12 @@ class device_row_comparator { } } - return cuda::std::make_pair(relational_compare(_lhs.element(lhs_element_index), - _rhs.element(rhs_element_index)), + return cuda::std::make_pair(_nan_result == weak_ordering::EQUIVALENT + ? relational_compare(_lhs.element(lhs_element_index), + _rhs.element(rhs_element_index)) + : relational_compare(_lhs.element(lhs_element_index), + _rhs.element(rhs_element_index), + _nan_result), std::numeric_limits::max()); } @@ -202,7 +216,8 @@ class device_row_comparator { ++depth; } - auto const comparator = element_comparator{_nulls, lcol, rcol, _null_precedence, depth}; + auto const comparator = + element_comparator{_nulls, lcol, rcol, _null_precedence, depth, _nan_result}; return cudf::type_dispatcher( lcol.type(), comparator, lhs_element_index, rhs_element_index); } @@ -213,18 +228,20 @@ class device_row_comparator { Nullate const _nulls; null_order const _null_precedence; int const _depth; + weak_ordering const _nan_result; }; public: /** * @brief Checks whether the row at `lhs_index` in the `lhs` table compares - * lexicographically less than the row at `rhs_index` in the `rhs` table. + * lexicographically less, greater, or equal to the row at `rhs_index` in the `rhs` table. * * @param lhs_index The index of row in the `lhs` table to examine * @param rhs_index The index of the row in the `rhs` table to examine - * @return `true` if row from the `lhs` table compares less than row in the `rhs` table + * @return weak ordering comparison of the row in the `lhs` table relative to the row in the `rhs` + * table */ - __device__ bool operator()(size_type const lhs_index, size_type const rhs_index) const noexcept + __device__ weak_ordering operator()(size_type lhs_index, size_type rhs_index) const noexcept { int last_null_depth = std::numeric_limits::max(); for (size_type i = 0; i < _lhs.num_columns(); ++i) { @@ -238,7 +255,18 @@ class device_row_comparator { _null_precedence.has_value() ? (*_null_precedence)[i] : null_order::BEFORE; auto const comparator = - element_comparator{_nulls, _lhs.column(i), _rhs.column(i), null_precedence, depth}; + NanConfig ? element_comparator{_nulls, + _lhs.column(i), + _rhs.column(i), + null_precedence, + depth, + ascending ? weak_ordering::GREATER : weak_ordering::LESS} + : element_comparator{_nulls, + _lhs.column(i), + _rhs.column(i), + null_precedence, + depth, + weak_ordering::EQUIVALENT}; weak_ordering state; cuda::std::tie(state, last_null_depth) = @@ -246,9 +274,11 @@ class device_row_comparator { if (state == weak_ordering::EQUIVALENT) { continue; } - return state == (ascending ? weak_ordering::LESS : weak_ordering::GREATER); + return ascending + ? state + : (state == weak_ordering::GREATER ? weak_ordering::LESS : weak_ordering::GREATER); } - return false; + return weak_ordering::EQUIVALENT; } private: @@ -258,6 +288,71 @@ class device_row_comparator { std::optional> const _depth; std::optional> const _column_order; std::optional> const _null_precedence; +}; // class device_row_generic_comparator + +/** + * @brief Computes whether one row is lexicographically *less* than another row. + * + * Lexicographic ordering is determined by: + * - Two rows are compared element by element. + * - The first mismatching element defines which row is lexicographically less + * or greater than the other. + * + * Lexicographic ordering is exactly equivalent to doing an alphabetical sort of + * two words, for example, `aac` would be *less* than (or precede) `abb`. The + * second letter in both words is the first non-equal letter, and `a < b`, thus + * `aac < abb`. + * + * @tparam Nullate A cudf::nullate type describing how to check for nulls. + */ +template +class device_row_comparator { + friend class self_comparator; + + /** + * @brief Construct a function object for performing a lexicographic + * comparison between the rows of two tables. + * + * @param has_nulls Indicates if either input table contains columns with nulls. + * @param lhs The first table + * @param rhs The second table (may be the same table as `lhs`) + * @param depth Optional, device array the same length as a row that contains starting depths of + * columns if they're nested, and 0 otherwise. + * @param column_order Optional, device array the same length as a row that indicates the desired + * ascending/descending order of each column in a row. If `nullopt`, it is assumed all columns are + * sorted in ascending order. + * @param null_precedence Optional, device array the same length as a row and indicates how null + * values compare to all other for every column. If `nullopt`, then null precedence would be + * `null_order::BEFORE` for all columns. + */ + device_row_comparator( + Nullate has_nulls, + table_device_view lhs, + table_device_view rhs, + std::optional> depth = std::nullopt, + std::optional> column_order = std::nullopt, + std::optional> null_precedence = std::nullopt) noexcept + : comparator{has_nulls, lhs, rhs, depth, column_order, null_precedence} + { + } + + public: + /** + * @brief Checks whether the row at `lhs_index` in the `lhs` table compares + * lexicographically less than the row at `rhs_index` in the `rhs` table. + * + * @param lhs_index The index of row in the `lhs` table to examine + * @param rhs_index The index of the row in the `rhs` table to examine + * @return `true` if row from the `lhs` table compares less than row in the `rhs` table + */ + __device__ bool operator()(size_type const lhs_index, size_type const rhs_index) const noexcept + { + auto const result = comparator(lhs_index, rhs_index); + return result == weak_ordering::LESS; + } + + private: + device_row_generic_comparator comparator; }; // class device_row_comparator struct preprocessed_table { From 9d50ac0742565de1d93d2afe6441c9723f3cd053 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Fri, 15 Apr 2022 17:40:35 -0700 Subject: [PATCH 44/54] Refactor struct binop comparison to use experimental ops --- cpp/CMakeLists.txt | 1 - .../cudf/table/experimental/row_operators.cuh | 39 +++++------ cpp/src/binaryop/compiled/binary_ops.cuh | 64 ++++++++++--------- cpp/src/binaryop/compiled/equality_ops.cu | 40 +++++++----- .../binaryop/compiled/struct_binary_ops.cu | 56 ---------------- .../binaryop/compiled/struct_binary_ops.cuh | 41 ------------ 6 files changed, 78 insertions(+), 163 deletions(-) delete mode 100644 cpp/src/binaryop/compiled/struct_binary_ops.cu delete mode 100644 cpp/src/binaryop/compiled/struct_binary_ops.cuh diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 6e90ccc54d0..b4e0891d127 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -198,7 +198,6 @@ add_library( src/binaryop/compiled/Sub.cu src/binaryop/compiled/TrueDiv.cu src/binaryop/compiled/binary_ops.cu - src/binaryop/compiled/struct_binary_ops.cu src/binaryop/compiled/util.cpp src/labeling/label_bins.cu src/bitmask/null_mask.cu diff --git a/cpp/include/cudf/table/experimental/row_operators.cuh b/cpp/include/cudf/table/experimental/row_operators.cuh index 3464712c6f0..9dfc083681f 100644 --- a/cpp/include/cudf/table/experimental/row_operators.cuh +++ b/cpp/include/cudf/table/experimental/row_operators.cuh @@ -81,7 +81,7 @@ namespace lexicographic { * @tparam Nullate A cudf::nullate type describing how to check for nulls. */ template -class device_row_generic_comparator { +class device_row_comparator { // private: // friend class device_row_comparator; // friend class template device_row_comparator; @@ -102,7 +102,7 @@ class device_row_generic_comparator { * values compare to all other for every column. If `nullopt`, then null precedence would be * `null_order::BEFORE` for all columns. */ - device_row_generic_comparator( + device_row_comparator( Nullate has_nulls, table_device_view lhs, table_device_view rhs, @@ -175,13 +175,14 @@ class device_row_generic_comparator { } } - return cuda::std::make_pair(_nan_result == weak_ordering::EQUIVALENT - ? relational_compare(_lhs.element(lhs_element_index), - _rhs.element(rhs_element_index)) - : relational_compare(_lhs.element(lhs_element_index), - _rhs.element(rhs_element_index), - _nan_result), - std::numeric_limits::max()); + weak_ordering res = NanConfig + // weak_ordering res = (_nan_result != weak_ordering::EQUIVALENT) + ? relational_compare(_lhs.element(lhs_element_index), + _rhs.element(rhs_element_index), + _nan_result) + : relational_compare(_lhs.element(lhs_element_index), + _rhs.element(rhs_element_index)); + return cuda::std::make_pair(res, std::numeric_limits::max()); } template > const _depth; std::optional> const _column_order; std::optional> const _null_precedence; -}; // class device_row_generic_comparator +}; // class device_row_comparator /** * @brief Computes whether one row is lexicographically *less* than another row. @@ -307,9 +309,10 @@ class device_row_generic_comparator { * @tparam Nullate A cudf::nullate type describing how to check for nulls. */ template -class device_row_comparator { +class device_less_comparator { friend class self_comparator; + public: /** * @brief Construct a function object for performing a lexicographic * comparison between the rows of two tables. @@ -326,7 +329,7 @@ class device_row_comparator { * values compare to all other for every column. If `nullopt`, then null precedence would be * `null_order::BEFORE` for all columns. */ - device_row_comparator( + device_less_comparator( Nullate has_nulls, table_device_view lhs, table_device_view rhs, @@ -353,8 +356,8 @@ class device_row_comparator { } private: - device_row_generic_comparator comparator; -}; // class device_row_comparator + device_row_comparator comparator; +}; // class device_less_comparator struct preprocessed_table { using table_device_view_owner = @@ -503,10 +506,10 @@ class self_comparator { * * @tparam Nullate Optional, A cudf::nullate type describing how to check for nulls. */ - template - device_row_comparator device_comparator(Nullate nullate = {}) const + template + device_less_comparator device_comparator(Nullate nullate = {}) const { - return device_row_comparator( + return device_less_comparator( nullate, *d_t, *d_t, d_t->depths(), d_t->column_order(), d_t->null_precedence()); } diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 6f2abb72415..f59428898a2 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -18,14 +18,15 @@ #include #include -#include #include #include #include +#include #include #include #include +#include #include #include @@ -290,9 +291,10 @@ void apply_binary_op(mutable_column_view& out, rmm::cuda_stream_view stream) { if (is_struct(lhs.type()) && is_struct(rhs.type())) { - auto op_order = detail::is_any_v - ? order::DESCENDING - : order::ASCENDING; + auto op_order = detail::is_any_v + ? order::DESCENDING + : order::ASCENDING; + auto accept_equality = detail::is_any_v; auto const nullability = structs::detail::contains_null_structs(lhs) || structs::detail::contains_null_structs(rhs) ? structs::detail::column_nullability::FORCE @@ -302,35 +304,35 @@ void apply_binary_op(mutable_column_view& out, auto const rhs_flattened = structs::detail::flatten_nested_columns(table_view{{rhs}}, {}, {}, nullability); - auto d_lhs = table_device_view::create(lhs_flattened); - auto d_rhs = table_device_view::create(rhs_flattened); + auto lhsd = table_device_view::create(lhs_flattened); + auto rhsd = table_device_view::create(rhs_flattened); auto compare_orders = cudf::detail::make_device_uvector_async(std::vector(lhs.size(), op_order), stream); - detail::is_any_v - ? detail::struct_compare( - out, - row_lexicographic_or_equal_comparator{ - nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, - *d_lhs, - *d_rhs, - compare_orders.data(), - nullptr}, - is_lhs_scalar, - is_rhs_scalar, - false, - stream) - : detail::struct_compare( - out, - row_lexicographic_comparator{ - nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, - *d_lhs, - *d_rhs, - compare_orders.data(), - nullptr}, - is_lhs_scalar, - is_rhs_scalar, - false, - stream); + auto comparator = + experimental::row::lexicographic::device_row_comparator{ + nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, + *lhsd, + *rhsd, + std::nullopt, + device_span{compare_orders}, + std::nullopt}; + + auto outd = column_device_view::create(out, stream); + auto optional_iter = + cudf::detail::make_optional_iterator(*outd, nullate::DYNAMIC{out.has_nulls()}); + thrust::tabulate( + rmm::exec_policy(stream), + out.begin(), + out.end(), + [optional_iter, is_lhs_scalar, is_rhs_scalar, accept_equality, comparator] __device__( + size_type i) { + auto lhs = is_lhs_scalar ? 0 : i; + auto rhs = is_rhs_scalar ? 0 : i; + return optional_iter[i].has_value() && + (accept_equality ? comparator(lhs, rhs) != weak_ordering::GREATER + : comparator(lhs, rhs) == weak_ordering::LESS); + }); + } else { auto common_dtype = get_common_type(out.type(), lhs.type(), rhs.type()); diff --git a/cpp/src/binaryop/compiled/equality_ops.cu b/cpp/src/binaryop/compiled/equality_ops.cu index 22158b32f2a..3b7666aa757 100644 --- a/cpp/src/binaryop/compiled/equality_ops.cu +++ b/cpp/src/binaryop/compiled/equality_ops.cu @@ -15,7 +15,6 @@ */ #include -#include #include #include @@ -40,22 +39,31 @@ void dispatch_equality_op(mutable_column_view& out, structs::detail::flatten_nested_columns(table_view{{lhs}}, {}, {}, nullability); auto const rhs_flattened = structs::detail::flatten_nested_columns(table_view{{rhs}}, {}, {}, nullability); - auto d_lhs = table_device_view::create(lhs_flattened); - auto d_rhs = table_device_view::create(rhs_flattened); + auto lhsd = table_device_view::create(lhs_flattened); + auto rhsd = table_device_view::create(rhs_flattened); + auto comparator = row_equality_comparator{ + nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, + *lhsd, + *rhsd, + null_equality::EQUAL, + nan_equality::UNEQUAL}; - if (op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL) - detail::struct_compare( - out, - row_equality_comparator{ - nullate::DYNAMIC{has_nested_nulls(lhs_flattened) || has_nested_nulls(rhs_flattened)}, - *d_lhs, - *d_rhs, - null_equality::EQUAL, - nan_equality::UNEQUAL}, - is_lhs_scalar, - is_rhs_scalar, - op == binary_operator::NOT_EQUAL, - stream); + auto outd = column_device_view::create(out, stream); + auto optional_iter = + cudf::detail::make_optional_iterator(*outd, nullate::DYNAMIC{out.has_nulls()}); + thrust::tabulate(rmm::exec_policy(stream), + out.begin(), + out.end(), + [optional_iter, + is_lhs_scalar, + is_rhs_scalar, + flip_output = (op == binary_operator::NOT_EQUAL), + comparator] __device__(size_type i) { + auto lhs = is_lhs_scalar ? 0 : i; + auto rhs = is_rhs_scalar ? 0 : i; + return optional_iter[i].has_value() and + (flip_output ? not comparator(lhs, rhs) : comparator(lhs, rhs)); + }); } else { auto common_dtype = get_common_type(out.type(), lhs.type(), rhs.type()); auto outd = mutable_column_device_view::create(out, stream); diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cu b/cpp/src/binaryop/compiled/struct_binary_ops.cu deleted file mode 100644 index 649cf611c0e..00000000000 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cu +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2021-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. - */ - -#include -#include - -#include -#include - -namespace cudf { -namespace binops::compiled::detail { -template -void struct_compare(mutable_column_view& out, - Comparator compare, - bool is_lhs_scalar, - bool is_rhs_scalar, - bool flip_output, - rmm::cuda_stream_view stream) -{ - auto d_out = column_device_view::create(out, stream); - auto optional_iter = - cudf::detail::make_optional_iterator(*d_out, nullate::DYNAMIC{out.has_nulls()}); - thrust::tabulate( - rmm::exec_policy(stream), - out.begin(), - out.end(), - [optional_iter, is_lhs_scalar, is_rhs_scalar, flip_output, compare] __device__(size_type i) { - auto lhs = is_lhs_scalar ? 0 : i; - auto rhs = is_rhs_scalar ? 0 : i; - return optional_iter[i].has_value() and - (flip_output ? not compare(lhs, rhs) : compare(lhs, rhs)); - }); -} -} // namespace binops::compiled::detail - -#define INSTANTIATE_STRUCT_COMPARE(...) \ - template void binops::compiled::detail::struct_compare<__VA_ARGS__>( \ - mutable_column_view&, __VA_ARGS__, bool, bool, bool, rmm::cuda_stream_view); -INSTANTIATE_STRUCT_COMPARE(row_equality_comparator); -INSTANTIATE_STRUCT_COMPARE(row_lexicographic_comparator); -INSTANTIATE_STRUCT_COMPARE(row_lexicographic_or_equal_comparator); - -} // namespace cudf diff --git a/cpp/src/binaryop/compiled/struct_binary_ops.cuh b/cpp/src/binaryop/compiled/struct_binary_ops.cuh deleted file mode 100644 index 0655187ad17..00000000000 --- a/cpp/src/binaryop/compiled/struct_binary_ops.cuh +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2021-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 - -namespace cudf::binops::compiled::detail { -/** - * @brief Generates comparison results for each row in the output column. Supports scalar columns - * and negation of comparison results to mimic !=, <=, and >= operators. - * - * @tparam Comparator comparator type - * @param out mutable column view of output column - * @param compare initialized comparator function - * @param is_lhs_scalar true if @p compare has a single element column representing a scalar on its - * lhs - * @param is_rhs_scalar true if @p compare has a single element column representing a scalar on its - * rhs - * @param flip_output true if the comparison results should be negated - * @param stream CUDA stream used for device memory operations - */ -template -void struct_compare(mutable_column_view& out, - Comparator compare, - bool is_lhs_scalar, - bool is_rhs_scalar, - bool flip_output, - rmm::cuda_stream_view stream); -} // namespace cudf::binops::compiled::detail From a53780551c1c87821b27db0195a72ab1e92f7e43 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 2 May 2022 10:41:06 -0700 Subject: [PATCH 45/54] fix performance regression and code cleanup --- .../cudf/table/experimental/row_operators.cuh | 45 ++-- cpp/include/cudf/table/row_operators.cuh | 206 +++--------------- cpp/tests/binaryop/binop-struct-test.cpp | 53 +---- 3 files changed, 55 insertions(+), 249 deletions(-) diff --git a/cpp/include/cudf/table/experimental/row_operators.cuh b/cpp/include/cudf/table/experimental/row_operators.cuh index b0c7247c88f..846731d7ad3 100644 --- a/cpp/include/cudf/table/experimental/row_operators.cuh +++ b/cpp/include/cudf/table/experimental/row_operators.cuh @@ -67,16 +67,17 @@ struct dispatch_void_if_nested { }; namespace row { - namespace lexicographic { /** - * @brief Computes whether one row is lexicographically *less* than another row. + * @brief Computes the lexicographic comparison between 2 rows. * * Lexicographic ordering is determined by: * - Two rows are compared element by element. * - The first mismatching element defines which row is lexicographically less * or greater than the other. + * - If the rows are compared without mismatched elements, the rows are equivalent + * * * Lexicographic ordering is exactly equivalent to doing an alphabetical sort of * two words, for example, `aac` would be *less* than (or precede) `abb`. The @@ -84,12 +85,11 @@ namespace lexicographic { * `aac < abb`. * * @tparam Nullate A cudf::nullate type describing how to check for nulls. + * @tparam NanConfig default configuration nans are equal, if set to true triggers specialized IEEE + * 754 compliant nan handling */ template class device_row_comparator { - // private: - // friend class device_row_comparator; - // friend class template device_row_comparator; public: /** * @brief Construct a function object for performing a lexicographic @@ -121,7 +121,6 @@ class device_row_comparator { _column_order{column_order}, _null_precedence{null_precedence} { - // CUDF_EXPECTS(_lhs.num_columns() == _rhs.num_columns(), "Mismatched number of columns."); } /** @@ -141,6 +140,7 @@ class device_row_comparator { * @param null_precedence Indicates how null values are ordered with other values * @param depth The depth of the column if part of a nested column @see * preprocessed_table::depths + * @param nan_result Specifies what value should be returned if either element is `nan` */ __device__ element_comparator(Nullate has_nulls, column_device_view lhs, @@ -180,13 +180,11 @@ class device_row_comparator { } } - weak_ordering res = NanConfig - // weak_ordering res = (_nan_result != weak_ordering::EQUIVALENT) - ? relational_compare(_lhs.element(lhs_element_index), - _rhs.element(rhs_element_index), - _nan_result) - : relational_compare(_lhs.element(lhs_element_index), - _rhs.element(rhs_element_index)); + weak_ordering res = NanConfig ? relational_compare(_lhs.element(lhs_element_index), + _rhs.element(rhs_element_index), + _nan_result) + : relational_compare(_lhs.element(lhs_element_index), + _rhs.element(rhs_element_index)); return cuda::std::make_pair(res, std::numeric_limits::max()); } @@ -301,25 +299,16 @@ class device_row_comparator { }; // class device_row_comparator /** - * @brief Computes whether one row is lexicographically *less* than another row. - * - * Lexicographic ordering is determined by: - * - Two rows are compared element by element. - * - The first mismatching element defines which row is lexicographically less - * or greater than the other. - * - * Lexicographic ordering is exactly equivalent to doing an alphabetical sort of - * two words, for example, `aac` would be *less* than (or precede) `abb`. The - * second letter in both words is the first non-equal letter, and `a < b`, thus - * `aac < abb`. + * @brief Wraps and interprets the result of device_row_comparator, true if the result is + * weak_ordering::LESS meaning one row is lexicographically *less* than another row. * * @tparam Nullate A cudf::nullate type describing how to check for nulls. + * @tparam NanConfig default configuration nans are equal, if set to true triggers specialized IEEE + * 754 compliant nan handling */ template class device_less_comparator { friend class self_comparator; - - public: /** * @brief Construct a function object for performing a lexicographic * comparison between the rows of two tables. @@ -358,8 +347,7 @@ class device_less_comparator { */ __device__ bool operator()(size_type const lhs_index, size_type const rhs_index) const noexcept { - auto const result = comparator(lhs_index, rhs_index); - return result == weak_ordering::LESS; + return comparator(lhs_index, rhs_index) == weak_ordering::LESS; } private: @@ -808,7 +796,6 @@ class self_comparator { }; } // namespace equality - } // namespace row } // namespace experimental } // namespace cudf diff --git a/cpp/include/cudf/table/row_operators.cuh b/cpp/include/cudf/table/row_operators.cuh index 98bb8c70a72..c551cac3a93 100644 --- a/cpp/include/cudf/table/row_operators.cuh +++ b/cpp/include/cudf/table/row_operators.cuh @@ -16,7 +16,6 @@ #pragma once -#include #include #include #include @@ -144,8 +143,7 @@ inline __device__ auto null_compare(bool lhs_is_null, bool rhs_is_null, null_ord * * @param[in] lhs first element * @param[in] rhs second element - * @param[in] nan_result ignored, allows for configurable `nan` handling in the - * corresponding float enabled functions + * @param nan_result ignored for non-floating point operation * @return Indicates the relationship between the elements in * the `lhs` and `rhs` columns. */ @@ -163,6 +161,7 @@ __device__ weak_ordering relational_compare(Element lhs, * * @param lhs first element * @param rhs second element + * @param nan_result specifies what value should be returned if either element is `nan` * @return `true` if `lhs` == `rhs` else `false`. */ template >* = nullptr> @@ -180,6 +179,7 @@ __device__ bool equality_compare(Element lhs, * * @param lhs first element * @param rhs second element + * @param nan_result ignored for non-floating point operation * @return `true` if `lhs` == `rhs` else `false`. */ template >* = nullptr> @@ -208,6 +208,7 @@ class element_equality_comparator { * @param lhs The column containing the first element * @param rhs The column containing the second element (may be the same as lhs) * @param nulls_are_equal Indicates if two null elements are treated as equivalent + * @param nan_result specifies what value should be returned if either element is `nan` */ __host__ __device__ element_equality_comparator(Nullate has_nulls, @@ -321,24 +322,19 @@ class element_relational_comparator { * @param rhs The column containing the second element (may be the same as lhs) * @param has_nulls Indicates if either input column contains nulls. * @param null_precedence Indicates how null values are ordered with other values - * @param nan_result Default set to EQUIVALENT, which will produce results consitent with `nan == - * nan` and `nan > non_nan`. If not equivalent, it specifies what value should be returned if - * either element is nan. */ - __host__ __device__ - element_relational_comparator(Nullate has_nulls, - column_device_view lhs, - column_device_view rhs, - null_order null_precedence, - weak_ordering nan_result = weak_ordering::EQUIVALENT) - : lhs{lhs}, rhs{rhs}, nulls{has_nulls}, null_precedence{null_precedence}, nan_result{nan_result} + __host__ __device__ element_relational_comparator(Nullate has_nulls, + column_device_view lhs, + column_device_view rhs, + null_order null_precedence) + : lhs{lhs}, rhs{rhs}, nulls{has_nulls}, null_precedence{null_precedence} { } __host__ __device__ element_relational_comparator(Nullate has_nulls, column_device_view lhs, column_device_view rhs) - : lhs{lhs}, rhs{rhs}, nulls{has_nulls}, nan_result{weak_ordering::EQUIVALENT} + : lhs{lhs}, rhs{rhs}, nulls{has_nulls} { } @@ -363,12 +359,9 @@ class element_relational_comparator { return null_compare(lhs_is_null, rhs_is_null, null_precedence); } } - return nan_result == weak_ordering::EQUIVALENT - ? relational_compare(lhs.element(lhs_element_index), - rhs.element(rhs_element_index)) - : relational_compare(lhs.element(lhs_element_index), - rhs.element(rhs_element_index), - nan_result); + + return relational_compare(lhs.element(lhs_element_index), + rhs.element(rhs_element_index)); } template -class row_generic_comparator { +template +class row_lexicographic_comparator { public: /** * @brief Construct a function object for performing a lexicographic @@ -427,11 +415,11 @@ class row_generic_comparator { * it is nullptr, then null precedence would be `null_order::BEFORE` for all * columns. */ - row_generic_comparator(Nullate has_nulls, - table_device_view lhs, - table_device_view rhs, - order const* column_order = nullptr, - null_order const* null_precedence = nullptr) + row_lexicographic_comparator(Nullate has_nulls, + table_device_view lhs, + table_device_view rhs, + order const* column_order = nullptr, + null_order const* null_precedence = nullptr) : _lhs{lhs}, _rhs{rhs}, _nulls{has_nulls}, @@ -443,14 +431,14 @@ class row_generic_comparator { /** * @brief Checks whether the row at `lhs_index` in the `lhs` table compares - * lexicographically less, greater, or equal to the row at `rhs_index` in the `rhs` table. + * lexicographically less than the row at `rhs_index` in the `rhs` table. * * @param lhs_index The index of row in the `lhs` table to examine * @param rhs_index The index of the row in the `rhs` table to examine * @return `true` if row from the `lhs` table compares less than row in the * `rhs` table */ - __device__ weak_ordering operator()(size_type lhs_index, size_type rhs_index) const noexcept + __device__ bool operator()(size_type lhs_index, size_type rhs_index) const noexcept { for (size_type i = 0; i < _lhs.num_columns(); ++i) { bool ascending = (_column_order == nullptr) or (_column_order[i] == order::ASCENDING); @@ -459,24 +447,16 @@ class row_generic_comparator { _null_precedence == nullptr ? null_order::BEFORE : _null_precedence[i]; auto comparator = - NanConfig - ? element_relational_comparator{_nulls, - _lhs.column(i), - _rhs.column(i), - null_precedence, - ascending ? weak_ordering::GREATER : weak_ordering::LESS} - : element_relational_comparator{ - _nulls, _lhs.column(i), _rhs.column(i), null_precedence, weak_ordering::EQUIVALENT}; + element_relational_comparator{_nulls, _lhs.column(i), _rhs.column(i), null_precedence}; + weak_ordering state = cudf::type_dispatcher(_lhs.column(i).type(), comparator, lhs_index, rhs_index); if (state == weak_ordering::EQUIVALENT) { continue; } - return ascending - ? state - : (state == weak_ordering::GREATER ? weak_ordering::LESS : weak_ordering::GREATER); + return state == (ascending ? weak_ordering::LESS : weak_ordering::GREATER); } - return weak_ordering::EQUIVALENT; + return false; } private: @@ -485,140 +465,8 @@ class row_generic_comparator { Nullate _nulls{}; null_order const* _null_precedence{}; order const* _column_order{}; -}; // class row_generic_comparator - -/** - * @brief Computes whether one row is lexicographically *less* than another row. - * - * Lexicographic ordering is determined by: - * - Two rows are compared element by element. - * - The first mismatching element defines which row is lexicographically less - * or greater than the other. - * - * Lexicographic ordering is exactly equivalent to doing an alphabetical sort of - * two words, for example, `aac` would be *less* than (or precede) `abb`. The - * second letter in both words is the first non-equal letter, and `a < b`, thus - * `aac < abb`. - * - * @tparam Nullate A cudf::nullate type describing how to check for nulls. - * @tparam NanConfig default configuration nans are equal, if set to true triggers specialized IEEE - * 754 compliant nan handling - */ -template -class row_lexicographic_comparator { - public: - /** - * @brief Construct a function object for performing a lexicographic - * comparison between the rows of two tables. - * - * @throws cudf::logic_error if `lhs.num_columns() != rhs.num_columns()` - * @throws cudf::logic_error if column types of `lhs` and `rhs` are not comparable. - * - * @param lhs The first table - * @param rhs The second table (may be the same table as `lhs`) - * @param has_nulls Indicates if either input table contains columns with nulls. - * @param column_order Optional, device array the same length as a row that - * indicates the desired ascending/descending order of each column in a row. - * If `nullptr`, it is assumed all columns are sorted in ascending order. - * @param null_precedence Optional, device array the same length as a row - * and indicates how null values compare to all other for every column. If - * it is nullptr, then null precedence would be `null_order::BEFORE` for all - * columns. - */ - row_lexicographic_comparator(Nullate has_nulls, - table_device_view lhs, - table_device_view rhs, - order const* column_order = nullptr, - null_order const* null_precedence = nullptr) - : comparator{has_nulls, lhs, rhs, column_order, null_precedence} - { - } - - /** - * @brief Checks whether the row at `lhs_index` in the `lhs` table compares - * lexicographically less than the row at `rhs_index` in the `rhs` table. - * - * @param lhs_index The index of row in the `lhs` table to examine - * @param rhs_index The index of the row in the `rhs` table to examine - * @return `true` if row from the `lhs` table compares less than row in the - * `rhs` table - */ - __device__ bool operator()(size_type lhs_index, size_type rhs_index) const noexcept - { - return comparator(lhs_index, rhs_index) == weak_ordering::LESS; - } - - private: - row_generic_comparator comparator; }; // class row_lexicographic_comparator -/** - * @brief Computes whether one row is lexicographically *less than or equal to* another row. - * - * Lexicographic ordering is determined by: - * - Two rows are compared element by element. - * - The first mismatching element defines which row is lexicographically less - * or greater than the other. - * - If the rows are compared without mismatched elements, the rows are equivalent - * - * Lexicographic ordering is exactly equivalent to doing an alphabetical sort of - * two words, for example, `aac` would be *less* than (or precede) `abb`. The - * second letter in both words is the first non-equal letter, and `a < b`, thus - * `aac < abb`. - * - * @tparam Nullate A cudf::nullate type describing how to check for nulls. - * @tparam NanConfig default configuration nans are equal, if set to true triggers specialized IEEE - * 754 compliant nan handling - */ -template -class row_lexicographic_or_equal_comparator { - public: - /** - * @brief Construct a function object for performing a lexicographic - * comparison between the rows of two tables. - * - * @throws cudf::logic_error if `lhs.num_columns() != rhs.num_columns()` - * @throws cudf::logic_error if column types of `lhs` and `rhs` are not comparable. - * - * @param lhs The first table - * @param rhs The second table (may be the same table as `lhs`) - * @param has_nulls Indicates if either input table contains columns with nulls. - * @param column_order Optional, device array the same length as a row that - * indicates the desired ascending/descending order of each column in a row. - * If `nullptr`, it is assumed all columns are sorted in ascending order. - * @param null_precedence Optional, device array the same length as a row - * and indicates how null values compare to all other for every column. If - * it is nullptr, then null precedence would be `null_order::BEFORE` for all - * columns. - */ - row_lexicographic_or_equal_comparator(Nullate has_nulls, - table_device_view lhs, - table_device_view rhs, - order const* column_order = nullptr, - null_order const* null_precedence = nullptr) - : comparator{has_nulls, lhs, rhs, column_order, null_precedence} - { - } - - /** - * @brief Checks whether the row at `lhs_index` in the `lhs` table compares - * lexicographically less than or equal to the row at `rhs_index` in the `rhs` table. - * - * @param lhs_index The index of row in the `lhs` table to examine - * @param rhs_index The index of the row in the `rhs` table to examine - * @return `true` if row from the `lhs` table compares less than or equal to the row in the `rhs` - * table - */ - __device__ bool operator()(size_type lhs_index, size_type rhs_index) const noexcept - { - weak_ordering result = comparator(lhs_index, rhs_index); - return result == weak_ordering::LESS || result == weak_ordering::EQUIVALENT; - } - - private: - row_generic_comparator comparator; -}; // class row_lexicographic_or_equal_comparator - /** * @brief Computes the hash value of an element in the given column. * diff --git a/cpp/tests/binaryop/binop-struct-test.cpp b/cpp/tests/binaryop/binop-struct-test.cpp index 5643fe28f52..d95908c32f3 100644 --- a/cpp/tests/binaryop/binop-struct-test.cpp +++ b/cpp/tests/binaryop/binop-struct-test.cpp @@ -38,17 +38,8 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_no_nulls) auto strings1 = strings_column_wrapper{"0a", "1c", "2d", "3b", "5c", "6", "7d", "9g", "0h"}; auto strings2 = strings_column_wrapper{"0b", "0c", "2d", "3a", "4c", "6", "8e", "9f", "0h"}; - std::vector> lhs_columns; - lhs_columns.push_back(col1.release()); - lhs_columns.push_back(strings1.release()); - auto lhs_col = cudf::make_structs_column(9, std::move(lhs_columns), 0, rmm::device_buffer{}); - std::vector> rhs_columns; - rhs_columns.push_back(col2.release()); - rhs_columns.push_back(strings2.release()); - auto rhs_col = cudf::make_structs_column(9, std::move(rhs_columns), 0, rmm::device_buffer{}); - - auto lhs = lhs_col->view(); - auto rhs = rhs_col->view(); + auto lhs = structs_column_wrapper{col1, strings1}; + auto rhs = structs_column_wrapper{col2, strings2}; data_type dt = cudf::data_type(type_id::BOOL8); auto res_eq = binary_operation(lhs, rhs, binary_operator::EQUAL, dt); @@ -67,7 +58,6 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_no_nulls) CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); @@ -94,24 +84,12 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_with_nulls) "2d", "3a", "4c", "6", "8e", "9f", "0h", "1f", "2g", "3h"}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1}}; - std::vector> lhs_columns; - lhs_columns.push_back(col1.release()); - lhs_columns.push_back(strings1.release()); - auto lhs_col = cudf::make_structs_column(21, std::move(lhs_columns), 0, rmm::device_buffer{}); - auto const lhs_nulls = thrust::host_vector( - std::vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}); - lhs_col->set_null_mask(cudf::test::detail::make_null_mask(lhs_nulls.begin(), lhs_nulls.end())); - - std::vector> rhs_columns; - rhs_columns.push_back(col2.release()); - rhs_columns.push_back(strings2.release()); - auto rhs_col = cudf::make_structs_column(21, std::move(rhs_columns), 0, rmm::device_buffer{}); - auto const rhs_nulls = thrust::host_vector( - std::vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}); - rhs_col->set_null_mask(cudf::test::detail::make_null_mask(rhs_nulls.begin(), rhs_nulls.end())); - - auto lhs = lhs_col->view(); - auto rhs = rhs_col->view(); + auto lhs = structs_column_wrapper{ + {col1, strings1}, + std::vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; + auto rhs = structs_column_wrapper{ + {col2, strings2}, + std::vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; data_type dt = cudf::data_type(cudf::type_id::BOOL8); auto res_eq = binary_operation(lhs, rhs, binary_operator::EQUAL, dt); @@ -142,7 +120,6 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_with_nulls) CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); @@ -205,13 +182,10 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_nested_structs) {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0}}; auto struct_col1 = structs_column_wrapper{col3, s1}; - auto nested_col1 = structs_column_wrapper{col1, struct_col1}.release(); auto struct_col2 = structs_column_wrapper{col4, s2}; - auto nested_col2 = structs_column_wrapper{col2, struct_col2}.release(); - - auto lhs = nested_col1->view(); - auto rhs = nested_col2->view(); - data_type dt = cudf::data_type(cudf::type_id::BOOL8); + auto lhs = structs_column_wrapper{col1, struct_col1}; + auto rhs = structs_column_wrapper{col2, struct_col2}; + data_type dt = cudf::data_type(cudf::type_id::BOOL8); auto res_eq = binary_operation(lhs, rhs, binary_operator::EQUAL, dt); auto res_neq = binary_operation(lhs, rhs, binary_operator::NOT_EQUAL, dt); @@ -235,7 +209,6 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_nested_structs) CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); @@ -255,8 +228,7 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_scalars) {"6S", "5G", "4a", "5G", "", "5Z", "5e", "9a", "5G", "5", "5Gs", "5G", "", "5G2", "5G"}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}}; auto struct_col1 = structs_column_wrapper{col2, s1}; - auto nested_col1 = structs_column_wrapper{col1, struct_col1}.release(); - auto col_val = nested_col1->view(); + auto col_val = structs_column_wrapper{col1, struct_col1}; cudf::test::fixed_width_column_wrapper col3{68}; cudf::test::fixed_width_column_wrapper col4{{18}, {0}}; @@ -284,7 +256,6 @@ TYPED_TEST(TypedBinopStructCompare, binopcompare_scalars) CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_eq, expected_eq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_neq, expected_neq); - CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lt, expected_lt); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_lteq, expected_lteq); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*res_gt, expected_gt); From 1af4643f670cf6f8a7f2dd5614fb3724299360dc Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 2 May 2022 17:05:50 -0700 Subject: [PATCH 46/54] fix merge errors --- .../cudf/table/experimental/row_operators.cuh | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/cpp/include/cudf/table/experimental/row_operators.cuh b/cpp/include/cudf/table/experimental/row_operators.cuh index 80ea702ae15..f27e1a16169 100644 --- a/cpp/include/cudf/table/experimental/row_operators.cuh +++ b/cpp/include/cudf/table/experimental/row_operators.cuh @@ -152,7 +152,7 @@ class device_row_comparator { weak_ordering nan_result = weak_ordering::EQUIVALENT) : _lhs{lhs}, _rhs{rhs}, - _nulls{has_nulls}, + _check_nulls{check_nulls}, _null_precedence{null_precedence}, _depth{depth}, _nan_result{nan_result} @@ -172,7 +172,7 @@ class device_row_comparator { __device__ cuda::std::pair operator()( size_type const lhs_element_index, size_type const rhs_element_index) const noexcept { - if (_nulls) { + if (_check_nulls) { bool const lhs_is_null{_lhs.is_null(lhs_element_index)}; bool const rhs_is_null{_rhs.is_null(rhs_element_index)}; @@ -181,12 +181,13 @@ class device_row_comparator { } } - weak_ordering res = NanConfig ? relational_compare(_lhs.element(lhs_element_index), - _rhs.element(rhs_element_index), - _nan_result) - : relational_compare(_lhs.element(lhs_element_index), - _rhs.element(rhs_element_index)); - return cuda::std::pair(res, std::numeric_limits::max()); + return cuda::std::pair(NanConfig + ? relational_compare(_lhs.element(lhs_element_index), + _rhs.element(rhs_element_index), + _nan_result) + : relational_compare(_lhs.element(lhs_element_index), + _rhs.element(rhs_element_index)), + std::numeric_limits::max()); } template ( lcol.type(), comparator, lhs_element_index, rhs_element_index); } @@ -233,7 +234,7 @@ class device_row_comparator { private: column_device_view const _lhs; column_device_view const _rhs; - Nullate const _nulls; + Nullate const _check_nulls; null_order const _null_precedence; int const _depth; weak_ordering _nan_result; @@ -263,14 +264,14 @@ class device_row_comparator { _null_precedence.has_value() ? (*_null_precedence)[i] : null_order::BEFORE; auto const comparator = - NanConfig ? element_comparator{_nulls, + NanConfig ? element_comparator{_check_nulls, _lhs.column(i), _rhs.column(i), null_precedence, depth, ascending ? weak_ordering::GREATER : weak_ordering::LESS} - : element_comparator{_nulls, + : element_comparator{_check_nulls, _lhs.column(i), _rhs.column(i), null_precedence, @@ -327,13 +328,13 @@ class device_less_comparator { * `null_order::BEFORE` for all columns. */ device_less_comparator( - Nullate has_nulls, + Nullate check_nulls, table_device_view lhs, table_device_view rhs, std::optional> depth = std::nullopt, std::optional> column_order = std::nullopt, std::optional> null_precedence = std::nullopt) noexcept - : comparator{has_nulls, lhs, rhs, depth, column_order, null_precedence} + : comparator{check_nulls, lhs, rhs, depth, column_order, null_precedence} { } From 229898878cce245df13165903031ebd6e61e0fd5 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 3 May 2022 17:01:37 -0500 Subject: [PATCH 47/54] Revert include changes. --- cpp/src/binaryop/compiled/ATan2.cu | 2 +- cpp/src/binaryop/compiled/Add.cu | 2 +- cpp/src/binaryop/compiled/BitwiseAnd.cu | 2 +- cpp/src/binaryop/compiled/BitwiseOr.cu | 2 +- cpp/src/binaryop/compiled/BitwiseXor.cu | 2 +- cpp/src/binaryop/compiled/Div.cu | 2 +- cpp/src/binaryop/compiled/FloorDiv.cu | 2 +- cpp/src/binaryop/compiled/Greater.cu | 2 +- cpp/src/binaryop/compiled/GreaterEqual.cu | 2 +- cpp/src/binaryop/compiled/Less.cu | 2 +- cpp/src/binaryop/compiled/LessEqual.cu | 2 +- cpp/src/binaryop/compiled/LogBase.cu | 2 +- cpp/src/binaryop/compiled/LogicalAnd.cu | 2 +- cpp/src/binaryop/compiled/LogicalOr.cu | 2 +- cpp/src/binaryop/compiled/Mod.cu | 2 +- cpp/src/binaryop/compiled/Mul.cu | 2 +- cpp/src/binaryop/compiled/NullEquals.cu | 2 +- cpp/src/binaryop/compiled/NullLogicalAnd.cu | 2 +- cpp/src/binaryop/compiled/NullLogicalOr.cu | 2 +- cpp/src/binaryop/compiled/NullMax.cu | 2 +- cpp/src/binaryop/compiled/NullMin.cu | 2 +- cpp/src/binaryop/compiled/PMod.cu | 2 +- cpp/src/binaryop/compiled/Pow.cu | 2 +- cpp/src/binaryop/compiled/PyMod.cu | 2 +- cpp/src/binaryop/compiled/ShiftLeft.cu | 2 +- cpp/src/binaryop/compiled/ShiftRight.cu | 2 +- cpp/src/binaryop/compiled/ShiftRightUnsigned.cu | 2 +- cpp/src/binaryop/compiled/Sub.cu | 2 +- cpp/src/binaryop/compiled/TrueDiv.cu | 2 +- cpp/src/binaryop/compiled/binary_ops.cu | 4 ++-- cpp/src/binaryop/compiled/binary_ops.cuh | 4 ++-- cpp/src/binaryop/compiled/binary_ops.hpp | 6 +++--- cpp/src/binaryop/compiled/equality_ops.cu | 2 +- cpp/src/binaryop/compiled/util.cpp | 2 +- 34 files changed, 38 insertions(+), 38 deletions(-) diff --git a/cpp/src/binaryop/compiled/ATan2.cu b/cpp/src/binaryop/compiled/ATan2.cu index 71f823ab95a..f43a469a2c9 100644 --- a/cpp/src/binaryop/compiled/ATan2.cu +++ b/cpp/src/binaryop/compiled/ATan2.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Add.cu b/cpp/src/binaryop/compiled/Add.cu index 77a829e4886..1dbfa5b4718 100644 --- a/cpp/src/binaryop/compiled/Add.cu +++ b/cpp/src/binaryop/compiled/Add.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/BitwiseAnd.cu b/cpp/src/binaryop/compiled/BitwiseAnd.cu index 29880c563e6..cfabb1402ce 100644 --- a/cpp/src/binaryop/compiled/BitwiseAnd.cu +++ b/cpp/src/binaryop/compiled/BitwiseAnd.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/BitwiseOr.cu b/cpp/src/binaryop/compiled/BitwiseOr.cu index 083df549e32..01ef118665b 100644 --- a/cpp/src/binaryop/compiled/BitwiseOr.cu +++ b/cpp/src/binaryop/compiled/BitwiseOr.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/BitwiseXor.cu b/cpp/src/binaryop/compiled/BitwiseXor.cu index 2578906c8fc..44f74bab876 100644 --- a/cpp/src/binaryop/compiled/BitwiseXor.cu +++ b/cpp/src/binaryop/compiled/BitwiseXor.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Div.cu b/cpp/src/binaryop/compiled/Div.cu index e329839466c..f377778c427 100644 --- a/cpp/src/binaryop/compiled/Div.cu +++ b/cpp/src/binaryop/compiled/Div.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/FloorDiv.cu b/cpp/src/binaryop/compiled/FloorDiv.cu index 20417a3b050..f9cd323caec 100644 --- a/cpp/src/binaryop/compiled/FloorDiv.cu +++ b/cpp/src/binaryop/compiled/FloorDiv.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Greater.cu b/cpp/src/binaryop/compiled/Greater.cu index 7f0d2533e00..db06cc409da 100644 --- a/cpp/src/binaryop/compiled/Greater.cu +++ b/cpp/src/binaryop/compiled/Greater.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/GreaterEqual.cu b/cpp/src/binaryop/compiled/GreaterEqual.cu index 82422193c39..c239e1e1345 100644 --- a/cpp/src/binaryop/compiled/GreaterEqual.cu +++ b/cpp/src/binaryop/compiled/GreaterEqual.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Less.cu b/cpp/src/binaryop/compiled/Less.cu index 38883701305..e8663715c87 100644 --- a/cpp/src/binaryop/compiled/Less.cu +++ b/cpp/src/binaryop/compiled/Less.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/LessEqual.cu b/cpp/src/binaryop/compiled/LessEqual.cu index d3252284537..d2f88fab81b 100644 --- a/cpp/src/binaryop/compiled/LessEqual.cu +++ b/cpp/src/binaryop/compiled/LessEqual.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/LogBase.cu b/cpp/src/binaryop/compiled/LogBase.cu index bc6237b1e65..8a2162c4ca4 100644 --- a/cpp/src/binaryop/compiled/LogBase.cu +++ b/cpp/src/binaryop/compiled/LogBase.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/LogicalAnd.cu b/cpp/src/binaryop/compiled/LogicalAnd.cu index fd8ba0d1cd5..64e5c1a31c0 100644 --- a/cpp/src/binaryop/compiled/LogicalAnd.cu +++ b/cpp/src/binaryop/compiled/LogicalAnd.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/LogicalOr.cu b/cpp/src/binaryop/compiled/LogicalOr.cu index 7b8c1433a29..a4b64cc6afc 100644 --- a/cpp/src/binaryop/compiled/LogicalOr.cu +++ b/cpp/src/binaryop/compiled/LogicalOr.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Mod.cu b/cpp/src/binaryop/compiled/Mod.cu index 9f60d353bdb..fcdd01b7be8 100644 --- a/cpp/src/binaryop/compiled/Mod.cu +++ b/cpp/src/binaryop/compiled/Mod.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Mul.cu b/cpp/src/binaryop/compiled/Mul.cu index 3fe4a3cb222..de6506d43f1 100644 --- a/cpp/src/binaryop/compiled/Mul.cu +++ b/cpp/src/binaryop/compiled/Mul.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/NullEquals.cu b/cpp/src/binaryop/compiled/NullEquals.cu index d5949e95775..f4780c13bef 100644 --- a/cpp/src/binaryop/compiled/NullEquals.cu +++ b/cpp/src/binaryop/compiled/NullEquals.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/NullLogicalAnd.cu b/cpp/src/binaryop/compiled/NullLogicalAnd.cu index f98bc46105f..55e71a52dae 100644 --- a/cpp/src/binaryop/compiled/NullLogicalAnd.cu +++ b/cpp/src/binaryop/compiled/NullLogicalAnd.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/NullLogicalOr.cu b/cpp/src/binaryop/compiled/NullLogicalOr.cu index a0b1112175b..ee3b27c0934 100644 --- a/cpp/src/binaryop/compiled/NullLogicalOr.cu +++ b/cpp/src/binaryop/compiled/NullLogicalOr.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/NullMax.cu b/cpp/src/binaryop/compiled/NullMax.cu index 27dfc291e4c..6fae253d41f 100644 --- a/cpp/src/binaryop/compiled/NullMax.cu +++ b/cpp/src/binaryop/compiled/NullMax.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/NullMin.cu b/cpp/src/binaryop/compiled/NullMin.cu index 281a27d426a..cb7fdb4f76a 100644 --- a/cpp/src/binaryop/compiled/NullMin.cu +++ b/cpp/src/binaryop/compiled/NullMin.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/PMod.cu b/cpp/src/binaryop/compiled/PMod.cu index f3a4a876864..63b1f1f8269 100644 --- a/cpp/src/binaryop/compiled/PMod.cu +++ b/cpp/src/binaryop/compiled/PMod.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Pow.cu b/cpp/src/binaryop/compiled/Pow.cu index 2abf88c404d..435e1ac044a 100644 --- a/cpp/src/binaryop/compiled/Pow.cu +++ b/cpp/src/binaryop/compiled/Pow.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/PyMod.cu b/cpp/src/binaryop/compiled/PyMod.cu index 046505d4482..1e213598681 100644 --- a/cpp/src/binaryop/compiled/PyMod.cu +++ b/cpp/src/binaryop/compiled/PyMod.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/ShiftLeft.cu b/cpp/src/binaryop/compiled/ShiftLeft.cu index 22734b3d3cb..797821a9057 100644 --- a/cpp/src/binaryop/compiled/ShiftLeft.cu +++ b/cpp/src/binaryop/compiled/ShiftLeft.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/ShiftRight.cu b/cpp/src/binaryop/compiled/ShiftRight.cu index c7b36002f79..8a2566ff775 100644 --- a/cpp/src/binaryop/compiled/ShiftRight.cu +++ b/cpp/src/binaryop/compiled/ShiftRight.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu index 637ad6f189e..827029bc75c 100644 --- a/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu +++ b/cpp/src/binaryop/compiled/ShiftRightUnsigned.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/Sub.cu b/cpp/src/binaryop/compiled/Sub.cu index 5a528d472e4..3022294f86f 100644 --- a/cpp/src/binaryop/compiled/Sub.cu +++ b/cpp/src/binaryop/compiled/Sub.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/TrueDiv.cu b/cpp/src/binaryop/compiled/TrueDiv.cu index 87f83246d17..4d0fc2d456b 100644 --- a/cpp/src/binaryop/compiled/TrueDiv.cu +++ b/cpp/src/binaryop/compiled/TrueDiv.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" namespace cudf::binops::compiled { template void apply_binary_op(mutable_column_view&, diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index fda922a40ef..995046b056d 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -14,8 +14,8 @@ * limitations under the License. */ -#include -#include +#include "binary_ops.hpp" +#include "operation.cuh" #include #include diff --git a/cpp/src/binaryop/compiled/binary_ops.cuh b/cpp/src/binaryop/compiled/binary_ops.cuh index 7efbac93495..b69cd2f8033 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cuh +++ b/cpp/src/binaryop/compiled/binary_ops.cuh @@ -16,8 +16,8 @@ #pragma once -#include -#include +#include "binary_ops.hpp" +#include "operation.cuh" #include #include diff --git a/cpp/src/binaryop/compiled/binary_ops.hpp b/cpp/src/binaryop/compiled/binary_ops.hpp index 2faab761f60..c31fc2e3aff 100644 --- a/cpp/src/binaryop/compiled/binary_ops.hpp +++ b/cpp/src/binaryop/compiled/binary_ops.hpp @@ -167,7 +167,7 @@ std::optional get_common_type(data_type out, data_type lhs, data_type * @param out output type of the binary operation * @param lhs first operand type of the binary operation * @param rhs second operand type of the binary operation - * @param op binary operator enum + * @param op binary operator enum. * @return true if given binary operator supports given input and output types. */ bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_operator op); @@ -214,8 +214,8 @@ void apply_binary_op(mutable_column_view& out, bool is_rhs_scalar, rmm::cuda_stream_view stream); /** - * @brief Deploys single type or double type dispatcher that runs equality operation on each - * element of @p lhsd and @p rhsd columns. + * @brief Deploys single type or double type dispatcher that runs equality operation on each element + * of @p lhsd and @p rhsd columns. * * Comparison operators are EQUAL, NOT_EQUAL, NULL_EQUALS. * @p outd type is boolean. diff --git a/cpp/src/binaryop/compiled/equality_ops.cu b/cpp/src/binaryop/compiled/equality_ops.cu index 3b7666aa757..344884ca51c 100644 --- a/cpp/src/binaryop/compiled/equality_ops.cu +++ b/cpp/src/binaryop/compiled/equality_ops.cu @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "binary_ops.cuh" #include #include diff --git a/cpp/src/binaryop/compiled/util.cpp b/cpp/src/binaryop/compiled/util.cpp index de6f3c660c8..f2d526a4834 100644 --- a/cpp/src/binaryop/compiled/util.cpp +++ b/cpp/src/binaryop/compiled/util.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "operation.cuh" #include #include From bf1c6ee050961f872782ee719165e9e2d58bb7ff Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Wed, 4 May 2022 10:15:44 -0700 Subject: [PATCH 48/54] split off weak ordering row operator changes --- cpp/CMakeLists.txt | 2 +- cpp/include/cudf/detail/structs/utilities.hpp | 16 +++- .../cudf/table/experimental/row_operators.cuh | 92 +++++++++++++++---- cpp/src/structs/utilities.cpp | 6 ++ 4 files changed, 98 insertions(+), 18 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index cbe2811afe4..7870366b714 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -189,7 +189,6 @@ add_library( src/ast/expression_parser.cpp src/ast/expressions.cpp src/binaryop/binaryop.cpp - src/binaryop/compiled/binary_ops.cu src/binaryop/compiled/Add.cu src/binaryop/compiled/ATan2.cu src/binaryop/compiled/BitwiseAnd.cu @@ -220,6 +219,7 @@ add_library( src/binaryop/compiled/ShiftRightUnsigned.cu src/binaryop/compiled/Sub.cu src/binaryop/compiled/TrueDiv.cu + src/binaryop/compiled/binary_ops.cu src/binaryop/compiled/util.cpp src/labeling/label_bins.cu src/bitmask/null_mask.cu diff --git a/cpp/include/cudf/detail/structs/utilities.hpp b/cpp/include/cudf/detail/structs/utilities.hpp index 751b7c00e8a..45d4c3b5ae4 100644 --- a/cpp/include/cudf/detail/structs/utilities.hpp +++ b/cpp/include/cudf/detail/structs/utilities.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, NVIDIA CORPORATION. + * Copyright (c) 2020-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. @@ -245,6 +245,20 @@ std::tuple> superimpose_parent table_view const& table, rmm::cuda_stream_view stream = rmm::cuda_stream_default, rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @brief Checks if a column or any of its children is a struct column with structs that are null. + * + * This function searches for structs that are null -- differentiating between structs that are null + * and structs containing null values. Null structs add a column to the result of the flatten column + * utility and necessitates column_nullability::FORCE when flattening the column for comparison + * operations. + * + * @param col Column to check for null structs + * @return A boolean indicating if the column is or contains a struct column that contains a null + * struct. + */ +bool contains_null_structs(column_view const& col); } // namespace detail } // namespace structs } // namespace cudf diff --git a/cpp/include/cudf/table/experimental/row_operators.cuh b/cpp/include/cudf/table/experimental/row_operators.cuh index 2ed45c71633..2a2b1f90d43 100644 --- a/cpp/include/cudf/table/experimental/row_operators.cuh +++ b/cpp/include/cudf/table/experimental/row_operators.cuh @@ -68,16 +68,17 @@ struct dispatch_void_if_nested { }; namespace row { - namespace lexicographic { /** - * @brief Computes whether one row is lexicographically *less* than another row. + * @brief Computes the lexicographic comparison between 2 rows. * * Lexicographic ordering is determined by: * - Two rows are compared element by element. * - The first mismatching element defines which row is lexicographically less * or greater than the other. + * - If the rows are compared without mismatched elements, the rows are equivalent + * * * Lexicographic ordering is exactly equivalent to doing an alphabetical sort of * two words, for example, `aac` would be *less* than (or precede) `abb`. The @@ -88,8 +89,7 @@ namespace lexicographic { */ template class device_row_comparator { - friend class self_comparator; - + public: /** * @brief Construct a function object for performing a lexicographic * comparison between the rows of two tables. @@ -145,7 +145,11 @@ class device_row_comparator { column_device_view rhs, null_order null_precedence = null_order::BEFORE, int depth = 0) - : _lhs{lhs}, _rhs{rhs}, _nulls{check_nulls}, _null_precedence{null_precedence}, _depth{depth} + : _lhs{lhs}, + _rhs{rhs}, + _check_nulls{check_nulls}, + _null_precedence{null_precedence}, + _depth{depth} { } @@ -162,7 +166,7 @@ class device_row_comparator { __device__ cuda::std::pair operator()( size_type const lhs_element_index, size_type const rhs_element_index) const noexcept { - if (_nulls) { + if (_check_nulls) { bool const lhs_is_null{_lhs.is_null(lhs_element_index)}; bool const rhs_is_null{_rhs.is_null(rhs_element_index)}; @@ -211,7 +215,7 @@ class device_row_comparator { ++depth; } - auto const comparator = element_comparator{_nulls, lcol, rcol, _null_precedence, depth}; + auto const comparator = element_comparator{_check_nulls, lcol, rcol, _null_precedence, depth}; return cudf::type_dispatcher( lcol.type(), comparator, lhs_element_index, rhs_element_index); } @@ -219,7 +223,7 @@ class device_row_comparator { private: column_device_view const _lhs; column_device_view const _rhs; - Nullate const _nulls; + Nullate const _check_nulls; null_order const _null_precedence; int const _depth; }; @@ -227,13 +231,14 @@ class device_row_comparator { public: /** * @brief Checks whether the row at `lhs_index` in the `lhs` table compares - * lexicographically less than the row at `rhs_index` in the `rhs` table. + * lexicographically less, greater, or equal to the row at `rhs_index` in the `rhs` table. * * @param lhs_index The index of row in the `lhs` table to examine * @param rhs_index The index of the row in the `rhs` table to examine - * @return `true` if row from the `lhs` table compares less than row in the `rhs` table + * @return weak ordering comparison of the row in the `lhs` table relative to the row in the `rhs` + * table */ - __device__ bool operator()(size_type const lhs_index, size_type const rhs_index) const noexcept + __device__ weak_ordering operator()(size_type lhs_index, size_type rhs_index) const noexcept { int last_null_depth = std::numeric_limits::max(); for (size_type i = 0; i < _lhs.num_columns(); ++i) { @@ -248,16 +253,17 @@ class device_row_comparator { auto const comparator = element_comparator{_check_nulls, _lhs.column(i), _rhs.column(i), null_precedence, depth}; - weak_ordering state; cuda::std::tie(state, last_null_depth) = cudf::type_dispatcher(_lhs.column(i).type(), comparator, lhs_index, rhs_index); if (state == weak_ordering::EQUIVALENT) { continue; } - return state == (ascending ? weak_ordering::LESS : weak_ordering::GREATER); + return ascending + ? state + : (state == weak_ordering::GREATER ? weak_ordering::LESS : weak_ordering::GREATER); } - return false; + return weak_ordering::EQUIVALENT; } private: @@ -269,6 +275,60 @@ class device_row_comparator { std::optional> const _null_precedence; }; // class device_row_comparator +/** + * @brief Wraps and interprets the result of device_row_comparator, true if the result is + * weak_ordering::LESS meaning one row is lexicographically *less* than another row. + * + * @tparam Nullate A cudf::nullate type describing whether to check for nulls. + */ +template +class device_less_comparator { + friend class self_comparator; + /** + * @brief Construct a function object for performing a lexicographic + * comparison between the rows of two tables. + * + * @param has_nulls Indicates if either input table contains columns with nulls. + * @param lhs The first table + * @param rhs The second table (may be the same table as `lhs`) + * @param depth Optional, device array the same length as a row that contains starting depths of + * columns if they're nested, and 0 otherwise. + * @param column_order Optional, device array the same length as a row that indicates the desired + * ascending/descending order of each column in a row. If `nullopt`, it is assumed all columns are + * sorted in ascending order. + * @param null_precedence Optional, device array the same length as a row and indicates how null + * values compare to all other for every column. If `nullopt`, then null precedence would be + * `null_order::BEFORE` for all columns. + */ + device_less_comparator( + Nullate check_nulls, + table_device_view lhs, + table_device_view rhs, + std::optional> depth = std::nullopt, + std::optional> column_order = std::nullopt, + std::optional> null_precedence = std::nullopt) noexcept + : comparator{check_nulls, lhs, rhs, depth, column_order, null_precedence} + { + } + + public: + /** + * @brief Checks whether the row at `lhs_index` in the `lhs` table compares + * lexicographically less than the row at `rhs_index` in the `rhs` table. + * + * @param lhs_index The index of row in the `lhs` table to examine + * @param rhs_index The index of the row in the `rhs` table to examine + * @return `true` if row from the `lhs` table compares less than row in the `rhs` table + */ + __device__ bool operator()(size_type const lhs_index, size_type const rhs_index) const noexcept + { + return comparator(lhs_index, rhs_index) == weak_ordering::LESS; + } + + private: + device_row_comparator comparator; +}; // class device_less_comparator + struct preprocessed_table { using table_device_view_owner = std::invoke_result_t; @@ -417,9 +477,9 @@ class self_comparator { * @tparam Nullate A cudf::nullate type describing whether to check for nulls. */ template - device_row_comparator device_comparator(Nullate nullate = {}) const + device_less_comparator device_comparator(Nullate nullate = {}) const { - return device_row_comparator( + return device_less_comparator( nullate, *d_t, *d_t, d_t->depths(), d_t->column_order(), d_t->null_precedence()); } diff --git a/cpp/src/structs/utilities.cpp b/cpp/src/structs/utilities.cpp index a2c173cae5f..5baab0f09a2 100644 --- a/cpp/src/structs/utilities.cpp +++ b/cpp/src/structs/utilities.cpp @@ -441,6 +441,12 @@ std::tuple> superimpose_parent return {table_view{superimposed_columns}, std::move(superimposed_nullmasks)}; } +bool contains_null_structs(column_view const& col) +{ + return (is_struct(col) && col.has_nulls()) || + std::any_of(col.child_begin(), col.child_end(), contains_null_structs); +} + } // namespace detail } // namespace structs } // namespace cudf From 5d87db2ee34f1f41dbd59ea50d82c06bcc5ae1b4 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Wed, 4 May 2022 12:27:06 -0700 Subject: [PATCH 49/54] device_row_comparator private with friend class --- cpp/include/cudf/table/experimental/row_operators.cuh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cpp/include/cudf/table/experimental/row_operators.cuh b/cpp/include/cudf/table/experimental/row_operators.cuh index 2a2b1f90d43..4aefa7cf948 100644 --- a/cpp/include/cudf/table/experimental/row_operators.cuh +++ b/cpp/include/cudf/table/experimental/row_operators.cuh @@ -70,6 +70,9 @@ struct dispatch_void_if_nested { namespace row { namespace lexicographic { +template +class device_less_comparator; + /** * @brief Computes the lexicographic comparison between 2 rows. * @@ -89,7 +92,7 @@ namespace lexicographic { */ template class device_row_comparator { - public: + friend class device_less_comparator; /** * @brief Construct a function object for performing a lexicographic * comparison between the rows of two tables. From 2dd2045d54b1e296fa0fe011f2d28efd0d6c23d7 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Fri, 6 May 2022 14:36:28 -0700 Subject: [PATCH 50/54] device_less conversion to templated struct --- .../cudf/table/experimental/row_operators.cuh | 92 ++++++++----------- 1 file changed, 39 insertions(+), 53 deletions(-) diff --git a/cpp/include/cudf/table/experimental/row_operators.cuh b/cpp/include/cudf/table/experimental/row_operators.cuh index 4aefa7cf948..0319c7e682c 100644 --- a/cpp/include/cudf/table/experimental/row_operators.cuh +++ b/cpp/include/cudf/table/experimental/row_operators.cuh @@ -45,6 +45,7 @@ #include namespace cudf { + namespace experimental { /** @@ -70,9 +71,6 @@ struct dispatch_void_if_nested { namespace row { namespace lexicographic { -template -class device_less_comparator; - /** * @brief Computes the lexicographic comparison between 2 rows. * @@ -92,7 +90,8 @@ class device_less_comparator; */ template class device_row_comparator { - friend class device_less_comparator; + // friend class device_less_comparator; + friend class self_comparator; /** * @brief Construct a function object for performing a lexicographic * comparison between the rows of two tables. @@ -234,7 +233,7 @@ class device_row_comparator { public: /** * @brief Checks whether the row at `lhs_index` in the `lhs` table compares - * lexicographically less, greater, or equal to the row at `rhs_index` in the `rhs` table. + * lexicographically less, greater, or equivalent to the row at `rhs_index` in the `rhs` table. * * @param lhs_index The index of row in the `lhs` table to examine * @param rhs_index The index of the row in the `rhs` table to examine @@ -278,6 +277,32 @@ class device_row_comparator { std::optional> const _null_precedence; }; // class device_row_comparator +template +__device__ bool any_equal(weak_ordering result, weak_ordering v, WeakOrderings... vs) +{ + if constexpr (sizeof...(WeakOrderings) == 0) { + return result == v; + } else { + return result == v or any_equal(result, vs...); + } +} + +/** + * @brief Wraps and interprets the result of templated Comparator that returns a weak_ordering. + * Returns true if the weak_ordering matches any of the templated values. + * + * @tparam Comparator generic comparator that returns a weak_ordering. + * @tparam values weak_ordering parameter pack of orderings to interpret as true + */ +template +struct weak_ordering_comparator_impl { + __device__ bool operator()(size_type const& lhs, size_type const& rhs) + { + return any_equal(comparator(lhs, rhs), values...); + } + Comparator comparator; +}; + /** * @brief Wraps and interprets the result of device_row_comparator, true if the result is * weak_ordering::LESS meaning one row is lexicographically *less* than another row. @@ -285,52 +310,13 @@ class device_row_comparator { * @tparam Nullate A cudf::nullate type describing whether to check for nulls. */ template -class device_less_comparator { - friend class self_comparator; - /** - * @brief Construct a function object for performing a lexicographic - * comparison between the rows of two tables. - * - * @param has_nulls Indicates if either input table contains columns with nulls. - * @param lhs The first table - * @param rhs The second table (may be the same table as `lhs`) - * @param depth Optional, device array the same length as a row that contains starting depths of - * columns if they're nested, and 0 otherwise. - * @param column_order Optional, device array the same length as a row that indicates the desired - * ascending/descending order of each column in a row. If `nullopt`, it is assumed all columns are - * sorted in ascending order. - * @param null_precedence Optional, device array the same length as a row and indicates how null - * values compare to all other for every column. If `nullopt`, then null precedence would be - * `null_order::BEFORE` for all columns. - */ - device_less_comparator( - Nullate check_nulls, - table_device_view lhs, - table_device_view rhs, - std::optional> depth = std::nullopt, - std::optional> column_order = std::nullopt, - std::optional> null_precedence = std::nullopt) noexcept - : comparator{check_nulls, lhs, rhs, depth, column_order, null_precedence} - { - } +using less_comparator = + weak_ordering_comparator_impl, weak_ordering::LESS>; - public: - /** - * @brief Checks whether the row at `lhs_index` in the `lhs` table compares - * lexicographically less than the row at `rhs_index` in the `rhs` table. - * - * @param lhs_index The index of row in the `lhs` table to examine - * @param rhs_index The index of the row in the `rhs` table to examine - * @return `true` if row from the `lhs` table compares less than row in the `rhs` table - */ - __device__ bool operator()(size_type const lhs_index, size_type const rhs_index) const noexcept - { - return comparator(lhs_index, rhs_index) == weak_ordering::LESS; - } - - private: - device_row_comparator comparator; -}; // class device_less_comparator +template +using less_equivalent_comparator = weak_ordering_comparator_impl, + weak_ordering::LESS, + weak_ordering::EQUIVALENT>; struct preprocessed_table { using table_device_view_owner = @@ -480,10 +466,10 @@ class self_comparator { * @tparam Nullate A cudf::nullate type describing whether to check for nulls. */ template - device_less_comparator device_comparator(Nullate nullate = {}) const + less_comparator device_comparator(Nullate nullate = {}) const { - return device_less_comparator( - nullate, *d_t, *d_t, d_t->depths(), d_t->column_order(), d_t->null_precedence()); + return less_comparator{device_row_comparator( + nullate, *d_t, *d_t, d_t->depths(), d_t->column_order(), d_t->null_precedence())}; } private: From 7ba960e0a5fe792041e641aac903542a098d0e53 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 9 May 2022 14:16:35 -0700 Subject: [PATCH 51/54] fold parameter pack --- .../cudf/table/experimental/row_operators.cuh | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/cpp/include/cudf/table/experimental/row_operators.cuh b/cpp/include/cudf/table/experimental/row_operators.cuh index 0319c7e682c..76daa6dbca4 100644 --- a/cpp/include/cudf/table/experimental/row_operators.cuh +++ b/cpp/include/cudf/table/experimental/row_operators.cuh @@ -277,16 +277,6 @@ class device_row_comparator { std::optional> const _null_precedence; }; // class device_row_comparator -template -__device__ bool any_equal(weak_ordering result, weak_ordering v, WeakOrderings... vs) -{ - if constexpr (sizeof...(WeakOrderings) == 0) { - return result == v; - } else { - return result == v or any_equal(result, vs...); - } -} - /** * @brief Wraps and interprets the result of templated Comparator that returns a weak_ordering. * Returns true if the weak_ordering matches any of the templated values. @@ -295,12 +285,12 @@ __device__ bool any_equal(weak_ordering result, weak_ordering v, WeakOrderings.. * @tparam values weak_ordering parameter pack of orderings to interpret as true */ template -struct weak_ordering_comparator_impl { - __device__ bool operator()(size_type const& lhs, size_type const& rhs) - { - return any_equal(comparator(lhs, rhs), values...); - } - Comparator comparator; +struct weak_ordering_comparator_impl{ + __device__ bool operator()(size_type const& lhs, size_type const& rhs){ + weak_ordering const result = comparator(lhs, rhs); + return ( (result == values) || ...); + } + Comparator comparator; }; /** From 84833e7f3f2f6fe4ccec3de890cb9966b29c9afd Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 9 May 2022 18:53:30 -0700 Subject: [PATCH 52/54] Apply suggestions from code review Co-authored-by: Bradley Dice --- cpp/include/cudf/table/experimental/row_operators.cuh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cpp/include/cudf/table/experimental/row_operators.cuh b/cpp/include/cudf/table/experimental/row_operators.cuh index 76daa6dbca4..98ccd6c2b8c 100644 --- a/cpp/include/cudf/table/experimental/row_operators.cuh +++ b/cpp/include/cudf/table/experimental/row_operators.cuh @@ -90,7 +90,6 @@ namespace lexicographic { */ template class device_row_comparator { - // friend class device_less_comparator; friend class self_comparator; /** * @brief Construct a function object for performing a lexicographic @@ -281,6 +280,9 @@ class device_row_comparator { * @brief Wraps and interprets the result of templated Comparator that returns a weak_ordering. * Returns true if the weak_ordering matches any of the templated values. * + * Note that this should never be used with only `weak_ordering::EQUIVALENT`. + * An equality comparator should be used instead for optimal performance. + * * @tparam Comparator generic comparator that returns a weak_ordering. * @tparam values weak_ordering parameter pack of orderings to interpret as true */ From 4d197eae7e2a68b8da86e8561b54629e18a3b8e3 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 9 May 2022 20:18:36 -0700 Subject: [PATCH 53/54] fix code style --- .../cudf/table/experimental/row_operators.cuh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cpp/include/cudf/table/experimental/row_operators.cuh b/cpp/include/cudf/table/experimental/row_operators.cuh index 76daa6dbca4..98d08c28d31 100644 --- a/cpp/include/cudf/table/experimental/row_operators.cuh +++ b/cpp/include/cudf/table/experimental/row_operators.cuh @@ -285,12 +285,13 @@ class device_row_comparator { * @tparam values weak_ordering parameter pack of orderings to interpret as true */ template -struct weak_ordering_comparator_impl{ - __device__ bool operator()(size_type const& lhs, size_type const& rhs){ - weak_ordering const result = comparator(lhs, rhs); - return ( (result == values) || ...); - } - Comparator comparator; +struct weak_ordering_comparator_impl { + __device__ bool operator()(size_type const& lhs, size_type const& rhs) + { + weak_ordering const result = comparator(lhs, rhs); + return ((result == values) || ...); + } + Comparator comparator; }; /** From 548dcf15a483aefef4a85911bd8c5e366df7a82f Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Mon, 9 May 2022 22:33:10 -0700 Subject: [PATCH 54/54] fix code format --- cpp/include/cudf/table/experimental/row_operators.cuh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cpp/include/cudf/table/experimental/row_operators.cuh b/cpp/include/cudf/table/experimental/row_operators.cuh index 0b4e69d1ce3..c4a1ad4747a 100644 --- a/cpp/include/cudf/table/experimental/row_operators.cuh +++ b/cpp/include/cudf/table/experimental/row_operators.cuh @@ -94,7 +94,7 @@ namespace lexicographic { template class device_row_comparator { // friend class self_comparator; -public: // needs to be removed, pending strict typing for indices + public: // needs to be removed, pending strict typing for indices /** * @brief Construct a function object for performing a lexicographic * comparison between the rows of two tables. @@ -333,9 +333,10 @@ using less_comparator = weak_ordering_comparator_impl, weak_ordering::LESS>; template -using less_equivalent_comparator = weak_ordering_comparator_impl, - weak_ordering::LESS, - weak_ordering::EQUIVALENT>; +using less_equivalent_comparator = + weak_ordering_comparator_impl, + weak_ordering::LESS, + weak_ordering::EQUIVALENT>; struct preprocessed_table { using table_device_view_owner =