Write a benchmark (part 1)
(no SIMD yet)
In the simd-benchmarks
directory:
Edit
CMakeLists.txt
and addadd_benchmark(peakflop)
at the bottom.
Create a new file
peakflop.cpp
and add the following boilerplate:
#include <benchmark/benchmark.h>
void peak(benchmark::State &state)
{
float x = 1;
for (auto _ : state) {
x = x * 3 + 1;
}
// compute FLOP/s and FLOP/cycle
constexpr double flop_per_iteration = 2;
state.counters["FLOP"] = {flop_per_iteration,
benchmark::Counter::kIsIterationInvariantRate};
if (state.counters.contains("CYCLES")) {
state.counters["FLOP/cycle"] = {flop_per_iteration / state.counters["CYCLES"],
benchmark::Counter::kIsIterationInvariant};
}
}
// Register the function as a benchmark
BENCHMARK(peak);
// Run the benchmark
BENCHMARK_MAIN();
Use
make run_peakflop
to compile and execute the benchmark (runmake
on the first time to create the new target)
Are the numbers correct? Anything wrong with the benchmark?
(optional) Inspect the binary with
vir_inspect.sh peakflop peak