Compute Library
 21.02
NEElementwiseOperations.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_NEELEMENTWISEOPERATIONS_H
25 #define ARM_COMPUTE_NEELEMENTWISEOPERATIONS_H
26 
27 #include "arm_compute/core/Types.h"
30 
31 namespace arm_compute
32 {
33 class ITensor;
34 
35 /** Basic function to run @ref cpu::kernels::CpuArithmeticKernel for max
36  *
37  * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
38  * @note The function performs a max operation between two tensors.
39  */
41 {
42 public:
43  /** Default Constructor */
45  /** Default Destructor */
47  /** Prevent instances of this class from being copied (As this class contains pointers) */
48  NEElementwiseMax(const NEElementwiseMax &) = delete;
49  /** Default move constructor */
51  /** Prevent instances of this class from being copied (As this class contains pointers) */
52  NEElementwiseMax &operator=(const NEElementwiseMax &) = delete;
53  /** Default move assignment operator */
55  /** Initialise the kernel's inputs, output and conversion policy.
56  *
57  * @param[in, out] input1 First tensor input. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
58  * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1.
59  * @param[out] output Output tensor. Data types supported: Same as @p input1.
60  * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
61  */
62  void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
63  /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuArithmeticKernel for max
64  *
65  * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
66  * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
67  * @param[in] output Output tensor info. Data types supported: Same as @p input1.
68  * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
69  *
70  * @return a status
71  */
72  static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
73 
74  // Inherited methods overridden:
75  void run() override;
76 
77 private:
78  struct Impl;
79  std::unique_ptr<Impl> _impl;
80 };
81 
82 /** Basic function to run @ref cpu::kernels::CpuArithmeticKernel for min
83  *
84  * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
85  * @note The function performs a min operation between two tensors.
86  */
88 {
89 public:
90  /** Default Constructor */
92  /** Default Destructor */
94  /** Prevent instances of this class from being copied (As this class contains pointers) */
95  NEElementwiseMin(const NEElementwiseMin &) = delete;
96  /** Default move constructor */
98  /** Prevent instances of this class from being copied (As this class contains pointers) */
99  NEElementwiseMin &operator=(const NEElementwiseMin &) = delete;
100  /** Default move assignment operator */
102  /** Initialise the kernel's inputs, output and conversion policy.
103  *
104  * @param[in, out] input1 First tensor input. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
105  * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1.
106  * @param[out] output Output tensor. Data types supported: Same as @p input1.
107  * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
108  */
109  void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
110  /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuArithmeticKernel for min
111  *
112  * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
113  * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
114  * @param[in] output Output tensor info. Data types supported: Same as @p input1.
115  * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
116  *
117  * @return a status
118  */
119  static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
120 
121  // Inherited methods overridden:
122  void run() override;
123 
124 private:
125  struct Impl;
126  std::unique_ptr<Impl> _impl;
127 };
128 
129 /** Basic function to run @ref cpu::kernels::CpuArithmeticKernel for squared difference
130  *
131  * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
132  * @note The function performs a squared different operation between two tensors (i.e., out[i] = (in1[i] - in2[i])^2
133  */
135 {
136 public:
137  /** Default Constructor */
139  /** Default Destructor */
141  /** Prevent instances of this class from being copied (As this class contains pointers) */
143  /** Default move constructor */
145  /** Prevent instances of this class from being copied (As this class contains pointers) */
147  /** Default move assignment operator */
149  /** Initialise the kernel's inputs, output and conversion policy.
150  *
151  * @param[in, out] input1 First tensor input. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
152  * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1.
153  * @param[out] output Output tensor. Data types supported: Same as @p input1.
154  * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
155  */
156  void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
157  /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuArithmeticKernel for squared difference
158  *
159  * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
160  * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
161  * @param[in] output Output tensor info. Data types supported: Same as @p input1.
162  * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
163  *
164  * @return a status
165  */
166  static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
167 
168  // Inherited methods overridden:
169  void run() override;
170 
171 private:
172  struct Impl;
173  std::unique_ptr<Impl> _impl;
174 };
175 
176 /** Basic function to run @ref cpu::kernels::CpuArithmeticKernel for division
177  *
178  * @note The tensor data type for the inputs must be F16/F32.
179  * @note The function performs a squared different operation between two tensors (i.e., out[i] = in1[i] / in2[i])
180  */
182 {
183 public:
184  /** Default Constructor */
186  /** Default Destructor */
188  /** Prevent instances of this class from being copied (As this class contains pointers) */
190  /** Default move constructor */
192  /** Prevent instances of this class from being copied (As this class contains pointers) */
194  /** Default move assignment operator */
196  /** Initialise the kernel's inputs, output and conversion policy.
197  *
198  * @param[in, out] input1 First tensor input. Data types supported: F16/F32.
199  * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1.
200  * @param[out] output Output tensor. Data types supported: Same as @p input1.
201  * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
202  */
203  void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
204  /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuArithmeticKernel for division
205  *
206  * @param[in] input1 First tensor input info. Data types supported: F16/F32.
207  * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
208  * @param[in] output Output tensor info. Data types supported: Same as @p input1.
209  * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
210  *
211  * @return a status
212  */
213  static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
214 
215  // Inherited methods overridden:
216  void run() override;
217 
218 private:
219  struct Impl;
220  std::unique_ptr<Impl> _impl;
221 };
222 
223 /** Basic function to run @ref cpu::kernels::CpuArithmeticKernel for power
224  *
225  * @note The tensor data type for the inputs must be F16/F32.
226  * @note The function performs a elementwise power of in1 to in2 (i.e., out[i] = in1[i] ^ in2[i])
227  * @note For an exponent that is a float, this function will only work with a positive base.
228  */
230 {
231 public:
232  /** Default Constructor */
234  /** Default Destructor */
236  /** Prevent instances of this class from being copied (As this class contains pointers) */
237  NEElementwisePower(const NEElementwisePower &) = delete;
238  /** Default move constructor */
240  /** Prevent instances of this class from being copied (As this class contains pointers) */
242  /** Default move assignment operator */
244  /** Initialise the kernel's inputs, output and conversion policy.
245  *
246  * @param[in, out] input1 First tensor input. Data types supported: F16/F32.
247  * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1.
248  * @param[out] output Output tensor. Data types supported: Same as @p input1.
249  * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
250  */
251  void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
252  /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuArithmeticKernel for power
253  *
254  * @param[in] input1 First tensor input info. Data types supported: F16/F32.
255  * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
256  * @param[in] output Output tensor info. Data types supported: Same as @p input1.
257  * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
258  *
259  * @return a status
260  */
261  static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
262 
263  // Inherited methods overridden:
264  void run() override;
265 
266 private:
267  struct Impl;
268  std::unique_ptr<Impl> _impl;
269 };
270 
271 /** Basic function to run @ref cpu::kernels::CpuComparisonKernel.
272  *
273  * @note The tensor data type for the inputs must be U8/QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
274  * @note The function performs a comparison operation between two tensors.
275  */
277 {
278 public:
279  /** Default Constructor */
281  /** Default Destructor */
283  /** Prevent instances of this class from being copied (As this class contains pointers) */
285  /** Default move constructor */
287  /** Prevent instances of this class from being copied (As this class contains pointers) */
289  /** Default move assignment operator */
291  /** Initialise the kernel's inputs, output and conversion policy.
292  *
293  * @param[in, out] input1 First tensor input. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
294  * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1.
295  * @param[out] output Output tensor. Data types supported: U8.
296  * @param[in] op Comparison Operation to be performed.
297  */
298  void configure(ITensor *input1, ITensor *input2, ITensor *output, ComparisonOperation op);
299  /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuComparisonKernel
300  *
301  * @param[in] input1 First tensor input info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
302  * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
303  * @param[in] output Output tensor info. Data types supported: U8.
304  * @param[in] op Comparison Operation to be performed.
305  *
306  * @return a status
307  */
308  static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ComparisonOperation op);
309 
310  // Inherited methods overridden:
311  void run() override;
312 
313 private:
314  struct Impl;
315  std::unique_ptr<Impl> _impl;
316 };
317 
318 /** Basic function to run @ref cpu::kernels::CpuComparisonKernel
319  *
320  * @note The tensor data type for the inputs must be U8/QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
321  * @note The function performs a comparison operation between two tensors.
322  */
323 template <ComparisonOperation op>
325 {
326 public:
327  /** Default Constructor */
329  /** Default Destructor */
331  /** Prevent instances of this class from being copied (As this class contains pointers) */
333  /** Default move constructor */
335  /** Prevent instances of this class from being copied (As this class contains pointers) */
337  /** Default move assignment operator */
339  /** Initialise the kernel's inputs, output and conversion policy.
340  *
341  * @param[in, out] input1 First tensor input. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
342  * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1.
343  * @param[out] output Output tensor. Data types supported: U16/U32.
344  */
345  void configure(ITensor *input1, ITensor *input2, ITensor *output);
346  /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuComparisonKernel
347  *
348  * @param[in] input1 First tensor input info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
349  * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
350  * @param[in] output Output tensor info. Data types supported: U16/U32.
351  *
352  * @return a status
353  */
354  static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
355 
356  // Inherited methods overridden:
357  void run() override;
358 
359 private:
360  struct Impl;
361  std::unique_ptr<Impl> _impl;
362 };
363 
364 /** Basic function to run equal comparison. */
366 /** Basic function to run not equal comparison. */
368 /** Basic function to run greater comparison. */
370 /** Basic function to run greater-equal comparison. */
372 /** Basic function to run less comparison. */
374 /** Basic function to run less-equal comparison. */
376 
377 } // namespace arm_compute
378 #endif /* ARM_COMPUTE_NEELEMENTWISEOPERATIONS_H */
Base class for all functions.
Definition: IFunction.h:30
Basic function to run cpu::kernels::CpuArithmeticKernel for min.
Basic function to run cpu::kernels::CpuArithmeticKernel for power.
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
Basic function to run cpu::kernels::CpuComparisonKernel.
Basic function to run cpu::kernels::CpuArithmeticKernel for max.
Activation Layer Information class.
Definition: Types.h:1550
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, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of cpu::kernels::CpuArithme...
~NEElementwiseMax()
Default Destructor.
Basic function to run cpu::kernels::CpuArithmeticKernel for division.
void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Initialise the kernel&#39;s inputs, output and conversion policy.
ComparisonOperation
Supported comparison operations.
Definition: Types.h:177
Basic function to run cpu::kernels::CpuArithmeticKernel for squared difference.
Basic function to run cpu::kernels::CpuComparisonKernel.
void run() override
Run the kernels contained in the function.
NEElementwiseMax & operator=(const NEElementwiseMax &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...