blob: d414168b2d19dc8c1b3039393a9f97224f9ffd7d [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
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/Types.h"
Michalis Spyrouebcebf12020-10-21 00:04:14 +010028#include "src/core/NEON/INEKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029
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 Lid6d1b362020-09-24 17:34:23 +010058 * Support: Broadcast? Scale=1/255?
59 * - (U8,U8) -> U8, S16 N Y
60 * - (U8,S16) -> S16 N Y
61 * - (S16,U8) -> S16 N Y
62 * - (S16,S16) -> S16 N Y
63 * - (S32,S32) -> S32 Y N
64 * - (F16,F16) -> F16 N Y
65 * - (F32,F32) -> F32 Y Y
66 * - (QASYMM8,QASYMM8) -> QASYMM8 Y Y
67 * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED Y Y
68 * - (QSYMM16,QSYMM16) -> QSYMM16, S32 N Y
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010069 *
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
71 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
72 *
SiCong Libb88f892020-08-28 11:18:47 +010073 * @param[in] input1 First input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
74 * @param[in] input2 Second input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
75 * @param[out] output Output tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
Anthony Barbier6ff3b192017-09-04 18:44:23 +010076 * @param[in] scale Scale to apply after multiplication.
77 * 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 +010078 * If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255
79 * @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 +010080 * @param[in] rounding_policy Rounding policy.
81 */
Michalis Spyrou6eb73452020-07-02 17:39:25 +010082 void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy);
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000083 /** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplicationKernel
84 *
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010085 * Valid configurations (Input1,Input2) -> Output :
SiCong Lid6d1b362020-09-24 17:34:23 +010086 * Support: Broadcast? Scale=1/255?
87 * - (U8,U8) -> U8, S16 N Y
88 * - (U8,S16) -> S16 N Y
89 * - (S16,U8) -> S16 N Y
90 * - (S16,S16) -> S16 N Y
91 * - (S32,S32) -> S32 Y N
92 * - (F16,F16) -> F16 N Y
93 * - (F32,F32) -> F32 Y Y
94 * - (QASYMM8,QASYMM8) -> QASYMM8 Y Y
95 * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED Y Y
96 * - (QSYMM16,QSYMM16) -> QSYMM16, S32 N Y
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010097 *
Michalis Spyrouafa5d812017-11-30 14:25:57 +000098 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
99 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000100 *
SiCong Libb88f892020-08-28 11:18:47 +0100101 * @param[in] input1 First input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
102 * @param[in] input2 Second input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
103 * @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 +0000104 * @param[in] scale Scale to apply after multiplication.
105 * 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 +0100106 * If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255
107 * @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 +0000108 * @param[in] rounding_policy Rounding policy.
109 *
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000110 * @return a status
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +0000111 */
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000112 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 +0100113
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100114 // Inherited methods overridden
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100115 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100116
117private:
118 /** Common signature for all the specialised multiplication functions with integer scaling factor
119 *
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100120 * @param[in] in1 Input1 tensor object.
121 * @param[in] in2 Input2 tensor object.
122 * @param[out] out Output tensor object.
123 * @param[in] window Region on which to execute the kernel
124 * @param[in] scale Integer scale factor.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100125 */
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100126 using MulFunctionInt = void(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, int scale);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100127 /** Common signature for all the specialised multiplication functions with float scaling factor
128 *
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100129 * @param[in] in1 Input1 tensor object.
130 * @param[in] in2 Input2 tensor object.
131 * @param[out] out Output tensor object.
132 * @param[in] window Region on which to execute the kernel
133 * @param[in] scale Float scale factor.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100134 */
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100135 using MulFunctionFloat = void(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, float scale);
Manuel Bottini79fa9a22019-02-22 17:54:22 +0000136 /** Common signature for all the specialised QASYMM8 multiplication functions with float scaling factor
137 *
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100138 * @param[in] in1 Input1 tensor object.
139 * @param[in] in2 Input2 tensor object.
140 * @param[out] out Output tensor object.
141 * @param[in] window Region on which to execute the kernel
142 * @param[in] scale Float scale factor.
Manuel Bottini79fa9a22019-02-22 17:54:22 +0000143 *
144 */
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100145 using MulFunctionQuantized = void(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, float scale);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100146
Manuel Bottini7bb56c62019-06-26 15:17:09 +0100147 MulFunctionFloat *_func_float;
148 MulFunctionInt *_func_int;
149 MulFunctionQuantized *_func_quantized;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100150
151private:
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100152 float _scale;
153 int _scale_exponent;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100154};
giuros01154bc1c2019-03-26 17:44:40 +0000155
156/** Interface for the complex pixelwise multiplication kernel. */
157class NEComplexPixelWiseMultiplicationKernel : public INEKernel
158{
159public:
160 const char *name() const override
161 {
162 return "NEComplexPixelWiseMultiplicationKernel";
163 }
giuros01154bc1c2019-03-26 17:44:40 +0000164 /** Initialise the kernel's input, output and border mode.
165 *
166 * @param[in] input1 An input tensor. Data types supported: F32. Number of channels supported: 2 (complex tensor).
167 * @param[in] input2 An input tensor. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
168 * @param[out] output The output tensor, Data types supported: same as @p input1. Number of channels supported: same as @p input1.
169 */
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100170 void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output);
giuros01154bc1c2019-03-26 17:44:40 +0000171 /** Static function to check if given info will lead to a valid configuration of @ref NEComplexPixelWiseMultiplicationKernel
172 *
173 * @param[in] input1 An input tensor info. Data types supported: F32. Number of channels supported: 2 (complex tensor).
174 * @param[in] input2 An input tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
175 * @param[in] output The output tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
176 *
177 * @return a status
178 */
179 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
180
181 // Inherited methods overridden:
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100182 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
giuros01154bc1c2019-03-26 17:44:40 +0000183};
184
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100185} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000186#endif /*ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H */