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 | #include "ref_functions.h" |
||
20 | |||
21 | void arm_avepool_q7_HWC_ref(const q7_t * Im_in, // input image |
||
22 | const uint16_t dim_im_in, // input image dimension |
||
23 | const uint16_t ch_im_in, // number of input image channels |
||
24 | const uint16_t dim_kernel, // window kernel size |
||
25 | const uint16_t padding, // padding sizes |
||
26 | const uint16_t stride, // stride |
||
27 | const uint16_t dim_im_out, // output image dimension |
||
28 | q7_t * bufferA, // a buffer for local storage |
||
29 | q7_t * Im_out) |
||
30 | { |
||
31 | int16_t i_ch_in, i_x, i_y; |
||
32 | int16_t k_x, k_y; |
||
33 | |||
34 | for (i_ch_in = 0; i_ch_in < ch_im_in; i_ch_in++) |
||
35 | { |
||
36 | for (i_y = 0; i_y < dim_im_out; i_y++) |
||
37 | { |
||
38 | for (i_x = 0; i_x < dim_im_out; i_x++) |
||
39 | { |
||
40 | int sum = 0; |
||
41 | int count = 0; |
||
42 | for (k_y = i_y * stride - padding; k_y < i_y * stride - padding + dim_kernel; k_y++) |
||
43 | { |
||
44 | for (k_x = i_x * stride - padding; k_x < i_x * stride - padding + dim_kernel; k_x++) |
||
45 | { |
||
46 | if (k_y >= 0 && k_x >= 0 && k_y < dim_im_in && k_x < dim_im_in) |
||
47 | { |
||
48 | sum += Im_in[i_ch_in + ch_im_in * (k_x + k_y * dim_im_in)]; |
||
49 | count++; |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 | Im_out[i_ch_in + ch_im_in * (i_x + i_y * dim_im_out)] = sum / count; |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 | |||
59 | void arm_maxpool_q7_HWC_ref(const q7_t * Im_in, // input image |
||
60 | const uint16_t dim_im_in, // input image dimension |
||
61 | const uint16_t ch_im_in, // number of input image channels |
||
62 | const uint16_t dim_kernel, // window kernel size |
||
63 | const uint16_t padding, // padding sizes |
||
64 | const uint16_t stride, // stride |
||
65 | const uint16_t dim_im_out, // output image dimension |
||
66 | q7_t * bufferA, // a buffer for local storage |
||
67 | q7_t * Im_out) |
||
68 | { |
||
69 | int16_t i_ch_in, i_x, i_y; |
||
70 | int16_t k_x, k_y; |
||
71 | |||
72 | for (i_ch_in = 0; i_ch_in < ch_im_in; i_ch_in++) |
||
73 | { |
||
74 | for (i_y = 0; i_y < dim_im_out; i_y++) |
||
75 | { |
||
76 | for (i_x = 0; i_x < dim_im_out; i_x++) |
||
77 | { |
||
78 | int max = -129; |
||
79 | for (k_y = i_y * stride - padding; k_y < i_y * stride - padding + dim_kernel; k_y++) |
||
80 | { |
||
81 | for (k_x = i_x * stride - padding; k_x < i_x * stride - padding + dim_kernel; k_x++) |
||
82 | { |
||
83 | if (k_y >= 0 && k_x >= 0 && k_y < dim_im_in && k_x < dim_im_in) |
||
84 | { |
||
85 | if (Im_in[i_ch_in + ch_im_in * (k_x + k_y * dim_im_in)] > max) |
||
86 | { |
||
87 | max = Im_in[i_ch_in + ch_im_in * (k_x + k_y * dim_im_in)]; |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 | } |
||
92 | Im_out[i_ch_in + ch_im_in * (i_x + i_y * dim_im_out)] = max; |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | } |