This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 220
/
qnnpack.h
336 lines (301 loc) · 8.44 KB
/
qnnpack.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* All rights reserved.
*
* 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 <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <pthreadpool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Status code for any QNNPACK function call.
*/
enum qnnp_status {
/** The call succeeded, and all output arguments now contain valid data. */
qnnp_status_success = 0,
qnnp_status_uninitialized = 1,
qnnp_status_invalid_parameter = 2,
qnnp_status_unsupported_parameter = 3,
qnnp_status_unsupported_hardware = 4,
qnnp_status_out_of_memory = 5,
};
enum qnnp_status qnnp_initialize(void);
enum qnnp_status qnnp_deinitialize(void);
typedef struct qnnp_operator* qnnp_operator_t;
enum qnnp_status qnnp_create_convolution2d_nhwc_q8(
uint32_t input_padding_top,
uint32_t input_padding_right,
uint32_t input_padding_bottom,
uint32_t input_padding_left,
uint32_t kernel_height,
uint32_t kernel_width,
uint32_t subsampling_height,
uint32_t subsampling_width,
uint32_t dilation_height,
uint32_t dilation_width,
uint32_t groups,
size_t group_input_channels,
size_t group_output_channels,
uint8_t input_zero_point,
float input_scale,
uint8_t kernel_zero_point,
float kernel_scale,
const uint8_t* kernel,
const int32_t* bias,
uint8_t output_zero_point,
float output_scale,
uint8_t output_min,
uint8_t output_max,
uint32_t flags,
qnnp_operator_t* convolution);
enum qnnp_status qnnp_setup_convolution2d_nhwc_q8(
qnnp_operator_t convolution,
size_t batch_size,
size_t input_height,
size_t input_width,
const uint8_t* input,
size_t input_stride,
uint8_t* output,
size_t output_stride,
pthreadpool_t threadpool);
enum qnnp_status qnnp_create_deconvolution2d_nhwc_q8(
uint32_t input_padding_top,
uint32_t input_padding_right,
uint32_t input_padding_bottom,
uint32_t input_padding_left,
uint32_t adjustment_height,
uint32_t adjustment_width,
uint32_t kernel_height,
uint32_t kernel_width,
uint32_t stride_height,
uint32_t stride_width,
uint32_t dilation_height,
uint32_t dilation_width,
uint32_t groups,
size_t group_input_channels,
size_t group_output_channels,
uint8_t input_zero_point,
float input_scale,
uint8_t kernel_zero_point,
float kernel_scale,
const uint8_t* kernel,
const int32_t* bias,
uint8_t output_zero_point,
float output_scale,
uint8_t output_min,
uint8_t output_max,
uint32_t flags,
qnnp_operator_t* deconvolution);
enum qnnp_status qnnp_setup_deconvolution2d_nhwc_q8(
qnnp_operator_t deconvolution,
size_t batch_size,
size_t input_height,
size_t input_width,
const uint8_t* input,
size_t input_stride,
uint8_t* output,
size_t output_stride,
pthreadpool_t threadpool);
enum qnnp_status qnnp_create_fully_connected_nc_q8(
size_t input_channels,
size_t output_channels,
uint8_t input_zero_point,
float input_scale,
uint8_t kernel_zero_point,
float kernel_scale,
const uint8_t* kernel,
const int32_t* bias,
uint8_t output_zero_point,
float output_scale,
uint8_t output_min,
uint8_t output_max,
uint32_t flags,
qnnp_operator_t* fully_connected);
enum qnnp_status qnnp_setup_fully_connected_nc_q8(
qnnp_operator_t fully_connected,
size_t batch_size,
const uint8_t* input,
size_t input_stride,
uint8_t* output,
size_t output_stride);
enum qnnp_status qnnp_create_global_average_pooling_nwc_q8(
size_t channels,
uint8_t input_zero_point,
float input_scale,
uint8_t output_zero_point,
float output_scale,
uint8_t output_min,
uint8_t output_max,
uint32_t flags,
qnnp_operator_t* global_average_pooling);
enum qnnp_status qnnp_setup_global_average_pooling_nwc_q8(
qnnp_operator_t global_average_pooling,
size_t batch_size,
size_t width,
const uint8_t* input,
size_t input_stride,
uint8_t* output,
size_t output_stride);
enum qnnp_status qnnp_create_average_pooling2d_nhwc_q8(
uint32_t input_padding_top,
uint32_t input_padding_right,
uint32_t input_padding_bottom,
uint32_t input_padding_left,
uint32_t pooling_height,
uint32_t pooling_width,
uint32_t stride_height,
uint32_t stride_width,
size_t channels,
uint8_t input_zero_point,
float input_scale,
uint8_t output_zero_point,
float output_scale,
uint8_t output_min,
uint8_t output_max,
uint32_t flags,
qnnp_operator_t* average_pooling);
enum qnnp_status qnnp_setup_average_pooling2d_nhwc_q8(
qnnp_operator_t average_pooling,
size_t batch_size,
size_t input_height,
size_t input_width,
const uint8_t* input,
size_t input_stride,
uint8_t* output,
size_t output_stride,
pthreadpool_t threadpool);
enum qnnp_status qnnp_create_max_pooling2d_nhwc_u8(
uint32_t input_padding_top,
uint32_t input_padding_right,
uint32_t input_padding_bottom,
uint32_t input_padding_left,
uint32_t pooling_height,
uint32_t pooling_width,
uint32_t stride_height,
uint32_t stride_width,
uint32_t dilation_height,
uint32_t dilation_width,
size_t channels,
uint8_t output_min,
uint8_t output_max,
uint32_t flags,
qnnp_operator_t* max_pooling);
enum qnnp_status qnnp_setup_max_pooling2d_nhwc_u8(
qnnp_operator_t max_pooling,
size_t batch_size,
size_t input_height,
size_t input_width,
const uint8_t* input,
size_t input_stride,
uint8_t* output,
size_t output_stride,
pthreadpool_t threadpool);
enum qnnp_status qnnp_create_channel_shuffle_nc_x8(
size_t groups,
size_t group_channels,
uint32_t flags,
qnnp_operator_t* channel_shuffle);
enum qnnp_status qnnp_setup_channel_shuffle_nc_x8(
qnnp_operator_t channel_shuffle,
size_t batch_size,
const uint8_t* input,
size_t input_stride,
uint8_t* output,
size_t output_stride);
enum qnnp_status qnnp_create_add_nc_q8(
size_t channels,
uint8_t a_zero_point,
float a_scale,
uint8_t b_zero_point,
float b_scale,
uint8_t sum_zero_point,
float sum_scale,
uint8_t sum_min,
uint8_t sum_max,
uint32_t flags,
qnnp_operator_t* add);
enum qnnp_status qnnp_setup_add_nc_q8(
qnnp_operator_t add,
size_t batch_size,
const uint8_t* a,
size_t a_stride,
const uint8_t* b,
size_t b_stride,
uint8_t* sum,
size_t sum_stride);
enum qnnp_status qnnp_create_clamp_nc_u8(
size_t channels,
uint8_t output_min,
uint8_t output_max,
uint32_t flags,
qnnp_operator_t* clamp);
enum qnnp_status qnnp_setup_clamp_nc_u8(
qnnp_operator_t clamp,
size_t batch_size,
const uint8_t* input,
size_t input_stride,
uint8_t* output,
size_t output_stride);
enum qnnp_status qnnp_create_sigmoid_nc_q8(
size_t channels,
uint8_t input_zero_point,
float input_scale,
uint8_t output_zero_point,
float output_scale,
uint8_t output_min,
uint8_t output_max,
uint32_t flags,
qnnp_operator_t* sigmoid);
enum qnnp_status qnnp_setup_sigmoid_nc_q8(
qnnp_operator_t sigmoid,
size_t batch_size,
const uint8_t* input,
size_t input_stride,
uint8_t* output,
size_t output_stride);
enum qnnp_status qnnp_create_leaky_relu_nc_q8(
size_t channels,
float negative_slope,
uint8_t input_zero_point,
float input_scale,
uint8_t output_zero_point,
float output_scale,
uint8_t output_min,
uint8_t output_max,
uint32_t flags,
qnnp_operator_t* leaky_relu);
enum qnnp_status qnnp_setup_leaky_relu_nc_q8(
qnnp_operator_t leaky_relu,
size_t batch_size,
const uint8_t* input,
size_t input_stride,
uint8_t* output,
size_t output_stride);
enum qnnp_status qnnp_create_softargmax_nc_q8(
size_t channels,
float input_scale,
uint8_t output_zero_point,
float output_scale,
uint32_t flags,
qnnp_operator_t* softargmax);
enum qnnp_status qnnp_setup_softargmax_nc_q8(
qnnp_operator_t softargmax,
size_t batch_size,
const uint8_t* input,
size_t input_stride,
uint8_t* output,
size_t output_stride);
enum qnnp_status qnnp_run_operator(
qnnp_operator_t op,
pthreadpool_t threadpool);
enum qnnp_status qnnp_delete_operator(
qnnp_operator_t op);
#ifdef __cplusplus
} /* extern "C" */
#endif