Subversion Repositories dashGPS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/*
2
 * Copyright (C) 2010-2018 Arm Limited or its affiliates. All rights reserved.
3
 *
4
 * SPDX-License-Identifier: Apache-2.0
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the License); you may
7
 * not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
 
19
#ifndef _REF_FUNCTIONS_H_
20
#define _REF_FUNCTIONS_H_
21
 
22
#include "arm_math.h"
23
#include "arm_nnfunctions.h"
24
//#include "arm_nnsupportfunctions.h"
25
#include "fully_connected_testing_weights.h"
26
 
27
#ifdef __cplusplus
28
extern    "C"
29
{
30
#endif
31
 
32
/*
33
 *
34
 * Convolution reference implemenation
35
 *
36
 */
37
 
38
    void      arm_convolve_HWC_q7_ref(const q7_t * Im_in,   // input image
39
                                      const uint16_t dim_im_in, // input image dimention
40
                                      const uint16_t ch_im_in,  // number of input image channels
41
                                      const q7_t * wt,  // kernel weights 
42
                                      const uint16_t ch_im_out, // number of filters, i.e., output image channels
43
                                      const uint16_t dim_kernel,    // filter kernel size
44
                                      const uint16_t padding,   // padding sizes
45
                                      const uint16_t stride,    // stride
46
                                      const q7_t * bias,    // bias
47
                                      const uint16_t bias_shift, const uint16_t out_shift, q7_t * Im_out,   // output image
48
                                      const uint16_t dim_im_out,    // output image dimension
49
                                      q15_t * bufferA,  //buffer space for input
50
                                      q7_t * bufferB    //buffer space for output
51
        );
52
 
53
    void      arm_convolve_HWC_q7_ref_nonsquare(const q7_t * Im_in, // input image
54
                                                const uint16_t dim_im_in_x, // input image dimention x
55
                                                const uint16_t dim_im_in_y, // input image dimention y
56
                                                const uint16_t ch_im_in,    // number of input image channels
57
                                                const q7_t * wt,    // kernel weights 
58
                                                const uint16_t ch_im_out,   // number of filters, i.e., output image channels
59
                                                const uint16_t dim_kernel_x,    // filter kernel size x
60
                                                const uint16_t dim_kernel_y,    // filter kernel size y
61
                                                const uint16_t padding_x,   // padding sizes x
62
                                                const uint16_t padding_y,   // padding sizes y
63
                                                const uint16_t stride_x,    // stride x
64
                                                const uint16_t stride_y,    // stride y
65
                                                const q7_t * bias,  // bias
66
                                                const uint16_t bias_shift, const uint16_t out_shift, q7_t * Im_out, // output image
67
                                                const uint16_t dim_im_out_x,    // output image dimension x
68
                                                const uint16_t dim_im_out_y,    // output image dimension y
69
                                                q15_t * bufferA,    //buffer space for input
70
                                                q7_t * bufferB  //buffer space for output
71
        );
72
 
73
    void      arm_convolve_HWC_q15_ref(const q15_t * Im_in, // input image
74
                                       const uint16_t dim_im_in,    // input image dimention
75
                                       const uint16_t ch_im_in, // number of input image channels
76
                                       const q15_t * wt,    // kernel weights 
77
                                       const uint16_t ch_im_out,    // number of filters, i.e., output image channels
78
                                       const uint16_t dim_kernel,   // filter kernel size
79
                                       const uint16_t padding,  // padding sizes
80
                                       const uint16_t stride,   // stride
81
                                       const q15_t * bias,  // bias
82
                                       const uint16_t bias_shift, const uint16_t out_shift, q15_t * Im_out, // output image
83
                                       const uint16_t dim_im_out,   // output image dimension
84
                                       q15_t * bufferA, //buffer space for input
85
                                       q7_t * bufferB   //buffer space for output
86
        );
