poulpy/poulpy-backend/src/cpu_spqlios/spqlios-arithmetic/test/spqlios_q120_arithmetic_bench.cpp
poulpy-backend/src/cpu_spqlios/spqlios-arithmetic/test/spqlios_q120_arithmetic_bench.cppRaw
1#include <benchmark/benchmark.h>
2
3#include <cstdint>
4
5#include "spqlios/q120/q120_arithmetic.h"
6
7#define ARGS Arg(128)->Arg(4096)->Arg(10000)
8
9template <typeof(q120_vec_mat1col_product_baa_ref) f>
10void benchmark_baa(benchmark::State& state) {
11 const uint64_t ell = state.range(0);
12 q120_mat1col_product_baa_precomp* precomp = q120_new_vec_mat1col_product_baa_precomp();
13
14 uint64_t* a = new uint64_t[ell * 4];
15 uint64_t* b = new uint64_t[ell * 4];
16 uint64_t* c = new uint64_t[4];
17 for (uint64_t i = 0; i < 4 * ell; i++) {
18 a[i] = rand();
19 b[i] = rand();
20 }
21 for (auto _ : state) {
22 f(precomp, ell, (q120b*)c, (q120a*)a, (q120a*)b);
23 }
24 delete[] c;
25 delete[] b;
26 delete[] a;
27 q120_delete_vec_mat1col_product_baa_precomp(precomp);
28}
29
30BENCHMARK(benchmark_baa<q120_vec_mat1col_product_baa_ref>)->Name("q120_vec_mat1col_product_baa_ref")->ARGS;
31BENCHMARK(benchmark_baa<q120_vec_mat1col_product_baa_avx2>)->Name("q120_vec_mat1col_product_baa_avx2")->ARGS;
32
33template <typeof(q120_vec_mat1col_product_bbb_ref) f>
34void benchmark_bbb(benchmark::State& state) {
35 const uint64_t ell = state.range(0);
36 q120_mat1col_product_bbb_precomp* precomp = q120_new_vec_mat1col_product_bbb_precomp();
37
38 uint64_t* a = new uint64_t[ell * 4];
39 uint64_t* b = new uint64_t[ell * 4];
40 uint64_t* c = new uint64_t[4];
41 for (uint64_t i = 0; i < 4 * ell; i++) {
42 a[i] = rand();
43 b[i] = rand();
44 }
45 for (auto _ : state) {
46 f(precomp, ell, (q120b*)c, (q120b*)a, (q120b*)b);
47 }
48 delete[] c;
49 delete[] b;
50 delete[] a;
51 q120_delete_vec_mat1col_product_bbb_precomp(precomp);
52}
53
54BENCHMARK(benchmark_bbb<q120_vec_mat1col_product_bbb_ref>)->Name("q120_vec_mat1col_product_bbb_ref")->ARGS;
55BENCHMARK(benchmark_bbb<q120_vec_mat1col_product_bbb_avx2>)->Name("q120_vec_mat1col_product_bbb_avx2")->ARGS;
56
57template <typeof(q120_vec_mat1col_product_bbc_ref) f>
58void benchmark_bbc(benchmark::State& state) {
59 const uint64_t ell = state.range(0);
60 q120_mat1col_product_bbc_precomp* precomp = q120_new_vec_mat1col_product_bbc_precomp();
61
62 uint64_t* a = new uint64_t[ell * 4];
63 uint64_t* b = new uint64_t[ell * 4];
64 uint64_t* c = new uint64_t[4];
65 for (uint64_t i = 0; i < 4 * ell; i++) {
66 a[i] = rand();
67 b[i] = rand();
68 }
69 for (auto _ : state) {
70 f(precomp, ell, (q120b*)c, (q120b*)a, (q120c*)b);
71 }
72 delete[] c;
73 delete[] b;
74 delete[] a;
75 q120_delete_vec_mat1col_product_bbc_precomp(precomp);
76}
77
78BENCHMARK(benchmark_bbc<q120_vec_mat1col_product_bbc_ref>)->Name("q120_vec_mat1col_product_bbc_ref")->ARGS;
79BENCHMARK(benchmark_bbc<q120_vec_mat1col_product_bbc_avx2>)->Name("q120_vec_mat1col_product_bbc_avx2")->ARGS;
80
81EXPORT void q120x2_vec_mat2cols_product_bbc_avx2(q120_mat1col_product_bbc_precomp* precomp, const uint64_t ell,
82 q120b* const res, const q120b* const x, const q120c* const y);
83EXPORT void q120x2_vec_mat1col_product_bbc_avx2(q120_mat1col_product_bbc_precomp* precomp, const uint64_t ell,
84 q120b* const res, const q120b* const x, const q120c* const y);
85
86template <typeof(q120_vec_mat1col_product_bbc_ref) f>
87void benchmark_x2c2_bbc(benchmark::State& state) {
88 const uint64_t ell = state.range(0);
89 q120_mat1col_product_bbc_precomp* precomp = q120_new_vec_mat1col_product_bbc_precomp();
90
91 uint64_t* a = new uint64_t[ell * 8];
92 uint64_t* b = new uint64_t[ell * 16];
93 uint64_t* c = new uint64_t[16];
94 for (uint64_t i = 0; i < 8 * ell; i++) {
95 a[i] = rand();
96 }
97 for (uint64_t i = 0; i < 16 * ell; i++) {
98 b[i] = rand();
99 }
100 for (auto _ : state) {
101 f(precomp, ell, (q120b*)c, (q120b*)a, (q120c*)b);
102 }
103 delete[] c;
104 delete[] b;
105 delete[] a;
106 q120_delete_vec_mat1col_product_bbc_precomp(precomp);
107}
108
109BENCHMARK(benchmark_x2c2_bbc<q120x2_vec_mat2cols_product_bbc_avx2>)->Name("q120x2_vec_mat2col_product_bbc_avx2")->ARGS;
110
111template <typeof(q120_vec_mat1col_product_bbc_ref) f>
112void benchmark_x2c1_bbc(benchmark::State& state) {
113 const uint64_t ell = state.range(0);
114 q120_mat1col_product_bbc_precomp* precomp = q120_new_vec_mat1col_product_bbc_precomp();
115
116 uint64_t* a = new uint64_t[ell * 8];
117 uint64_t* b = new uint64_t[ell * 8];
118 uint64_t* c = new uint64_t[8];
119 for (uint64_t i = 0; i < 8 * ell; i++) {
120 a[i] = rand();
121 }
122 for (uint64_t i = 0; i < 8 * ell; i++) {
123 b[i] = rand();
124 }
125 for (auto _ : state) {
126 f(precomp, ell, (q120b*)c, (q120b*)a, (q120c*)b);
127 }
128 delete[] c;
129 delete[] b;
130 delete[] a;
131 q120_delete_vec_mat1col_product_bbc_precomp(precomp);
132}
133
134BENCHMARK(benchmark_x2c1_bbc<q120x2_vec_mat1col_product_bbc_avx2>)->Name("q120x2_vec_mat1col_product_bbc_avx2")->ARGS;
135
136BENCHMARK_MAIN();