blob: 594ee4cfdcfbb1df2fcf8d77c23ce23f9d1b336d [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/runtime/IFunction.h"
28
29#include "arm_compute/core/Types.h"
30
31#include <memory>
Michalis Spyroue9362622018-11-23 17:41:37 +000032
33namespace arm_compute
34{
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010035class CLCompileContext;
Michalis Spyroue9362622018-11-23 17:41:37 +000036class ICLTensor;
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010037class ITensorInfo;
Michalis Spyroue9362622018-11-23 17:41:37 +000038
39/** Basic function to perform inverse square root on an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +010040class CLRsqrtLayer : public IFunction
Michalis Spyroue9362622018-11-23 17:41:37 +000041{
42public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +010043 /** 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 */
50 CLRsqrtLayer(CLRsqrtLayer &&);
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 */
54 CLRsqrtLayer &operator=(CLRsqrtLayer &&);
Michalis Spyroue9362622018-11-23 17:41:37 +000055 /** Initialize the function
56 *
Sheri Zhang6124ce62021-05-04 14:03:13 +010057 * Valid data layouts:
58 * - All
59 *
60 * Valid data type configurations:
61 * |src |dst |
62 * |:--------------|:--------------|
63 * |F16 |F16 |
64 * |F32 |F32 |
65 *
Michalis Spyroue9362622018-11-23 17:41:37 +000066 * @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);
Manuel Bottini2b84be52020-04-08 10:15:51 +010070 /** 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);
Michalis Spyroue9362622018-11-23 17:41:37 +000077 /** 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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +010085
86 // Inherited methods overridden:
87 void run() override;
88
89private:
90 struct Impl;
91 std::unique_ptr<Impl> _impl;
Michalis Spyroue9362622018-11-23 17:41:37 +000092};
93
94/** Basic function to perform exponential on an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +010095class CLExpLayer : public IFunction
Michalis Spyroue9362622018-11-23 17:41:37 +000096{
97public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +010098 /** 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 */
105 CLExpLayer(CLExpLayer &&);
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 */
109 CLExpLayer &operator=(CLExpLayer &&);
Michalis Spyroue9362622018-11-23 17:41:37 +0000110 /** Initialize the function
111 *
Sheri Zhang6124ce62021-05-04 14:03:13 +0100112 * Valid data layouts:
113 * - All
114 *
115 * Valid data type configurations:
116 * |src |dst |
117 * |:--------------|:--------------|
118 * |F16 |F16 |
119 * |F32 |F32 |
120 *
Michalis Spyroue9362622018-11-23 17:41:37 +0000121 * @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);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100125 /** 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);
Michalis Spyroue9362622018-11-23 17:41:37 +0000132 /** 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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100140
141 // Inherited methods overridden:
142 void run() override;
143
144private:
145 struct Impl;
146 std::unique_ptr<Impl> _impl;
Michalis Spyroue9362622018-11-23 17:41:37 +0000147};
Usama Arifeb312ef2019-05-13 17:45:54 +0100148
149/** Basic function to negate an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100150class CLNegLayer : public IFunction
Usama Arifeb312ef2019-05-13 17:45:54 +0100151{
152public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100153 /** 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 */
160 CLNegLayer(CLNegLayer &&);
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 */
164 CLNegLayer &operator=(CLNegLayer &&);
Usama Arifeb312ef2019-05-13 17:45:54 +0100165 /** Initialize the function
166 *
Sheri Zhang6124ce62021-05-04 14:03:13 +0100167 * Valid data layouts:
168 * - All
169 *
170 * Valid data type configurations:
171 * |src |dst |
172 * |:--------------|:--------------|
173 * |F16 |F16 |
174 * |F32 |F32 |
Suhail Munshiee220302021-05-06 12:43:07 +0100175 * |S32 |S32 |
Sheri Zhang6124ce62021-05-04 14:03:13 +0100176 *
Suhail Munshiee220302021-05-06 12:43:07 +0100177 * @param[in] input Input tensor. Data types supported: F16/F32/S32
Usama Arifeb312ef2019-05-13 17:45:54 +0100178 * @param[out] output Output tensor. Data types supported: same as @p input.
179 */
180 void configure(const ICLTensor *input, ICLTensor *output);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100181 /** Initialize the function
182 *
183 * @param[in] compile_context The compile context to be used.
Suhail Munshiee220302021-05-06 12:43:07 +0100184 * @param[in] input Input tensor. Data types supported: F16/F32/S32
Manuel Bottini2b84be52020-04-08 10:15:51 +0100185 * @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);
Usama Arifeb312ef2019-05-13 17:45:54 +0100188 /** Static function to check if given info will lead to a valid configuration of @ref CLNegLayer
189 *
Suhail Munshiee220302021-05-06 12:43:07 +0100190 * @param[in] input First tensor input info. Data types supported: F16/F32/S32
Usama Arifeb312ef2019-05-13 17:45:54 +0100191 * @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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100196
197 // Inherited methods overridden:
198 void run() override;
199
200private:
201 struct Impl;
202 std::unique_ptr<Impl> _impl;
Usama Arifeb312ef2019-05-13 17:45:54 +0100203};
Michalis Spyrou0af44182019-05-17 14:04:47 +0100204
205/** Basic function to calculate sine of an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100206class CLSinLayer : public IFunction
Michalis Spyrou0af44182019-05-17 14:04:47 +0100207{
208public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100209 /** 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 */
216 CLSinLayer(CLSinLayer &&);
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 */
220 CLSinLayer &operator=(CLSinLayer &&);
Michalis Spyrou0af44182019-05-17 14:04:47 +0100221 /** Initialize the function
222 *
Sheri Zhang6124ce62021-05-04 14:03:13 +0100223 * Valid data layouts:
224 * - All
225 *
226 * Valid data type configurations:
227 * |src |dst |
228 * |:--------------|:--------------|
229 * |F16 |F16 |
230 * |F32 |F32 |
231 *
Michalis Spyrou0af44182019-05-17 14:04:47 +0100232 * @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);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100236 /** 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);
Michalis Spyrou0af44182019-05-17 14:04:47 +0100243 /** 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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100251
252 // Inherited methods overridden:
253 void run() override;
254
255private:
256 struct Impl;
257 std::unique_ptr<Impl> _impl;
Michalis Spyrou0af44182019-05-17 14:04:47 +0100258};
giuros01f24411f2019-05-16 11:47:13 +0100259
Usama Arifac33d7e2019-05-20 14:21:40 +0100260/** Basic function to perform elementwise log on an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100261class CLLogLayer : public IFunction
Usama Arifac33d7e2019-05-20 14:21:40 +0100262{
263public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100264 /** 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 */
271 CLLogLayer(CLLogLayer &&);
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 */
275 CLLogLayer &operator=(CLLogLayer &&);
Usama Arifac33d7e2019-05-20 14:21:40 +0100276 /** Initialize the function
277 *
Sheri Zhang6124ce62021-05-04 14:03:13 +0100278 * Valid data layouts:
279 * - All
280 *
281 * Valid data type configurations:
282 * |src |dst |
283 * |:--------------|:--------------|
284 * |F16 |F16 |
285 * |F32 |F32 |
286 *
Usama Arifac33d7e2019-05-20 14:21:40 +0100287 * @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);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100291 /** 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);
Usama Arifac33d7e2019-05-20 14:21:40 +0100298 /** 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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100306
307 // Inherited methods overridden:
308 void run() override;
309
310private:
311 struct Impl;
312 std::unique_ptr<Impl> _impl;
Usama Arifac33d7e2019-05-20 14:21:40 +0100313};
314
giuros01f24411f2019-05-16 11:47:13 +0100315/** Basic function to get the absolute value of an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100316class CLAbsLayer : public IFunction
giuros01f24411f2019-05-16 11:47:13 +0100317{
318public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100319 /** 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 */
326 CLAbsLayer(CLAbsLayer &&);
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 */
330 CLAbsLayer &operator=(CLAbsLayer &&);
giuros01f24411f2019-05-16 11:47:13 +0100331 /** Initialize the function
332 *
Sheri Zhang6124ce62021-05-04 14:03:13 +0100333 * Valid data layouts:
334 * - All
335 *
336 * Valid data type configurations:
337 * |src |dst |
338 * |:--------------|:--------------|
339 * |F16 |F16 |
340 * |F32 |F32 |
341 *
giuros01f24411f2019-05-16 11:47:13 +0100342 * @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);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100346 /** 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);
giuros01f24411f2019-05-16 11:47:13 +0100353 /** 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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100361
362 // Inherited methods overridden:
363 void run() override;
364
365private:
366 struct Impl;
367 std::unique_ptr<Impl> _impl;
giuros01f24411f2019-05-16 11:47:13 +0100368};
Usama Arif6a4d5422019-05-24 14:53:59 +0100369
370/** Basic function to get the round (to the nearest even) value of an input tensor. */
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100371class CLRoundLayer : public IFunction
Usama Arif6a4d5422019-05-24 14:53:59 +0100372{
373public:
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100374 /** 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 */
381 CLRoundLayer(CLRoundLayer &&);
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 */
385 CLRoundLayer &operator=(CLRoundLayer &&);
Usama Arif6a4d5422019-05-24 14:53:59 +0100386 /** Initialize the function
387 *
Sheri Zhang6124ce62021-05-04 14:03:13 +0100388 * Valid data layouts:
389 * - All
390 *
391 * Valid data type configurations:
392 * |src |dst |
393 * |:--------------|:--------------|
394 * |F16 |F16 |
395 * |F32 |F32 |
396 *
Usama Arif6a4d5422019-05-24 14:53:59 +0100397 * @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);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100401 /** 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);
Usama Arif6a4d5422019-05-24 14:53:59 +0100408 /** 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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100416
417 // Inherited methods overridden:
418 void run() override;
419
420private:
421 struct Impl;
422 std::unique_ptr<Impl> _impl;
Usama Arif6a4d5422019-05-24 14:53:59 +0100423};
Michalis Spyroue9362622018-11-23 17:41:37 +0000424} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000425#endif /* ARM_COMPUTE_CLELEMENTWISEUNARYLAYER_H */