xref: /aosp_15_r20/external/ComputeLibrary/src/runtime/NEON/functions/NELogical.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2020-2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "arm_compute/runtime/NEON/functions/NELogical.h"
25 
26 #include "arm_compute/runtime/NEON/NEScheduler.h"
27 #include "arm_compute/runtime/Tensor.h"
28 #include "src/common/utils/Log.h"
29 #include "src/core/NEON/kernels/NELogicalKernel.h"
30 
31 namespace arm_compute
32 {
33 struct LogicalArgs
34 {
35     std::unique_ptr<kernels::NELogicalKernel> kernel{ nullptr };
36     ITensorPack                               pack{};
37 };
38 
39 struct NELogicalAnd::Impl : public LogicalArgs
40 {
41 };
NELogicalAnd()42 NELogicalAnd::NELogicalAnd()
43     : _impl(std::make_unique<Impl>())
44 {
45 }
46 NELogicalAnd::~NELogicalAnd() = default;
47 
configure(const ITensor * input1,const ITensor * input2,ITensor * output)48 void NELogicalAnd::configure(const ITensor *input1, const ITensor *input2, ITensor *output)
49 {
50     ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
51     ARM_COMPUTE_LOG_PARAMS(input1, input2, output);
52 
53     _impl->kernel = std::make_unique<kernels::NELogicalKernel>();
54     _impl->kernel->configure(input1->info(), input2->info(), output->info(), LogicalOperation::And);
55 
56     _impl->pack = ITensorPack();
57     _impl->pack.add_tensor(TensorType::ACL_SRC_0, input1);
58     _impl->pack.add_tensor(TensorType::ACL_SRC_1, input2);
59     _impl->pack.add_tensor(TensorType::ACL_DST, output);
60 }
61 
validate(const ITensorInfo * input1,const ITensorInfo * input2,const ITensorInfo * output)62 Status NELogicalAnd::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
63 {
64     return kernels::NELogicalKernel::validate(input1, input2, output, LogicalOperation::And);
65 }
66 
run()67 void NELogicalAnd::run()
68 {
69     NEScheduler::get().schedule_op(_impl->kernel.get(), Window::DimY, _impl->kernel->window(), _impl->pack);
70 }
71 
72 struct NELogicalOr::Impl : public LogicalArgs
73 {
74 };
NELogicalOr()75 NELogicalOr::NELogicalOr()
76     : _impl(std::make_unique<Impl>())
77 {
78 }
79 NELogicalOr::~NELogicalOr() = default;
80 
configure(const ITensor * input1,const ITensor * input2,ITensor * output)81 void NELogicalOr::configure(const ITensor *input1, const ITensor *input2, ITensor *output)
82 {
83     ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
84     ARM_COMPUTE_LOG_PARAMS(input1, input2, output);
85 
86     _impl->kernel = std::make_unique<kernels::NELogicalKernel>();
87     _impl->kernel->configure(input1->info(), input2->info(), output->info(), LogicalOperation::Or);
88 
89     _impl->pack = ITensorPack();
90     _impl->pack.add_tensor(TensorType::ACL_SRC_0, input1);
91     _impl->pack.add_tensor(TensorType::ACL_SRC_1, input2);
92     _impl->pack.add_tensor(TensorType::ACL_DST, output);
93 }
94 
validate(const ITensorInfo * input1,const ITensorInfo * input2,const ITensorInfo * output)95 Status NELogicalOr::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
96 {
97     return kernels::NELogicalKernel::validate(input1, input2, output, LogicalOperation::Or);
98 }
99 
run()100 void NELogicalOr::run()
101 {
102     NEScheduler::get().schedule_op(_impl->kernel.get(), Window::DimY, _impl->kernel->window(), _impl->pack);
103 }
104 
105 struct NELogicalNot::Impl : public LogicalArgs
106 {
107 };
NELogicalNot()108 NELogicalNot::NELogicalNot()
109     : _impl(std::make_unique<Impl>())
110 {
111 }
112 NELogicalNot::~NELogicalNot() = default;
113 
configure(const ITensor * input,ITensor * output)114 void NELogicalNot::configure(const ITensor *input, ITensor *output)
115 {
116     ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
117     ARM_COMPUTE_LOG_PARAMS(input, output);
118 
119     _impl->kernel = std::make_unique<kernels::NELogicalKernel>();
120     _impl->kernel->configure(input->info(), nullptr, output->info(), LogicalOperation::Not);
121 
122     _impl->pack = ITensorPack();
123     _impl->pack.add_tensor(TensorType::ACL_SRC_0, input);
124     _impl->pack.add_tensor(TensorType::ACL_DST, output);
125 }
126 
validate(const ITensorInfo * input,const ITensorInfo * output)127 Status NELogicalNot::validate(const ITensorInfo *input, const ITensorInfo *output)
128 {
129     return kernels::NELogicalKernel::validate(input, nullptr, output, LogicalOperation::Not);
130 }
131 
run()132 void NELogicalNot::run()
133 {
134     NEScheduler::get().schedule_op(_impl->kernel.get(), Window::DimY, _impl->kernel->window(), _impl->pack);
135 }
136 } // namespace arm_compute
137