2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2018 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.
18 #include "kernels/Utils.h"
19 #include "TISOKernel.h"
21 #include "PALLogicalCommon.h"
23 namespace luci_interpreter
27 bool LogicalAnd(bool x, bool y) { return x && y; }
30 void configure_kernel_CircleLogicalAnd(const circle::Operator *cur_op,
31 BaseRuntimeGraph *runtime_graph)
33 kernels::TISOKernel kernel(cur_op, runtime_graph);
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);
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()));
47 // TODO: reduce code duplication with LogicalOr
48 void execute_kernel_CircleLogicalAnd(const circle::Operator *cur_op,
49 BaseRuntimeGraph *runtime_graph)
51 kernels::TISOKernel kernel(cur_op, runtime_graph);
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()));
57 assert(x_data != nullptr);
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()));
63 assert(y_data != nullptr);
65 auto output_data = kernels::getTensorData<bool>(runtime_graph->getDataByTensor(kernel.output()));
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);
71 } // namespace luci_interpreter