Skip to content

Commit 3e8338a

Browse files
committed
Move strings/numeric convert benchmarks to nvbench
1 parent ac5b3ed commit 3e8338a

File tree

3 files changed

+79
-174
lines changed

3 files changed

+79
-174
lines changed

cpp/benchmarks/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,6 @@ ConfigureBench(
358358
STRINGS_BENCH
359359
string/convert_datetime.cpp
360360
string/convert_durations.cpp
361-
string/convert_fixed_point.cpp
362-
string/convert_numerics.cpp
363361
string/copy.cu
364362
string/factory.cu
365363
string/filter.cpp
@@ -375,6 +373,8 @@ ConfigureNVBench(
375373
string/char_types.cpp
376374
string/combine.cpp
377375
string/contains.cpp
376+
string/convert_fixed_point.cpp
377+
string/convert_numerics.cpp
378378
string/copy_if_else.cpp
379379
string/copy_range.cpp
380380
string/count.cpp

cpp/benchmarks/string/convert_fixed_point.cpp

Lines changed: 33 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -16,93 +16,48 @@
1616

1717
#include <benchmarks/common/generate_input.hpp>
1818
#include <benchmarks/fixture/benchmark_fixture.hpp>
19-
#include <benchmarks/synchronization/synchronization.hpp>
2019

2120
#include <cudf/strings/convert/convert_fixed_point.hpp>
2221
#include <cudf/strings/convert/convert_floats.hpp>
2322
#include <cudf/types.hpp>
2423

25-
namespace {
24+
#include <nvbench/nvbench.cuh>
2625

27-
std::unique_ptr<cudf::column> get_strings_column(cudf::size_type rows)
28-
{
29-
auto result =
30-
create_random_column(cudf::type_id::FLOAT32, row_count{static_cast<cudf::size_type>(rows)});
31-
return cudf::strings::from_floats(result->view());
32-
}
33-
34-
} // anonymous namespace
35-
36-
class StringsToFixedPoint : public cudf::benchmark {};
37-
38-
template <typename fixed_point_type>
39-
void convert_to_fixed_point(benchmark::State& state)
40-
{
41-
auto const rows = static_cast<cudf::size_type>(state.range(0));
42-
auto const strings_col = get_strings_column(rows);
43-
auto const strings_view = cudf::strings_column_view(strings_col->view());
44-
auto const dtype = cudf::data_type{cudf::type_to_id<fixed_point_type>(), numeric::scale_type{-2}};
45-
46-
for (auto _ : state) {
47-
cuda_event_timer raii(state, true);
48-
auto volatile results = cudf::strings::to_fixed_point(strings_view, dtype);
49-
}
26+
using Types = nvbench::type_list<numeric::decimal32, numeric::decimal64>;
5027

51-
// bytes_processed = bytes_input + bytes_output
52-
state.SetBytesProcessed(
53-
state.iterations() *
54-
(strings_view.chars_size(cudf::get_default_stream()) + rows * cudf::size_of(dtype)));
55-
}
56-
57-
class StringsFromFixedPoint : public cudf::benchmark {};
28+
NVBENCH_DECLARE_TYPE_STRINGS(numeric::decimal32, "decimal32", "decimal32");
29+
NVBENCH_DECLARE_TYPE_STRINGS(numeric::decimal64, "decimal64", "decimal64");
5830

59-
template <typename fixed_point_type>
60-
void convert_from_fixed_point(benchmark::State& state)
31+
template <typename DataType>
32+
void bench_convert_fixed_point(nvbench::state& state, nvbench::type_list<DataType>)
6133
{
62-
auto const rows = static_cast<cudf::size_type>(state.range(0));
63-
auto const strings_col = get_strings_column(rows);
64-
auto const dtype = cudf::data_type{cudf::type_to_id<fixed_point_type>(), numeric::scale_type{-2}};
65-
auto const fp_col =
66-
cudf::strings::to_fixed_point(cudf::strings_column_view(strings_col->view()), dtype);
67-
68-
std::unique_ptr<cudf::column> results = nullptr;
69-
70-
for (auto _ : state) {
71-
cuda_event_timer raii(state, true);
72-
results = cudf::strings::from_fixed_point(fp_col->view());
34+
auto const num_rows = static_cast<cudf::size_type>(state.get_int64("num_rows"));
35+
auto const from_num = state.get_string("dir") == "from";
36+
37+
auto const data_type = cudf::data_type{cudf::type_to_id<DataType>(), numeric::scale_type{-2}};
38+
auto const fp_col = create_random_column(data_type.id(), row_count{num_rows});
39+
40+
auto const strings_col = cudf::strings::from_fixed_point(fp_col->view());
41+
auto const sv = cudf::strings_column_view(strings_col->view());
42+
43+
auto stream = cudf::get_default_stream();
44+
state.set_cuda_stream(nvbench::make_cuda_stream_view(stream.value()));
45+
46+
if (from_num) {
47+
state.add_global_memory_reads<int8_t>(num_rows * cudf::size_of(data_type));
48+
state.add_global_memory_writes<int8_t>(sv.chars_size(stream));
49+
state.exec(nvbench::exec_tag::sync,
50+
[&](nvbench::launch& launch) { cudf::strings::to_fixed_point(sv, data_type); });
51+
} else {
52+
state.add_global_memory_reads<int8_t>(sv.chars_size(stream));
53+
state.add_global_memory_writes<int8_t>(num_rows * cudf::size_of(data_type));
54+
state.exec(nvbench::exec_tag::sync,
55+
[&](nvbench::launch& launch) { cudf::strings::from_fixed_point(fp_col->view()); });
7356
}
74-
75-
// bytes_processed = bytes_input + bytes_output
76-
state.SetBytesProcessed(
77-
state.iterations() *
78-
(cudf::strings_column_view(results->view()).chars_size(cudf::get_default_stream()) +
79-
rows * cudf::size_of(dtype)));
8057
}
8158

82-
#define CONVERT_TO_FIXED_POINT_BMD(name, fixed_point_type) \
83-
BENCHMARK_DEFINE_F(StringsToFixedPoint, name)(::benchmark::State & state) \
84-
{ \
85-
convert_to_fixed_point<fixed_point_type>(state); \
86-
} \
87-
BENCHMARK_REGISTER_F(StringsToFixedPoint, name) \
88-
->RangeMultiplier(4) \
89-
->Range(1 << 12, 1 << 24) \
90-
->UseManualTime() \
91-
->Unit(benchmark::kMicrosecond);
92-
93-
#define CONVERT_FROM_FIXED_POINT_BMD(name, fixed_point_type) \
94-
BENCHMARK_DEFINE_F(StringsFromFixedPoint, name)(::benchmark::State & state) \
95-
{ \
96-
convert_from_fixed_point<fixed_point_type>(state); \
97-
} \
98-
BENCHMARK_REGISTER_F(StringsFromFixedPoint, name) \
99-
->RangeMultiplier(4) \
100-
->Range(1 << 12, 1 << 24) \
101-
->UseManualTime() \
102-
->Unit(benchmark::kMicrosecond);
103-
104-
CONVERT_TO_FIXED_POINT_BMD(strings_to_decimal32, numeric::decimal32);
105-
CONVERT_TO_FIXED_POINT_BMD(strings_to_decimal64, numeric::decimal64);
106-
107-
CONVERT_FROM_FIXED_POINT_BMD(strings_from_decimal32, numeric::decimal32);
108-
CONVERT_FROM_FIXED_POINT_BMD(strings_from_decimal64, numeric::decimal64);
59+
NVBENCH_BENCH_TYPES(bench_convert_fixed_point, NVBENCH_TYPE_AXES(Types))
60+
.set_name("fixed_point")
61+
.set_type_axes_names({"DataType"})
62+
.add_string_axis("dir", {"to", "from"})
63+
.add_int64_axis("num_rows", {1 << 16, 1 << 18, 1 << 20, 1 << 22});

cpp/benchmarks/string/convert_numerics.cpp

Lines changed: 44 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -16,117 +16,67 @@
1616

1717
#include <benchmarks/common/generate_input.hpp>
1818
#include <benchmarks/fixture/benchmark_fixture.hpp>
19-
#include <benchmarks/synchronization/synchronization.hpp>
2019

2120
#include <cudf/strings/convert/convert_floats.hpp>
2221
#include <cudf/strings/convert/convert_integers.hpp>
2322
#include <cudf/types.hpp>
2423

25-
namespace {
24+
#include <nvbench/nvbench.cuh>
2625

27-
template <typename NumericType>
28-
std::unique_ptr<cudf::column> get_numerics_column(cudf::size_type rows)
29-
{
30-
return create_random_column(cudf::type_to_id<NumericType>(), row_count{rows});
31-
}
26+
namespace {
3227

3328
template <typename NumericType>
34-
std::unique_ptr<cudf::column> get_strings_column(cudf::size_type rows)
29+
std::unique_ptr<cudf::column> get_strings_column(cudf::column_view const& nv)
3530
{
36-
auto const numerics_col = get_numerics_column<NumericType>(rows);
3731
if constexpr (std::is_floating_point_v<NumericType>) {
38-
return cudf::strings::from_floats(numerics_col->view());
32+
return cudf::strings::from_floats(nv);
3933
} else {
40-
return cudf::strings::from_integers(numerics_col->view());
41-
}
42-
}
43-
} // anonymous namespace
44-
45-
class StringsToNumeric : public cudf::benchmark {};
46-
47-
template <typename NumericType>
48-
void convert_to_number(benchmark::State& state)
49-
{
50-
auto const rows = static_cast<cudf::size_type>(state.range(0));
51-
52-
auto const strings_col = get_strings_column<NumericType>(rows);
53-
auto const strings_view = cudf::strings_column_view(strings_col->view());
54-
auto const col_type = cudf::type_to_id<NumericType>();
55-
56-
for (auto _ : state) {
57-
cuda_event_timer raii(state, true);
58-
if constexpr (std::is_floating_point_v<NumericType>) {
59-
cudf::strings::to_floats(strings_view, cudf::data_type{col_type});
60-
} else {
61-
cudf::strings::to_integers(strings_view, cudf::data_type{col_type});
62-
}
34+
return cudf::strings::from_integers(nv);
6335
}
64-
65-
// bytes_processed = bytes_input + bytes_output
66-
state.SetBytesProcessed(
67-
state.iterations() *
68-
(strings_view.chars_size(cudf::get_default_stream()) + rows * sizeof(NumericType)));
6936
}
37+
} // namespace
7038

71-
class StringsFromNumeric : public cudf::benchmark {};
39+
using Types = nvbench::type_list<float, double, int32_t, int64_t, uint8_t, uint16_t>;
7240

7341
template <typename NumericType>
74-
void convert_from_number(benchmark::State& state)
42+
void bench_convert_number(nvbench::state& state, nvbench::type_list<NumericType>)
7543
{
76-
auto const rows = static_cast<cudf::size_type>(state.range(0));
77-
78-
auto const numerics_col = get_numerics_column<NumericType>(rows);
79-
auto const numerics_view = numerics_col->view();
80-
81-
std::unique_ptr<cudf::column> results = nullptr;
82-
83-
for (auto _ : state) {
84-
cuda_event_timer raii(state, true);
85-
if constexpr (std::is_floating_point_v<NumericType>)
86-
results = cudf::strings::from_floats(numerics_view);
87-
else
88-
results = cudf::strings::from_integers(numerics_view);
44+
auto const num_rows = static_cast<cudf::size_type>(state.get_int64("num_rows"));
45+
auto const from_num = state.get_string("dir") == "from";
46+
47+
auto const data_type = cudf::data_type(cudf::type_to_id<NumericType>());
48+
auto const num_col = create_random_column(data_type.id(), row_count{num_rows});
49+
50+
auto const strings_col = get_strings_column<NumericType>(num_col->view());
51+
auto const sv = cudf::strings_column_view(strings_col->view());
52+
53+
auto stream = cudf::get_default_stream();
54+
state.set_cuda_stream(nvbench::make_cuda_stream_view(stream.value()));
55+
56+
if (from_num) {
57+
state.add_global_memory_reads<NumericType>(num_rows);
58+
state.add_global_memory_writes<int8_t>(sv.chars_size(stream));
59+
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
60+
if constexpr (std::is_floating_point_v<NumericType>) {
61+
cudf::strings::to_floats(sv, data_type);
62+
} else {
63+
cudf::strings::to_integers(sv, data_type);
64+
}
65+
});
66+
} else {
67+
state.add_global_memory_reads<int8_t>(sv.chars_size(stream));
68+
state.add_global_memory_writes<NumericType>(num_rows);
69+
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
70+
if constexpr (std::is_floating_point_v<NumericType>)
71+
cudf::strings::from_floats(num_col->view());
72+
else
73+
cudf::strings::from_integers(num_col->view());
74+
});
8975
}
90-
91-
// bytes_processed = bytes_input + bytes_output
92-
state.SetBytesProcessed(
93-
state.iterations() *
94-
(cudf::strings_column_view(results->view()).chars_size(cudf::get_default_stream()) +
95-
rows * sizeof(NumericType)));
9676
}
9777

