|
1 | 1 | /* |
2 | | - * SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION. |
| 2 | + * SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
3 | 3 | * SPDX-License-Identifier: Apache-2.0 |
4 | 4 | */ |
5 | 5 |
|
6 | 6 | #include <benchmarks/common/generate_input.hpp> |
7 | 7 | #include <benchmarks/common/memory_stats.hpp> |
8 | 8 |
|
9 | 9 | #include <cudf/binaryop.hpp> |
| 10 | +#include <cudf/transform.hpp> |
10 | 11 |
|
| 12 | +#include <cudf_benchmark_fragments.hpp> |
11 | 13 | #include <nvbench/nvbench.cuh> |
12 | 14 |
|
13 | 15 | template <typename TypeLhs, typename TypeRhs, typename TypeOut> |
@@ -72,6 +74,7 @@ BINARYOP_BENCHMARK_DEFINE(timestamp_s, duration_s, ADD, time |
72 | 74 | BINARYOP_BENCHMARK_DEFINE(duration_s, duration_D, SUB, duration_ms); |
73 | 75 | BINARYOP_BENCHMARK_DEFINE(int64_t, int64_t, SUB, int64_t); |
74 | 76 | BINARYOP_BENCHMARK_DEFINE(float, float, MUL, int64_t); |
| 77 | +BINARYOP_BENCHMARK_DEFINE(float, float, MUL, float); |
75 | 78 | BINARYOP_BENCHMARK_DEFINE(duration_s, int64_t, MUL, duration_s); |
76 | 79 | BINARYOP_BENCHMARK_DEFINE(int64_t, int64_t, DIV, int64_t); |
77 | 80 | BINARYOP_BENCHMARK_DEFINE(duration_ms, int32_t, DIV, duration_ms); |
@@ -101,3 +104,115 @@ BINARYOP_BENCHMARK_DEFINE(duration_ms, duration_ns, NULL_EQUALS, bool |
101 | 104 | BINARYOP_BENCHMARK_DEFINE(duration_ms, duration_ns, NULL_NOT_EQUALS, bool); |
102 | 105 | BINARYOP_BENCHMARK_DEFINE(decimal32, decimal32, NULL_MAX, decimal32); |
103 | 106 | BINARYOP_BENCHMARK_DEFINE(timestamp_D, timestamp_s, NULL_MIN, timestamp_s); |
| 107 | +// clang-format on |
| 108 | + |
| 109 | +template <typename TypeLhs, typename TypeRhs, typename TypeOut> |
| 110 | +void BM_jit_binaryop(nvbench::state& state, cudf::binary_operator binop) |
| 111 | +{ |
| 112 | + constexpr auto const jit_mul_cuda = R"***( |
| 113 | +__device__ void transform(float* out, float a, float b) { |
| 114 | + *out = a * b; |
| 115 | +} |
| 116 | +)***"; |
| 117 | + |
| 118 | + constexpr auto const jit_add_cuda = R"***( |
| 119 | +__device__ void transform(float* out, float a, float b) { |
| 120 | + *out = a + b; |
| 121 | +} |
| 122 | +)***"; |
| 123 | + |
| 124 | + auto const num_rows = static_cast<cudf::size_type>(state.get_int64("num_rows")); |
| 125 | + auto const use_lto = state.get_string("use_lto") == "true"; |
| 126 | + static_assert(std::is_same_v<TypeLhs, TypeRhs> && std::is_same_v<TypeRhs, TypeOut>); |
| 127 | + static_assert(std::is_same_v<TypeLhs, float>); |
| 128 | + |
| 129 | + auto const source_table = create_random_table( |
| 130 | + {cudf::type_to_id<TypeLhs>(), cudf::type_to_id<TypeRhs>()}, row_count{num_rows}); |
| 131 | + |
| 132 | + auto lhs = cudf::column_view(source_table->get_column(0)); |
| 133 | + auto rhs = cudf::column_view(source_table->get_column(1)); |
| 134 | + |
| 135 | + size_t fragment_id = 0; |
| 136 | + char const* cuda = nullptr; |
| 137 | + |
| 138 | + switch (binop) { |
| 139 | + case cudf::binary_operator::ADD: { |
| 140 | + fragment_id = cudf_benchmark_fragments::add_f32; |
| 141 | + cuda = jit_add_cuda; |
| 142 | + } break; |
| 143 | + case cudf::binary_operator::MUL: { |
| 144 | + fragment_id = cudf_benchmark_fragments::mul_f32; |
| 145 | + cuda = jit_mul_cuda; |
| 146 | + } break; |
| 147 | + default: throw std::runtime_error("Unsupported binary operator for JIT benchmark"); |
| 148 | + } |
| 149 | + |
| 150 | + // Call once for hot cache. |
| 151 | + cudf::transform_input inputs[] = {lhs, rhs}; |
| 152 | + cudf::transform_output outputs[] = { |
| 153 | + {cudf::data_type{cudf::type_to_id<TypeOut>()}, cudf::output_nullability::ALL_VALID}}; |
| 154 | + |
| 155 | + auto const range = cudf_benchmark_fragments::file_ranges[fragment_id]; |
| 156 | + std::span<uint8_t const> udf{cudf_benchmark_fragments::files.subspan(range[0], range[1])}; |
| 157 | + |
| 158 | + auto result = use_lto ? cudf::transform_lto(udf, |
| 159 | + cudf::lto_binary_type::FATBIN, |
| 160 | + cudf::null_aware::NO, |
| 161 | + std::nullopt, |
| 162 | + inputs, |
| 163 | + outputs, |
| 164 | + {}, |
| 165 | + std::nullopt) |
| 166 | + : cudf::multi_transform(cuda, |
| 167 | + cudf::udf_source_type::CUDA, |
| 168 | + cudf::null_aware::NO, |
| 169 | + std::nullopt, |
| 170 | + inputs, |
| 171 | + outputs, |
| 172 | + {}, |
| 173 | + std::nullopt); |
| 174 | + |
| 175 | + // use number of bytes read and written to global memory |
| 176 | + state.add_global_memory_reads<TypeLhs>(num_rows); |
| 177 | + state.add_global_memory_reads<TypeRhs>(num_rows); |
| 178 | + state.add_global_memory_writes<TypeOut>(num_rows); |
| 179 | + |
| 180 | + state.exec(nvbench::exec_tag::sync, [&](nvbench::launch&) { |
| 181 | + [[maybe_unused]] auto result = use_lto ? cudf::transform_lto(udf, |
| 182 | + cudf::lto_binary_type::FATBIN, |
| 183 | + cudf::null_aware::NO, |
| 184 | + std::nullopt, |
| 185 | + inputs, |
| 186 | + outputs, |
| 187 | + {}, |
| 188 | + std::nullopt) |
| 189 | + : cudf::multi_transform(cuda, |
| 190 | + cudf::udf_source_type::CUDA, |
| 191 | + cudf::null_aware::NO, |
| 192 | + std::nullopt, |
| 193 | + inputs, |
| 194 | + outputs, |
| 195 | + {}, |
| 196 | + std::nullopt); |
| 197 | + }); |
| 198 | +} |
| 199 | + |
| 200 | +#define BM_JIT_BINARYOP_BENCHMARK_DEFINE(name, lhs, rhs, bop, tout) \ |
| 201 | + static void name(::nvbench::state& st) \ |
| 202 | + { \ |
| 203 | + ::BM_jit_binaryop<lhs, rhs, tout>(st, ::cudf::binary_operator::bop); \ |
| 204 | + } \ |
| 205 | + NVBENCH_BENCH(name) \ |
| 206 | + .set_name("jit_binary_op_" BM_STRINGIFY(name)) \ |
| 207 | + .add_int64_axis("num_rows", {10'000, 100'000, 1'000'000, 10'000'000, 100'000'000}) \ |
| 208 | + .add_string_axis("use_lto", {"true", "false"}) |
| 209 | + |
| 210 | +#define build_name_jit(a, b, c, d) a##_##b##_##c##_##d##_jit |
| 211 | + |
| 212 | +#define JIT_BINARYOP_BENCHMARK_DEFINE(lhs, rhs, bop, tout) \ |
| 213 | + BM_JIT_BINARYOP_BENCHMARK_DEFINE(build_name_jit(bop, lhs, rhs, tout), lhs, rhs, bop, tout) |
| 214 | + |
| 215 | +// clang-format off |
| 216 | +JIT_BINARYOP_BENCHMARK_DEFINE(float, float, ADD, float); |
| 217 | +JIT_BINARYOP_BENCHMARK_DEFINE(float, float, MUL, float); |
| 218 | +// clang-format on |
0 commit comments