-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Haoyang Li <[email protected]>
- Loading branch information
1 parent
25febbc
commit 101a929
Showing
13 changed files
with
291 additions
and
38 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,61 @@ | ||
/* | ||
* Copyright (c) 2020-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 structs_view = cudf::structs_column_view{structs_column}; | ||
auto const orders = structs_view.get_sliced_child(1); | ||
|
||
auto indices = type_dispatcher(orders.type(), | ||
group_reduction_dispatcher<aggregation::ARGMIN>{}, | ||
orders, | ||
num_groups, | ||
group_labels, | ||
stream, | ||
mr); | ||
|
||
auto indices_view = indices->mutable_view(); | ||
|
||
auto res = cudf::detail::gather(table_view{{structs_column}}, | ||
indices_view, | ||
out_of_bounds_policy::NULLIFY, | ||
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); | ||
} |
Oops, something went wrong.