98-
#define CONVERT_TO_NUMERICS_BD(name, type) \
99-
BENCHMARK_DEFINE_F(StringsToNumeric, name)(::benchmark::State & state) \
100-
{ \
101-
convert_to_number<type>(state); \
102-
} \
103-
BENCHMARK_REGISTER_F(StringsToNumeric, name) \
104-
->RangeMultiplier(4) \
105-
->Range(1 << 10, 1 << 17) \
106-
->UseManualTime() \
107-
->Unit(benchmark::kMicrosecond);
108-
109-
#define CONVERT_FROM_NUMERICS_BD(name, type) \
110-
BENCHMARK_DEFINE_F(StringsFromNumeric, name)(::benchmark::State & state) \
111-
{ \
112-
convert_from_number<type>(state); \
113-
} \
114-
BENCHMARK_REGISTER_F(StringsFromNumeric, name) \
115-
->RangeMultiplier(4) \
116-
->Range(1 << 10, 1 << 17) \
117-
->UseManualTime() \
118-
->Unit(benchmark::kMicrosecond);
119-
120-
CONVERT_TO_NUMERICS_BD(strings_to_float32, float);
121-
CONVERT_TO_NUMERICS_BD(strings_to_float64, double);
122-
CONVERT_TO_NUMERICS_BD(strings_to_int32, int32_t);
123-
CONVERT_TO_NUMERICS_BD(strings_to_int64, int64_t);
124-
CONVERT_TO_NUMERICS_BD(strings_to_uint8, uint8_t);
125-
CONVERT_TO_NUMERICS_BD(strings_to_uint16, uint16_t);
126-
127-
CONVERT_FROM_NUMERICS_BD(strings_from_float32, float);
128-
CONVERT_FROM_NUMERICS_BD(strings_from_float64, double);
129-
CONVERT_FROM_NUMERICS_BD(strings_from_int32, int32_t);
130-
CONVERT_FROM_NUMERICS_BD(strings_from_int64, int64_t);
131-
CONVERT_FROM_NUMERICS_BD(strings_from_uint8, uint8_t);
132-
CONVERT_FROM_NUMERICS_BD(strings_from_uint16, uint16_t);
78+
NVBENCH_BENCH_TYPES(bench_convert_number, NVBENCH_TYPE_AXES(Types))
79+
.set_name("numeric")
80+
.set_type_axes_names({"NumericType"})
81+
.add_string_axis("dir", {"to", "from"})
82+
.add_int64_axis("num_rows", {1 << 16, 1 << 18, 1 << 20, 1 << 22});

0 commit comments

Comments
 (0)