87
    void      arm_convolve_HWC_q15_nonsquare_ref(const q15_t * Im_in,
88
                                                      const uint16_t dim_im_in_x,
89
                                                      const uint16_t dim_im_in_y,
90
                                                      const uint16_t ch_im_in,
91
                                                      const q15_t * wt,
92
                                                      const uint16_t ch_im_out,
93
                                                      const uint16_t dim_kernel_x,
94
                                                      const uint16_t dim_kernel_y,
95
                                                      const uint16_t padding_x,
96
                                                      const uint16_t padding_y,
97
                                                      const uint16_t stride_x,
98
                                                      const uint16_t stride_y,
99
                                                      const q15_t * bias,
100
                                                      const uint16_t bias_shift,
101
                                                      const uint16_t out_shift,
102
                                                      q15_t * Im_out,
103
                                                      const uint16_t dim_im_out_x,
104
                                                      const uint16_t dim_im_out_y,
105
                                                      q15_t * bufferA,
106
                                                      q7_t * bufferB);
107
 
108
    void      arm_depthwise_separable_conv_HWC_q7_ref(const q7_t * Im_in,   // input image
109
                                                      const uint16_t dim_im_in, // input image dimention
110
                                                      const uint16_t ch_im_in,  // number of input image channels
111
                                                      const q7_t * wt,  // kernel weights 
112
                                                      const uint16_t ch_im_out, // number of filters, i.e., output image channels
113
                                                      const uint16_t dim_kernel,    // filter kernel size
114
                                                      const uint16_t padding,   // padding sizes
115
                                                      const uint16_t stride,    // stride
116
                                                      const q7_t * bias,    // bias
117
                                                      const uint16_t bias_shift,    // amount of left-shift for bias
118
                                                      const uint16_t out_shift, // amount of right-shift for output
119
                                                      q7_t * Im_out,    // output image
120
                                                      const uint16_t dim_im_out,    // output image dimension
121
                                                      q15_t * bufferA,  //buffer space for input
122
                                                      q7_t * bufferB    //buffer space for output
123
        );
124
    void      arm_depthwise_separable_conv_HWC_q7_ref_nonsquare(const q7_t * Im_in, // input image
125
                                                                const uint16_t dim_im_in_x, // input image dimention x
126
                                                                const uint16_t dim_im_in_y, // input image dimention y
127
                                                                const uint16_t ch_im_in,    // number of input image channels
128
                                                                const q7_t * wt,    // kernel weights 
129
                                                                const uint16_t ch_im_out,   // number of filters, i.e., output image channels
130
                                                                const uint16_t dim_kernel_x,    // filter kernel size x
131
                                                                const uint16_t dim_kernel_y,    // filter kernel size y
132
                                                                const uint16_t padding_x,   // padding sizes x
133
                                                                const uint16_t padding_y,   // padding sizes y
134
                                                                const uint16_t stride_x,    // stride x
135
                                                                const uint16_t stride_y,    // stride y
136
                                                                const q7_t * bias,  // bias
137
                                                                const uint16_t bias_shift,  // amount of left-shift for bias
138
                                                                const uint16_t out_shift,   // amount of right-shift for output
139
                                                                q7_t * Im_out,  // output image
140
                                                                const uint16_t dim_im_out_x,    // output image dimension x
141
                                                                const uint16_t dim_im_out_y,    // output image dimension y
142
                                                                q15_t * bufferA,    //buffer space for input
143
                                                                q7_t * bufferB  //buffer space for output
144
        );
145
 
146
/*
147
 *
148
 * Fully-connected reference implemenation
149
 *
150
 */
151
 
152
    void      arm_fully_connected_q7_ref(const q7_t * pV,   // pointer to vector
153
                                         const q7_t * pM,   // pointer to matrix
154
                                         const uint16_t dim_vec,    // length of the vector
155
                                         const uint16_t num_of_rows,    // numCol of A
156
                                         const uint16_t bias_shift, // amount of left-shift for bias
157
                                         const uint16_t out_shift,  // amount of right-shift for output
158
                                         const q7_t * bias, q7_t * pOut,    // output operand
159
                                         q15_t * vec_buffer);
160
 
161
    void      arm_fully_connected_q15_ref(const q15_t * pV, // pointer to vector
162
                                          const q15_t * pM, // pointer to matrix
163
                                          const uint16_t dim_vec,   // length of the vector
164
                                          const uint16_t num_of_rows,   // numCol of A
165
                                          const uint16_t bias_shift,    // amount of left-shift for bias
166
                                          const uint16_t out_shift, // amount of right-shift for output
167
                                          const q15_t * bias, q15_t * pOut, // output operand
168
                                          q15_t * vec_buffer);
