Compute Library
 21.02
CLElementWiseUnaryLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-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 
28 #include "src/core/CL/ICLKernel.h"
30 
31 namespace arm_compute
32 {
33 struct CLRsqrtLayer::Impl
34 {
35  const ICLTensor *src{ nullptr };
36  ICLTensor *dst{ nullptr };
37  std::unique_ptr<opencl::ClRsqrt> op{ nullptr };
38 };
39 
41  : _impl(std::make_unique<Impl>())
42 {
43 }
44 
47 CLRsqrtLayer::~CLRsqrtLayer() = default;
48 
50 {
51  configure(CLKernelLibrary::get().get_compile_context(), input, output);
52 }
53 
54 void CLRsqrtLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
55 {
56  _impl->src = input;
57  _impl->dst = output;
58  _impl->op = std::make_unique<opencl::ClRsqrt>();
59  _impl->op->configure(compile_context, input->info(), output->info());
60 }
61 
63 {
64  return opencl::ClRsqrt::validate(input, output);
65 }
66 
68 {
69  ITensorPack pack;
70  pack.add_tensor(TensorType::ACL_SRC, _impl->src);
71  pack.add_tensor(TensorType::ACL_DST, _impl->dst);
72  _impl->op->run(pack);
73 }
74 
75 struct CLExpLayer::Impl
76 {
77  const ICLTensor *src{ nullptr };
78  ICLTensor *dst{ nullptr };
79  std::unique_ptr<opencl::ClExp> op{ nullptr };
80 };
81 
83  : _impl(std::make_unique<Impl>())
84 {
85 }
86 
89 CLExpLayer::~CLExpLayer() = default;
90 
92 {
93  configure(CLKernelLibrary::get().get_compile_context(), input, output);
94 }
95 
96 void CLExpLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
97 {
98  _impl->src = input;
99  _impl->dst = output;
100  _impl->op = std::make_unique<opencl::ClExp>();
101  _impl->op->configure(compile_context, input->info(), output->info());
102 }
103 
105 {
106  return opencl::ClExp::validate(input, output);
107 }
108 
110 {
111  ITensorPack pack;
112  pack.add_tensor(TensorType::ACL_SRC, _impl->src);
113  pack.add_tensor(TensorType::ACL_DST, _impl->dst);
114  _impl->op->run(pack);
115 }
116 
117 struct CLNegLayer::Impl
118 {
119  const ICLTensor *src{ nullptr };
120  ICLTensor *dst{ nullptr };
121  std::unique_ptr<opencl::ClNeg> op{ nullptr };
122 };
123 
125  : _impl(std::make_unique<Impl>())
126 {
127 }
128 
129 CLNegLayer::CLNegLayer(CLNegLayer &&) = default;
131 CLNegLayer::~CLNegLayer() = default;
132 
134 {
135  configure(CLKernelLibrary::get().get_compile_context(), input, output);
136 }
137 
138 void CLNegLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
139 {
140  _impl->src = input;
141  _impl->dst = output;
142  _impl->op = std::make_unique<opencl::ClNeg>();
143  _impl->op->configure(compile_context, input->info(), output->info());
144 }
146 {
147  return opencl::ClNeg::validate(input, output);
148 }
149 
151 {
152  ITensorPack pack;
153  pack.add_tensor(TensorType::ACL_SRC, _impl->src);
154  pack.add_tensor(TensorType::ACL_DST, _impl->dst);
155  _impl->op->run(pack);
156 }
157 
158 struct CLSinLayer::Impl
159 {
160  const ICLTensor *src{ nullptr };
161  ICLTensor *dst{ nullptr };
162  std::unique_ptr<opencl::ClSin> op{ nullptr };
163 };
164 
166  : _impl(std::make_unique<Impl>())
167 {
168 }
169 
170 CLSinLayer::CLSinLayer(CLSinLayer &&) = default;
172 CLSinLayer::~CLSinLayer() = default;
173 
175 {
176  configure(CLKernelLibrary::get().get_compile_context(), input, output);
177 }
178 
179 void CLSinLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
180 {
181  _impl->src = input;
182  _impl->dst = output;
183  _impl->op = std::make_unique<opencl::ClSin>();
184  _impl->op->configure(compile_context, input->info(), output->info());
185 }
187 {
188  return opencl::ClSin::validate(input, output);
189 }
190 
192 {
193  ITensorPack pack;
194  pack.add_tensor(TensorType::ACL_SRC, _impl->src);
195  pack.add_tensor(TensorType::ACL_DST, _impl->dst);
196  _impl->op->run(pack);
197 }
198 
199 struct CLAbsLayer::Impl
200 {
201  const ICLTensor *src{ nullptr };
202  ICLTensor *dst{ nullptr };
203  std::unique_ptr<opencl::ClAbs> op{ nullptr };
204 };
205 
207  : _impl(std::make_unique<Impl>())
208 {
209 }
210 
211 CLAbsLayer::CLAbsLayer(CLAbsLayer &&) = default;
213 CLAbsLayer::~CLAbsLayer() = default;
214 
216 {
217  configure(CLKernelLibrary::get().get_compile_context(), input, output);
218 }
219 
220 void CLAbsLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
221 {
222  _impl->src = input;
223  _impl->dst = output;
224  _impl->op = std::make_unique<opencl::ClAbs>();
225  _impl->op->configure(compile_context, input->info(), output->info());
226 }
228 {
229  return opencl::ClAbs::validate(input, output);
230 }
231 
233 {
234  ITensorPack pack;
235  pack.add_tensor(TensorType::ACL_SRC, _impl->src);
236  pack.add_tensor(TensorType::ACL_DST, _impl->dst);
237  _impl->op->run(pack);
238 }
239 
240 struct CLLogLayer::Impl
241 {
242  const ICLTensor *src{ nullptr };
243  ICLTensor *dst{ nullptr };
244  std::unique_ptr<opencl::ClLog> op{ nullptr };
245 };
246 
248  : _impl(std::make_unique<Impl>())
249 {
250 }
251 
252 CLLogLayer::CLLogLayer(CLLogLayer &&) = default;
254 CLLogLayer::~CLLogLayer() = default;
255 
257 {
258  configure(CLKernelLibrary::get().get_compile_context(), input, output);
259 }
260 
261 void CLLogLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
262 {
263  _impl->src = input;
264  _impl->dst = output;
265  _impl->op = std::make_unique<opencl::ClLog>();
266  _impl->op->configure(compile_context, input->info(), output->info());
267 }
269 {
270  return opencl::ClLog::validate(input, output);
271 }
272 
274 {
275  ITensorPack pack;
276  pack.add_tensor(TensorType::ACL_SRC, _impl->src);
277  pack.add_tensor(TensorType::ACL_DST, _impl->dst);
278  _impl->op->run(pack);
279 }
280 
281 struct CLRoundLayer::Impl
282 {
283  const ICLTensor *src{ nullptr };
284  ICLTensor *dst{ nullptr };
285  std::unique_ptr<opencl::ClRound> op{ nullptr };
286 };
287 
289  : _impl(std::make_unique<Impl>())
290 {
291 }
292 
295 CLRoundLayer::~CLRoundLayer() = default;
296 
298 {
299  configure(CLKernelLibrary::get().get_compile_context(), input, output);
300 }
301 
302 void CLRoundLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
303 {
304  _impl->src = input;
305  _impl->dst = output;
306  _impl->op = std::make_unique<opencl::ClRound>();
307  _impl->op->configure(compile_context, input->info(), output->info());
308 }
310 {
311  return opencl::ClRound::validate(input, output);
312 }
313 
315 {
316  ITensorPack pack;
317  pack.add_tensor(TensorType::ACL_SRC, _impl->src);
318  pack.add_tensor(TensorType::ACL_DST, _impl->dst);
319  _impl->op->run(pack);
320 }
321 } // namespace arm_compute
Basic function to get the absolute value of an input tensor.
void run() override
Run the kernels contained in the function.
CLLogLayer & operator=(const CLLogLayer &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
CLAbsLayer & operator=(const CLAbsLayer &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLNegLayer.
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration of ClAbs.
void run() override
Run the kernels contained in the function.
Basic function to perform exponential on an input tensor.
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLRsqrtLayer.
CLSinLayer & operator=(const CLSinLayer &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
Basic function to perform inverse square root on an input tensor.
CLAbsLayer()
Default Constructor.
CLExpLayer & operator=(const CLExpLayer &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
CLRsqrtLayer & operator=(const CLRsqrtLayer &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
void configure(const ICLTensor *input, ICLTensor *output)
Initialize the function.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
~CLSinLayer()
Default Destructor.
void configure(const ICLTensor *input, ICLTensor *output)
Initialize the function.
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLAbsLayer.
Status class.
Definition: Error.h:52
Basic function to get the round (to the nearest even) value of an input tensor.
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2021 Arm Limited.
void configure(const ICLTensor *input, ICLTensor *output)
Initialize the function.
~CLExpLayer()
Default Destructor.
~CLRsqrtLayer()
Default Destructor.
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration of ClSin.
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration of ClRsqrt.
void run() override
Run the kernels contained in the function.
void run() override
Run the kernels contained in the function.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
void configure(const ICLTensor *input, ICLTensor *output)
Initialize the function.
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLExpLayer.
CLRsqrtLayer()
Default Constructor.
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLRoundLayer.
Basic function to calculate sine of an input tensor.
CLCompileContext class.
void configure(const ICLTensor *input, ICLTensor *output)
Initialize the function.
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration of ClExp.
CLNegLayer & operator=(const CLNegLayer &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLSinLayer.
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
~CLLogLayer()
Default Destructor.
CLSinLayer()
Default Constructor.
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLLogLayer.
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context...
~CLRoundLayer()
Default Destructor.
CLRoundLayer()
Default Constructor.
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration of ClRound.
CLNegLayer()
Default Constructor.
~CLNegLayer()
Default Destructor.
Basic function to negate an input tensor.
CLRoundLayer & operator=(const CLRoundLayer &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
~CLAbsLayer()
Default Destructor.
void configure(const ICLTensor *input, ICLTensor *output)
Initialize the function.
Tensor packing service.
Definition: ITensorPack.h:37
CLLogLayer()
Default Constructor.
void run() override
Run the kernels contained in the function.
void configure(const ICLTensor *input, ICLTensor *output)
Initialize the function.
CLExpLayer()
Default Constructor.
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration of ClNeg.
void run() override
Run the kernels contained in the function.
Basic function to perform elementwise log on an input tensor.
void run() override
Run the kernels contained in the function.
void add_tensor(int id, ITensor *tensor)
Add tensor to the pack.
Definition: ITensorPack.cpp:30
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration of ClLog.