Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / onert-micro / luci-interpreter / src / kernels / GreaterEqual.cpp
1 /*
2  * Copyright (c) 2020 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 #include "kernels/Utils.h"
19 #include "TISOKernel.h"
20
21 #include "PALComparisons.h"
22
23 namespace luci_interpreter
24 {
25
26 namespace
27 {
28 // TODO: reduce code duplication with less
29 template <typename T>
30 void evalGeneric(const circle::Tensor *x, const circle::Tensor *y, const circle::Tensor *output,
31                  BaseRuntimeGraph *runtime_graph)
32 {
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));
36
37   assert(x_data != nullptr);
38
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));
42
43   assert(y_data != nullptr);
44
45   auto output_data = kernels::getTensorData<bool>(runtime_graph->getDataByTensor(output));
46
47   luci_interpreter_pal::ComparisonParams op_params;
48   op_params.is_broadcast = Tensor::num_elements(x) != Tensor::num_elements(y);
49
50   const int64_t flat_size = kernels::getTensorShape(x).flatSize();
51   luci_interpreter_pal::ComparisonNoScaling<T>(flat_size, x_data, y_data, output_data,
52                                                luci_interpreter_pal::GreaterEqualFn);
53 }
54
55 } // namespace
56
57 void configure_kernel_CircleGreaterEqual(const circle::Operator *cur_op,
58                                          BaseRuntimeGraph *runtime_graph)
59 {
60   kernels::TISOKernel kernel(cur_op, runtime_graph);
61
62   LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) ==
63                          Tensor::element_type(kernel.input2()));
64   LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.output()) == DataType::BOOL);
65 }
66
67 void execute_kernel_CircleGreaterEqual(const circle::Operator *cur_op,
68                                        BaseRuntimeGraph *runtime_graph)
69 {
70   kernels::TISOKernel kernel(cur_op, runtime_graph);
71
72   switch (Tensor::element_type(kernel.input1()))
73   {
74     case DataType::S64:
75       evalGeneric<int64_t>(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph);
76       break;
77     case DataType::S32:
78       evalGeneric<int32_t>(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph);
79       break;
80 #ifndef DIS_FLOAT
81     case DataType::FLOAT32:
82       evalGeneric<float>(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph);
83       break;
84 #endif // DIS_FLOAT
85     default:
86       assert(false && "Unsupported type.");
87   }
88 }
89
90 } // namespace luci_interpreter