blob: a7cb8b42261116c11e2bb3cef980d11c42c3f3d1 [file] [log] [blame]
giuros01164a2722018-11-20 18:34:46 +00001/*
George Wort5a97b282018-12-21 16:21:04 +00002 * Copyright (c) 2018-2019 ARM Limited.
giuros01164a2722018-11-20 18:34:46 +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
George Wort5a97b282018-12-21 16:21:04 +000020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
giuros01164a2722018-11-20 18:34:46 +000021 * 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_CLELEMENTWISEOPERATIONS_H
25#define ARM_COMPUTE_CLELEMENTWISEOPERATIONS_H
giuros01164a2722018-11-20 18:34:46 +000026
27#include "arm_compute/core/Types.h"
28#include "arm_compute/runtime/CL/ICLSimpleFunction.h"
29
30namespace arm_compute
31{
32class ICLTensor;
33
34/** Basic function to run @ref CLSaturatedArithmeticOperationKernel for addition
35 *
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010036 * @note The tensor data type for the inputs must be U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32.
giuros01164a2722018-11-20 18:34:46 +000037 * @note The function performs an arithmetic addition between two tensors.
38 */
39class CLArithmeticAddition : public ICLSimpleFunction
40{
41public:
42 /** Initialise the kernel's inputs, output and conversion policy.
43 *
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010044 * @param[in, out] input1 First tensor input. Data types supported: U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32.
giuros01164a2722018-11-20 18:34:46 +000045 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010046 * @param[in, out] input2 Second tensor input. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), QSYMM16 (only if @p input1 is QSYMM16), S16/F16/F32.
giuros01164a2722018-11-20 18:34:46 +000047 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010048 * @param[out] output Output tensor. Data types supported: U8 (Only if both inputs are U8), QASYMM8 (only if both inputs are QASYMM8), QSYMM16 (only if both inputs is QSYMM16), S16/F16/F32.
giuros01164a2722018-11-20 18:34:46 +000049 * @param[in] policy Policy to use to handle overflow.
50 */
51 void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy);
52 /** Static function to check if given info will lead to a valid configuration of @ref CLSaturatedArithmeticOperationKernel for addition
53 *
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010054 * @param[in] input1 First tensor input info. Data types supported: U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32.
55 * @param[in] input2 Second tensor input info. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), QSYMM16 (only if @p input1 is QSYMM16), S16/F16/F32.
56 * @param[in] output Output tensor info. Data types supported: U8 (Only if both inputs are U8), QASYMM8 (only if both inputs are QASYMM8), QSYMM16 (only if both inputs is QSYMM16), S16/F16/F32.
giuros01164a2722018-11-20 18:34:46 +000057 * @param[in] policy Policy to use to handle overflow.
58 *
59 * @return a status
60 */
61 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy);
62};
63
64/** Basic function to run @ref CLSaturatedArithmeticOperationKernel for subtraction
65 *
66 * @note The tensor data type for the inputs must be U8/QASYMM8/S16/S32/U32/F16/F32.
67 * @note The function performs an arithmetic subtraction between two tensors.
68 */
69class CLArithmeticSubtraction : public ICLSimpleFunction
70{
71public:
72 /** Initialise the kernel's inputs, output and conversion policy.
73 *
74 * @param[in, out] input1 First tensor input. Data types supported: U8/QASYMM8/S16/S32/U32/F16/F32.
75 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
76 * @param[in, out] input2 Second tensor input. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), S16/F16/F32.
77 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
78 * @param[out] output Output tensor. Data types supported: U8 (Only if both inputs are U8), QASYMM8 (only if both inputs are QASYMM8), S16/F16/F32.
79 * @param[in] policy Policy to use to handle overflow.
80 */
81 void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy);
82 /** Static function to check if given info will lead to a valid configuration of @ref CLSaturatedArithmeticOperationKernel for subtraction
83 *
84 * @param[in] input1 First tensor input info. Data types supported: U8/QASYMM8/S16/S32/U32/F16/F32.
85 * @param[in] input2 Second tensor input info. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), S16/F16/F32.
86 * @param[in] output Output tensor info. Data types supported: U8 (Only if both inputs are U8), QASYMM8 ( only if both inputs are QASYMM8), S16/F16/F32.
87 * @param[in] policy Policy to use to handle overflow.
88 *
89 * @return a status
90 */
91 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy);
92};
93
94/** Basic function to run @ref CLSaturatedArithmeticOperationKernel for division
95 *
96 * @note The tensor data type for the inputs must be F16/F32.
97 * @note The function performs an arithmetic division between two tensors.
98 */
99class CLArithmeticDivision : public ICLSimpleFunction
100{
101public:
102 /** Initialise the kernel's inputs, output.
103 *
104 * @param[in, out] input1 First tensor input. Data types supported: F16/F32.
105 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
106 * @param[in, out] input2 Second tensor input. Same as @p input1.
107 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
108 * @param[out] output Output tensor. Data types supported: Same as @p input1.
109 */
110 void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output);
111 /** Static function to check if given info will lead to a valid configuration of @ref CLArithmeticDivision
112 *
113 * @param[in] input1 First tensor input info. Data types supported: F16/F32.
114 * @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(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
120};
121
122/** Basic function to run @ref CLArithmeticOperationKernel for max
123 *
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100124 * @note The tensor data type for the inputs must be U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000125 * @note The function performs a max operation between two tensors.
126 */
127class CLElementwiseMax : public ICLSimpleFunction
128{
129public:
130 /** Initialise the kernel's inputs, output and conversion policy.
131 *
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100132 * @param[in, out] input1 First tensor input. Data types supported: U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000133 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100134 * @param[in, out] input2 Second tensor input. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), S16, QSYMM16 (only if @p input1 is QSYMM16), F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000135 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100136 * @param[out] output Output tensor. Data types supported: U8 (Only if both inputs are U8), QASYMM8 (only if both inputs are QASYMM8), S16, QSYMM16 (only if both inputs are QSYMM16), F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000137 */
138 void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output);
139 /** Static function to check if given info will lead to a valid configuration of @ref CLArithmeticOperationKernel for max
140 *
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100141 * @param[in] input1 First tensor input info. Data types supported: U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32.
142 * @param[in] input2 Second tensor input info. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), S16, QSYMM16 (only if @p input1 is QSYMM16), F16/F32.
143 * @param[in] output Output tensor info. Data types supported: U8 (Only if both inputs are U8), QASYMM8 ( only if both inputs are QASYMM8), S16, QSYMM16 (only if both inputs are QSYMM16), F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000144 *
145 * @return a status
146 */
147 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
148};
149
150/** Basic function to run @ref CLArithmeticOperationKernel for min
151 *
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100152 * @note The tensor data type for the inputs must be U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000153 * @note The function performs a max operation between two tensors.
154 */
155class CLElementwiseMin : public ICLSimpleFunction
156{
157public:
158 /** Initialise the kernel's inputs, output and conversion policy.
159 *
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100160 * @param[in, out] input1 First tensor input. Data types supported: U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000161 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100162 * @param[in, out] input2 Second tensor input. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), S16, QSYMM16 (only if @p input1 is QSYMM16), F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000163 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100164 * @param[out] output Output tensor. Data types supported: U8 (Only if both inputs are U8), QASYMM8 (only if both inputs are QASYMM8), S16, QSYMM16 (only if both inputs are QSYMM16), F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000165 */
166 void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output);
167 /** Static function to check if given info will lead to a valid configuration of @ref CLArithmeticOperationKernel for min
168 *
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100169 * @param[in] input1 First tensor input info. Data types supported: U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32.
170 * @param[in] input2 Second tensor input info. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), S16, QSYMM16 (only if @p input1 is QSYMM16), F16/F32.
171 * @param[in] output Output tensor info. Data types supported: U8 (Only if both inputs are U8), QASYMM8 ( only if both inputs are QASYMM8), S16, QSYMM16 (only if both inputs are QSYMM16), F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000172 *
173 * @return a status
174 */
175 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
176};
177
178/** Basic function to run @ref CLArithmeticOperationKernel for squared difference
179 *
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100180 * @note The tensor data type for the inputs must be QASYMM8/U8/S16/QSYMM16/F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000181 * @note The function performs a squared different operation between two tensors (i.e., out[i] = (in1[i] - in2[i])^2
182 */
183class CLElementwiseSquaredDiff : public ICLSimpleFunction
184{
185public:
186 /** Initialise the kernel's inputs, output and conversion policy.
187 *
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100188 * @param[in, out] input1 First tensor input. Data types supported: U8/QASYMM8/S16/QSYMM16/F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000189 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100190 * @param[in, out] input2 Second tensor input. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), S16, QSYMM16 (only if @p input1 is QSYMM16), F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000191 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100192 * @param[out] output Output tensor. Data types supported: U8 (Only if both inputs are U8), QASYMM8 (only if both inputs are QASYMM8), S16, QSYMM16 (only if both inputs are QSYMM16), F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000193 */
194 void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output);
195 /** Static function to check if given info will lead to a valid configuration of @ref CLArithmeticOperationKernel for squared difference
196 *
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100197 * @param[in] input1 First tensor input info. Data types supported: U8/QASYMM8/S16/QSYMM16/F16/F32.
198 * @param[in] input2 Second tensor input info. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), S16, QSYMM16 (only if @p input1 is QSYMM16), F16/F32.
199 * @param[in] output Output tensor info. Data types supported: U8 (Only if both inputs are U8), QASYMM8 ( only if both inputs are QASYMM8), S16, QSYMM16 (only if both inputs are QSYMM16), F16/F32.
giuros01164a2722018-11-20 18:34:46 +0000200 *
201 * @return a status
202 */
203 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
204};
Usama Arif52c54f62019-05-14 10:22:36 +0100205
206/** Basic function to run @ref CLArithmeticOperationKernel for power
207 *
208 * @note The tensor data type for the inputs must be F16/F32.
209 * @note The function performs an elementwise power of in1 to in2 (i.e., out[i] = in1[i] ^ in2[i])
210 */
211class CLElementwisePower : public ICLSimpleFunction
212{
213public:
214 /** Initialise the kernel's inputs, output and conversion policy.
215 *
216 * @param[in, out] input1 First tensor input. Data types supported: F16/F32.
217 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
218 * @param[in, out] input2 Second tensor input. Data types supported: F16/F32.
219 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
220 * @param[out] output Output tensor. Data types supported:F16/F32.
221 */
222 void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output);
223 /** Static function to check if given info will lead to a valid configuration of @ref CLArithmeticOperationKernel for power
224 *
225 * @param[in] input1 First tensor input info. Data types supported: F16/F32.
226 * @param[in] input2 Second tensor input info. Data types supported: F16/F32.
227 * @param[in] output Output tensor info. Data types supported: F16/F32.
228 *
229 * @return a status
230 */
231 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
232};
giuros01164a2722018-11-20 18:34:46 +0000233} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000234#endif /* ARM_COMPUTE_CLELEMENTWISEOPERATIONS_H */