blob: d186b70d937ede4de2cae7905d75d3fa4230d0d0 [file] [log] [blame]
Michalis Spyroue9362622018-11-23 17:41:37 +00001/*
Michele Di Giorgioc9c89052021-01-26 10:20:17 +00002 * Copyright (c) 2018-2021 Arm Limited.
Michalis Spyroue9362622018-11-23 17:41:37 +00003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CLELEMENTWISEUNARYLAYER_H
25#define ARM_COMPUTE_CLELEMENTWISEUNARYLAYER_H
Michalis Spyroue9362622018-11-23 17:41:37 +000026
Michele Di Giorgioc9c89052021-01-26 10:20:17 +000027#include "arm_compute/core/Types.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028#include "arm_compute/runtime/IFunction.h"
Michele Di Giorgioc9c89052021-01-26 10:20:17 +000029
30#include <memory>
Michalis Spyroue9362622018-11-23 17:41:37 +000031
32namespace arm_compute
33{
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010034class CLCompileContext;
Michalis Spyroue9362622018-11-23 17:41:37 +000035class ICLTensor;
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010036class ITensorInfo;
Michalis Spyroue9362622018-11-23 17:41:37 +000037
38/** Basic function to perform inverse square root on an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +010039class CLRsqrtLayer : public IFunction
Michalis Spyroue9362622018-11-23 17:41:37 +000040{
41public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +010042 /** Default Constructor */
43 CLRsqrtLayer();
44 /** Default Destructor */
45 ~CLRsqrtLayer();
46 /** Prevent instances of this class from being copied (As this class contains pointers) */
47 CLRsqrtLayer(const CLRsqrtLayer &) = delete;
48 /** Default move constructor */
49 CLRsqrtLayer(CLRsqrtLayer &&);
50 /** Prevent instances of this class from being copied (As this class contains pointers) */
51 CLRsqrtLayer &operator=(const CLRsqrtLayer &) = delete;
52 /** Default move assignment operator */
53 CLRsqrtLayer &operator=(CLRsqrtLayer &&);
Michalis Spyroue9362622018-11-23 17:41:37 +000054 /** Initialize the function
55 *
Sheri Zhang6124ce62021-05-04 14:03:13 +010056 * Valid data layouts:
57 * - All
58 *
59 * Valid data type configurations:
60 * |src |dst |
61 * |:--------------|:--------------|
62 * |F16 |F16 |
63 * |F32 |F32 |
64 *
Michalis Spyroue9362622018-11-23 17:41:37 +000065 * @param[in] input Input tensor. Data types supported: F16/F32.
66 * @param[out] output Output tensor. Data types supported: same as @p input.
67 */
68 void configure(const ICLTensor *input, ICLTensor *output);
Manuel Bottini2b84be52020-04-08 10:15:51 +010069 /** Initialize the function
70 *
71 * @param[in] compile_context The compile context to be used.
72 * @param[in] input Input tensor. Data types supported: F16/F32.
73 * @param[out] output Output tensor. Data types supported: same as @p input.
74 */
75 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
Michalis Spyroue9362622018-11-23 17:41:37 +000076 /** Static function to check if given info will lead to a valid configuration of @ref CLRsqrtLayer
77 *
78 * @param[in] input First tensor input info. Data types supported: F16/F32.
79 * @param[in] output Output tensor info. Data types supported: Same as @p input.
80 *
81 * @return a status
82 */
83 static Status validate(const ITensorInfo *input, const ITensorInfo *output);
Michalis Spyrouf738fe62020-07-15 18:10:17 +010084
85 // Inherited methods overridden:
86 void run() override;
87
88private:
89 struct Impl;
90 std::unique_ptr<Impl> _impl;
Michalis Spyroue9362622018-11-23 17:41:37 +000091};
92
93/** Basic function to perform exponential on an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +010094class CLExpLayer : public IFunction
Michalis Spyroue9362622018-11-23 17:41:37 +000095{
96public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +010097 /** Default Constructor */
98 CLExpLayer();
99 /** Default Destructor */
100 ~CLExpLayer();
101 /** Prevent instances of this class from being copied (As this class contains pointers) */
102 CLExpLayer(const CLExpLayer &) = delete;
103 /** Default move constructor */
104 CLExpLayer(CLExpLayer &&);
105 /** Prevent instances of this class from being copied (As this class contains pointers) */
106 CLExpLayer &operator=(const CLExpLayer &) = delete;
107 /** Default move assignment operator */
108 CLExpLayer &operator=(CLExpLayer &&);
Michalis Spyroue9362622018-11-23 17:41:37 +0000109 /** Initialize the function
110 *
Sheri Zhang6124ce62021-05-04 14:03:13 +0100111 * Valid data layouts:
112 * - All
113 *
114 * Valid data type configurations:
115 * |src |dst |
116 * |:--------------|:--------------|
117 * |F16 |F16 |
118 * |F32 |F32 |
119 *
Michalis Spyroue9362622018-11-23 17:41:37 +0000120 * @param[in] input Input tensor. Data types supported: F16/F32.
121 * @param[out] output Output tensor. Data types supported: same as @p input.
122 */
123 void configure(const ICLTensor *input, ICLTensor *output);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100124 /** Initialize the function
125 *
126 * @param[in] compile_context The compile context to be used.
127 * @param[in] input Input tensor. Data types supported: F16/F32.
128 * @param[out] output Output tensor. Data types supported: same as @p input.
129 */
130 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
Michalis Spyroue9362622018-11-23 17:41:37 +0000131 /** Static function to check if given info will lead to a valid configuration of @ref CLExpLayer
132 *
133 * @param[in] input First tensor input info. Data types supported: F16/F32.
134 * @param[in] output Output tensor info. Data types supported: Same as @p input.
135 *
136 * @return a status
137 */
138 static Status validate(const ITensorInfo *input, const ITensorInfo *output);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100139
140 // Inherited methods overridden:
141 void run() override;
142
143private:
144 struct Impl;
145 std::unique_ptr<Impl> _impl;
Michalis Spyroue9362622018-11-23 17:41:37 +0000146};
Usama Arifeb312ef2019-05-13 17:45:54 +0100147
148/** Basic function to negate an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100149class CLNegLayer : public IFunction
Usama Arifeb312ef2019-05-13 17:45:54 +0100150{
151public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100152 /** Default Constructor */
153 CLNegLayer();
154 /** Default Destructor */
155 ~CLNegLayer();
156 /** Prevent instances of this class from being copied (As this class contains pointers) */
157 CLNegLayer(const CLNegLayer &) = delete;
158 /** Default move constructor */
159 CLNegLayer(CLNegLayer &&);
160 /** Prevent instances of this class from being copied (As this class contains pointers) */
161 CLNegLayer &operator=(const CLNegLayer &) = delete;
162 /** Default move assignment operator */
163 CLNegLayer &operator=(CLNegLayer &&);
Usama Arifeb312ef2019-05-13 17:45:54 +0100164 /** Initialize the function
165 *
Sheri Zhang6124ce62021-05-04 14:03:13 +0100166 * Valid data layouts:
167 * - All
168 *
169 * Valid data type configurations:
170 * |src |dst |
171 * |:--------------|:--------------|
172 * |F16 |F16 |
173 * |F32 |F32 |
Suhail Munshiee220302021-05-06 12:43:07 +0100174 * |S32 |S32 |
Sheri Zhang6124ce62021-05-04 14:03:13 +0100175 *
Suhail Munshiee220302021-05-06 12:43:07 +0100176 * @param[in] input Input tensor. Data types supported: F16/F32/S32
Usama Arifeb312ef2019-05-13 17:45:54 +0100177 * @param[out] output Output tensor. Data types supported: same as @p input.
178 */
179 void configure(const ICLTensor *input, ICLTensor *output);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100180 /** Initialize the function
181 *
182 * @param[in] compile_context The compile context to be used.
Suhail Munshiee220302021-05-06 12:43:07 +0100183 * @param[in] input Input tensor. Data types supported: F16/F32/S32
Manuel Bottini2b84be52020-04-08 10:15:51 +0100184 * @param[out] output Output tensor. Data types supported: same as @p input.
185 */
186 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
Usama Arifeb312ef2019-05-13 17:45:54 +0100187 /** Static function to check if given info will lead to a valid configuration of @ref CLNegLayer
188 *
Suhail Munshiee220302021-05-06 12:43:07 +0100189 * @param[in] input First tensor input info. Data types supported: F16/F32/S32
Usama Arifeb312ef2019-05-13 17:45:54 +0100190 * @param[in] output Output tensor info. Data types supported: Same as @p input.
191 *
192 * @return a status
193 */
194 static Status validate(const ITensorInfo *input, const ITensorInfo *output);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100195
196 // Inherited methods overridden:
197 void run() override;
198
199private:
200 struct Impl;
201 std::unique_ptr<Impl> _impl;
Usama Arifeb312ef2019-05-13 17:45:54 +0100202};
Michalis Spyrou0af44182019-05-17 14:04:47 +0100203
204/** Basic function to calculate sine of an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100205class CLSinLayer : public IFunction
Michalis Spyrou0af44182019-05-17 14:04:47 +0100206{
207public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100208 /** Default Constructor */
209 CLSinLayer();
210 /** Default Destructor */
211 ~CLSinLayer();
212 /** Prevent instances of this class from being copied (As this class contains pointers) */
213 CLSinLayer(const CLSinLayer &) = delete;
214 /** Default move constructor */
215 CLSinLayer(CLSinLayer &&);
216 /** Prevent instances of this class from being copied (As this class contains pointers) */
217 CLSinLayer &operator=(const CLSinLayer &) = delete;
218 /** Default move assignment operator */
219 CLSinLayer &operator=(CLSinLayer &&);
Michalis Spyrou0af44182019-05-17 14:04:47 +0100220 /** Initialize the function
221 *
Sheri Zhang6124ce62021-05-04 14:03:13 +0100222 * Valid data layouts:
223 * - All
224 *
225 * Valid data type configurations:
226 * |src |dst |
227 * |:--------------|:--------------|
228 * |F16 |F16 |
229 * |F32 |F32 |
230 *
Michalis Spyrou0af44182019-05-17 14:04:47 +0100231 * @param[in] input Input tensor. Data types supported: F16/F32.
232 * @param[out] output Output tensor. Data types supported: same as @p input.
233 */
234 void configure(const ICLTensor *input, ICLTensor *output);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100235 /** Initialize the function
236 *
237 * @param[in] compile_context The compile context to be used.
238 * @param[in] input Input tensor. Data types supported: F16/F32.
239 * @param[out] output Output tensor. Data types supported: same as @p input.
240 */
241 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
Michalis Spyrou0af44182019-05-17 14:04:47 +0100242 /** Static function to check if given info will lead to a valid configuration of @ref CLSinLayer
243 *
244 * @param[in] input First tensor input info. Data types supported: F16/F32.
245 * @param[in] output Output tensor info. Data types supported: Same as @p input.
246 *
247 * @return a status
248 */
249 static Status validate(const ITensorInfo *input, const ITensorInfo *output);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100250
251 // Inherited methods overridden:
252 void run() override;
253
254private:
255 struct Impl;
256 std::unique_ptr<Impl> _impl;
Michalis Spyrou0af44182019-05-17 14:04:47 +0100257};
giuros01f24411f2019-05-16 11:47:13 +0100258
Usama Arifac33d7e2019-05-20 14:21:40 +0100259/** Basic function to perform elementwise log on an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100260class CLLogLayer : public IFunction
Usama Arifac33d7e2019-05-20 14:21:40 +0100261{
262public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100263 /** Default Constructor */
264 CLLogLayer();
265 /** Default Destructor */
266 ~CLLogLayer();
267 /** Prevent instances of this class from being copied (As this class contains pointers) */
268 CLLogLayer(const CLLogLayer &) = delete;
269 /** Default move constructor */
270 CLLogLayer(CLLogLayer &&);
271 /** Prevent instances of this class from being copied (As this class contains pointers) */
272 CLLogLayer &operator=(const CLLogLayer &) = delete;
273 /** Default move assignment operator */
274 CLLogLayer &operator=(CLLogLayer &&);
Usama Arifac33d7e2019-05-20 14:21:40 +0100275 /** Initialize the function
276 *
Sheri Zhang6124ce62021-05-04 14:03:13 +0100277 * Valid data layouts:
278 * - All
279 *
280 * Valid data type configurations:
281 * |src |dst |
282 * |:--------------|:--------------|
283 * |F16 |F16 |
284 * |F32 |F32 |
285 *
Usama Arifac33d7e2019-05-20 14:21:40 +0100286 * @param[in] input Input tensor. Data types supported: F16/F32.
287 * @param[out] output Output tensor. Data types supported: same as @p input.
288 */
289 void configure(const ICLTensor *input, ICLTensor *output);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100290 /** Initialize the function
291 *
292 * @param[in] compile_context The compile context to be used.
293 * @param[in] input Input tensor. Data types supported: F16/F32.
294 * @param[out] output Output tensor. Data types supported: same as @p input.
295 */
296 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
Usama Arifac33d7e2019-05-20 14:21:40 +0100297 /** Static function to check if given info will lead to a valid configuration of @ref CLLogLayer
298 *
299 * @param[in] input First tensor input info. Data types supported: F16/F32.
300 * @param[in] output Output tensor info. Data types supported: Same as @p input.
301 *
302 * @return a status
303 */
304 static Status validate(const ITensorInfo *input, const ITensorInfo *output);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100305
306 // Inherited methods overridden:
307 void run() override;
308
309private:
310 struct Impl;
311 std::unique_ptr<Impl> _impl;
Usama Arifac33d7e2019-05-20 14:21:40 +0100312};
313
giuros01f24411f2019-05-16 11:47:13 +0100314/** Basic function to get the absolute value of an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100315class CLAbsLayer : public IFunction
giuros01f24411f2019-05-16 11:47:13 +0100316{
317public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100318 /** Default Constructor */
319 CLAbsLayer();
320 /** Default Destructor */
321 ~CLAbsLayer();
322 /** Prevent instances of this class from being copied (As this class contains pointers) */
323 CLAbsLayer(const CLAbsLayer &) = delete;
324 /** Default move constructor */
325 CLAbsLayer(CLAbsLayer &&);
326 /** Prevent instances of this class from being copied (As this class contains pointers) */
327 CLAbsLayer &operator=(const CLAbsLayer &) = delete;
328 /** Default move assignment operator */
329 CLAbsLayer &operator=(CLAbsLayer &&);
giuros01f24411f2019-05-16 11:47:13 +0100330 /** Initialize the function
331 *
Sheri Zhang6124ce62021-05-04 14:03:13 +0100332 * Valid data layouts:
333 * - All
334 *
335 * Valid data type configurations:
336 * |src |dst |
337 * |:--------------|:--------------|
338 * |F16 |F16 |
339 * |F32 |F32 |
340 *
giuros01f24411f2019-05-16 11:47:13 +0100341 * @param[in] input Input tensor. Data types supported: F16/F32.
342 * @param[out] output Output tensor. Data types supported: same as @p input.
343 */
344 void configure(const ICLTensor *input, ICLTensor *output);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100345 /** Initialize the function
346 *
347 * @param[in] compile_context The compile context to be used.
348 * @param[in] input Input tensor. Data types supported: F16/F32.
349 * @param[out] output Output tensor. Data types supported: same as @p input.
350 */
351 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
giuros01f24411f2019-05-16 11:47:13 +0100352 /** Static function to check if given info will lead to a valid configuration of @ref CLAbsLayer
353 *
354 * @param[in] input First tensor input info. Data types supported: F16/F32.
355 * @param[in] output Output tensor info. Data types supported: Same as @p input.
356 *
357 * @return a status
358 */
359 static Status validate(const ITensorInfo *input, const ITensorInfo *output);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100360
361 // Inherited methods overridden:
362 void run() override;
363
364private:
365 struct Impl;
366 std::unique_ptr<Impl> _impl;
giuros01f24411f2019-05-16 11:47:13 +0100367};
Usama Arif6a4d5422019-05-24 14:53:59 +0100368
369/** Basic function to get the round (to the nearest even) value of an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100370class CLRoundLayer : public IFunction
Usama Arif6a4d5422019-05-24 14:53:59 +0100371{
372public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100373 /** Default Constructor */
374 CLRoundLayer();
375 /** Default Destructor */
376 ~CLRoundLayer();
377 /** Prevent instances of this class from being copied (As this class contains pointers) */
378 CLRoundLayer(const CLRoundLayer &) = delete;
379 /** Default move constructor */
380 CLRoundLayer(CLRoundLayer &&);
381 /** Prevent instances of this class from being copied (As this class contains pointers) */
382 CLRoundLayer &operator=(const CLRoundLayer &) = delete;
383 /** Default move assignment operator */
384 CLRoundLayer &operator=(CLRoundLayer &&);
Usama Arif6a4d5422019-05-24 14:53:59 +0100385 /** Initialize the function
386 *
Sheri Zhang6124ce62021-05-04 14:03:13 +0100387 * Valid data layouts:
388 * - All
389 *
390 * Valid data type configurations:
391 * |src |dst |
392 * |:--------------|:--------------|
393 * |F16 |F16 |
394 * |F32 |F32 |
395 *
Usama Arif6a4d5422019-05-24 14:53:59 +0100396 * @param[in] input Input tensor. Data types supported: F16/F32.
397 * @param[out] output Output tensor. Data types supported: same as @p input.
398 */
399 void configure(const ICLTensor *input, ICLTensor *output);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100400 /** Initialize the function
401 *
402 * @param[in] compile_context The compile context to be used.
403 * @param[in] input Input tensor. Data types supported: F16/F32.
404 * @param[out] output Output tensor. Data types supported: same as @p input.
405 */
406 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output);
Usama Arif6a4d5422019-05-24 14:53:59 +0100407 /** Static function to check if given info will lead to a valid configuration of @ref CLRoundLayer
408 *
409 * @param[in] input First tensor input info. Data types supported: F16/F32.
410 * @param[in] output Output tensor info. Data types supported: Same as @p input.
411 *
412 * @return a status
413 */
414 static Status validate(const ITensorInfo *input, const ITensorInfo *output);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100415
416 // Inherited methods overridden:
417 void run() override;
418
419private:
420 struct Impl;
421 std::unique_ptr<Impl> _impl;
Usama Arif6a4d5422019-05-24 14:53:59 +0100422};
Michalis Spyroue9362622018-11-23 17:41:37 +0000423} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000424#endif /* ARM_COMPUTE_CLELEMENTWISEUNARYLAYER_H */