Compute Library
 22.05
CLElementwiseUnaryLayer.h
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  */
24 #ifndef ARM_COMPUTE_CLELEMENTWISEUNARYLAYER_H
25 #define ARM_COMPUTE_CLELEMENTWISEUNARYLAYER_H
26 
28 
29 #include "arm_compute/core/Types.h"
30 
31 #include <memory>
32 
33 namespace arm_compute
34 {
35 class CLCompileContext;
36 class ICLTensor;
37 class ITensorInfo;
38 
39 /** Basic function to perform inverse square root on an input tensor. */
40 class CLRsqrtLayer : public IFunction
41 {
42 public:
43  /** Default Constructor */
44  CLRsqrtLayer();
45  /** Default Destructor */
46  ~CLRsqrtLayer();
47  /** Prevent instances of this class from being copied (As this class contains pointers) */
48  CLRsqrtLayer(const CLRsqrtLayer &) = delete;
49  /** Default move constructor */
51  /** Prevent instances of this class from being copied (As this class contains pointers) */
52  CLRsqrtLayer &operator=(const CLRsqrtLayer &) = delete;
53  /** Default move assignment operator */
55  /** Initialize the function
56  *
57  * Valid data layouts:
58  * - All
59  *
60  * Valid data type configurations:
61  * |src |dst |
62  * |:--------------|:--------------|
63  * |F16 |F16 |
64  * |F32 |F32 |
65  *
66  * @param[in] input Input tensor. Data types supported: F16/F32.
67  * @param[out] output Output tensor. Data types supported: same as @p input.
68  */
69  void configure(const ICLTensor *input, ICLTensor *output);
70  /** Initialize the function
71  *
72  * @param[in] compile_context The compile context to be used.
73  * @param[in] input Input tensor. Data types supported: F16/F32.
74  * @param[out] output Output tensor. Data types supported: same as @p input.
75  */
76  void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
77  /** Static function to check if given info will lead to a valid configuration of @ref CLRsqrtLayer
78  *
79  * @param[in] input First tensor input info. Data types supported: F16/F32.
80  * @param[in] output Output tensor info. Data types supported: Same as @p input.
81  *
82  * @return a status
83  */
84  static Status validate(const ITensorInfo *input, const ITensorInfo *output);
85 
86  // Inherited methods overridden:
87  void run() override;
88 
89 private:
90  struct Impl;
91  std::unique_ptr<Impl> _impl;
92 };
93 
94 /** Basic function to perform exponential on an input tensor. */
95 class CLExpLayer : public IFunction
96 {
97 public:
98  /** Default Constructor */
99  CLExpLayer();
100  /** Default Destructor */
101  ~CLExpLayer();
102  /** Prevent instances of this class from being copied (As this class contains pointers) */
103  CLExpLayer(const CLExpLayer &) = delete;
104  /** Default move constructor */
106  /** Prevent instances of this class from being copied (As this class contains pointers) */
107  CLExpLayer &operator=(const CLExpLayer &) = delete;
108  /** Default move assignment operator */
110  /** Initialize the function
111  *
112  * Valid data layouts:
113  * - All
114  *
115  * Valid data type configurations:
116  * |src |dst |
117  * |:--------------|:--------------|
118  * |F16 |F16 |
119  * |F32 |F32 |
120  *
121  * @param[in] input Input tensor. Data types supported: F16/F32.
122  * @param[out] output Output tensor. Data types supported: same as @p input.
123  */
124  void configure(const ICLTensor *input, ICLTensor *output);
125  /** Initialize the function
126  *
127  * @param[in] compile_context The compile context to be used.
128  * @param[in] input Input tensor. Data types supported: F16/F32.
129  * @param[out] output Output tensor. Data types supported: same as @p input.
130  */
131  void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
132  /** Static function to check if given info will lead to a valid configuration of @ref CLExpLayer
133  *
134  * @param[in] input First tensor input info. Data types supported: F16/F32.
135  * @param[in] output Output tensor info. Data types supported: Same as @p input.
136  *
137  * @return a status
138  */
139  static Status validate(const ITensorInfo *input, const ITensorInfo *output);
140 
141  // Inherited methods overridden:
142  void run() override;
143 
144 private:
145  struct Impl;
146  std::unique_ptr<Impl> _impl;
147 };
148 
149 /** Basic function to negate an input tensor. */
150 class CLNegLayer : public IFunction
151 {
152 public:
153  /** Default Constructor */
154  CLNegLayer();
155  /** Default Destructor */
156  ~CLNegLayer();
157  /** Prevent instances of this class from being copied (As this class contains pointers) */
158  CLNegLayer(const CLNegLayer &) = delete;
159  /** Default move constructor */
161  /** Prevent instances of this class from being copied (As this class contains pointers) */
162  CLNegLayer &operator=(const CLNegLayer &) = delete;
163  /** Default move assignment operator */
165  /** Initialize the function
166  *
167  * Valid data layouts:
168  * - All
169  *
170  * Valid data type configurations:
171  * |src |dst |
172  * |:--------------|:--------------|
173  * |F16 |F16 |
174  * |F32 |F32 |
175  * |S32 |S32 |
176  *
177  * @param[in] input Input tensor. Data types supported: F16/F32/S32
178  * @param[out] output Output tensor. Data types supported: same as @p input.
179  */
180  void configure(const ICLTensor *input, ICLTensor *output);
181  /** Initialize the function
182  *
183  * @param[in] compile_context The compile context to be used.
184  * @param[in] input Input tensor. Data types supported: F16/F32/S32
185  * @param[out] output Output tensor. Data types supported: same as @p input.
186  */
187  void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
188  /** Static function to check if given info will lead to a valid configuration of @ref CLNegLayer
189  *
190  * @param[in] input First tensor input info. Data types supported: F16/F32/S32
191  * @param[in] output Output tensor info. Data types supported: Same as @p input.
192  *
193  * @return a status
194  */
195  static Status validate(const ITensorInfo *input, const ITensorInfo *output);
196 
197  // Inherited methods overridden:
198  void run() override;
199 
200 private:
201  struct Impl;
202  std::unique_ptr<Impl> _impl;
203 };
204 
205 /** Basic function to calculate sine of an input tensor. */
206 class CLSinLayer : public IFunction
207 {
208 public:
209  /** Default Constructor */
210  CLSinLayer();
211  /** Default Destructor */
212  ~CLSinLayer();
213  /** Prevent instances of this class from being copied (As this class contains pointers) */
214  CLSinLayer(const CLSinLayer &) = delete;
215  /** Default move constructor */
217  /** Prevent instances of this class from being copied (As this class contains pointers) */
218  CLSinLayer &operator=(const CLSinLayer &) = delete;
219  /** Default move assignment operator */
221  /** Initialize the function
222  *
223  * Valid data layouts:
224  * - All
225  *
226  * Valid data type configurations:
227  * |src |dst |
228  * |:--------------|:--------------|
229  * |F16 |F16 |
230  * |F32 |F32 |
231  *
232  * @param[in] input Input tensor. Data types supported: F16/F32.
233  * @param[out] output Output tensor. Data types supported: same as @p input.
234  */
235  void configure(const ICLTensor *input, ICLTensor *output);
236  /** Initialize the function
237  *
238  * @param[in] compile_context The compile context to be used.
239  * @param[in] input Input tensor. Data types supported: F16/F32.
240  * @param[out] output Output tensor. Data types supported: same as @p input.
241  */
242  void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
243  /** Static function to check if given info will lead to a valid configuration of @ref CLSinLayer
244  *
245  * @param[in] input First tensor input info. Data types supported: F16/F32.
246  * @param[in] output Output tensor info. Data types supported: Same as @p input.
247  *
248  * @return a status
249  */
250  static Status validate(const ITensorInfo *input, const ITensorInfo *output);
251 
252  // Inherited methods overridden:
253  void run() override;
254 
255 private:
256  struct Impl;
257  std::unique_ptr<Impl> _impl;
258 };
259 
260 /** Basic function to perform elementwise log on an input tensor. */
261 class CLLogLayer : public IFunction
262 {
263 public:
264  /** Default Constructor */
265  CLLogLayer();
266  /** Default Destructor */
267  ~CLLogLayer();
268  /** Prevent instances of this class from being copied (As this class contains pointers) */
269  CLLogLayer(const CLLogLayer &) = delete;
270  /** Default move constructor */
272  /** Prevent instances of this class from being copied (As this class contains pointers) */
273  CLLogLayer &operator=(const CLLogLayer &) = delete;
274  /** Default move assignment operator */
276  /** Initialize the function
277  *
278  * Valid data layouts:
279  * - All
280  *
281  * Valid data type configurations:
282  * |src |dst |
283  * |:--------------|:--------------|
284  * |F16 |F16 |
285  * |F32 |F32 |
286  *
287  * @param[in] input Input tensor. Data types supported: F16/F32.
288  * @param[out] output Output tensor. Data types supported: same as @p input.
289  */
290  void configure(const ICLTensor *input, ICLTensor *output);
291  /** Initialize the function
292  *
293  * @param[in] compile_context The compile context to be used.
294  * @param[in] input Input tensor. Data types supported: F16/F32.
295  * @param[out] output Output tensor. Data types supported: same as @p input.
296  */
297  void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
298  /** Static function to check if given info will lead to a valid configuration of @ref CLLogLayer
299  *
300  * @param[in] input First tensor input info. Data types supported: F16/F32.
301  * @param[in] output Output tensor info. Data types supported: Same as @p input.
302  *
303  * @return a status
304  */
305  static Status validate(const ITensorInfo *input, const ITensorInfo *output);
306 
307  // Inherited methods overridden:
308  void run() override;
309 
310 private:
311  struct Impl;
312  std::unique_ptr<Impl> _impl;
313 };
314 
315 /** Basic function to get the absolute value of an input tensor. */
316 class CLAbsLayer : public IFunction
317 {
318 public:
319  /** Default Constructor */
320  CLAbsLayer();
321  /** Default Destructor */
322  ~CLAbsLayer();
323  /** Prevent instances of this class from being copied (As this class contains pointers) */
324  CLAbsLayer(const CLAbsLayer &) = delete;
325  /** Default move constructor */
327  /** Prevent instances of this class from being copied (As this class contains pointers) */
328  CLAbsLayer &operator=(const CLAbsLayer &) = delete;
329  /** Default move assignment operator */
331  /** Initialize the function
332  *
333  * Valid data layouts:
334  * - All
335  *
336  * Valid data type configurations:
337  * |src |dst |
338  * |:--------------|:--------------|
339  * |F16 |F16 |
340  * |F32 |F32 |
341  *
342  * @param[in] input Input tensor. Data types supported: F16/F32.
343  * @param[out] output Output tensor. Data types supported: same as @p input.
344  */
345  void configure(const ICLTensor *input, ICLTensor *output);
346  /** Initialize the function
347  *
348  * @param[in] compile_context The compile context to be used.
349  * @param[in] input Input tensor. Data types supported: F16/F32.
350  * @param[out] output Output tensor. Data types supported: same as @p input.
351  */
352  void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
353  /** Static function to check if given info will lead to a valid configuration of @ref CLAbsLayer
354  *
355  * @param[in] input First tensor input info. Data types supported: F16/F32.
356  * @param[in] output Output tensor info. Data types supported: Same as @p input.
357  *
358  * @return a status
359  */
360  static Status validate(const ITensorInfo *input, const ITensorInfo *output);
361 
362  // Inherited methods overridden:
363  void run() override;
364 
365 private:
366  struct Impl;
367  std::unique_ptr<Impl> _impl;
368 };
369 
370 /** Basic function to get the round (to the nearest even) value of an input tensor. */
371 class CLRoundLayer : public IFunction
372 {
373 public:
374  /** Default Constructor */
375  CLRoundLayer();
376  /** Default Destructor */
377  ~CLRoundLayer();
378  /** Prevent instances of this class from being copied (As this class contains pointers) */
379  CLRoundLayer(const CLRoundLayer &) = delete;
380  /** Default move constructor */
382  /** Prevent instances of this class from being copied (As this class contains pointers) */
383  CLRoundLayer &operator=(const CLRoundLayer &) = delete;
384  /** Default move assignment operator */
386  /** Initialize the function
387  *
388  * Valid data layouts:
389  * - All
390  *
391  * Valid data type configurations:
392  * |src |dst |
393  * |:--------------|:--------------|
394  * |F16 |F16 |
395  * |F32 |F32 |
396  *
397  * @param[in] input Input tensor. Data types supported: F16/F32.
398  * @param[out] output Output tensor. Data types supported: same as @p input.
399  */
400  void configure(const ICLTensor *input, ICLTensor *output);
401  /** Initialize the function
402  *
403  * @param[in] compile_context The compile context to be used.
404  * @param[in] input Input tensor. Data types supported: F16/F32.
405  * @param[out] output Output tensor. Data types supported: same as @p input.
406  */
407  void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
408  /** Static function to check if given info will lead to a valid configuration of @ref CLRoundLayer
409  *
410  * @param[in] input First tensor input info. Data types supported: F16/F32.
411  * @param[in] output Output tensor info. Data types supported: Same as @p input.
412  *
413  * @return a status
414  */
415  static Status validate(const ITensorInfo *input, const ITensorInfo *output);
416 
417  // Inherited methods overridden:
418  void run() override;
419 
420 private:
421  struct Impl;
422  std::unique_ptr<Impl> _impl;
423 };
424 } // namespace arm_compute
425 #endif /* ARM_COMPUTE_CLELEMENTWISEUNARYLAYER_H */
Basic function to get the absolute value of an input tensor.
void run() override
Run the kernels contained in the function.
Base class for all functions.
Definition: IFunction.h:30
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.
Basic function to perform inverse square root on an input tensor.
CLRsqrtLayer & operator=(const CLRsqrtLayer &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
Basic function to get the round (to the nearest even) value of an input tensor.
Copyright (c) 2017-2022 Arm Limited.
~CLRsqrtLayer()
Default Destructor.
CLRsqrtLayer()
Default Constructor.
Basic function to calculate sine of an input tensor.
CLCompileContext class.
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
Basic function to negate an input tensor.
void configure(const ICLTensor *input, ICLTensor *output)
Initialize the function.
Basic function to perform elementwise log on an input tensor.