forked from rapidsai/cudf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rapidsai#6 from thirtiseven/min_by_cudf_sort_only
Min by cudf sort only
- Loading branch information
Showing
13 changed files
with
288 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright (c) 2024, 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 "groupby/sort/group_single_pass_reduction_util.cuh" | ||
|
||
#include <cudf/detail/gather.hpp> | ||
#include <cudf/utilities/span.hpp> | ||
|
||
#include <rmm/cuda_stream_view.hpp> | ||
#include <rmm/resource_ref.hpp> | ||
|
||
#include <thrust/gather.h> | ||
|
||
namespace cudf { | ||
namespace groupby { | ||
namespace detail { | ||
std::unique_ptr<column> group_min_by(column_view const& structs_column, | ||
cudf::device_span<size_type const> group_labels, | ||
size_type num_groups, | ||
rmm::cuda_stream_view stream, | ||
rmm::device_async_resource_ref mr) | ||
{ | ||
auto const values = structs_column.child(0); | ||
auto const orders = structs_column.child(1); | ||
|
||
// Nulls in orders column should be excluded, so we need to create a new bitmask | ||
// that is the combination of the nulls in both values and orders columns. | ||
auto const new_mask_buffer_cnt = bitmask_and(table_view{{values, orders}}); | ||
|
||
std::vector<column_view> struct_children(values.num_children()); | ||
for (size_type i = 0; i < values.num_children(); i++) { | ||
struct_children[i] = values.child(i); | ||
} | ||
|
||
column_view const values_null_excluded( | ||
values.type(), | ||
values.size(), | ||
values.head(), | ||
static_cast<bitmask_type const*>(new_mask_buffer_cnt.first.data()), | ||
new_mask_buffer_cnt.second, | ||
values.offset(), | ||
struct_children); | ||
|
||
column_view const structs_column_null_excluded( | ||
structs_column.type(), | ||
structs_column.size(), | ||
structs_column.head(), | ||
nullptr, | ||
0, | ||
structs_column.offset(), | ||
{values_null_excluded, orders}); | ||
|
||
auto const indices = type_dispatcher(orders.type(), | ||
group_reduction_dispatcher<aggregation::ARGMIN>{}, | ||
orders, | ||
num_groups, | ||
group_labels, | ||
stream, | ||
mr); | ||
|
||
column_view const null_removed_map( | ||
data_type(type_to_id<size_type>()), | ||
indices->size(), | ||
static_cast<void const*>(indices->view().template data<size_type>()), | ||
nullptr, | ||
0); | ||
|
||
auto res = cudf::detail::gather(table_view{{structs_column_null_excluded}}, | ||
null_removed_map, | ||
indices->nullable() ? cudf::out_of_bounds_policy::NULLIFY | ||
: cudf::out_of_bounds_policy::DONT_CHECK, | ||
cudf::detail::negative_index_policy::NOT_ALLOWED, | ||
stream, | ||
mr); | ||
|
||
return std::move(res->release()[0]); | ||
} | ||
|
||
} // namespace detail | ||
} // namespace groupby | ||
} // namespace cudf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2024, 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 <tests/groupby/groupby_test_util.hpp> | ||
|
||
#include <cudf_test/base_fixture.hpp> | ||
#include <cudf_test/column_wrapper.hpp> | ||
#include <cudf_test/iterator_utilities.hpp> | ||
#include <cudf_test/type_lists.hpp> | ||
|
||
#include <cudf/detail/aggregation/aggregation.hpp> | ||
|
||
using namespace cudf::test::iterators; | ||
|
||
template <typename V> | ||
struct groupby_min_by_test : public cudf::test::BaseFixture {}; | ||
using K = int32_t; | ||
|
||
TYPED_TEST_SUITE(groupby_min_by_test, cudf::test::FixedWidthTypes); | ||
|
||
TYPED_TEST(groupby_min_by_test, basic) | ||
{ | ||
using V = TypeParam; | ||
|
||
if (std::is_same_v<V, bool>) return; | ||
|
||
cudf::test::fixed_width_column_wrapper<K> keys{1, 2, 3, 1, 2, 2, 1, 3, 3, 2}; | ||
cudf::test::fixed_width_column_wrapper<K> values{4, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
cudf::test::fixed_width_column_wrapper<V> orders{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | ||
cudf::test::structs_column_wrapper vals{values, orders}; | ||
|
||
cudf::test::fixed_width_column_wrapper<K> expect_keys{1, 2, 3}; | ||
cudf::test::fixed_width_column_wrapper<K> expect_values{4, 1, 2}; | ||
cudf::test::fixed_width_column_wrapper<V> expect_orders{1, 2, 3}; | ||
cudf::test::structs_column_wrapper expect_vals{expect_values, expect_orders}; | ||
|
||
auto agg = cudf::make_min_by_aggregation<cudf::groupby_aggregation>(); | ||
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg)); | ||
|
||
auto agg2 = cudf::make_min_by_aggregation<cudf::groupby_aggregation>(); | ||
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg2), force_use_sort_impl::YES); | ||
} | ||
|
||
struct groupby_min_by_string_test : public cudf::test::BaseFixture {}; | ||
|
||
TEST_F(groupby_min_by_string_test, basic) | ||
{ | ||
cudf::test::fixed_width_column_wrapper<K> keys{1, 2, 3, 1, 2, 2, 1, 3, 3, 2}; | ||
cudf::test::fixed_width_column_wrapper<K> values{4, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
cudf::test::strings_column_wrapper orders{ | ||
"año", "bit", "₹1", "aaa", "zit", "bat", "aab", "$1", "€1", "wut"}; | ||
cudf::test::structs_column_wrapper vals{values, orders}; | ||
|
||
cudf::test::fixed_width_column_wrapper<K> expect_keys{1, 2, 3}; | ||
cudf::test::fixed_width_column_wrapper<K> expect_values{3, 5, 7}; | ||
cudf::test::strings_column_wrapper expect_orders{"aaa", "bat", "$1"}; | ||
cudf::test::structs_column_wrapper expect_vals{expect_values, expect_orders}; | ||
|
||
auto agg = cudf::make_min_by_aggregation<cudf::groupby_aggregation>(); | ||
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg)); | ||
|
||
auto agg2 = cudf::make_min_by_aggregation<cudf::groupby_aggregation>(); | ||
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg2), force_use_sort_impl::YES); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.