forked from intel/hexl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench-eltwise-add-mod.cpp
117 lines (92 loc) · 3.2 KB
/
bench-eltwise-add-mod.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (C) 2020-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#include <benchmark/benchmark.h>
#include <vector>
#include "eltwise/eltwise-add-mod-avx512.hpp"
#include "eltwise/eltwise-add-mod-internal.hpp"
#include "hexl/eltwise/eltwise-add-mod.hpp"
#include "logging/logging.hpp"
#include "number-theory/number-theory.hpp"
#include "util/aligned-allocator.hpp"
namespace intel {
namespace hexl {
// state[0] is the degree
static void BM_EltwiseAddModInPlace(benchmark::State& state) { // NOLINT
size_t input_size = state.range(0);
uint64_t modulus = 0xffffffffffc0001ULL;
AlignedVector64<uint64_t> input1(input_size, 1);
AlignedVector64<uint64_t> input2(input_size, 2);
AlignedVector64<uint64_t> output(input_size, 0);
for (auto _ : state) {
EltwiseAddMod(input1.data(), input1.data(), input2.data(), input_size,
modulus);
}
}
BENCHMARK(BM_EltwiseAddModInPlace)
->Unit(benchmark::kMicrosecond)
->MinTime(1.0)
->Args({1024})
->Args({4096})
->Args({16384});
//=================================================================
// state[0] is the degree
static void BM_EltwiseAddModCopy(benchmark::State& state) { // NOLINT
size_t input_size = state.range(0);
uint64_t modulus = 0xffffffffffc0001ULL;
AlignedVector64<uint64_t> input1(input_size, 1);
AlignedVector64<uint64_t> input2(input_size, 2);
AlignedVector64<uint64_t> output(input_size, 0);
for (auto _ : state) {
EltwiseAddMod(output.data(), input1.data(), input2.data(), input_size,
modulus);
}
}
BENCHMARK(BM_EltwiseAddModCopy)
->Unit(benchmark::kMicrosecond)
->MinTime(1.0)
->Args({1024})
->Args({4096})
->Args({16384});
//=================================================================
// state[0] is the degree
static void BM_EltwiseAddModNative(benchmark::State& state) { // NOLINT
size_t input_size = state.range(0);
uint64_t modulus = 0xffffffffffc0001ULL;
AlignedVector64<uint64_t> input1(input_size, 1);
AlignedVector64<uint64_t> input2(input_size, 2);
AlignedVector64<uint64_t> output(input_size, 0);
for (auto _ : state) {
EltwiseAddModNative(output.data(), input1.data(), input2.data(), input_size,
modulus);
}
}
BENCHMARK(BM_EltwiseAddModNative)
->Unit(benchmark::kMicrosecond)
->MinTime(1.0)
->Args({1024})
->Args({4096})
->Args({16384});
//=================================================================
#ifdef HEXL_HAS_AVX512DQ
// state[0] is the degree
static void BM_EltwiseAddModAVX512(benchmark::State& state) { // NOLINT
size_t input_size = state.range(0);
size_t modulus = 1152921504606877697;
AlignedVector64<uint64_t> input1(input_size, 1);
AlignedVector64<uint64_t> input2(input_size, 2);
AlignedVector64<uint64_t> output(input_size, 0);
for (auto _ : state) {
EltwiseAddModAVX512(output.data(), input1.data(), input2.data(), input_size,
modulus);
}
}
BENCHMARK(BM_EltwiseAddModAVX512)
->Unit(benchmark::kMicrosecond)
->MinTime(1.0)
->Args({1024})
->Args({4096})
->Args({16384});
#endif
//=================================================================
} // namespace hexl
} // namespace intel