ONE - On-device Neural Engine
Loading...
Searching...
No Matches
PALAveragePool2D.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2020 The TensorFlow Authors. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef LUCI_INTERPRETER_PAL_CMSIS_NN_AVERAGE_POOL_2D_H
19#define LUCI_INTERPRETER_PAL_CMSIS_NN_AVERAGE_POOL_2D_H
20
21#include "PALAveragePool2DCommon.h"
22
23#include <arm_nnfunctions.h>
24
26{
27inline void AveragePool(const PoolParams &params, const luci_interpreter::RuntimeShape &input_shape,
28 const uint8_t *input_data,
29 const luci_interpreter::RuntimeShape &output_shape, uint8_t *output_data,
31{
32 cmsis_nn_dims input_dims;
33 cmsis_nn_dims output_dims;
34 cmsis_nn_pool_params pool_params;
35 cmsis_nn_dims filter_dims;
36 cmsis_nn_context ctx;
37
38 const int depth = input_shape.dims(3);
39 const int output_width = output_shape.dims(2);
40
41 input_dims.n = 1;
42 input_dims.h = input_shape.dims(1);
43 input_dims.w = input_shape.dims(2);
44 input_dims.c = depth;
45
46 output_dims.n = 1;
47 output_dims.h = output_shape.dims(1);
48 output_dims.w = output_width;
49 output_dims.c = depth;
50
51 pool_params.stride.h = params.stride_height;
52 pool_params.stride.w = params.stride_width;
53 pool_params.padding.h = params.padding_values.height;
54 pool_params.padding.w = params.padding_values.width;
55 pool_params.activation.min = params.quantized_activation_min;
56 pool_params.activation.max = params.quantized_activation_max;
57
58 filter_dims.n = 1;
59 filter_dims.h = params.filter_height;
60 filter_dims.w = params.filter_width;
61 filter_dims.c = 1;
62
63 const int32_t buffer_size = data_type == luci_interpreter::DataType::S16
64 ? arm_avgpool_s16_get_buffer_size(output_width, depth)
65 : arm_avgpool_s8_get_buffer_size(output_width, depth);
66 int8_t *buffer = nullptr;
67 if (buffer_size > 0)
68 {
69 buffer = new int8_t[buffer_size];
70 }
71
72 ctx.buf = buffer;
73 ctx.size = buffer_size;
74
75 if (data_type == luci_interpreter::DataType::S8)
76 {
77 arm_avgpool_s8(&ctx, &pool_params, &input_dims,
78 luci_interpreter::kernels::getTensorData<int8_t>(input_data), &filter_dims,
79 &output_dims, luci_interpreter::kernels::getTensorData<int8_t>(output_data));
80 }
81 else
82 {
83 arm_avgpool_s16(&ctx, &pool_params, &input_dims,
84 luci_interpreter::kernels::getTensorData<int16_t>(input_data), &filter_dims,
85 &output_dims, luci_interpreter::kernels::getTensorData<int16_t>(output_data));
86 }
87
88 if (buffer_size > 0)
89 delete[] buffer;
90}
91} // namespace luci_interpreter_pal
92
93#endif // LUCI_INTERPRETER_PAL_CMSIS_NN_AVERAGE_POOL_2D_H
int32_t dims(int i) const
Definition Tensor.h:108
const luci_interpreter::RuntimeShape output_shape
DataType
"scalar" value type
Definition DataType.h:32