blob: c65f7880914a461029b4010865271e7e6c0fcf46 [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_NEPIXELWISEMULTIPLICATIONKERNEL_H
25#define ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
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 the kernel to perform addition between two tensors */
35class NEPixelWiseMultiplicationKernel : public INEKernel
36{
37public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000038 const char *name() const override
39 {
40 return "NEPixelWiseMultiplicationKernel";
41 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010042 /** Default constructor */
43 NEPixelWiseMultiplicationKernel();
44 /** Prevent instances of this class from being copied (As this class contains pointers) */
45 NEPixelWiseMultiplicationKernel(const NEPixelWiseMultiplicationKernel &) = delete;
46 /** Prevent instances of this class from being copied (As this class contains pointers) */
47 NEPixelWiseMultiplicationKernel &operator=(const NEPixelWiseMultiplicationKernel &) = delete;
48 /** Allow instances of this class to be moved */
49 NEPixelWiseMultiplicationKernel(NEPixelWiseMultiplicationKernel &&) = default;
50 /** Allow instances of this class to be moved */
51 NEPixelWiseMultiplicationKernel &operator=(NEPixelWiseMultiplicationKernel &&) = default;
52 /** Default destructor */
53 ~NEPixelWiseMultiplicationKernel() = default;
54 /** Initialise the kernel's input, output and border mode.
55 *
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010056 * Valid configurations (Input1,Input2) -> Output :
57 *
SiCong Libb88f892020-08-28 11:18:47 +010058 * - (U8,U8) -> U8, S16
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010059 * - (U8,S16) -> S16
60 * - (S16,U8) -> S16
61 * - (S16,S16) -> S16
SiCong Libb88f892020-08-28 11:18:47 +010062 * - (S32,S32) -> S32
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010063 * - (F16,F16) -> F16
64 * - (F32,F32) -> F32
65 * - (QASYMM8,QASYMM8) -> QASYMM8
66 * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED
SiCong Libb88f892020-08-28 11:18:47 +010067 * - (QSYMM16,QSYMM16) -> QSYMM16, S32
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010068 *
Anthony Barbier6ff3b192017-09-04 18:44:23 +010069 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
70 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
71 *
SiCong Libb88f892020-08-28 11:18:47 +010072 * @param[in] input1 First input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
73 * @param[in] input2 Second input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
74 * @param[out] output Output tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075 * @param[in] scale Scale to apply after multiplication.
76 * 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 +010077 * If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255
78 * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype
Anthony Barbier6ff3b192017-09-04 18:44:23 +010079 * @param[in] rounding_policy Rounding policy.
80 */
Michalis Spyrou6eb73452020-07-02 17:39:25 +010081 void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy);
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000082 /** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplicationKernel
83 *
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010084 * Valid configurations (Input1,Input2) -> Output :
85 *
SiCong Libb88f892020-08-28 11:18:47 +010086 * - (U8,U8) -> U8, S16
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010087 * - (U8,S16) -> S16
88 * - (S16,U8) -> S16
89 * - (S16,S16) -> S16
SiCong Libb88f892020-08-28 11:18:47 +010090 * - (S32,S32) -> S32
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010091 * - (F16,F16) -> F16
92 * - (F32,F32) -> F32
93 * - (QASYMM8,QASYMM8) -> QASYMM8
94 * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED
SiCong Libb88f892020-08-28 11:18:47 +010095 * - (QSYMM16,QSYMM16) -> QSYMM16, S32
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010096 *
Michalis Spyrouafa5d812017-11-30 14:25:57 +000097 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
98 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000099 *
SiCong Libb88f892020-08-28 11:18:47 +0100100 * @param[in] input1 First input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
101 * @param[in] input2 Second input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
102 * @param[in] output Output tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +0000103 * @param[in] scale Scale to apply after multiplication.
104 * 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 +0100105 * If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255
106 * @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 +0000107 * @param[in] rounding_policy Rounding policy.
108 *
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000109 * @return a status
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +0000110 */
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000111 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100112
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100113 // Inherited methods overridden
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100114 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100115
116private:
117 /** Common signature for all the specialised multiplication functions with integer scaling factor
118 *
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100119 * @param[in] in1 Input1 tensor object.
120 * @param[in] in2 Input2 tensor object.
121 * @param[out] out Output tensor object.
122 * @param[in] window Region on which to execute the kernel
123 * @param[in] scale Integer scale factor.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100124 */
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100125 using MulFunctionInt = void(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, int scale);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100126 /** Common signature for all the specialised multiplication functions with float scaling factor
127 *
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100128 * @param[in] in1 Input1 tensor object.
129 * @param[in] in2 Input2 tensor object.
130 * @param[out] out Output tensor object.
131 * @param[in] window Region on which to execute the kernel
132 * @param[in] scale Float scale factor.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100133 */
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100134 using MulFunctionFloat = void(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, float scale);
Manuel Bottini79fa9a22019-02-22 17:54:22 +0000135 /** Common signature for all the specialised QASYMM8 multiplication functions with float scaling factor
136 *
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100137 * @param[in] in1 Input1 tensor object.
138 * @param[in] in2 Input2 tensor object.
139 * @param[out] out Output tensor object.
140 * @param[in] window Region on which to execute the kernel
141 * @param[in] scale Float scale factor.
Manuel Bottini79fa9a22019-02-22 17:54:22 +0000142 *
143 */
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100144 using MulFunctionQuantized = void(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, float scale);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100145
Manuel Bottini7bb56c62019-06-26 15:17:09 +0100146 MulFunctionFloat *_func_float;
147 MulFunctionInt *_func_int;
148 MulFunctionQuantized *_func_quantized;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100149
150private:
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100151 float _scale;
152 int _scale_exponent;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100153};
giuros01154bc1c2019-03-26 17:44:40 +0000154
155/** Interface for the complex pixelwise multiplication kernel. */
156class NEComplexPixelWiseMultiplicationKernel : public INEKernel
157{
158public:
159 const char *name() const override
160 {
161 return "NEComplexPixelWiseMultiplicationKernel";
162 }
giuros01154bc1c2019-03-26 17:44:40 +0000163 /** Initialise the kernel's input, output and border mode.
164 *
165 * @param[in] input1 An input tensor. Data types supported: F32. Number of channels supported: 2 (complex tensor).
166 * @param[in] input2 An input tensor. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
167 * @param[out] output The output tensor, Data types supported: same as @p input1. Number of channels supported: same as @p input1.
168 */
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100169 void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output);
giuros01154bc1c2019-03-26 17:44:40 +0000170 /** Static function to check if given info will lead to a valid configuration of @ref NEComplexPixelWiseMultiplicationKernel
171 *
172 * @param[in] input1 An input tensor info. Data types supported: F32. Number of channels supported: 2 (complex tensor).
173 * @param[in] input2 An input tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
174 * @param[in] output The output tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
175 *
176 * @return a status
177 */
178 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
179
180 // Inherited methods overridden:
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100181 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
giuros01154bc1c2019-03-26 17:44:40 +0000182};
183
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100184} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000185#endif /*ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H */