35#ifdef HAVE_GOOGLE_BENCHMARK
45#include <benchmark/benchmark.h>
81 throw std::runtime_error(
"Benchmark state is not set.");
87 benchmark::State *
st_ =
nullptr;
157 template <
typename Func,
typename... Args>
158 benchmark::internal::Benchmark *
add_gbench(
const char *name, Func f, Args &&...args)
160 std::tuple<Args...> cargs(std::forward<Args>(args)...);
162 auto benchptr = benchmark::RegisterBenchmark(
164 [f, cargs = std::move(cargs)](benchmark::State &st)
mutable
167 std::apply([&](
auto &&...unpacked)
168 { f(std::forward<
decltype(unpacked)>(unpacked)...); }, cargs);
169 benchmark::ClobberMemory();
184 benchmark::RunSpecifiedBenchmarks();
185 benchmark::Shutdown();
199 << std::left << comppare::internal::ansi::BOLD
200 <<
"*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=\n============= "
201 << comppare::internal::ansi::ITALIC(
"Google Benchmark")
202 <<
" =============\n=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*"
203 << comppare::internal::ansi::BOLD_OFF <<
"\n\n";
205 std::cout <<
"Google Benchmark cmdline arguments:\n";
208 std::cout << std::setw(2) << std::right <<
" "
209 <<
" [" << i <<
"] " << std::quoted(
gbench_argv[i]) <<
"\n";
212 std::cout << std::left
213 << comppare::internal::ansi::BOLD(
"=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*")
229 template <
class InTup,
class OutTup>
249 static std::shared_ptr<Self> inst{
new Self};
268 template <
class Func>
274 return std::apply([&](
auto const &...in_vals)
275 {
return std::apply([&](
auto &&...outs_vals)
277 std::forward<Func>(user_fn),
278 in_vals..., outs_vals...); }, outs); }, inputs);
320 template <comppare::
internal::concepts::FloatingPo
int T>
324 st.SetIterationTime(
static_cast<double>(time * 1e-6));
340 template <
typename Rep,
typename Period>
344 double elapsed_seconds = std::chrono::duration_cast<std::chrono::duration<double>>(time).count();
345 st.SetIterationTime(elapsed_seconds);
353#define PLUGIN_HOTLOOP_BENCH \
354 benchmark::State &st = comppare::plugin::google_benchmark::state::get_state(); \
360#if defined(__CUDACC__)
361#define GPU_PLUGIN_HOTLOOP_BENCH \
362 cudaEvent_t __LINE__stop; \
363 cudaEventCreate(&__LINE__stop); \
364 benchmark::State &st = comppare::plugin::google_benchmark::state::get_state(); \
371 cudaEventRecord(__LINE__stop); \
372 cudaEventSynchronize(__LINE__stop); \
374#elif defined(__HIPCC__)
375#define GPU_PLUGIN_HOTLOOP_BENCH \
376 hipEvent_t __LINE__stop; \
377 hipEventCreate(&__LINE__stop); \
378 benchmark::State &st = comppare::plugin::google_benchmark::state::get_state(); \
385 hipEventRecord(__LINE__stop); \
386 hipEventSynchronize(__LINE__stop); \
391#define PLUGIN_SET_ITERATION_TIME(TIME) \
392 comppare::plugin::google_benchmark::SetIterationTime(TIME);
This file contains utilities for applying ANSI styles and colors to console output.
Argument parser for plugin command-line arguments.
Definition plugin.hpp:107
std::pair< int, char ** > parse(int argc, char **argv)
Definition plugin.hpp:118
Base class for plugins in the ComPPare framework.
Definition plugin.hpp:60
Google Benchmark plugin for the ComPPare framework.
Definition google_benchmark.hpp:231
GoogleBenchmarkPlugin()=default
static std::shared_ptr< Self > instance()
Get the singleton instance of the GoogleBenchmarkPlugin.
Definition google_benchmark.hpp:247
comppare::plugin::google_benchmark::google_benchmark_manager gb_
Definition google_benchmark.hpp:233
void initialize(int &argc, char **argv) override
Initialize the Google Benchmark plugin.
Definition google_benchmark.hpp:289
benchmark::internal::Benchmark * register_impl(const std::string &name, Func &&user_fn, const InTup &inputs, OutTup &outs)
Register an implementation with the Google Benchmark plugin.
Definition google_benchmark.hpp:269
GoogleBenchmarkPlugin & operator=(const GoogleBenchmarkPlugin &)=delete
void run() override
Run the registered benchmarks.
Definition google_benchmark.hpp:299
GoogleBenchmarkPlugin(const GoogleBenchmarkPlugin &)=delete
Manager class for Google Benchmark integration.
Definition google_benchmark.hpp:98
~google_benchmark_manager()=default
void run()
Run the registered benchmarks.
Definition google_benchmark.hpp:182
int gbench_argc
Definition google_benchmark.hpp:189
benchmark::internal::Benchmark * add_gbench(const char *name, Func f, Args &&...args)
Register a benchmark function with Google Benchmark.
Definition google_benchmark.hpp:158
char ** gbench_argv
Definition google_benchmark.hpp:190
comppare::plugin::PluginArgParser gbench_parser_
Argument parser for Google Benchmark.
Definition google_benchmark.hpp:192
void initialize(int &argc, char **argv)
Initialize the Google Benchmark library.
Definition google_benchmark.hpp:113
google_benchmark_manager()=default
void print_benchmark_header()
Print the benchmark header.
Definition google_benchmark.hpp:195
State class to manage the benchmark state.
Definition google_benchmark.hpp:60
static state & instance()
Definition google_benchmark.hpp:67
state & operator=(state &&)=delete
benchmark::State * st_
Definition google_benchmark.hpp:87
static void set_state(benchmark::State &st)
Definition google_benchmark.hpp:73
state & operator=(const state &)=delete
state(const state &)=delete
static benchmark::State & get_state()
Definition google_benchmark.hpp:78
Definition google_benchmark.hpp:51
void SetIterationTime(T time)
Set the iteration time for the current benchmark.
Definition google_benchmark.hpp:321
This file contains the base Plugin class and concept of a valid Plugin class for the ComPPare framewo...