blob: 4ff7f1d112b0f0df1f554b9f4409ddb78ea34859 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2016-2020 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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_NEPIXELWISEMULTIPLICATION_H
25#define ARM_COMPUTE_NEPIXELWISEMULTIPLICATION_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/Types.h"
Michalis Spyrou6eb73452020-07-02 17:39:25 +010028#include "arm_compute/runtime/IFunction.h"
29#include "arm_compute/runtime/NEON/INEOperator.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030
31namespace arm_compute
32{
33class ITensor;
34
Michalis Spyrou6eb73452020-07-02 17:39:25 +010035namespace experimental
36{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037/** Basic function to run @ref NEPixelWiseMultiplicationKernel */
Michalis Spyrou6eb73452020-07-02 17:39:25 +010038class NEPixelWiseMultiplication : public INEOperator
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039{
40public:
41 /** Initialise the kernel's inputs, output and convertion policy.
42 *
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010043 * Valid configurations (Input1,Input2) -> Output :
44 *
SiCong Libb88f892020-08-28 11:18:47 +010045 * - (U8,U8) -> U8, S16
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010046 * - (U8,S16) -> S16
47 * - (S16,U8) -> S16
48 * - (S16,S16) -> S16
SiCong Libb88f892020-08-28 11:18:47 +010049 * - (S32,S32) -> S32
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010050 * - (F16,F16) -> F16
51 * - (F32,F32) -> F32
52 * - (QASYMM8,QASYMM8) -> QASYMM8
53 * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED
SiCong Libb88f892020-08-28 11:18:47 +010054 * - (QSYMM16,QSYMM16) -> QSYMM16, S32
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010055 *
Manuel Bottini79fa9a22019-02-22 17:54:22 +000056 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
57 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
58 *
SiCong Libb88f892020-08-28 11:18:47 +010059 * @param[in, out] input1 First input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
Manuel Bottini79fa9a22019-02-22 17:54:22 +000060 * This input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
SiCong Libb88f892020-08-28 11:18:47 +010061 * @param[in, out] input2 Second input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
Manuel Bottini79fa9a22019-02-22 17:54:22 +000062 * This input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010063 * @param[out] output Output tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32/S32
Michalis Spyrou861f0db2018-02-26 16:47:58 +000064 * @param[in] scale Scale to apply after multiplication.
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010065 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
SiCong Libb88f892020-08-28 11:18:47 +010066 * If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255
67 * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype
Michalis Spyrou861f0db2018-02-26 16:47:58 +000068 * @param[in] rounding_policy Rounding policy.
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000069 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070 */
Michalis Spyrou6eb73452020-07-02 17:39:25 +010071 void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy,
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000072 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000073 /** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplication
74 *
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010075 * Valid configurations (Input1,Input2) -> Output :
76 *
SiCong Libb88f892020-08-28 11:18:47 +010077 * - (U8,U8) -> U8, S16
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010078 * - (U8,S16) -> S16
79 * - (S16,U8) -> S16
80 * - (S16,S16) -> S16
SiCong Libb88f892020-08-28 11:18:47 +010081 * - (S32,S32) -> S32
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010082 * - (F16,F16) -> F16
83 * - (F32,F32) -> F32
84 * - (QASYMM8,QASYMM8) -> QASYMM8
85 * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED
SiCong Libb88f892020-08-28 11:18:47 +010086 * - (QSYMM16,QSYMM16) -> QSYMM16, S32
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010087 *
Manuel Bottini79fa9a22019-02-22 17:54:22 +000088 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
89 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
90 *
SiCong Libb88f892020-08-28 11:18:47 +010091 * @param[in] input1 First input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
92 * @param[in] input2 Second input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010093 * @param[in] output Output tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32/S32
Manuel Bottini79fa9a22019-02-22 17:54:22 +000094 * @param[in] scale Scale to apply after multiplication.
95 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
SiCong Libb88f892020-08-28 11:18:47 +010096 * If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255
97 * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000098 * @param[in] rounding_policy Rounding policy.
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000099 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +0000100 *
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000101 * @return a status
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +0000102 */
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000103 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy,
104 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100105};
giuros01154bc1c2019-03-26 17:44:40 +0000106
107/** Basic function to run @ref NEComplexPixelWiseMultiplicationKernel. */
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100108class NEComplexPixelWiseMultiplication : public INEOperator
giuros01154bc1c2019-03-26 17:44:40 +0000109{
110public:
111 /** Initialise the kernel's inputs, output.
112 *
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000113 * @param[in, out] input1 An input tensor. Data types supported: F32. Number of channels supported: 2 (complex tensor).
114 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
115 * @param[in, out] input2 An input tensor. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
116 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
117 * @param[out] output The output tensor. Data types supported: same as @p input1. Number of channels: same as @p input1.
118 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
giuros01154bc1c2019-03-26 17:44:40 +0000119 */
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100120 void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
121 /** Static function to check if given info will lead to a valid configuration of @ref NEComplexPixelWiseMultiplication
122 *
123 * @param[in] input1 An input tensor info. Data types supported: F32. Number of channels supported: 2 (complex tensor).
124 * @param[in] input2 An input tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
125 * @param[in] output The output tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
126 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
127 */
128 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100129};
130} // namespace experimental
131
132/** Basic function to run @ref NEPixelWiseMultiplicationKernel */
133class NEPixelWiseMultiplication : public IFunction
134{
135public:
136 /** Default Constructor */
137 NEPixelWiseMultiplication();
138 /** Default Destructor */
139 ~NEPixelWiseMultiplication();
140 /** Prevent instances of this class from being copied (As this class contains pointers) */
141 NEPixelWiseMultiplication(const NEPixelWiseMultiplication &) = delete;
142 /** Default move constructor */
143 NEPixelWiseMultiplication(NEPixelWiseMultiplication &&);
144 /** Prevent instances of this class from being copied (As this class contains pointers) */
145 NEPixelWiseMultiplication &operator=(const NEPixelWiseMultiplication &) = delete;
146 /** Default move assignment operator */
147 NEPixelWiseMultiplication &operator=(NEPixelWiseMultiplication &&);
148 /** Initialise the kernel's inputs, output and convertion policy.
149 *
150 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
151 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
152 *
SiCong Libb88f892020-08-28 11:18:47 +0100153 * @param[in, out] input1 An input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100154 * This input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
SiCong Libb88f892020-08-28 11:18:47 +0100155 * @param[in, out] input2 An input tensor. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), QASYMM8_SIGNED (only if @p input1 is QASYMM8_SIGNED), S16, S32, QSYMM16 (only if @p input1 is QSYMM16), F16 (only if @p input1 is F16), F32 (only if @p input1 is F32).
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100156 * This input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
157 * @param[out] output Output tensor. Data types supported:
158 * - U8, only if both inputs are U8.
159 * - QASYMM8, only if both inputs are QASYMM8.
160 * - QASYMM8_SIGNED, only if @p input1 is QASYMM8_SIGNED.
161 * - S16.
162 * - QSYMM16, only if both inputs are QSYMM16.
SiCong Libb88f892020-08-28 11:18:47 +0100163 * - S32, only if both inputs are S32 or both are QSYMM16.
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100164 * - F16, only if @p input1 is F16.
165 * - F32, only if both inputs are F32.
166 * @param[in] scale Scale to apply after multiplication.
167 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
SiCong Libb88f892020-08-28 11:18:47 +0100168 * If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255
169 * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100170 * @param[in] rounding_policy Rounding policy.
171 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
172 */
173 void configure(const ITensor *input1, const ITensor *input2, ITensor *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy,
174 const ActivationLayerInfo &act_info = ActivationLayerInfo());
175 /** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplication
176 *
177 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
178 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
179 *
SiCong Libb88f892020-08-28 11:18:47 +0100180 * @param[in] input1 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
181 * @param[in] input2 An input tensor info. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), QASYMM8_SIGNED (only if @p input1 is QASYMM8_SIGNED), S16, S32, QSYMM16 (only if both inputs are QSYMM16), F16 (only if @p input1 is F16), F32 (only if @p input1 is F32).
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100182 * @param[in] output Output tensor info. Data types supported:
183 * - U8, only if both inputs are U8.
184 * - QASYMM8, only if both inputs are QASYMM8.
185 * - QASYMM8_SIGNED, only if @p input1 is QASYMM8_SIGNED.
186 * - S16.
187 * - QSYMM16, only if both inputs are QSYMM16.
SiCong Libb88f892020-08-28 11:18:47 +0100188 * - S32, only if both inputs are S32 or both are QSYMM16.
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100189 * - F16, only if @p input1 is F16.
190 * - F32, only if both inputs are F32.
191 * @param[in] scale Scale to apply after multiplication.
192 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
SiCong Libb88f892020-08-28 11:18:47 +0100193 * If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255
194 * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100195 * @param[in] rounding_policy Rounding policy.
196 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
197 *
198 * @return a status
199 */
200 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy,
201 const ActivationLayerInfo &act_info = ActivationLayerInfo());
202
203 // Inherited methods overridden:
204 void run() override;
205
206private:
207 struct Impl;
208 std::unique_ptr<Impl> _impl;
209};
210
211/** Basic function to run @ref NEComplexPixelWiseMultiplicationKernel. */
212class NEComplexPixelWiseMultiplication : public IFunction
213{
214public:
215 /** Default Constructor */
216 NEComplexPixelWiseMultiplication();
217 /** Default Destructor */
218 ~NEComplexPixelWiseMultiplication();
219 /** Prevent instances of this class from being copied (As this class contains pointers) */
220 NEComplexPixelWiseMultiplication(const NEComplexPixelWiseMultiplication &) = delete;
221 /** Default move constructor */
222 NEComplexPixelWiseMultiplication(NEComplexPixelWiseMultiplication &&);
223 /** Prevent instances of this class from being copied (As this class contains pointers) */
224 NEComplexPixelWiseMultiplication &operator=(const NEComplexPixelWiseMultiplication &) = delete;
225 /** Default move assignment operator */
226 NEComplexPixelWiseMultiplication &operator=(NEComplexPixelWiseMultiplication &&);
227 /** Initialise the kernel's inputs, output.
228 *
229 * @param[in, out] input1 An input tensor. Data types supported: F32. Number of channels supported: 2 (complex tensor).
230 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
231 * @param[in, out] input2 An input tensor. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
232 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
233 * @param[out] output The output tensor. Data types supported: same as @p input1. Number of channels: same as @p input1.
234 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
235 */
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000236 void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
giuros01154bc1c2019-03-26 17:44:40 +0000237 /** Static function to check if given info will lead to a valid configuration of @ref NEComplexPixelWiseMultiplication
238 *
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000239 * @param[in] input1 An input tensor info. Data types supported: F32. Number of channels supported: 2 (complex tensor).
240 * @param[in] input2 An input tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
241 * @param[in] output The output tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
242 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
giuros01154bc1c2019-03-26 17:44:40 +0000243 */
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000244 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100245
246 // Inherited methods overridden:
247 void run() override;
248
249private:
250 struct Impl;
251 std::unique_ptr<Impl> _impl;
giuros01154bc1c2019-03-26 17:44:40 +0000252};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100253}
Michalis Spyrouf4643372019-11-29 16:17:13 +0000254#endif /*ARM_COMPUTE_NEPIXELWISEMULTIPLICATION_H */