Compute Library
 21.02
NELogical.cpp
Go to the documentation of this file.
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  */
25 
29 
30 namespace arm_compute
31 {
32 struct LogicalArgs
33 {
34  std::unique_ptr<kernels::NELogicalKernel> kernel{ nullptr };
35  ITensorPack pack{};
36 };
37 
38 struct NELogicalAnd::Impl : public LogicalArgs
39 {
40 };
42  : _impl(std::make_unique<Impl>())
43 {
44 }
46 NELogicalAnd::~NELogicalAnd() = default;
47 
48 void NELogicalAnd::configure(const ITensor *input1, const ITensor *input2, ITensor *output)
49 {
50  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
51 
52  _impl->kernel = std::make_unique<kernels::NELogicalKernel>();
53  _impl->kernel->configure(input1->info(), input2->info(), output->info(), LogicalOperation::And);
54 
55  _impl->pack = ITensorPack();
56  _impl->pack.add_tensor(TensorType::ACL_SRC_0, input1);
57  _impl->pack.add_tensor(TensorType::ACL_SRC_1, input2);
58  _impl->pack.add_tensor(TensorType::ACL_DST, output);
59 }
60 
61 Status NELogicalAnd::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
62 {
63  return kernels::NELogicalKernel::validate(input1, input2, output, LogicalOperation::And);
64 }
65 
67 {
68  NEScheduler::get().schedule_op(_impl->kernel.get(), Window::DimY, _impl->kernel->window(), _impl->pack);
69 }
70 
71 struct NELogicalOr::Impl : public LogicalArgs
72 {
73 };
75  : _impl(std::make_unique<Impl>())
76 {
77 }
79 NELogicalOr::~NELogicalOr() = default;
80 
81 void NELogicalOr::configure(const ITensor *input1, const ITensor *input2, ITensor *output)
82 {
83  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
84 
85  _impl->kernel = std::make_unique<kernels::NELogicalKernel>();
86  _impl->kernel->configure(input1->info(), input2->info(), output->info(), LogicalOperation::Or);
87 
88  _impl->pack = ITensorPack();
89  _impl->pack.add_tensor(TensorType::ACL_SRC_0, input1);
90  _impl->pack.add_tensor(TensorType::ACL_SRC_1, input2);
91  _impl->pack.add_tensor(TensorType::ACL_DST, output);
92 }
93 
94 Status NELogicalOr::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
95 {
96  return kernels::NELogicalKernel::validate(input1, input2, output, LogicalOperation::Or);
97 }
98 
100 {
101  NEScheduler::get().schedule_op(_impl->kernel.get(), Window::DimY, _impl->kernel->window(), _impl->pack);
102 }
103 
104 struct NELogicalNot::Impl : public LogicalArgs
105 {
106 };
108  : _impl(std::make_unique<Impl>())
109 {
110 }
112 NELogicalNot::~NELogicalNot() = default;
113 
115 {
116  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
117 
118  _impl->kernel = std::make_unique<kernels::NELogicalKernel>();
119  _impl->kernel->configure(input->info(), nullptr, output->info(), LogicalOperation::Not);
120 
121  _impl->pack = ITensorPack();
122  _impl->pack.add_tensor(TensorType::ACL_SRC_0, input);
123  _impl->pack.add_tensor(TensorType::ACL_DST, output);
124 }
125 
127 {
128  return kernels::NELogicalKernel::validate(input, nullptr, output, LogicalOperation::Not);
129 }
130 
132 {
133  NEScheduler::get().schedule_op(_impl->kernel.get(), Window::DimY, _impl->kernel->window(), _impl->pack);
134 }
135 } // namespace arm_compute
NELogicalOr()
Constructor.
Definition: NELogical.cpp:74
NELogicalNot()
Constructor.
Definition: NELogical.cpp:107
~NELogicalAnd()
Destructor.
Basic function to perform logical NOT.
Definition: NELogical.h:110
virtual void schedule_op(ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors)=0
Runs the kernel in the same thread as the caller synchronously.
Basic function to perform logical OR.
Definition: NELogical.h:75
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of NELogicalNot.
Definition: NELogical.cpp:126
Interface for Neon tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, LogicalOperation op)
Static function to check if given info will lead to a valid configuration of NELogicalKernel.
void configure(const ITensor *input1, const ITensor *input2, ITensor *output)
Initialise the kernel&#39;s inputs and output.
Definition: NELogical.cpp:48
NELogicalAnd & operator=(const NELogicalAnd &)=delete
~NELogicalOr()
Destructor.
void configure(const ITensor *input1, const ITensor *input2, ITensor *output)
Initialise the kernel&#39;s inputs and output.
Definition: NELogical.cpp:81
void run() override
Run the kernels contained in the function.
Definition: NELogical.cpp:99
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Basic function to perform logical AND.
Definition: NELogical.h:40
void run() override
Run the kernels contained in the function.
Definition: NELogical.cpp:131
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
void run() override
Run the kernels contained in the function.
Definition: NELogical.cpp:66
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of NELogicalAnd.
Definition: NELogical.cpp:61
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of NELogicalOr.
Definition: NELogical.cpp:94
Tensor packing service.
Definition: ITensorPack.h:37
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
void configure(const ITensor *input, ITensor *output)
Initialise the kernel&#39;s inputs and output.
Definition: NELogical.cpp:114
NELogicalNot & operator=(const NELogicalNot &)=delete
~NELogicalNot()
Destructor.
NELogicalAnd()
Constructor.
Definition: NELogical.cpp:41
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94
NELogicalOr & operator=(const NELogicalOr &)=delete