From d6959f23e7c0ab8fe35c534635c689aea2e1e768 Mon Sep 17 00:00:00 2001 From: Yunsong Wang Date: Mon, 10 Jan 2022 11:39:04 -0500 Subject: [PATCH] Move random_int to a common header --- .../groupby/group_benchmark_common.hpp | 29 +++++++++++++++++++ .../groupby/group_no_requests_benchmark.cu | 21 ++++---------- cpp/benchmarks/groupby/group_nth_benchmark.cu | 21 ++++---------- .../groupby/group_scan_benchmark.cu | 21 ++++---------- .../groupby/group_shift_benchmark.cu | 19 ++---------- cpp/benchmarks/groupby/group_sum_benchmark.cu | 21 ++++---------- 6 files changed, 56 insertions(+), 76 deletions(-) create mode 100644 cpp/benchmarks/groupby/group_benchmark_common.hpp diff --git a/cpp/benchmarks/groupby/group_benchmark_common.hpp b/cpp/benchmarks/groupby/group_benchmark_common.hpp new file mode 100644 index 00000000000..fba5bc28822 --- /dev/null +++ b/cpp/benchmarks/groupby/group_benchmark_common.hpp @@ -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 + +template +T random_int(T min, T max) +{ + static unsigned seed = 13377331; + static std::mt19937 engine{seed}; + static std::uniform_int_distribution uniform{min, max}; + + return uniform(engine); +} diff --git a/cpp/benchmarks/groupby/group_no_requests_benchmark.cu b/cpp/benchmarks/groupby/group_no_requests_benchmark.cu index 7dbe1888cee..209155862bd 100644 --- a/cpp/benchmarks/groupby/group_no_requests_benchmark.cu +++ b/cpp/benchmarks/groupby/group_no_requests_benchmark.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. @@ -14,32 +14,23 @@ * limitations under the License. */ +#include +#include +#include + #include #include #include #include #include + #include -#include -#include #include -#include class Groupby : public cudf::benchmark { }; -// TODO: put it in a struct so `uniform` can be remade with different min, max -template -T random_int(T min, T max) -{ - static unsigned seed = 13377331; - static std::mt19937 engine{seed}; - static std::uniform_int_distribution uniform{min, max}; - - return uniform(engine); -} - void BM_basic_no_requests(benchmark::State& state) { using wrapper = cudf::test::fixed_width_column_wrapper; diff --git a/cpp/benchmarks/groupby/group_nth_benchmark.cu b/cpp/benchmarks/groupby/group_nth_benchmark.cu index 8d1de36db95..107b3839c4c 100644 --- a/cpp/benchmarks/groupby/group_nth_benchmark.cu +++ b/cpp/benchmarks/groupby/group_nth_benchmark.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, NVIDIA CORPORATION. + * Copyright (c) 2020-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. @@ -14,32 +14,23 @@ * limitations under the License. */ +#include +#include +#include + #include #include #include #include #include + #include -#include -#include #include -#include class Groupby : public cudf::benchmark { }; -// TODO: put it in a struct so `uniform` can be remade with different min, max -template -T random_int(T min, T max) -{ - static unsigned seed = 13377331; - static std::mt19937 engine{seed}; - static std::uniform_int_distribution uniform{min, max}; - - return uniform(engine); -} - void BM_pre_sorted_nth(benchmark::State& state) { using wrapper = cudf::test::fixed_width_column_wrapper; diff --git a/cpp/benchmarks/groupby/group_scan_benchmark.cu b/cpp/benchmarks/groupby/group_scan_benchmark.cu index b22b8ea3f14..d9849e53498 100644 --- a/cpp/benchmarks/groupby/group_scan_benchmark.cu +++ b/cpp/benchmarks/groupby/group_scan_benchmark.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, NVIDIA CORPORATION. + * 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. @@ -14,30 +14,21 @@ * limitations under the License. */ +#include +#include +#include + #include #include #include #include #include -#include -#include -#include -#include +#include class Groupby : public cudf::benchmark { }; -template -T random_int(T min, T max) -{ - static unsigned seed = 13377331; - static std::mt19937 engine{seed}; - static std::uniform_int_distribution uniform{min, max}; - - return uniform(engine); -} - void BM_basic_sum_scan(benchmark::State& state) { using wrapper = cudf::test::fixed_width_column_wrapper; diff --git a/cpp/benchmarks/groupby/group_shift_benchmark.cu b/cpp/benchmarks/groupby/group_shift_benchmark.cu index 81afcdd80e1..6b0710f4044 100644 --- a/cpp/benchmarks/groupby/group_shift_benchmark.cu +++ b/cpp/benchmarks/groupby/group_shift_benchmark.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-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. @@ -13,7 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include +#include #include #include @@ -24,24 +26,9 @@ #include -#include - -#include - class Groupby : public cudf::benchmark { }; -// TODO: put it in a struct so `uniform` can be remade with different min, max -template -T random_int(T min, T max) -{ - static unsigned seed = 13377331; - static std::mt19937 engine{seed}; - static std::uniform_int_distribution uniform{min, max}; - - return uniform(engine); -} - void BM_group_shift(benchmark::State& state) { using wrapper = cudf::test::fixed_width_column_wrapper; diff --git a/cpp/benchmarks/groupby/group_sum_benchmark.cu b/cpp/benchmarks/groupby/group_sum_benchmark.cu index 0e9f5061a1a..63f9aa02070 100644 --- a/cpp/benchmarks/groupby/group_sum_benchmark.cu +++ b/cpp/benchmarks/groupby/group_sum_benchmark.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, NVIDIA CORPORATION. + * Copyright (c) 2019-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. @@ -14,32 +14,23 @@ * limitations under the License. */ +#include +#include +#include + #include #include #include #include #include + #include -#include -#include #include -#include class Groupby : public cudf::benchmark { }; -// TODO: put it in a struct so `uniform` can be remade with different min, max -template -T random_int(T min, T max) -{ - static unsigned seed = 13377331; - static std::mt19937 engine{seed}; - static std::uniform_int_distribution uniform{min, max}; - - return uniform(engine); -} - void BM_basic_sum(benchmark::State& state) { using wrapper = cudf::test::fixed_width_column_wrapper;