2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include "kernels/Utils.h"
23 namespace luci_interpreter
30 void evalGeneric(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
32 const auto output_index = cur_op->outputs()->operator[](0);
33 assert(output_index != -1);
34 const auto output = runtime_graph->getCircleTensorByIndex(output_index);
36 const auto input_sizes = cur_op->inputs()->size();
38 auto input1_index = cur_op->inputs()->operator[](0);
39 const auto *tensor1 = runtime_graph->getCircleTensorByIndex(input1_index);
41 const int flat_size = Tensor::num_elements(tensor1);
43 std::vector<const T *> all_input_data;
44 for (int32_t i = 0; i < input_sizes; ++i)
46 auto input_index = cur_op->inputs()->operator[](i);
47 const auto *tensor = runtime_graph->getCircleTensorByIndex(input_index);
49 const auto *tensor_data = runtime_graph->getDataByTensor(tensor);
50 if (tensor_data == nullptr)
51 tensor_data = runtime_graph->getConstDataByTensor(tensor);
53 auto *data = reinterpret_cast<const T *>(tensor_data);
54 all_input_data.push_back(data);
57 auto *output_data = reinterpret_cast<T *>(runtime_graph->getDataByTensor(output));
59 luci_interpreter_pal::AddN(flat_size, input_sizes, all_input_data.data(), output_data);
64 void configure_kernel_CircleAddN(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
66 const int num_inputs = cur_op->inputs()->size();
68 LUCI_INTERPRETER_CHECK(num_inputs >= 2);
69 LUCI_INTERPRETER_CHECK(cur_op->outputs()->size() == 1);
71 const auto input1_index = cur_op->inputs()->operator[](0);
72 assert(input1_index != -1);
74 const auto input1_tensor = runtime_graph->getCircleTensorByIndex(input1_index);
75 assert(input1_tensor != nullptr);
77 for (int i = 1; i < num_inputs; ++i)
79 const auto input_index = cur_op->inputs()->operator[](i);
80 assert(input_index != -1);
82 const auto input_tensor = runtime_graph->getCircleTensorByIndex(input_index);
83 assert(input_tensor != nullptr);
85 LUCI_INTERPRETER_CHECK(Tensor::element_type(input1_tensor) ==
86 Tensor::element_type(input_tensor));
87 LUCI_INTERPRETER_CHECK(Tensor::num_dims(input1_tensor) == Tensor::num_dims(input_tensor));
88 LUCI_INTERPRETER_CHECK(Tensor::num_elements(input1_tensor) ==
89 Tensor::num_elements(input_tensor));
93 void execute_kernel_CircleAddN(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
95 const auto output_index = cur_op->outputs()->operator[](0);
96 assert(output_index != -1);
97 const auto output = runtime_graph->getCircleTensorByIndex(output_index);
99 switch (Tensor::element_type(output))
102 case DataType::FLOAT32:
104 evalGeneric<float>(cur_op, runtime_graph);
109 assert(false && "Unsupported type.");
113 } // namespace luci_interpreter