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 #include "ref_functions.h"
20
21 void
arm_convolve_HWC_q15_nonsquare_ref(const q15_t * Im_in,const uint16_t dim_im_in_x,const uint16_t dim_im_in_y,const uint16_t ch_im_in,const q15_t * wt,const uint16_t ch_im_out,const uint16_t dim_kernel_x,const uint16_t dim_kernel_y,const uint16_t padding_x,const uint16_t padding_y,const uint16_t stride_x,const uint16_t stride_y,const q15_t * bias,const uint16_t bias_shift,const uint16_t out_shift,q15_t * Im_out,const uint16_t dim_im_out_x,const uint16_t dim_im_out_y,q15_t * bufferA,q7_t * bufferB)22 arm_convolve_HWC_q15_nonsquare_ref(const q15_t * Im_in,
23 const uint16_t dim_im_in_x,
24 const uint16_t dim_im_in_y,
25 const uint16_t ch_im_in,
26 const q15_t * wt,
27 const uint16_t ch_im_out,
28 const uint16_t dim_kernel_x,
29 const uint16_t dim_kernel_y,
30 const uint16_t padding_x,
31 const uint16_t padding_y,
32 const uint16_t stride_x,
33 const uint16_t stride_y,
34 const q15_t * bias,
35 const uint16_t bias_shift,
36 const uint16_t out_shift,
37 q15_t * Im_out,
38 const uint16_t dim_im_out_x,
39 const uint16_t dim_im_out_y,
40 q15_t * bufferA,
41 q7_t * bufferB)
42
43 {
44 uint16_t i, j, k, l, m, n;
45 int conv_out;
46 signed char in_row, in_col;
47
48 for (i = 0; i < ch_im_out; i++)
49 {
50 for (j = 0; j < dim_im_out_y; j++)
51 {
52 for (k = 0; k < dim_im_out_x; k++)
53 {
54 #ifndef ARM_NN_TRUNCATE
55 conv_out = (bias[i] << bias_shift) + (0x1 << (out_shift - 1));
56 #else
57 conv_out = bias[i] << bias_shift;
58 #endif
59 for (m = 0; m < dim_kernel_y; m++)
60 {
61 for (n = 0; n < dim_kernel_x; n++)
62 {
63 in_row = stride_y * j + m - padding_y;
64 in_col = stride_x * k + n - padding_x;
65 if (in_row >= 0 && in_col >= 0 && in_row < dim_im_in_y && in_col < dim_im_in_x)
66 {
67 for (l = 0; l < ch_im_in; l++)
68 {
69 conv_out +=
70 Im_in[(in_row * dim_im_in_x + in_col) * ch_im_in +
71 l] * wt[i * ch_im_in * dim_kernel_x * dim_kernel_y + (m * dim_kernel_x +
72 n) * ch_im_in + l];
73 }
74 }
75 }
76 }
77 Im_out[i + (j * dim_im_out_x + k) * ch_im_out] = (q15_t) __SSAT((conv_out >> out_shift), 16);
78 }
79 }
80 }
81 }
82
83
84