ONE - On-device Neural Engine
Loading...
Searching...
No Matches
LogicalOr.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2019 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{
25
26namespace
27{
28bool LogicalOr(bool x, bool y) { return x || y; }
29} // namespace
30
31void configure_kernel_CircleLogicalOr(const circle::Operator *cur_op,
32 BaseRuntimeGraph *runtime_graph)
33{
34 kernels::TISOKernel kernel(cur_op, runtime_graph);
35
36 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) ==
37 Tensor::element_type(kernel.input2()));
38 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) == DataType::BOOL);
39 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.output()) == DataType::BOOL);
40
41 // TODO support broadcast
42 LUCI_INTERPRETER_CHECK(Tensor::num_elements(kernel.input1()) ==
43 Tensor::num_elements(kernel.input2()));
44 LUCI_INTERPRETER_CHECK(Tensor::num_dims(kernel.input1()) == Tensor::num_dims(kernel.input2()));
45}
46
47// TODO: add inplace
48// TODO: reduce code duplication with LogicalAnd
49void execute_kernel_CircleLogicalOr(const circle::Operator *cur_op, 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, LogicalOr);
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 execute_kernel_CircleLogicalOr(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition LogicalOr.cpp:49
void configure_kernel_CircleLogicalOr(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition LogicalOr.cpp:31