ONE - On-device Neural Engine
Loading...
Searching...
No Matches
LogicalAnd.cpp
Go to the documentation of this file.
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
23namespace luci_interpreter
24{
25namespace
26{
27bool LogicalAnd(bool x, bool y) { return x && y; }
28} // namespace
29
30void 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
48void 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
uint8_t * getConstDataByTensor(const circle::Tensor *raw_tensor)
uint8_t * getDataByTensor(const circle::Tensor *raw_tensor)
const circle::Tensor * output() const
Definition TISOKernel.h:62
const circle::Tensor * input2() const
Definition TISOKernel.h:61
const circle::Tensor * input1() const
Definition TISOKernel.h:60
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194
void LogicalCommon(const int flat_size, const bool *input1_data, const bool *input2_data, bool *output_data, bool(*f)(bool, bool))
void configure_kernel_CircleLogicalAnd(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
void execute_kernel_CircleLogicalAnd(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)