Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ops / LogicalOrLayer.cc
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 "LogicalOrLayer.h"
18
19 #include "OperationUtils.h"
20
21 #include <cker/operation/LogicalOr.h>
22
23 namespace onert
24 {
25 namespace backend
26 {
27 namespace cpu
28 {
29 namespace ops
30 {
31 void LogicalOrLayer::lorBool8()
32 {
33   if (!HaveSameShapes(_lhs, _rhs))
34   {
35     nnfw::cker::LogicalOrBroadcast<bool>(
36         getTensorShape(_lhs), reinterpret_cast<const bool *>(_lhs->buffer()), getTensorShape(_rhs),
37         reinterpret_cast<const bool *>(_rhs->buffer()), getTensorShape(_output),
38         reinterpret_cast<bool *>(_output->buffer()));
39   }
40   else
41   {
42     nnfw::cker::LogicalOrElementwise<bool>(getTensorShape(_lhs),
43                                            reinterpret_cast<const bool *>(_lhs->buffer()),
44                                            reinterpret_cast<const bool *>(_rhs->buffer()),
45                                            reinterpret_cast<bool *>(_output->buffer()));
46   }
47 }
48
49 void LogicalOrLayer::configure(const IPortableTensor *lhs, const IPortableTensor *rhs,
50                                IPortableTensor *output)
51 {
52   assert(lhs != nullptr);
53   assert(rhs != nullptr);
54   assert(output != nullptr);
55
56   _lhs = lhs;
57   _rhs = rhs;
58   _output = output;
59 }
60
61 void LogicalOrLayer::run()
62 {
63   if ((_lhs->data_type() == OperandType::BOOL8) && (_rhs->data_type() == OperandType::BOOL8))
64   {
65     lorBool8();
66   }
67   else
68   {
69     throw std::runtime_error{"LogicalOr: Unsupported data type"};
70   }
71 }
72
73 } // namespace ops
74 } // namespace cpu
75 } // namespace backend
76 } // namespace onert