forked from google/XNNPACK
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdwconv-microkernel-tester.h
293 lines (233 loc) · 8.51 KB
/
dwconv-microkernel-tester.h
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
// Copyright (c) Facebook, Inc. and its affiliates.
// All rights reserved.
//
// Copyright 2019 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
#pragma once
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <string>
#include <gtest/gtest.h>
#include "xnnpack.h"
#include "xnnpack/aligned-allocator.h"
#include "xnnpack/common.h"
#include "xnnpack/microfnptr.h"
#include "xnnpack/microkernel-utils.h"
#include "xnnpack/microparams-init.h"
#include "xnnpack/pack.h"
#include "xnnpack/requantization.h"
class DWConvMicrokernelTester {
public:
DWConvMicrokernelTester& width(uint32_t width) {
assert(width >= 1);
this->width_ = width;
return *this;
}
uint32_t width() const { return this->width_; }
DWConvMicrokernelTester& step(uint32_t step) {
assert(step >= 1);
this->step_ = step;
return *this;
}
uint32_t step() const { return this->step_; }
DWConvMicrokernelTester& channels(uint32_t channels) {
assert(channels >= 1);
this->channels_ = channels;
return *this;
}
uint32_t channels() const { return this->channels_; }
DWConvMicrokernelTester& channel_tile(uint32_t channel_tile) {
assert(channel_tile != 0);
this->channel_tile_ = channel_tile;
return *this;
}
uint32_t channel_tile() const { return this->channel_tile_; }
DWConvMicrokernelTester& channel_subtile(uint32_t channel_subtile) {
assert(channel_subtile != 0);
this->channel_subtile_ = channel_subtile;
return *this;
}
uint32_t channel_subtile() const { return this->channel_subtile_; }
DWConvMicrokernelTester& channel_round(uint32_t channel_round) {
assert(channel_round != 0);
this->channel_round_ = channel_round;
return *this;
}
uint32_t channel_round() const { return this->channel_round_; }
DWConvMicrokernelTester& kernel_tile(uint32_t kernel_tile) {
assert(kernel_tile != 0);
this->kernel_tile_ = kernel_tile;
return *this;
}
uint32_t kernel_tile() const { return this->kernel_tile_; }
DWConvMicrokernelTester& kernel_size(uint32_t kernel_size) {
assert(kernel_size != 0);
this->kernel_size_ = kernel_size;
return *this;
}
uint32_t kernel_size() const { return this->kernel_size_; }
uint32_t packed_channels() const {
return (channels() / channel_tile() + !!(channels() % channel_tile())) *
channel_tile();
}
DWConvMicrokernelTester& output_stride(uint32_t output_stride) {
assert(output_stride != 0);
this->output_stride_ = output_stride;
return *this;
}
uint32_t output_stride() const {
if (this->output_stride_ == 0) {
return channels();
} else {
assert(this->output_stride_ >= channels());
return this->output_stride_;
}
}
DWConvMicrokernelTester& input_zero_point(uint8_t input_zero_point) {
this->input_zero_point_ = input_zero_point;
return *this;
}
uint8_t input_zero_point() const { return this->input_zero_point_; }
DWConvMicrokernelTester& kernel_zero_point(uint8_t kernel_zero_point) {
this->kernel_zero_point_ = kernel_zero_point;
return *this;
}
uint8_t kernel_zero_point() const { return this->kernel_zero_point_; }
DWConvMicrokernelTester& qmin(uint8_t qmin) {
this->qmin_ = qmin;
return *this;
}
uint8_t qmin() const { return this->qmin_; }
DWConvMicrokernelTester& qmax(uint8_t qmax) {
this->qmax_ = qmax;
return *this;
}
uint8_t qmax() const { return this->qmax_; }
DWConvMicrokernelTester& input_offset(size_t input_offset) {
this->input_offset_ = input_offset;
return *this;
}
size_t input_offset() const { return this->input_offset_; }
DWConvMicrokernelTester& zero_index(size_t zero_index) {
this->zero_index_ = zero_index;
return *this;
}
size_t zero_index() const { return this->zero_index_; }
DWConvMicrokernelTester& iterations(size_t iterations) {
this->iterations_ = iterations;
return *this;
}
size_t iterations() const { return this->iterations_; }
DWConvMicrokernelTester& first_pass_tile(size_t first_pass_tile) {
this->first_pass_tile_ = first_pass_tile;
return *this;
}
size_t first_pass_tile() const { return this->first_pass_tile_; }
DWConvMicrokernelTester& middle_pass_tile(size_t middle_pass_tile) {
this->middle_pass_tile_ = middle_pass_tile;
return *this;
}
size_t middle_pass_tile() const { return this->middle_pass_tile_; }
DWConvMicrokernelTester& last_pass_tile(size_t last_pass_tile) {
this->last_pass_tile_ = last_pass_tile;
return *this;
}
size_t last_pass_tile() const { return this->last_pass_tile_; }
void Test(xnn_qu8_dwconv_minmax_unipass_ukernel_fn dwconv_minmax,
xnn_init_qu8_conv_minmax_params_fn init_params,
xnn_qu8_requantize_fn requantize) const;
void Test(xnn_qu8_dwconv_minmax_multipass_ukernel_fn dwconv_minmax,
xnn_init_qu8_conv_minmax_params_fn init_params,
xnn_qu8_requantize_fn requantize) const;
void Test(xnn_qs8_qc8w_dwconv_minmax_unipass_ukernel_fn dwconv_minmax,
xnn_init_qs8_qc8w_conv_minmax_params_fn init_params,
xnn_qs8_requantize_fn requantize) const;
void Test(xnn_qs8_qc8w_dwconv_minmax_multipass_ukernel_fn dwconv_minmax,
xnn_init_qs8_qc8w_conv_minmax_params_fn init_params,
xnn_qs8_requantize_fn requantize) const;
void Test(xnn_qs8_dwconv_minmax_unipass_ukernel_fn dwconv_minmax,
xnn_init_qs8_conv_minmax_params_fn init_params,
xnn_qs8_requantize_fn requantize) const;
void Test(xnn_qs8_dwconv_minmax_multipass_ukernel_fn dwconv_minmax,
xnn_init_qs8_conv_minmax_params_fn init_params,
xnn_qs8_requantize_fn requantize) const;
void Test(xnn_f16_dwconv_minmax_unipass_ukernel_fn dwconv_minmax,
xnn_init_f16_minmax_params_fn init_params) const;
void Test(xnn_f16_dwconv_minmax_multipass_ukernel_fn dwconv_minmax,
xnn_init_f16_minmax_params_fn init_params) const;
void Test(xnn_f32_dwconv_unipass_ukernel_fn dwconv, const void* = nullptr) const;
void Test(xnn_f32_dwconv_minmax_unipass_ukernel_fn dwconv_minmax,
xnn_init_f32_minmax_params_fn init_params) const;
void Test(xnn_f32_dwconv_multipass_ukernel_fn dwconv, const void* = nullptr) const;
void Test(xnn_f32_dwconv_minmax_multipass_ukernel_fn dwconv_minmax,
xnn_init_f32_minmax_params_fn init_params) const;
private:
uint32_t channels_{1};
uint32_t channel_tile_{1};
uint32_t channel_subtile_{1};
uint32_t channel_round_{1};
uint32_t kernel_tile_{1};
uint32_t kernel_size_{1};
uint32_t width_{1};
uint32_t step_{1};
uint32_t output_stride_{0};
uint8_t input_zero_point_{127};
uint8_t kernel_zero_point_{127};
uint8_t qmin_{0};
uint8_t qmax_{255};
size_t input_offset_{0};
size_t zero_index_{SIZE_MAX};
size_t iterations_{3};
size_t first_pass_tile_{0};
size_t middle_pass_tile_{0};
size_t last_pass_tile_{0};
};
struct LoopParams {
LoopParams() = default;
explicit LoopParams(size_t from, size_t to, size_t step)
: is_set(true), from(from), to(to), step(step) {}
bool is_set = false;
size_t from = 1;
size_t to = 1;
size_t step = 1;
};
struct DWConvTestParams {
DWConvTestParams(std::string test_name, DWConvMicrokernelTester tester,
std::function<void(DWConvMicrokernelTester& tester)> test_func,
std::function<void(void)> isa_check = nullptr)
: test_name(test_name),
tester(tester),
test_func(test_func),
isa_check(isa_check) {}
// Setters for the loops over `k`, `m`, and `n`.
DWConvTestParams& loop_kernel_size(size_t from, size_t to, size_t step = 1) {
loop_kernel_size_ = LoopParams(from, to, step);
return *this;
}
DWConvTestParams& loop_channels(size_t from, size_t to, size_t step = 1) {
loop_channels_ = LoopParams(from, to, step);
return *this;
}
DWConvTestParams& loop_step(size_t from, size_t to, size_t step = 1) {
loop_step_ = LoopParams(from, to, step);
return *this;
}
DWConvTestParams& loop_zi(size_t from, size_t to, size_t step = 1) {
loop_zi_ = LoopParams(from, to, step);
return *this;
}
std::string test_name;
DWConvMicrokernelTester tester;
std::function<void(DWConvMicrokernelTester& tester)> test_func;
std::function<void(void)> isa_check;
LoopParams loop_kernel_size_;
LoopParams loop_channels_;
LoopParams loop_step_;
LoopParams loop_zi_;
};
using DWConvTest = testing::TestWithParam<DWConvTestParams>;