ONE - On-device Neural Engine
Loading...
Searching...
No Matches
PALMaxPool2D.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_MAX_POOL_2D_H
19#define LUCI_INTERPRETER_PAL_CMSIS_NN_MAX_POOL_2D_H
20
21#include "PALMaxPool2DCommon.h"
22
23#include <arm_nnfunctions.h>
24
26{
27
28inline void MaxPool(const PoolParams &params, const luci_interpreter::RuntimeShape &input_shape,
29 const uint8_t *input_data, const luci_interpreter::RuntimeShape &output_shape,
30 uint8_t *output_data, luci_interpreter::DataType data_type)
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 if (data_type == luci_interpreter::DataType::S8)
64 {
65 arm_max_pool_s8(&ctx, &pool_params, &input_dims,
66 luci_interpreter::kernels::getTensorData<int8_t>(input_data), &filter_dims,
67 &output_dims, luci_interpreter::kernels::getTensorData<int8_t>(output_data));
68 }
69 else
70 {
71 arm_max_pool_s16(&ctx, &pool_params, &input_dims,
72 luci_interpreter::kernels::getTensorData<int16_t>(input_data), &filter_dims,
73 &output_dims, luci_interpreter::kernels::getTensorData<int16_t>(output_data));
74 }
75}
76} // namespace luci_interpreter_pal
77
78#endif // LUCI_INTERPRETER_PAL_CMSIS_NN_MAX_POOL_2D_H
int32_t dims(int i) const
Definition Tensor.h:108
const luci_interpreter::RuntimeShape output_shape
void MaxPool(const PoolParams &params, const luci_interpreter::RuntimeShape &input_shape, const uint8_t *input_data, const luci_interpreter::RuntimeShape &output_shape, uint8_t *output_data, luci_interpreter::DataType data_type)
DataType
"scalar" value type
Definition DataType.h:32