Skip to content

Commit

Permalink
Add groupby nunique aggregation benchmark (NVIDIA#11472)
Browse files Browse the repository at this point in the history
This adds a simple benchmark for groupby `nunique` aggregation.

Authors:
  - Nghia Truong (https://github.com/ttnghia)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Tobias Ribizel (https://github.com/upsj)

URL: rapidsai/cudf#11472
  • Loading branch information
ttnghia authored Aug 8, 2022
1 parent e1a4e03 commit 6b20f2a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cpp/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ ConfigureBench(
)

ConfigureNVBench(
GROUPBY_NVBENCH groupby/group_max.cpp groupby/group_rank.cpp groupby/group_struct_keys.cpp
GROUPBY_NVBENCH groupby/group_max.cpp groupby/group_nunique.cpp groupby/group_rank.cpp
groupby/group_struct_keys.cpp
)

# ##################################################################################################
Expand Down
85 changes: 85 additions & 0 deletions cpp/benchmarks/groupby/group_nunique.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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/common/generate_input.hpp>
#include <benchmarks/fixture/rmm_pool_raii.hpp>

#include <cudf/groupby.hpp>

#include <nvbench/nvbench.cuh>

namespace {

template <typename... Args>
auto make_aggregation_request_vector(cudf::column_view const& values, Args&&... args)
{
std::vector<std::unique_ptr<cudf::groupby_aggregation>> aggregations;
(aggregations.emplace_back(std::forward<Args>(args)), ...);

std::vector<cudf::groupby::aggregation_request> requests;
requests.emplace_back(cudf::groupby::aggregation_request{values, std::move(aggregations)});

return requests;
}

} // namespace

template <typename Type>
void bench_groupby_nunique(nvbench::state& state, nvbench::type_list<Type>)
{
cudf::rmm_pool_raii pool_raii;
const auto size = static_cast<cudf::size_type>(state.get_int64("num_rows"));

auto const keys_table = [&] {
data_profile profile;
profile.set_null_frequency(std::nullopt);
profile.set_cardinality(0);
profile.set_distribution_params<int32_t>(
cudf::type_to_id<int32_t>(), distribution_id::UNIFORM, 0, 100);
return create_random_table({cudf::type_to_id<int32_t>()}, row_count{size}, profile);
}();

auto const vals_table = [&] {
data_profile profile;
if (const auto null_freq = state.get_float64("null_frequency"); null_freq > 0) {
profile.set_null_frequency({null_freq});
} else {
profile.set_null_frequency(std::nullopt);
}
profile.set_cardinality(0);
profile.set_distribution_params<Type>(cudf::type_to_id<Type>(),
distribution_id::UNIFORM,
static_cast<Type>(0),
static_cast<Type>(1000));
return create_random_table({cudf::type_to_id<Type>()}, row_count{size}, profile);
}();

auto const& keys = keys_table->get_column(0);
auto const& vals = vals_table->get_column(0);

auto gb_obj = cudf::groupby::groupby(cudf::table_view({keys, keys, keys}));
auto const requests = make_aggregation_request_vector(
vals, cudf::make_nunique_aggregation<cudf::groupby_aggregation>());

state.set_cuda_stream(nvbench::make_cuda_stream_view(cudf::default_stream_value.value()));
state.exec(nvbench::exec_tag::sync,
[&](nvbench::launch& launch) { auto const result = gb_obj.aggregate(requests); });
}

NVBENCH_BENCH_TYPES(bench_groupby_nunique, NVBENCH_TYPE_AXES(nvbench::type_list<int32_t, int64_t>))
.set_name("groupby_nunique")
.add_int64_power_of_two_axis("num_rows", {12, 16, 20, 24})
.add_float64_axis("null_frequency", {0, 0.5});

0 comments on commit 6b20f2a

Please sign in to comment.