-
Notifications
You must be signed in to change notification settings - Fork 915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize groupby::scan
#9754
Merged
rapids-bot
merged 8 commits into
rapidsai:branch-22.02
from
PointKernel:optimize-groupby-scan
Jan 10, 2022
Merged
Optimize groupby::scan
#9754
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7b743bd
Add values_pre_sorted member variable in scan_request
PointKernel 49a3a10
Merge remote-tracking branch 'upstream/branch-22.02' into optimize-gr…
PointKernel d6d2881
Correction: use _keys_are_sorted in groupby
PointKernel 52af2bf
Add early exit for overloaded function
PointKernel 86ce4df
Add pre-sorted scan unit tests
PointKernel 2b24f60
Fix a typo
PointKernel cb4adb4
Add sum scan benchmark
PointKernel d6959f2
Move random_int to a common header
PointKernel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2022, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <random> | ||
|
||
template <typename T> | ||
T random_int(T min, T max) | ||
{ | ||
static unsigned seed = 13377331; | ||
static std::mt19937 engine{seed}; | ||
static std::uniform_int_distribution<T> uniform{min, max}; | ||
|
||
return uniform(engine); | ||
} |
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,110 @@ | ||
/* | ||
* Copyright (c) 2022, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <benchmarks/fixture/benchmark_fixture.hpp> | ||
#include <benchmarks/groupby/group_benchmark_common.hpp> | ||
#include <benchmarks/synchronization/synchronization.hpp> | ||
|
||
#include <cudf/copying.hpp> | ||
#include <cudf/detail/aggregation/aggregation.hpp> | ||
#include <cudf/groupby.hpp> | ||
#include <cudf/sorting.hpp> | ||
#include <cudf/table/table.hpp> | ||
|
||
#include <cudf_test/column_wrapper.hpp> | ||
|
||
class Groupby : public cudf::benchmark { | ||
}; | ||
|
||
void BM_basic_sum_scan(benchmark::State& state) | ||
{ | ||
using wrapper = cudf::test::fixed_width_column_wrapper<int64_t>; | ||
|
||
const cudf::size_type column_size{(cudf::size_type)state.range(0)}; | ||
|
||
auto data_it = cudf::detail::make_counting_transform_iterator( | ||
0, [=](cudf::size_type row) { return random_int(0, 100); }); | ||
|
||
wrapper keys(data_it, data_it + column_size); | ||
wrapper vals(data_it, data_it + column_size); | ||
|
||
cudf::groupby::groupby gb_obj(cudf::table_view({keys, keys, keys})); | ||
|
||
std::vector<cudf::groupby::scan_request> requests; | ||
requests.emplace_back(cudf::groupby::scan_request()); | ||
requests[0].values = vals; | ||
requests[0].aggregations.push_back(cudf::make_sum_aggregation<cudf::groupby_scan_aggregation>()); | ||
|
||
for (auto _ : state) { | ||
cuda_event_timer timer(state, true); | ||
|
||
auto result = gb_obj.scan(requests); | ||
} | ||
} | ||
|
||
BENCHMARK_DEFINE_F(Groupby, BasicSumScan)(::benchmark::State& state) { BM_basic_sum_scan(state); } | ||
|
||
BENCHMARK_REGISTER_F(Groupby, BasicSumScan) | ||
->UseManualTime() | ||
->Unit(benchmark::kMillisecond) | ||
->Arg(1000000) | ||
->Arg(10000000) | ||
->Arg(100000000); | ||
|
||
void BM_pre_sorted_sum_scan(benchmark::State& state) | ||
{ | ||
using wrapper = cudf::test::fixed_width_column_wrapper<int64_t>; | ||
|
||
const cudf::size_type column_size{(cudf::size_type)state.range(0)}; | ||
|
||
auto data_it = cudf::detail::make_counting_transform_iterator( | ||
0, [=](cudf::size_type row) { return random_int(0, 100); }); | ||
auto valid_it = cudf::detail::make_counting_transform_iterator( | ||
0, [=](cudf::size_type row) { return random_int(0, 100) < 90; }); | ||
|
||
wrapper keys(data_it, data_it + column_size); | ||
wrapper vals(data_it, data_it + column_size, valid_it); | ||
|
||
auto keys_table = cudf::table_view({keys}); | ||
auto sort_order = cudf::sorted_order(keys_table); | ||
auto sorted_keys = cudf::gather(keys_table, *sort_order); | ||
// No need to sort values using sort_order because they were generated randomly | ||
|
||
cudf::groupby::groupby gb_obj(*sorted_keys, cudf::null_policy::EXCLUDE, cudf::sorted::YES); | ||
|
||
std::vector<cudf::groupby::scan_request> requests; | ||
requests.emplace_back(cudf::groupby::scan_request()); | ||
requests[0].values = vals; | ||
requests[0].aggregations.push_back(cudf::make_sum_aggregation<cudf::groupby_scan_aggregation>()); | ||
|
||
for (auto _ : state) { | ||
cuda_event_timer timer(state, true); | ||
|
||
auto result = gb_obj.scan(requests); | ||
} | ||
} | ||
|
||
BENCHMARK_DEFINE_F(Groupby, PreSortedSumScan)(::benchmark::State& state) | ||
{ | ||
BM_pre_sorted_sum_scan(state); | ||
} | ||
|
||
BENCHMARK_REGISTER_F(Groupby, PreSortedSumScan) | ||
->UseManualTime() | ||
->Unit(benchmark::kMillisecond) | ||
->Arg(1000000) | ||
->Arg(10000000) | ||
->Arg(100000000); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
nvbench
is preferred over googlebench for any new benchmarks.We want to move our all benchmarks to nvbench.
If it's not much effort, please use nvbench here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvbench
requires target kernels to take an explicit stream (see here) but CUDA stream is not exposed to the publicgroupby::scan
. What I did inJOIN_NVBENCH
is to expose stream arguments to hash join APIs. Do we want to do the same forgroupby::scan
? @jrhemstad Any comments?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather do this: NVIDIA/nvbench#13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I will leave the new scan benchmark as gbench for this PR and look into NVIDIA/nvbench#13.