19#include "kernels/Utils.h"
22#include <tensorflow/lite/kernels/internal/quantization_util.h>
35 {output, scratchpad_activation_state, scratchpad_1, scratchpad_2,
36 scratchpad_3, scratchpad_4, scratchpad_5, scratchpad_6},
50 input()->element_type() == loco::DataType::S8);
54 if (
input()->element_type() == loco::DataType::S8)
58 weight_time()->element_type() == loco::DataType::S8);
69 else if (
weight_feature()->element_type() == loco::DataType::FLOAT32)
78 else if ((
weight_feature()->element_type() == loco::DataType::U8 ||
80 input()->element_type() == loco::DataType::FLOAT32)
83 throw std::runtime_error(
"Hybrid type is not currently supported");
87 throw std::runtime_error(
"luci-intp SVDF Unsupported type.");
93 const int batch_size = input_shape.
dim(0);
94 const int num_filters = weight_features_shape.
dim(0);
98 const int num_units = num_filters / rank;
99 const int memory_size = weight_time_shape.
dim(1);
120 scratchpad_activation_state->resize({batch_size, memory_size * num_filters});
125 luci_interpreter_pal::SetupScratchpadTensor(
128 getOutputTensors()[7], input_shape, weight_time_shape, batch_size, num_filters, num_units);
135 case loco::DataType::FLOAT32:
138 case loco::DataType::S8:
140 if (
input()->element_type() == loco::DataType::S8)
144 throw std::runtime_error(
"Hybrid type is not currently supported");
148 throw std::runtime_error(
"Unsupported type");
152void SVDF::evalInteger()
const
159 int32_t effective_scale_1_a;
160 int effective_scale_1_b;
161 int32_t effective_scale_2_a;
162 int effective_scale_2_b;
164 tflite::QuantizeMultiplier(effective_scale_1, &effective_scale_1_a, &effective_scale_1_b);
165 tflite::QuantizeMultiplier(effective_scale_2, &effective_scale_2_a, &effective_scale_2_b);
167 TfLiteSVDFParams params_svdf{};
175 auto scratchpad_data = getTensorData<int16_t>(scratchpad_activation_state);
176 std::fill_n(scratchpad_data, scratchpad_activation_state->shape().num_elements(), 0);
183 luci_interpreter_pal::IntegerSVDF(
188 getTensorData<int8_t>(
output()), getTensorData<int32_t>(scratchpad),
189 getTensorData<int32_t>(output_temp), effective_scale_1_a, effective_scale_1_b,
190 effective_scale_2_a, effective_scale_2_b, input_zp, output_zp);
193void SVDF::evalFloat()
const
195 TfLiteSVDFParams params_svdf{};
203 auto scratchpad_data = getTensorData<float>(scratchpad_activation_state);
204 std::fill_n(scratchpad_data, scratchpad_activation_state->shape().num_elements(), 0);
208 luci_interpreter_pal::FloatSVDF(
212 getTensorData<float>(
bias()), getTensorData<float>(scratchpad_1), scratchpad_data,
const std::vector< Tensor * > & getOutputTensors() const
const SVDFParams & params() const
void resize(const Shape &new_shape)
const Shape & shape() const
int32_t zero_point() const
const Tensor * input() const
void execute() const override
SVDF(const Tensor *input, const Tensor *weight_feature, const Tensor *weight_time, const Tensor *bias, const Tensor *input_activation_state, Tensor *output, Tensor *scratchpad_activation_state, Tensor *scratchpad_1, Tensor *scratchpad_2, Tensor *scratchpad_3, Tensor *scratchpad_4, Tensor *scratchpad_5, Tensor *scratchpad_6, const SVDFParams ¶ms)
const Tensor * input_activation_state() const
const Tensor * bias() const
const Tensor * weight_feature() const
const Tensor * weight_time() const
void configure() override
#define LUCI_INTERPRETER_CHECK(cond)
TfLiteFusedActivation getTfLiteActivation(Activation activation)
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
bool asymmetric_quantize_inputs