19#include "kernels/Utils.h"
21#include "PALAveragePool2d.h"
39 if (
input()->element_type() !=
output()->element_type())
41 throw std::runtime_error(
"Input Tensor and Output Tensor Type must be same");
43 if (
input()->shape().num_dims() != 4)
45 throw std::runtime_error(
"Input Tensor Shape must be 4-D");
49 const int32_t batches = input_shape.
dim(0);
50 const int32_t input_height = input_shape.
dim(1);
51 const int32_t input_width = input_shape.
dim(2);
52 const int32_t depth = input_shape.
dim(3);
54 const int32_t output_height =
56 const int32_t output_width =
63 if (
input()->element_type() == DataType::U8)
68 else if (
input()->element_type() == DataType::S16)
73 else if (
input()->element_type() == DataType::S8)
78 output()->
resize({batches, output_height, output_width, depth});
81 luci_interpreter_pal::SetupScratchpadTensor(scratchpad,
input()->element_type(),
87 switch (
input()->element_type())
89 case DataType::FLOAT32:
102 throw std::runtime_error(
"luci-intp AveragePool2D Unsupported type.");
106void AveragePool2D::evalFloat()
const
108 float activation_min{};
109 float activation_max{};
112 tflite::PoolParams
params{};
113 params.padding_values.height = _padding_height;
114 params.padding_values.width = _padding_width;
119 params.float_activation_min = activation_min;
120 params.float_activation_max = activation_max;
126void AveragePool2D::evalQuantized()
const
128 int32_t activation_min{};
129 int32_t activation_max{};
132 tflite::PoolParams
params{};
133 params.padding_values.height = _padding_height;
134 params.padding_values.width = _padding_width;
139 params.quantized_activation_min = activation_min;
140 params.quantized_activation_max = activation_max;
144 getTensorData<uint8_t>(
output()));
147void AveragePool2D::evalSInt8()
const
149 int32_t activation_min{};
150 int32_t activation_max{};
152 tflite::PoolParams
params{};
153 params.padding_values.height = _padding_height;
154 params.padding_values.width = _padding_width;
159 params.quantized_activation_min = activation_min;
160 params.quantized_activation_max = activation_max;
163 int8_t *scratchpad_data =
nullptr;
164 if (scratchpad->is_allocatable())
165 scratchpad_data = scratchpad->data<int8_t>();
172void AveragePool2D::evalSInt16()
const
174 int32_t activation_min{};
175 int32_t activation_max{};
178 tflite::PoolParams
params{};
179 params.padding_values.height = _padding_height;
180 params.padding_values.width = _padding_width;
185 params.quantized_activation_min = activation_min;
186 params.quantized_activation_max = activation_max;
188 tflite::reference_integer_ops::AveragePool(
const std::vector< Tensor * > & getOutputTensors() const
const Pool2DParams _params
const Pool2DParams & params() const
void resize(const Shape &new_shape)
const Shape & shape() const
void configure() override
AveragePool2D(const Tensor *input, Tensor *output, Tensor *scratchpad, const Pool2DParams ¶ms)
void execute() const override
const Tensor * input() const
#define LUCI_INTERPRETER_CHECK(cond)
int32_t computePadding(int32_t stride, int32_t dilation_rate, int32_t in_size, int32_t filter_size, int32_t out_size)
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
void calculateActivationRange(Activation activation, T *activation_min, T *activation_max)
void calculateActivationRangeQuantized(Activation activation, const Tensor *output, int32_t *activation_min, int32_t *activation_max)
int32_t computeOutputSize(Padding padding, int32_t image_size, int32_t filter_size, int32_t stride, int32_t dilation_rate=1)
void AveragePool< int8_t >(const tflite::PoolParams ¶ms, const tflite::RuntimeShape &input_shape, const int8_t *input_data, const tflite::RuntimeShape &output_shape, int8_t *output_data, const tflite::RuntimeShape &scratchpad_shape, int8_t *scratchpad_data)