blob: 43e4966484487243367d3960e37dc67b2316981f [file] [log] [blame]
giuros0192fd9432018-12-03 17:30:00 +00001/*
George Wortd88590f2018-12-12 17:39:58 +00002 * Copyright (c) 2018-2019 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
60 // Inherited methods overridden:
61 void run(const Window &window, const ThreadInfo &info) override;
62
George Wortd88590f2018-12-12 17:39:58 +000063 /** Common signature for all the specialised arithmetic functions
64 *
65 * @param[in] input1 First tensor input. Data types supported: QASYMM8/S16/F16/S32/F32.
66 * @param[in] input2 Second tensor input. Data types supported: Same as @p input1.
67 * @param[in] output Output tensor. Data types supported: Dependent on subclass.
68 * @param[in] window Region on which to execute the kernel.
69 */
70 using ElementwiseFunction = void(const ITensor *input1, const ITensor *input2, ITensor *output, const Window &window);
71
giuros0192fd9432018-12-03 17:30:00 +000072protected:
73 /** Validate the argument passed to the kernel
74 *
George Wortd88590f2018-12-12 17:39:58 +000075 * @param[in] input1 First tensor input. Data types supported: QASYMM8/S16/F16/S32/F32.
giuros0192fd9432018-12-03 17:30:00 +000076 * @param[in] input2 Second tensor input. Data types supported: Same as @p input1.
George Wortd88590f2018-12-12 17:39:58 +000077 * @param[in] output Output tensor. Data types supported: Dependent on subclass.
giuros0192fd9432018-12-03 17:30:00 +000078 */
George Wortd88590f2018-12-12 17:39:58 +000079 static Status validate_arguments_common(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output);
giuros0192fd9432018-12-03 17:30:00 +000080
81 /** Commmon configure function for element-wise operators with no additional options (e.g. Min, Max, SquaredDiff)
82 *
83 */
giuros0192fd9432018-12-03 17:30:00 +000084 void configure_common(const ITensor *input1, const ITensor *input2, ITensor *output);
85
George Wortd88590f2018-12-12 17:39:58 +000086 /** Function to use for the particular tensor types passed to configure() */
87 std::function<void(const ITensor *input1, const ITensor *input2, ITensor *output, const Window &window)> _function;
giuros0192fd9432018-12-03 17:30:00 +000088
George Wortd88590f2018-12-12 17:39:58 +000089 const ITensor *_input1;
90 const ITensor *_input2;
91 ITensor *_output;
giuros0192fd9432018-12-03 17:30:00 +000092};
93
94class NEArithmeticOperationKernel : public NEElementwiseOperationKernel
95{
96public:
George Worta1e7e282019-01-15 11:00:29 +000097 /** Default constructor */
98 NEArithmeticOperationKernel() = default;
giuros0192fd9432018-12-03 17:30:00 +000099
100 /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel
101 *
102 * @param[in] op Arithmetic operation to be executed.
103 * @param[in] input1 First tensor input. Data types supported: QASYMM8/S16/F16/S32/F32.
giuros0192fd9432018-12-03 17:30:00 +0000104 * @param[in] input2 Second tensor input. Data types supported: Same as @p input1.
105 * @param[in] output Output tensor. Data types supported: Same as @p input1.
106 */
107 void configure(ArithmeticOperation op, const ITensor *input1, const ITensor *input2, ITensor *output);
108
109 /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel
110 *
111 * @param[in] op Arithmetic operation to be executed.
112 * @param[in] input1 First tensor input info. Data types supported: QASYMM8/S16/F16/S32/F32.
giuros0192fd9432018-12-03 17:30:00 +0000113 * @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 *
116 * @return a Status
117 */
118 static Status validate(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
119
120protected:
121 // Inherited methods overridden:
George Wortd88590f2018-12-12 17:39:58 +0000122 static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output);
123};
124
George Worta1e7e282019-01-15 11:00:29 +0000125class NEDivisionOperationKernel : public NEArithmeticOperationKernel
126{
127public:
128 /** Default constructor */
129 NEDivisionOperationKernel() = default;
130
131 /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel
132 *
133 * @param[in] input1 First tensor input. Data types supported: F16/F32.
134 * @param[in] input2 Second tensor input. Data types supported: Same as @p input1.
135 * @param[in] output Output tensor. Data types supported: Same as @p input1.
136 */
137 void configure(const ITensor *input1, const ITensor *input2, ITensor *output);
138
139 /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel
140 *
141 * @param[in] input1 First tensor input info. Data types supported: F16/F32.
142 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
143 * @param[in] output Output tensor info. Data types supported: Same as @p input1.
144 *
145 * @return a Status
146 */
147 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
148
149protected:
150 // Inherited methods overridden:
151 static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output);
152};
153
Usama Arif81e671e2019-05-13 13:33:14 +0100154class NEPowerOperationKernel : public NEArithmeticOperationKernel
155{
156public:
157 /** Default constructor */
158 NEPowerOperationKernel() = default;
159
160 /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel
161 *
162 * @param[in] input1 First tensor input. Data types supported: F16/F32.
163 * @param[in] input2 Second tensor input. Data types supported: Same as @p input1.
164 * @param[out] output Output tensor. Data types supported: Same as @p input1.
165 */
166 void configure(const ITensor *input1, const ITensor *input2, ITensor *output);
167
168 /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel
169 *
170 * @param[in] input1 First tensor input info. Data types supported: F16/F32.
171 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
172 * @param[out] output Output tensor info. Data types supported: Same as @p input1.
173 *
174 * @return a Status
175 */
176 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
177
178protected:
179 // Inherited methods overridden:
180 static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output);
181};
182
George Wortd88590f2018-12-12 17:39:58 +0000183class NEComparisonOperationKernel : public NEElementwiseOperationKernel
184{
185public:
George Worta1e7e282019-01-15 11:00:29 +0000186 /** Default constructor */
187 NEComparisonOperationKernel() = default;
George Wortd88590f2018-12-12 17:39:58 +0000188
189 /** Static function to check if given info will lead to a valid configuration of @ref NEComparisonOperationKernel
190 *
191 * @param[in] op Comparison operation to be executed.
192 * @param[in] input1 First tensor input. Data types supported: QASYMM8/S16/F16/S32/F32.
193 * @param[in] input2 Second tensor input. Data types supported: Same as @p input1.
194 * @param[in] output Output tensor. Data types supported: U16/U32.
195 */
196 void configure(ComparisonOperation op, const ITensor *input1, const ITensor *input2, ITensor *output);
197
198 /** Static function to check if given info will lead to a valid configuration of @ref NEComparisonOperationKernel
199 *
200 * @param[in] op Comparison operation to be executed.
201 * @param[in] input1 First tensor input info. Data types supported: QASYMM8/S16/F16/S32/F32.
202 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
203 * @param[in] output Output tensor info. Data types supported: U16/U32.
204 *
205 * @return a Status
206 */
207 static Status validate(ComparisonOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
208
209protected:
210 // Inherited methods overridden:
211 static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output);
giuros0192fd9432018-12-03 17:30:00 +0000212};
213} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000214#endif /* ARM_COMPUTE_NEELEMENTWISEOPERATIONKERNEL_H */