Write a benchmark (part 1)

(no SIMD yet)

In the simd-benchmarks directory:

:pencil:

Edit CMakeLists.txt and add add_benchmark(peakflop) at the bottom.

:pencil:

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();

:pencil:

Use make run_peakflop to compile and execute the benchmark (run make on the first time to create the new target)

:question:

Are the numbers correct? Anything wrong with the benchmark?

:pencil:

(optional) Inspect the binary with

vir_inspect.sh peakflop peak

results matching ""

    No results matching ""