forked from google/XNNPACK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf32-vscaleexpminusmax.cc
211 lines (193 loc) · 9.69 KB
/
f32-vscaleexpminusmax.cc
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include <algorithm>
#include <cfloat>
#include <chrono>
#include <cmath>
#include <functional>
#include <random>
#include <vector>
#include <benchmark/benchmark.h>
#include "bench/utils.h"
#include <xnnpack.h>
#include <xnnpack/aligned-allocator.h>
#include <xnnpack/common.h>
#include <xnnpack/microfnptr.h>
#include <xnnpack/rmax.h>
#include <xnnpack/raddexpminusmax.h>
#include <xnnpack/vscaleexpminusmax.h>
static void f32_vscaleexpminusmax(
benchmark::State& state,
xnn_f32_rmax_ukernel_fn rmax,
xnn_f32_raddexpminusmax_ukernel_fn raddexpminusmax,
xnn_f32_vscaleexpminusmax_ukernel_fn vscaleexpminusmax,
benchmark::utils::IsaCheckFunction isa_check = nullptr)
{
if (isa_check != nullptr && !isa_check(state)) {
return;
}
const size_t elements = state.range(0);
const size_t cache_line_size_max = 128;
const size_t packed_elements = benchmark::utils::RoundUp(elements, cache_line_size_max / sizeof(float));
std::random_device random_device;
auto rng = std::mt19937(random_device());
auto f32rng = std::bind(std::uniform_real_distribution<float>(-1000.0f, 1000.0f), std::ref(rng));
const size_t num_buffers = 1 +
benchmark::utils::DivideRoundUp<size_t>(benchmark::utils::GetMaxCacheSize(), packed_elements * sizeof(float));
std::vector<float, AlignedAllocator<float, 64>> x(elements);
std::vector<float, AlignedAllocator<float, 64>> y(packed_elements * num_buffers);
std::generate(x.begin(), x.end(), std::ref(f32rng));
benchmark::utils::DisableDenormals();
size_t buffer_index = 0;
for (auto _ : state) {
state.PauseTiming();
float x_max = nanf("");
rmax(elements * sizeof(float), x.data(), &x_max);
float y_sum = nanf("");
raddexpminusmax(elements * sizeof(float), x.data(), &y_sum, x_max);
if (++buffer_index == num_buffers) {
buffer_index = 0;
}
state.ResumeTiming();
vscaleexpminusmax(elements * sizeof(float), x.data(), y.data() + packed_elements * buffer_index, x_max, 1.0f / y_sum);
}
const uint64_t cpu_frequency = benchmark::utils::GetCurrentCpuFrequency();
if (cpu_frequency != 0) {
state.counters["cpufreq"] = cpu_frequency;
}
const size_t elements_per_iteration = elements;
state.counters["elements"] =
benchmark::Counter(uint64_t(state.iterations()) * elements_per_iteration, benchmark::Counter::kIsRate);
const size_t bytes_per_iteration = 2 * elements * sizeof(float);
state.counters["bytes"] =
benchmark::Counter(uint64_t(state.iterations()) * bytes_per_iteration, benchmark::Counter::kIsRate);
}
static void CharacteristicArguments(benchmark::internal::Benchmark* b) {
b->ArgName("N");
for (int32_t n = 10000; n <= 100000000; n *= 10) {
b->Arg(n);
}
}
#if XNN_ARCH_X86 || XNN_ARCH_X86_64
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx512f_p5_scalef_x16,
xnn_f32_rmax_ukernel__avx512f,
xnn_f32_raddexpminusmax_ukernel__avx512f_p5_scalef_x128_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx512f_p5_scalef_x16,
benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx512f_p5_scalef_x32,
xnn_f32_rmax_ukernel__avx512f,
xnn_f32_raddexpminusmax_ukernel__avx512f_p5_scalef_x128_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx512f_p5_scalef_x32,
benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx512f_p5_scalef_x48,
xnn_f32_rmax_ukernel__avx512f,
xnn_f32_raddexpminusmax_ukernel__avx512f_p5_scalef_x128_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx512f_p5_scalef_x48,
benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx512f_p5_scalef_x64,
xnn_f32_rmax_ukernel__avx512f,
xnn_f32_raddexpminusmax_ukernel__avx512f_p5_scalef_x128_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx512f_p5_scalef_x64,
benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx512f_p5_scalef_x80,
xnn_f32_rmax_ukernel__avx512f,
xnn_f32_raddexpminusmax_ukernel__avx512f_p5_scalef_x128_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx512f_p5_scalef_x80,
benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx512f_p5_scalef_x96,
xnn_f32_rmax_ukernel__avx512f,
xnn_f32_raddexpminusmax_ukernel__avx512f_p5_scalef_x128_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx512f_p5_scalef_x96,
benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx512f_p5_scalef_x112,
xnn_f32_rmax_ukernel__avx512f,
xnn_f32_raddexpminusmax_ukernel__avx512f_p5_scalef_x128_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx512f_p5_scalef_x112,
benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx512f_p5_scalef_x128,
xnn_f32_rmax_ukernel__avx512f,
xnn_f32_raddexpminusmax_ukernel__avx512f_p5_scalef_x128_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx512f_p5_scalef_x128,
benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx512f_p5_scalef_x144,
xnn_f32_rmax_ukernel__avx512f,
xnn_f32_raddexpminusmax_ukernel__avx512f_p5_scalef_x128_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx512f_p5_scalef_x144,
benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx512f_p5_scalef_x160,
xnn_f32_rmax_ukernel__avx512f,
xnn_f32_raddexpminusmax_ukernel__avx512f_p5_scalef_x128_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx512f_p5_scalef_x160,
benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx512f_p5_scalef_x176,
xnn_f32_rmax_ukernel__avx512f,
xnn_f32_raddexpminusmax_ukernel__avx512f_p5_scalef_x128_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx512f_p5_scalef_x176,
benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx512f_p5_scalef_x192,
xnn_f32_rmax_ukernel__avx512f,
xnn_f32_raddexpminusmax_ukernel__avx512f_p5_scalef_x128_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx512f_p5_scalef_x192,
benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx2_p5_x8,
xnn_f32_rmax_ukernel__avx,
xnn_f32_raddexpminusmax_ukernel__avx2_p5_x80_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx2_p5_x8,
benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx2_p5_x16,
xnn_f32_rmax_ukernel__avx,
xnn_f32_raddexpminusmax_ukernel__avx2_p5_x80_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx2_p5_x16,
benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx2_p5_x24,
xnn_f32_rmax_ukernel__avx,
xnn_f32_raddexpminusmax_ukernel__avx2_p5_x80_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx2_p5_x24,
benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx2_p5_x32,
xnn_f32_rmax_ukernel__avx,
xnn_f32_raddexpminusmax_ukernel__avx2_p5_x80_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx2_p5_x32,
benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx2_p5_x40,
xnn_f32_rmax_ukernel__avx,
xnn_f32_raddexpminusmax_ukernel__avx2_p5_x80_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx2_p5_x40,
benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx2_p5_x48,
xnn_f32_rmax_ukernel__avx,
xnn_f32_raddexpminusmax_ukernel__avx2_p5_x80_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx2_p5_x48,
benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx2_p5_x56,
xnn_f32_rmax_ukernel__avx,
xnn_f32_raddexpminusmax_ukernel__avx2_p5_x80_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx2_p5_x56,
benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx2_p5_x64,
xnn_f32_rmax_ukernel__avx,
xnn_f32_raddexpminusmax_ukernel__avx2_p5_x80_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx2_p5_x64,
benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx2_p5_x72,
xnn_f32_rmax_ukernel__avx,
xnn_f32_raddexpminusmax_ukernel__avx2_p5_x80_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx2_p5_x72,
benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx2_p5_x80,
xnn_f32_rmax_ukernel__avx,
xnn_f32_raddexpminusmax_ukernel__avx2_p5_x80_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx2_p5_x80,
benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx2_p5_x88,
xnn_f32_rmax_ukernel__avx,
xnn_f32_raddexpminusmax_ukernel__avx2_p5_x80_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx2_p5_x88,
benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime();
BENCHMARK_CAPTURE(f32_vscaleexpminusmax, avx2_p5_x96,
xnn_f32_rmax_ukernel__avx,
xnn_f32_raddexpminusmax_ukernel__avx2_p5_x80_acc2,
xnn_f32_vscaleexpminusmax_ukernel__avx2_p5_x96,
benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime();
#endif // XNN_ARCH_X86 || XNN_ARCH_X86_64
#ifndef XNNPACK_BENCHMARK_NO_MAIN
BENCHMARK_MAIN();
#endif