17#ifndef ONERT_MICRO_EXECUTE_UTILS_H
18#define ONERT_MICRO_EXECUTE_UTILS_H
34void readQuantParams(
const circle::Tensor *tensor,
long &zero_point,
float &scale);
41 case circle::ActivationFunctionType::ActivationFunctionType_NONE:
42 *activation_min = std::numeric_limits<T>::lowest();
43 *activation_max = std::numeric_limits<T>::max();
45 case circle::ActivationFunctionType::ActivationFunctionType_RELU:
47 *activation_max = std::numeric_limits<T>::max();
49 case circle::ActivationFunctionType::ActivationFunctionType_RELU_N1_TO_1:
53 case circle::ActivationFunctionType::ActivationFunctionType_RELU6:
58 assert(
false &&
"Unsupported activation.");
68 const double input_product_scale =
static_cast<double>(input_scale * filter_scale);
70 assert(input_product_scale >= 0);
72 assert(output_scale != 0.f);
74 return input_product_scale /
static_cast<double>(output_scale);
84void quantizeMultiplier(
double double_multiplier, int32_t *quantized_multiplier,
int *shift);
94inline std::vector<double>
98 std::vector<double> effective_output_scales;
99 size_t n = filter_scale->
size();
100 effective_output_scales.reserve(n);
101 for (
size_t i = 0; i < n; ++i)
103 effective_output_scales.push_back(
106 return effective_output_scales;
110 int32_t output_zero_point,
float output_scale,
111 circle::TensorType data_type, int32_t *activation_min,
112 int32_t *activation_max);
114inline int computeOutSize(circle::Padding padding,
int image_size,
int filter_size,
int stride,
115 int dilation_rate = 1)
117 int effective_filter_size = (filter_size - 1) * dilation_rate + 1;
124 case circle::Padding_SAME:
125 return (image_size + stride - 1) / stride;
126 case circle::Padding_VALID:
127 return (image_size + stride - effective_filter_size) / stride;
134 int32_t filter_size, int32_t out_size)
136 int32_t effective_filter_size = (filter_size - 1) * dilation_rate + 1;
137 int32_t padding = ((out_size - 1) * stride + effective_filter_size - in_size) / 2;
138 return padding > 0 ? padding : 0;
142 int32_t dilation_rate_height, int32_t dilation_rate_width,
143 int32_t in_height, int32_t in_width, int32_t filter_height,
144 int32_t filter_width, circle::Padding padding,
145 int32_t *padding_h, int32_t *padding_w)
149 computeOutSize(padding, in_width, filter_width, stride_width, dilation_rate_width);
151 computeOutSize(padding, in_height, filter_height, stride_height, dilation_rate_height);
154 computePadding(stride_height, dilation_rate_height, in_height, filter_height, out_height);
156 *padding_w =
computePadding(stride_width, dilation_rate_width, in_width, filter_width, out_width);
160 const circle::Tensor *input2,
const circle::Tensor *output,
161 circle::ActivationFunctionType act);
164 const circle::Tensor **output, uint8_t **input_data, uint8_t **output_data);
167 const circle::Tensor **input2,
const circle::Tensor **output,
168 OMRuntimeKernel *runtime_kernel);
172 const double max_input_rescaled = 1.0 * ((1 << input_integer_bits) - 1) *
173 (1LL << (total_signed_bits - input_integer_bits)) /
174 (1LL << input_left_shift);
178 return static_cast<int>(std::floor(max_input_rescaled));
void quantizeMultiplier(double double_multiplier, int32_t *quantized_multiplier, int *shift)
double getQuantizedConvolutionMultipler(float input_scale, float filter_scale, float output_scale)
int computeOutSize(circle::Padding padding, int image_size, int filter_size, int stride, int dilation_rate=1)
OMStatus SISOHeader(const OMExecuteArgs &execute_args, const circle::Tensor **input, const circle::Tensor **output, uint8_t **input_data, uint8_t **output_data)
std::vector< double > getQuantizedConvolutionMultiplers(float input_scale, const flatbuffers::Vector< float > *filter_scale, float output_scale)
void readQuantParams(const circle::Tensor *tensor, long &zero_point, float &scale)
OMStatus calculateActivationRangeQuantized(circle::ActivationFunctionType activation, int32_t output_zero_point, float output_scale, circle::TensorType data_type, int32_t *activation_min, int32_t *activation_max)
void calculateQuantParams(core::ArithmeticQuantParams ¶ms, const circle::Tensor *input1, const circle::Tensor *input2, const circle::Tensor *output, circle::ActivationFunctionType act)
void quantizeMultiplierSmallerThanOneExp(double double_multiplier, int32_t *quantized_multiplier, int *left_shift)
OMStatus calculateActivationRange(circle::ActivationFunctionType activation, T *activation_min, T *activation_max)
OMStatus TISOHeader(const OMExecuteArgs &execute_args, const circle::Tensor **input1, const circle::Tensor **input2, const circle::Tensor **output, OMRuntimeKernel *runtime_kernel)
int calculateInputRadius(int input_integer_bits, int input_left_shift, int total_signed_bits)
int computePadding(int32_t stride, int32_t dilation_rate, int32_t in_size, int32_t filter_size, int32_t out_size)
void computePaddingHeightWidth(int32_t stride_height, int32_t stride_width, int32_t dilation_rate_height, int32_t dilation_rate_width, int32_t in_height, int32_t in_width, int32_t filter_height, int32_t filter_width, circle::Padding padding, int32_t *padding_h, int32_t *padding_w)