blob: cf43aca4b0ddfee2ba8e04ebf70c0cb7ad73be1c [file] [log] [blame]
giuros0192fd9432018-12-03 17:30:00 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
giuros0192fd9432018-12-03 17:30:00 +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
George Wortd88590f2018-12-12 17:39:58 +000017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
giuros0192fd9432018-12-03 17:30:00 +000018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
George Wortd88590f2018-12-12 17:39:58 +000019 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
giuros0192fd9432018-12-03 17:30:00 +000020 * 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_NEELEMENTWISEOPERATIONKERNEL_H
25#define ARM_COMPUTE_NEELEMENTWISEOPERATIONKERNEL_H
giuros0192fd9432018-12-03 17:30:00 +000026
27#include "arm_compute/core/NEON/INEKernel.h"
28#include "arm_compute/core/Types.h"
29
30namespace arm_compute
31{
32class ITensor;
33
34/** Interface for an element-wise operation kernel
35 *
36 * Element-wise operation is computed by:
37 * @f[ output(x,y) = OP(input1(x,y), input2(x,y))@f]
38 *
39 */
40class NEElementwiseOperationKernel : public INEKernel
41{
42public:
43 const char *name() const override
44 {
45 return "NEElementwiseOperationKernel";
46 }
47 /** Default constructor */
48 NEElementwiseOperationKernel();
49 /** Prevent instances of this class from being copied (As this class contains pointers) */
50 NEElementwiseOperationKernel(const NEElementwiseOperationKernel &) = delete;
51 /** Prevent instances of this class from being copied (As this class contains pointers) */
52 NEElementwiseOperationKernel &operator=(const NEElementwiseOperationKernel &) = delete;
53 /** Allow instances of this class to be moved */
54 NEElementwiseOperationKernel(NEElementwiseOperationKernel &&) = default;
55 /** Allow instances of this class to be moved */
56 NEElementwiseOperationKernel &operator=(NEElementwiseOperationKernel &&) = default;
57 /** Default destructor */
58 ~NEElementwiseOperationKernel() = default;
59
George Wortd88590f2018-12-12 17:39:58 +000060 /** Common signature for all the specialised arithmetic functions
61 *
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010062 * @param[in] input1 First tensor input info. Data types supported: QASYMM8/S16/F16/S32/F32.
63 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
64 * @param[out] output Output tensor info. Data types supported: Dependent on subclass.
65 * @param[in] window Region on which to execute the kernel.
George Wortd88590f2018-12-12 17:39:58 +000066 */
67 using ElementwiseFunction = void(const ITensor *input1, const ITensor *input2, ITensor *output, const Window &window);
68
Michalis Spyrouce0c6752020-06-18 10:14:57 +010069 // Inherited methods overridden:
70 void run_op(const InputTensorMap &inputs, const OutputTensorMap &outputs,
71 const Window &window, const ThreadInfo &info) override;
72
giuros0192fd9432018-12-03 17:30:00 +000073protected:
74 /** Validate the argument passed to the kernel
75 *
George Wortd88590f2018-12-12 17:39:58 +000076 * @param[in] input1 First tensor input. Data types supported: QASYMM8/S16/F16/S32/F32.
giuros0192fd9432018-12-03 17:30:00 +000077 * @param[in] input2 Second tensor input. Data types supported: Same as @p input1.
George Wortd88590f2018-12-12 17:39:58 +000078 * @param[in] output Output tensor. Data types supported: Dependent on subclass.
giuros0192fd9432018-12-03 17:30:00 +000079 */
George Wortd88590f2018-12-12 17:39:58 +000080 static Status validate_arguments_common(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output);
giuros0192fd9432018-12-03 17:30:00 +000081
82 /** Commmon configure function for element-wise operators with no additional options (e.g. Min, Max, SquaredDiff)
83 *
84 */
Michalis Spyrouce0c6752020-06-18 10:14:57 +010085 void configure_common(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output);
giuros0192fd9432018-12-03 17:30:00 +000086
George Wortd88590f2018-12-12 17:39:58 +000087 /** Function to use for the particular tensor types passed to configure() */
88 std::function<void(const ITensor *input1, const ITensor *input2, ITensor *output, const Window &window)> _function;
giuros0192fd9432018-12-03 17:30:00 +000089
George Wortd88590f2018-12-12 17:39:58 +000090 const ITensor *_input1;
91 const ITensor *_input2;
92 ITensor *_output;
giuros0192fd9432018-12-03 17:30:00 +000093};
94
95class NEArithmeticOperationKernel : public NEElementwiseOperationKernel
96{
97public:
George Worta1e7e282019-01-15 11:00:29 +000098 /** Default constructor */
99 NEArithmeticOperationKernel() = default;
giuros0192fd9432018-12-03 17:30:00 +0000100
101 /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel
102 *
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +0100103 * @param[in] op Arithmetic operation to be executed.
104 * @param[in] input1 First tensor input info. Data types supported: QASYMM8/S16/F16/S32/F32.
105 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
106 * @param[out] output Output tensor info. Data types supported: Same as @p input1.
giuros0192fd9432018-12-03 17:30:00 +0000107 */
Michalis Spyrouce0c6752020-06-18 10:14:57 +0100108 void configure(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output);
giuros0192fd9432018-12-03 17:30:00 +0000109
110 /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel
111 *
112 * @param[in] op Arithmetic operation to be executed.
113 * @param[in] input1 First tensor input info. Data types supported: QASYMM8/S16/F16/S32/F32.
giuros0192fd9432018-12-03 17:30:00 +0000114 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
115 * @param[in] output Output tensor info. Data types supported: Same as @p input1.
116 *
117 * @return a Status
118 */
119 static Status validate(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
120
121protected:
122 // Inherited methods overridden:
George Wortd88590f2018-12-12 17:39:58 +0000123 static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output);
124};
125
George Worta1e7e282019-01-15 11:00:29 +0000126class NEDivisionOperationKernel : public NEArithmeticOperationKernel
127{
128public:
129 /** Default constructor */
130 NEDivisionOperationKernel() = default;
131
132 /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel
133 *
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +0100134 * @param[in] input1 First tensor input info. Data types supported: F16/F32.
135 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
136 * @param[out] output Output tensor info. Data types supported: Same as @p input1.
George Worta1e7e282019-01-15 11:00:29 +0000137 */
Michalis Spyrouce0c6752020-06-18 10:14:57 +0100138 void configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output);
George Worta1e7e282019-01-15 11:00:29 +0000139
140 /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel
141 *
142 * @param[in] input1 First tensor input info. Data types supported: F16/F32.
143 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
144 * @param[in] output Output tensor info. Data types supported: Same as @p input1.
145 *
146 * @return a Status
147 */
148 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
149
150protected:
151 // Inherited methods overridden:
152 static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output);
153};
154
Usama Arif81e671e2019-05-13 13:33:14 +0100155class NEPowerOperationKernel : public NEArithmeticOperationKernel
156{
157public:
158 /** Default constructor */
159 NEPowerOperationKernel() = default;
160
161 /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel
162 *
Michalis Spyrouce0c6752020-06-18 10:14:57 +0100163 * @param[in] input1 First tensor input info. Data types supported: F16/F32.
164 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
165 * @param[out] output Output tensor info. Data types supported: Same as @p input1.
Usama Arif81e671e2019-05-13 13:33:14 +0100166 */
Michalis Spyrouce0c6752020-06-18 10:14:57 +0100167 void configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output);
Usama Arif81e671e2019-05-13 13:33:14 +0100168
169 /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel
170 *
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +0100171 * @param[in] input1 First tensor input info. Data types supported: F16/F32.
172 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
173 * @param[in] output Output tensor info. Data types supported: Same as @p input1.
Usama Arif81e671e2019-05-13 13:33:14 +0100174 *
175 * @return a Status
176 */
177 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
178
179protected:
180 // Inherited methods overridden:
181 static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output);
182};
183
George Wortd88590f2018-12-12 17:39:58 +0000184class NEComparisonOperationKernel : public NEElementwiseOperationKernel
185{
186public:
George Worta1e7e282019-01-15 11:00:29 +0000187 /** Default constructor */
188 NEComparisonOperationKernel() = default;
George Wortd88590f2018-12-12 17:39:58 +0000189
190 /** Static function to check if given info will lead to a valid configuration of @ref NEComparisonOperationKernel
191 *
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +0100192 * @param[in] op Comparison operation to be executed.
193 * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
194 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
195 * @param[out] output Output tensor info. Data types supported: U8.
George Wortd88590f2018-12-12 17:39:58 +0000196 */
Michalis Spyrouce0c6752020-06-18 10:14:57 +0100197 void configure(ComparisonOperation op, const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output);
George Wortd88590f2018-12-12 17:39:58 +0000198
199 /** Static function to check if given info will lead to a valid configuration of @ref NEComparisonOperationKernel
200 *
201 * @param[in] op Comparison operation to be executed.
morgolock74a16962020-01-15 11:40:49 +0000202 * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
George Wortd88590f2018-12-12 17:39:58 +0000203 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +0100204 * @param[in] output Output tensor info. Data types supported: U8.
George Wortd88590f2018-12-12 17:39:58 +0000205 *
206 * @return a Status
207 */
208 static Status validate(ComparisonOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
209
210protected:
211 // Inherited methods overridden:
212 static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output);
giuros0192fd9432018-12-03 17:30:00 +0000213};
214} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000215#endif /* ARM_COMPUTE_NEELEMENTWISEOPERATIONKERNEL_H */