Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / onert-micro / luci-interpreter / src / kernels / LogicalAnd.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  * Copyright 2018 The TensorFlow Authors. All Rights Reserved.
4  *
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
8  *
9  *    http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 #include "Builders.h"
18 #include "kernels/Utils.h"
19 #include "TISOKernel.h"
20
21 #include "PALLogicalCommon.h"
22
23 namespace luci_interpreter
24 {
25 namespace
26 {
27 bool LogicalAnd(bool x, bool y) { return x && y; }
28 } // namespace
29
30 void configure_kernel_CircleLogicalAnd(const circle::Operator *cur_op,
31                                        BaseRuntimeGraph *runtime_graph)
32 {
33   kernels::TISOKernel kernel(cur_op, runtime_graph);
34
35   LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) ==
36                          Tensor::element_type(kernel.input2()));
37   LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) == DataType::BOOL);
38   LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.output()) == DataType::BOOL);
39
40   // TODO support broadcast
41   LUCI_INTERPRETER_CHECK(Tensor::num_elements(kernel.input1()) ==
42                          Tensor::num_elements(kernel.input2()));
43   LUCI_INTERPRETER_CHECK(Tensor::num_dims(kernel.input1()) == Tensor::num_dims(kernel.input2()));
44 }
45
46 // TODO: add inplace
47 // TODO: reduce code duplication with LogicalOr
48 void execute_kernel_CircleLogicalAnd(const circle::Operator *cur_op,
49                                      BaseRuntimeGraph *runtime_graph)
50 {
51   kernels::TISOKernel kernel(cur_op, runtime_graph);
52
53   auto x_data = kernels::getTensorData<bool>(runtime_graph->getDataByTensor(kernel.input1()));
54   if (x_data == nullptr)
55     x_data = kernels::getTensorData<bool>(runtime_graph->getConstDataByTensor(kernel.input1()));
56
57   assert(x_data != nullptr);
58
59   auto y_data = kernels::getTensorData<bool>(runtime_graph->getDataByTensor(kernel.input2()));
60   if (y_data == nullptr)
61     y_data = kernels::getTensorData<bool>(runtime_graph->getConstDataByTensor(kernel.input2()));
62
63   assert(y_data != nullptr);
64
65   auto output_data = kernels::getTensorData<bool>(runtime_graph->getDataByTensor(kernel.output()));
66
67   const int64_t flat_size = kernels::getTensorShape(kernel.input1()).flatSize();
68   luci_interpreter_pal::LogicalCommon(flat_size, x_data, y_data, output_data, LogicalAnd);
69 }
70
71 } // namespace luci_interpreter