arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/spqlios/lib/test/spqlios_reim4_arithmetic_bench.cpp
spqlios/lib/test/spqlios_reim4_arithmetic_bench.cppRaw
 1#include <benchmark/benchmark.h>
 2
 3#include "spqlios/reim4/reim4_arithmetic.h"
 4
 5void init_random_values(uint64_t n, double* v) {
 6  for (uint64_t i = 0; i < n; ++i)
 7    v[i] = (double(rand() % (UINT64_C(1) << 14)) - (UINT64_C(1) << 13)) / (UINT64_C(1) << 12);
 8}
 9
10// Run the benchmark
11BENCHMARK_MAIN();
12
13#undef ARGS
14#define ARGS Args({47, 16384})->Args({93, 32768})
15
16/*
17 *  reim4_vec_mat1col_product
18 *  reim4_vec_mat2col_product
19 *  reim4_vec_mat3col_product
20 *  reim4_vec_mat4col_product
21 */
22
23template <uint64_t X,
24          void (*fnc)(const uint64_t nrows, double* const dst, const double* const u, const double* const v)>
25void benchmark_reim4_vec_matXcols_product(benchmark::State& state) {
26  const uint64_t nrows = state.range(0);
27
28  double* u = new double[nrows * 8];
29  init_random_values(8 * nrows, u);
30  double* v = new double[nrows * X * 8];
31  init_random_values(X * 8 * nrows, v);
32  double* dst = new double[X * 8];
33
34  for (auto _ : state) {
35    fnc(nrows, dst, u, v);
36  }
37
38  delete[] dst;
39  delete[] v;
40  delete[] u;
41}
42
43#undef ARGS
44#define ARGS Arg(128)->Arg(1024)->Arg(4096)
45
46#ifdef __x86_64__
47BENCHMARK(benchmark_reim4_vec_matXcols_product<1, reim4_vec_mat1col_product_avx2>)->ARGS;
48// TODO: please remove when fixed:
49BENCHMARK(benchmark_reim4_vec_matXcols_product<2, reim4_vec_mat2cols_product_avx2>)->ARGS;
50#endif
51BENCHMARK(benchmark_reim4_vec_matXcols_product<1, reim4_vec_mat1col_product_ref>)->ARGS;
52BENCHMARK(benchmark_reim4_vec_matXcols_product<2, reim4_vec_mat2cols_product_ref>)->ARGS;