2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "AvgPoolLayer.h"
19 #include <cker/operation/AveragePool.h>
30 #define AVGPOOLING_PARAMETERS \
31 nnfw::cker::PoolParams op_params; \
32 op_params.stride_height = _strideHeight; \
33 op_params.stride_width = _strideWidth; \
34 op_params.filter_height = _kernelHeight; \
35 op_params.filter_width = _kernelWidth; \
36 op_params.padding_values.height = (int8_t)_paddingTop; \
37 op_params.padding_values.width = (int8_t)_paddingLeft;
39 AvgPoolLayer::AvgPoolLayer()
40 : _input(nullptr), _output(nullptr), _paddingLeft(0), _paddingTop(0), _paddingRight(0),
41 _paddingBottom(0), _strideWidth(0), _strideHeight(0), _kernelWidth(0), _kernelHeight(0),
42 _activation(ir::Activation::NONE)
47 void AvgPoolLayer::averagePoolFloat32()
50 float output_activation_min, output_activation_max;
51 CalculateActivationRangeFloat(_activation, &output_activation_min, &output_activation_max);
52 op_params.float_activation_min = output_activation_min;
53 op_params.float_activation_max = output_activation_max;
55 nnfw::cker::AveragePool(op_params, convertTensorToCkerShape(_input),
56 reinterpret_cast<const float *>(_input->buffer()),
57 convertTensorToCkerShape(_output),
58 reinterpret_cast<float *>(_output->buffer()));
60 void AvgPoolLayer::averagePoolQuant8()
63 int32_t output_activation_min = 0;
64 int32_t output_activation_max = 0;
65 CalculateActivationRangeUint8(_activation, _output, &output_activation_min,
66 &output_activation_max);
67 op_params.quantized_activation_min = output_activation_min;
68 op_params.quantized_activation_max = output_activation_max;
70 nnfw::cker::AveragePool(op_params, convertTensorToCkerShape(_input),
71 reinterpret_cast<const uint8_t *>(_input->buffer()),
72 convertTensorToCkerShape(_output),
73 reinterpret_cast<uint8_t *>(_output->buffer()));
76 void AvgPoolLayer::configure(const operand::Tensor *input, const uint32_t paddingLeft,
77 const uint32_t paddingRight, const uint32_t paddingTop,
78 const uint32_t paddingBottom, const uint32_t strideWidth,
79 const uint32_t strideHeight, const uint32_t kernelWidth,
80 const uint32_t kernelHeight, const ir::Activation activation,
81 operand::Tensor *output)
83 assert(input != nullptr);
84 assert(output != nullptr);
87 _paddingLeft = paddingLeft;
88 _paddingRight = paddingRight;
89 _paddingTop = paddingTop;
90 _paddingBottom = paddingBottom;
91 _strideWidth = strideWidth;
92 _strideHeight = strideHeight;
93 _kernelWidth = kernelWidth;
94 _kernelHeight = kernelHeight;
95 _activation = activation;
99 void AvgPoolLayer::run()
101 if (_input->data_type() == OperandType::FLOAT32)
103 averagePoolFloat32();
105 else if (_input->data_type() == OperandType::QUANT8_ASYMM)
111 #undef AVGPOOLING_PARAMETERS
113 } // namespace kernel
115 } // namespace backend