18#include "kernels/Utils.h"
30void calculateArithmeticData(
const circle::Tensor *input,
const circle::Tensor *output,
31 int32_t &input_zero_point, int32_t &input_range_radius,
32 int32_t &input_multiplier,
int &input_left_shift)
34 const auto input_dtype = Tensor::element_type(input);
41 static constexpr int input_integer_bits = 4;
42 const double input_real_multiplier =
static_cast<double>(Tensor::scale(input)) *
43 static_cast<double>(1 << (31 - input_integer_bits));
45 const double q = std::frexp(input_real_multiplier, &input_left_shift);
46 input_multiplier =
static_cast<int32_t
>(std::round(q * (1ll << 31)));
53 static constexpr int input_integer_bits = 3;
54 static constexpr int output_fractional_bits = 15;
65 int input_scale_log2_rounded;
68 input_left_shift = (15 - input_integer_bits) + input_scale_log2_rounded;
69 param_scale_pot &= (input_left_shift == 0 || input_left_shift == 1);
83 double multiplier =
static_cast<double>(Tensor::scale(input)) * 4096.0 * 3.0;
86 while (multiplier <= 32767.0 / 2.0 && input_left_shift <= 30)
89 multiplier = multiplier * 2.0;
92 input_multiplier =
static_cast<int32_t
>(multiplier);
95 int output_scale_log2_rounded;
97 assert(output_scale_log2_rounded == -output_fractional_bits);
101 assert(
false &&
"Unsupported type");
107void evalInteger(
const circle::Tensor *input,
const circle::Tensor *output,
110 int32_t input_zero_point = 0;
111 int32_t input_range_radius = 0;
112 int32_t input_multiplier = 0;
113 int input_left_shift = 0;
115 calculateArithmeticData(input, output, input_zero_point, input_range_radius, input_multiplier,
126 const auto input_dtype = Tensor::element_type(input);
133 input_zero_point, input_range_radius, input_multiplier, input_left_shift,
134 flat_size, kernels::getTensorData<int8_t>(input_data), kernels::getTensorData<int8_t>(output_data));
139 kernels::getTensorData<int16_t>(input_data),
140 kernels::getTensorData<int16_t>(output_data));
143 assert(
false &&
"Not support yet");
153 Tensor::element_type(kernel.
output()));
167 switch (Tensor::element_type(kernel.
input()))
170 case DataType::FLOAT32:
172 const float *input_data_float = kernels::getTensorData<float>(input_data);
173 float *output_data_float = kernels::getTensorData<float>(output_data);
176 output_data_float =
const_cast<float *
>(input_data_float);
179 assert(output_data_float);
181 const int flat_size =
198 assert(
false &&
"Unsupported type");
void makeInplaceOperation(const circle::Tensor *src_tensor, const circle::Tensor *dst_tensor)
bool is_inplace_op(const circle::Operator *op)
uint8_t * getDataByTensor(const circle::Tensor *raw_tensor)
const circle::Tensor * output() const
const circle::Tensor * input() const
#define LUCI_INTERPRETER_CHECK(cond)
bool checkedLog2(const float x, int *log2_result)
int calculateInputRadius(int input_integer_bits, int input_left_shift, int total_signed_bits)
luci_interpreter::RuntimeShape getTensorRuntimeShape(const circle::Tensor *circle_tensor, BaseRuntimeGraph *runtime_graph)
void Tanh(const int flat_size, const float *input_data, float *output_data)
void evalInteger(const circle::Tensor *input, const circle::Tensor *output, BaseRuntimeGraph *runtime_graph)
void execute_kernel_CircleTanh(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
void configure_kernel_CircleTanh(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)