169
 
170
    void      arm_fully_connected_mat_q7_vec_q15_ref(const q15_t * pV,  // pointer to vector
171
                                                     const q7_t * pM,   // pointer to matrix
172
                                                     const uint16_t dim_vec,    // length of the vector
173
                                                     const uint16_t num_of_rows,    // numCol of A
174
                                                     const uint16_t bias_shift, // amount of left-shift for bias
175
                                                     const uint16_t out_shift,  // amount of right-shift for output
176
                                                     const q7_t * bias, q15_t * pOut,   // output operand
177
                                                     q15_t * vec_buffer);
178
 
179
    void      arm_fully_connected_q7_opt_ref(const q7_t * pV,   // pointer to vector
180
                                             const q7_t * pM,   // pointer to matrix
181
                                             const uint16_t dim_vec,    // length of the vector
182
                                             const uint16_t num_of_rows,    // numCol of A
183
                                             const uint16_t bias_shift, // amount of left-shift for bias
184
                                             const uint16_t out_shift,  // amount of right-shift for output
185
                                             const q7_t * bias, q7_t * pOut,    // output operand
186
                                             q15_t * vec_buffer);
187
 
188
    void      arm_fully_connected_q15_opt_ref(const q15_t * pV, // pointer to vector
189
                                              const q15_t * pM, // pointer to matrix
190
                                              const uint16_t dim_vec,   // length of the vector
191
                                              const uint16_t num_of_rows,   // numCol of A
192
                                              const uint16_t bias_shift,    // amount of left-shift for bias
193
                                              const uint16_t out_shift, // amount of right-shift for output
194
                                              const q15_t * bias, q15_t * pOut, // output operand
195
                                              q15_t * vec_buffer);
196
 
197
    void      arm_fully_connected_mat_q7_vec_q15_opt_ref(const q15_t * pV,  // pointer to vector
198
                                                         const q7_t * pM,   // pointer to matrix
199
                                                         const uint16_t dim_vec,    // length of the vector
200
                                                         const uint16_t num_of_rows,    // numCol of A
201
                                                         const uint16_t bias_shift, // amount of left-shift for bias
202
                                                         const uint16_t out_shift,  // amount of right-shift for output
203
                                                         const q7_t * bias, q15_t * pOut,   // output operand
204
                                                         q15_t * vec_buffer);
205
 
206
/*
207
 *
208
 * Pooling reference implemenation
209
 *
210
 */
211
 
212
    void      arm_avepool_q7_HWC_ref(const q7_t * Im_in,    // input image
213
                                     const uint16_t dim_im_in,  // input image dimension
214
                                     const uint16_t ch_im_in,   // number of input image channels
215
                                     const uint16_t dim_kernel, // window kernel size
216
                                     const uint16_t padding,    // padding sizes
217
                                     const uint16_t stride, // stride
218
                                     const uint16_t dim_im_out, // output image dimension
219
                                     q7_t * bufferA,    // a buffer for local storage
220
                                     q7_t * Im_out);
221
 
222
    void      arm_maxpool_q7_HWC_ref(const q7_t * Im_in,    // input image
223
                                     const uint16_t dim_im_in,  // input image dimension
224
                                     const uint16_t ch_im_in,   // number of input image channels
225
                                     const uint16_t dim_kernel, // window kernel size
226
                                     const uint16_t padding,    // padding sizes
227
                                     const uint16_t stride, // stride
228
                                     const uint16_t dim_im_out, // output image dimension
229
                                     q7_t * bufferA,    // a buffer for local storage
230
                                     q7_t * Im_out);
231
 
232
/*
233
 *
234
 * Other reference implemenation
235
 *
236
 */
237
 
238
    void      arm_relu_q7_ref(q7_t * data, uint16_t size);
239
 
240
    void      arm_relu_q15_ref(q15_t * data, uint16_t size);
241
 
242
    void      arm_nn_mult_q7_ref(q7_t * pSrcA, q7_t * pSrcB, q7_t * pDst, const uint16_t out_shift, uint32_t blockSize);
243
 
244
    void      arm_nn_mult_q15_ref(q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, const uint16_t out_shift, uint32_t blockSize);
245
 
246
#ifdef __cplusplus
247
}
248
#endif
249
 
250
#endif