19#include "kernels/Utils.h"
23#include <tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h>
46 switch (
input1()->element_type())
48 case DataType::FLOAT32:
52 evalInteger<int64_t>();
55 evalInteger<int32_t>();
61 throw std::runtime_error(
"luci-intp Sub Unsupported type.");
65void Sub::evalFloat()
const
67 tflite::ArithmeticParams
params{};
70 const bool need_broadcast = tflite::reference_ops::ProcessBroadcastShapes(
75 tflite::reference_ops::BroadcastSubSlow(
87template <
typename T>
void Sub::evalInteger()
const
89 tflite::ArithmeticParams
params{};
92 const bool need_broadcast = tflite::reference_ops::ProcessBroadcastShapes(
97 tflite::reference_ops::BroadcastSubSlow(
109void Sub::evalQuantized()
const
111 const auto input1_scale =
static_cast<double>(
input1()->
scale());
112 const auto input2_scale =
static_cast<double>(
input2()->
scale());
113 const auto output_scale =
static_cast<double>(
output()->
scale());
115 const int left_shift = 20;
116 const double twice_max_input_scale = 2 * std::max(input1_scale, input2_scale);
117 const double real_input1_multiplier = input1_scale / twice_max_input_scale;
118 const double real_input2_multiplier = input2_scale / twice_max_input_scale;
119 const double real_output_multiplier = twice_max_input_scale / ((1 << left_shift) * output_scale);
121 int32_t input1_multiplier{}, input2_multiplier{}, output_multiplier{};
122 int input1_shift{}, input2_shift{}, output_shift{};
127 int32_t activation_min{};
128 int32_t activation_max{};
131 tflite::ArithmeticParams
params{};
132 params.left_shift = left_shift;
135 params.input1_multiplier = input1_multiplier;
136 params.input1_shift = input1_shift;
138 params.input2_multiplier = input2_multiplier;
139 params.input2_shift = input2_shift;
141 params.output_multiplier = output_multiplier;
142 params.output_shift = output_shift;
143 params.quantized_activation_min = activation_min;
144 params.quantized_activation_max = activation_max;
146 const bool need_broadcast = tflite::reference_ops::ProcessBroadcastShapes(
151 tflite::reference_ops::BroadcastQuantSubSlow(
const SubParams & params() const
void resize(const Shape &new_shape)
int32_t zero_point() const
const Tensor * input2() const
void configure() override
Sub(const Tensor *input1, const Tensor *input2, Tensor *output, const SubParams ¶ms)
void execute() const override
const Tensor * input1() const
#define LUCI_INTERPRETER_CHECK(cond)
Shape calculateShapeForBroadcast(const Shape &input1_shape, const Shape &input2_shape)
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
void quantizeMultiplierSmallerThanOneExp(double double_multiplier, int32_t *quantized_multiplier, int *left_shift)
void calculateActivationRangeQuantized(Activation activation, const Tensor *output, int32_t *activation_min, int32_t *activation_max)