2 * Copyright (c) 2020 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.
18 #include "kernels/Utils.h"
19 #include "TISOKernel.h"
21 #include "PALComparisons.h"
23 namespace luci_interpreter
28 // TODO: reduce code duplication with less
30 void evalGeneric(const circle::Tensor *x, const circle::Tensor *y, const circle::Tensor *output,
31 BaseRuntimeGraph *runtime_graph)
33 auto x_data = kernels::getTensorData<T>(runtime_graph->getDataByTensor(x));
34 if (x_data == nullptr)
35 x_data = kernels::getTensorData<T>(runtime_graph->getConstDataByTensor(x));
37 assert(x_data != nullptr);
39 auto y_data = kernels::getTensorData<T>(runtime_graph->getDataByTensor(y));
40 if (y_data == nullptr)
41 y_data = kernels::getTensorData<T>(runtime_graph->getConstDataByTensor(y));
43 assert(y_data != nullptr);
45 auto output_data = kernels::getTensorData<bool>(runtime_graph->getDataByTensor(output));
47 luci_interpreter_pal::ComparisonParams op_params;
48 op_params.is_broadcast = Tensor::num_elements(x) != Tensor::num_elements(y);
50 if (op_params.is_broadcast)
52 luci_interpreter_pal::BroadcastComparison4DSlowNoScaling<T>(
53 op_params, kernels::getTensorShape(x), x_data, kernels::getTensorShape(y), y_data,
54 kernels::getTensorShape(output), output_data, luci_interpreter_pal::EqualFn);
58 const int64_t flat_size = kernels::getTensorShape(x).flatSize();
59 luci_interpreter_pal::ComparisonNoScaling<T>(flat_size, x_data, y_data, output_data,
60 luci_interpreter_pal::EqualFn);
66 void configure_kernel_CircleEqual(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
68 kernels::TISOKernel kernel(cur_op, runtime_graph);
70 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) ==
71 Tensor::element_type(kernel.input2()));
72 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.output()) == DataType::BOOL);
75 void execute_kernel_CircleEqual(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
77 kernels::TISOKernel kernel(cur_op, runtime_graph);
79 switch (Tensor::element_type(kernel.input1()))
82 evalGeneric<int64_t>(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph);
85 evalGeneric<int32_t>(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph);
88 case DataType::FLOAT32:
89 evalGeneric<float>(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph);
93 assert(false && "Unsupported type.");
97 } // namespace luci_interpreter