forked from rapidsai/cudf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clamp.cpp
75 lines (65 loc) · 2.91 KB
/
clamp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Copyright (c) 2021-2023, 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/benchmark_fixture.hpp>
#include <benchmarks/synchronization/synchronization.hpp>
#include <cudf/column/column.hpp>
#include <cudf/column/column_view.hpp>
#include <cudf/reduction.hpp>
#include <cudf/replace.hpp>
#include <cudf/table/table.hpp>
#include <cudf/types.hpp>
class ReplaceClamp : public cudf::benchmark {};
template <typename type>
static void BM_clamp(benchmark::State& state, bool include_nulls)
{
cudf::size_type const n_rows{(cudf::size_type)state.range(0)};
auto const dtype = cudf::type_to_id<type>();
auto const input = create_random_column(dtype, row_count{n_rows});
if (!include_nulls) input->set_null_mask(rmm::device_buffer{}, 0);
auto [low_scalar, high_scalar] = cudf::minmax(*input);
// set the clamps 2 in from the min and max
{
using ScalarType = cudf::scalar_type_t<type>;
auto lvalue = static_cast<ScalarType*>(low_scalar.get());
auto hvalue = static_cast<ScalarType*>(high_scalar.get());
// super heavy clamp
auto mid = lvalue->value() + (hvalue->value() - lvalue->value()) / 2;
lvalue->set_value(mid - 10);
hvalue->set_value(mid + 10);
}
for (auto _ : state) {
cuda_event_timer timer(state, true);
auto result = cudf::clamp(*input, *low_scalar, *high_scalar);
}
}
#define CLAMP_BENCHMARK_DEFINE(name, type, nulls) \
BENCHMARK_DEFINE_F(ReplaceClamp, name) \
(::benchmark::State & state) { BM_clamp<type>(state, nulls); } \
BENCHMARK_REGISTER_F(ReplaceClamp, name) \
->UseManualTime() \
->Arg(10000) /* 10k */ \
->Arg(100000) /* 100k */ \
->Arg(1000000) /* 1M */ \
->Arg(10000000) /* 10M */ \
->Arg(100000000); /* 100M */
CLAMP_BENCHMARK_DEFINE(int8_no_nulls, int8_t, false);
CLAMP_BENCHMARK_DEFINE(int32_no_nulls, int32_t, false);
CLAMP_BENCHMARK_DEFINE(uint64_no_nulls, uint64_t, false);
CLAMP_BENCHMARK_DEFINE(float_no_nulls, float, false);
CLAMP_BENCHMARK_DEFINE(int16_nulls, int16_t, true);
CLAMP_BENCHMARK_DEFINE(uint32_nulls, uint32_t, true);
CLAMP_BENCHMARK_DEFINE(double_nulls, double, true);