|
16 | 16 |
|
17 | 17 | #include <benchmarks/common/generate_input.hpp>
|
18 | 18 | #include <benchmarks/fixture/benchmark_fixture.hpp>
|
19 |
| -#include <benchmarks/synchronization/synchronization.hpp> |
20 | 19 |
|
21 | 20 | #include <cudf/strings/convert/convert_floats.hpp>
|
22 | 21 | #include <cudf/strings/convert/convert_integers.hpp>
|
23 | 22 | #include <cudf/types.hpp>
|
24 | 23 |
|
25 |
| -namespace { |
| 24 | +#include <nvbench/nvbench.cuh> |
26 | 25 |
|
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 { |
32 | 27 |
|
33 | 28 | 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) |
35 | 30 | {
|
36 |
| - auto const numerics_col = get_numerics_column<NumericType>(rows); |
37 | 31 | if constexpr (std::is_floating_point_v<NumericType>) {
|
38 |
| - return cudf::strings::from_floats(numerics_col->view()); |
| 32 | + return cudf::strings::from_floats(nv); |
39 | 33 | } 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); |
63 | 35 | }
|
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))); |
69 | 36 | }
|
| 37 | +} // namespace |
70 | 38 |
|
71 |
| -class StringsFromNumeric : public cudf::benchmark {}; |
| 39 | +using Types = nvbench::type_list<float, double, int32_t, int64_t, uint8_t, uint16_t>; |
72 | 40 |
|
73 | 41 | template <typename NumericType>
|
74 |
| -void convert_from_number(benchmark::State& state) |
| 42 | +void bench_convert_number(nvbench::state& state, nvbench::type_list<NumericType>) |
75 | 43 | {
|
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 | + }); |
89 | 75 | }
|
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))); |
96 | 76 | }
|
97 | 77 |
|
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