2 * Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "kernels/SVDF.h"
21 namespace luci_interpreter
24 std::unique_ptr<Kernel> build_kernel_CircleSVDF(std::vector<const Tensor *> &&inputs,
25 std::vector<Tensor *> &&outputs,
26 const uint32_t op_index, KernelBuilder &builder)
28 assert(inputs.size() == 5);
30 const Tensor *input = inputs.at(0);
31 const Tensor *feature = inputs.at(1);
32 const Tensor *time = inputs.at(2);
33 const Tensor *bias = inputs.at(3);
34 const Tensor *input_activation_state = inputs.at(4);
35 Tensor *output = outputs.at(0);
37 auto scratchpad_tensor =
38 std::make_unique<Tensor>(input_activation_state->element_type(), Shape({}), nullptr);
39 scratchpad_tensor->set_data_buffer(nullptr);
40 Tensor *tmp = builder.get_runtime_graph()->addTensor(std::move(scratchpad_tensor));
42 DataType data_type = input->element_type() == DataType::S8 ? DataType::S32 : DataType::FLOAT32;
44 scratchpad_tensor = std::make_unique<Tensor>(data_type, Shape({}), nullptr);
45 scratchpad_tensor->set_data_buffer(nullptr);
46 Tensor *tmp_1 = builder.get_runtime_graph()->addTensor(std::move(scratchpad_tensor));
48 if (data_type == DataType::FLOAT32 &&
49 (feature->element_type() == DataType::S8 || feature->element_type() == DataType::U8))
51 data_type = feature->element_type();
54 scratchpad_tensor = std::make_unique<Tensor>(data_type, Shape({}), nullptr);
55 scratchpad_tensor->set_data_buffer(nullptr);
56 Tensor *tmp_2 = builder.get_runtime_graph()->addTensor(std::move(scratchpad_tensor));
58 data_type = DataType::FLOAT32;
60 scratchpad_tensor = std::make_unique<Tensor>(data_type, Shape({}), nullptr);
61 scratchpad_tensor->set_data_buffer(nullptr);
62 Tensor *tmp_3 = builder.get_runtime_graph()->addTensor(std::move(scratchpad_tensor));
64 scratchpad_tensor = std::make_unique<Tensor>(data_type, Shape({}), nullptr);
65 scratchpad_tensor->set_data_buffer(nullptr);
66 Tensor *tmp_4 = builder.get_runtime_graph()->addTensor(std::move(scratchpad_tensor));
68 scratchpad_tensor = std::make_unique<Tensor>(data_type, Shape({}), nullptr);
69 scratchpad_tensor->set_data_buffer(nullptr);
70 Tensor *tmp_5 = builder.get_runtime_graph()->addTensor(std::move(scratchpad_tensor));
72 scratchpad_tensor = std::make_unique<Tensor>(data_type, Shape({}), nullptr);
73 scratchpad_tensor->set_data_buffer(nullptr);
74 Tensor *tmp_6 = builder.get_runtime_graph()->addTensor(std::move(scratchpad_tensor));
76 circle::OperatorT oper_t;
77 builder.get_circle_reader()->operators()[op_index]->UnPackTo(&oper_t);
78 const auto *options = oper_t.builtin_options.AsSVDFOptions();
81 params.activation = luci_actfunc(options->fused_activation_function);
82 params.svdf_rank = options->rank;
83 params.asymmetric_quantize_inputs = options->asymmetric_quantize_inputs;
85 return std::make_unique<kernels::SVDF>(input, feature, time, bias, input_activation_state, output,
86 tmp, tmp_1, tmp_2, tmp_3, tmp_4, tmp_5, tmp_6, params);
89 } // namespace luci_interpreter