ONE - On-device Neural Engine
Loading...
Searching...
No Matches
SVDF.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#include "Builders.h"
18
19#include "kernels/SVDF.h"
20
21namespace luci_interpreter
22{
23
24std::unique_ptr<Kernel> build_kernel_CircleSVDF(const luci::CircleNode *circle_node,
25 KernelBuilderHelper &helper)
26{
27 const auto *node = loco::must_cast<const luci::CircleSVDF *>(circle_node);
28 assert(node->arity() == 5);
29
30 const Tensor *input = helper.getInputTensor(node->input());
31 const Tensor *feature = helper.getInputTensor(node->weight_feature());
32 const Tensor *time = helper.getInputTensor(node->weight_time());
33 const Tensor *bias = helper.getOptionalInputTensor(node->bias());
34 const Tensor *input_activation_state = helper.getInputTensor(node->input_activation_state());
35 Tensor *output = helper.getOutputTensor(node);
36
37 auto scratchpad_tensor = std::make_unique<Tensor>(input_activation_state->element_type(),
38 Shape({}), AffineQuantization{}, "");
39 scratchpad_tensor->set_observable(false);
40 scratchpad_tensor->set_data_buffer(nullptr);
41 Tensor *tmp = helper.getRuntimeGraph(node->graph())->addTensor(std::move(scratchpad_tensor));
42
43 DataType data_type = input->element_type() == DataType::S8 ? DataType::S32 : DataType::FLOAT32;
44
45 scratchpad_tensor = std::make_unique<Tensor>(data_type, Shape({}), AffineQuantization{}, "");
46 scratchpad_tensor->set_observable(false);
47 scratchpad_tensor->set_data_buffer(nullptr);
48 Tensor *tmp_1 = helper.getRuntimeGraph(node->graph())->addTensor(std::move(scratchpad_tensor));
49
50 if (data_type == DataType::FLOAT32 &&
51 (feature->element_type() == DataType::S8 || feature->element_type() == DataType::U8))
52 {
53 data_type = feature->element_type();
54 }
55
56 scratchpad_tensor = std::make_unique<Tensor>(data_type, Shape({}), AffineQuantization{}, "");
57 scratchpad_tensor->set_observable(false);
58 scratchpad_tensor->set_data_buffer(nullptr);
59 Tensor *tmp_2 = helper.getRuntimeGraph(node->graph())->addTensor(std::move(scratchpad_tensor));
60
61 data_type = DataType::FLOAT32;
62
63 scratchpad_tensor = std::make_unique<Tensor>(data_type, Shape({}), AffineQuantization{}, "");
64 scratchpad_tensor->set_observable(false);
65 scratchpad_tensor->set_data_buffer(nullptr);
66 Tensor *tmp_3 = helper.getRuntimeGraph(node->graph())->addTensor(std::move(scratchpad_tensor));
67
68 scratchpad_tensor = std::make_unique<Tensor>(data_type, Shape({}), AffineQuantization{}, "");
69 scratchpad_tensor->set_observable(false);
70 scratchpad_tensor->set_data_buffer(nullptr);
71 Tensor *tmp_4 = helper.getRuntimeGraph(node->graph())->addTensor(std::move(scratchpad_tensor));
72
73 scratchpad_tensor = std::make_unique<Tensor>(data_type, Shape({}), AffineQuantization{}, "");
74 scratchpad_tensor->set_observable(false);
75 scratchpad_tensor->set_data_buffer(nullptr);
76 Tensor *tmp_5 = helper.getRuntimeGraph(node->graph())->addTensor(std::move(scratchpad_tensor));
77
78 scratchpad_tensor = std::make_unique<Tensor>(data_type, Shape({}), AffineQuantization{}, "");
79 scratchpad_tensor->set_observable(false);
80 scratchpad_tensor->set_data_buffer(nullptr);
81 Tensor *tmp_6 = helper.getRuntimeGraph(node->graph())->addTensor(std::move(scratchpad_tensor));
82
83 SVDFParams params{};
84 params.activation = node->fusedActivationFunction();
85 params.svdf_rank = node->svdf_rank();
86 params.asymmetric_quantize_inputs = node->asymmetric_quantize_inputs();
87
88 return std::make_unique<kernels::SVDF>(input, feature, time, bias, input_activation_state, output,
89 tmp, tmp_1, tmp_2, tmp_3, tmp_4, tmp_5, tmp_6, params);
90}
91
92} // namespace luci_interpreter
Tensor * getOutputTensor(const loco::Node *node) const
const Tensor * getOptionalInputTensor(const loco::Node *node) const
RuntimeGraph * getRuntimeGraph(const loco::Graph *graph) const
const Tensor * getInputTensor(const loco::Node *node) const
Tensor * addTensor(std::unique_ptr< Tensor > &&tensor)
void set_observable(bool value)
Definition Tensor.h:164
DataType element_type() const
Definition Tensor.h:105
std::unique_ptr< Kernel > build_kernel_CircleSVDF(const luci::CircleNode *circle_node, KernelBuilderHelper &helper)
Definition SVDF.cpp:24
DataType
"scalar" value type
Definition DataType.h:32