Skip to content
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
merged 8 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/include/cudf/groupby.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct aggregation_request {
struct scan_request {
column_view values; ///< The elements to aggregate
std::vector<std::unique_ptr<groupby_scan_aggregation>> aggregations; ///< Desired aggregations
sorted values_pre_sorted{sorted::NO}; ///< Whether or not the values are sorted
PointKernel marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand Down
19 changes: 17 additions & 2 deletions cpp/src/groupby/sort/functors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,23 @@ struct store_result_functor {
sort::sort_groupby_helper& helper,
cudf::detail::result_cache& cache,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
: helper(helper), cache(cache), values(values), stream(stream), mr(mr)
rmm::mr::device_memory_resource* mr,
sorted values_pre_sorted = sorted::NO)
: helper(helper),
cache(cache),
values(values),
stream(stream),
mr(mr),
values_pre_sorted(values_pre_sorted)
{
}

protected:
/**
* @brief Check if the groupby values are presorted
*/
bool is_presorted() const { return values_pre_sorted == sorted::YES; }

/**
* @brief Get the grouped values
*
Expand All @@ -54,6 +65,8 @@ struct store_result_functor {
*/
column_view get_grouped_values()
{
if (is_presorted()) { return values; }

// TODO (dm): After implementing single pass multi-agg, explore making a
// cache of all grouped value columns rather than one at a time
if (grouped_values)
Expand All @@ -74,6 +87,7 @@ struct store_result_functor {
*/
column_view get_sorted_values()
{
if (is_presorted()) { return values; }
return sorted_values ? sorted_values->view()
: (sorted_values = helper.sorted_values(values, stream))->view();
};
Expand All @@ -86,6 +100,7 @@ struct store_result_functor {
rmm::cuda_stream_view stream; ///< CUDA stream on which to execute kernels
rmm::mr::device_memory_resource* mr; ///< Memory resource to allocate space for results

sorted values_pre_sorted; ///< Whether the values are sorted
std::unique_ptr<column> sorted_values; ///< Memoised grouped and sorted values
std::unique_ptr<column> grouped_values; ///< Memoised grouped values
};
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/groupby/sort/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ std::pair<std::unique_ptr<table>, std::vector<aggregation_result>> groupby::sort
cudf::detail::result_cache cache(requests.size());

for (auto const& request : requests) {
auto store_functor = detail::scan_result_functor(request.values, helper(), cache, stream, mr);
auto store_functor = detail::scan_result_functor(
request.values, helper(), cache, stream, mr, request.values_pre_sorted);
for (auto const& aggregation : request.aggregations) {
// TODO (dm): single pass compute all supported reductions
cudf::detail::aggregation_dispatcher(aggregation->kind, store_functor, *aggregation);
Expand Down