blob: 612177152b3bc9e19ea3fce432cd423bf18e3224 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Manuel Bottini79fa9a22019-02-22 17:54:22 +00002 * Copyright (c) 2016-2019 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 *
56 * @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 *
Manuel Bottini7bb56c62019-06-26 15:17:09 +010059 * @param[in] input1 An input tensor. Data types supported: U8/QASYMM8/S16/QSYMM16/F16/F32
60 * @param[in] input2 An input tensor. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), S16, QSYMM16 (only if @p input1 is QSYMM16), F16 (only if @p input1 is F16), F32 (only if @p input1 is F32).
61 * @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 (only if @p input1 is F16), F32 (only if both inputs are F32).
Anthony Barbier6ff3b192017-09-04 18:44:23 +010062 * @param[in] scale Scale to apply after multiplication.
63 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
Manuel Bottini7bb56c62019-06-26 15:17:09 +010064 * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if datatype is QASYMM8 or QSYMM16.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010065 * @param[in] rounding_policy Rounding policy.
66 */
67 void configure(const ITensor *input1, const ITensor *input2, ITensor *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy);
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000068 /** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplicationKernel
69 *
Michalis Spyrouafa5d812017-11-30 14:25:57 +000070 * @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.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000072 *
Manuel Bottini7bb56c62019-06-26 15:17:09 +010073 * @param[in] input1 An input tensor info. Data types supported: U8/QASYMM8/QSYMM16/S16/F16/F32
74 * @param[in] input2 An input tensor info. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), S16, QSYMM16 (only if @p input1 is QSYMM16), F16 (only if @p input1 is F16), F32 (only if @p input1 is F32).
75 * @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 (only if @p input1 is F16), F32 (only if both inputs are F32).
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000076 * @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.
Manuel Bottini7bb56c62019-06-26 15:17:09 +010078 * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if datatype is QASYMM8 or QSYMM16.
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000079 * @param[in] rounding_policy Rounding policy.
80 *
Georgios Pinitas631c41a2017-12-06 11:53:03 +000081 * @return a status
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000082 */
Georgios Pinitas631c41a2017-12-06 11:53:03 +000083 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 +010084
85 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010086 void run(const Window &window, const ThreadInfo &info) override;
Michalis Spyrou861f0db2018-02-26 16:47:58 +000087 BorderSize border_size() const override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010088
89private:
90 /** Common signature for all the specialised multiplication functions with integer scaling factor
91 *
92 * @param[in] input1_ptr Pointer to the first input tensor.
93 * @param[in] input2_ptr Pointer to the second input tensor.
94 * @param[out] output_ptr Pointer to the output tensor.
Manuel Bottini79fa9a22019-02-22 17:54:22 +000095 * @param[in] scale Integer scale factor.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096 */
97 using MulFunctionInt = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, int scale);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010098 /** Common signature for all the specialised multiplication functions with float scaling factor
99 *
100 * @param[in] input1_ptr Pointer to the first input tensor.
101 * @param[in] input2_ptr Pointer to the second input tensor.
102 * @param[out] output_ptr Pointer to the output tensor.
Manuel Bottini79fa9a22019-02-22 17:54:22 +0000103 * @param[in] scale Float scale factor.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100104 */
105 using MulFunctionFloat = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, float scale);
Manuel Bottini79fa9a22019-02-22 17:54:22 +0000106 /** Common signature for all the specialised QASYMM8 multiplication functions with float scaling factor
107 *
108 * @param[in] input1_ptr Pointer to the first input tensor.
109 * @param[in] input2_ptr Pointer to the second input tensor.
110 * @param[out] output_ptr Pointer to the output tensor.
111 * @param[in] scale Float scale factor.
112 * @param[in] input1_qua_info Quantization Info of tensor input1.
113 * @param[in] input2_qua_info Quantization Info of tensor input2.
114 * @param[in] output_qua_info Quantization Info of tensor output.
115 *
116 */
Manuel Bottini7bb56c62019-06-26 15:17:09 +0100117 using MulFunctionQuantized = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, float scale,
118 const UniformQuantizationInfo &input1_qua_info, const UniformQuantizationInfo &input2_qua_info, const UniformQuantizationInfo &output_qua_info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100119
Manuel Bottini7bb56c62019-06-26 15:17:09 +0100120 MulFunctionFloat *_func_float;
121 MulFunctionInt *_func_int;
122 MulFunctionQuantized *_func_quantized;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100123
124private:
125 const ITensor *_input1;
126 const ITensor *_input2;
127 ITensor *_output;
128 float _scale;
129 int _scale_exponent;
Gian Marco Iodiceb19c55d2019-08-30 17:50:15 +0100130 bool _run_optimized_qasymm8;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100131};
giuros01154bc1c2019-03-26 17:44:40 +0000132
133/** Interface for the complex pixelwise multiplication kernel. */
134class NEComplexPixelWiseMultiplicationKernel : public INEKernel
135{
136public:
137 const char *name() const override
138 {
139 return "NEComplexPixelWiseMultiplicationKernel";
140 }
141 /** Default constructor.*/
142 NEComplexPixelWiseMultiplicationKernel();
143 /** Prevent instances of this class from being copied (As this class contains pointers) */
144 NEComplexPixelWiseMultiplicationKernel(const NEComplexPixelWiseMultiplicationKernel &) = delete;
145 /** Prevent instances of this class from being copied (As this class contains pointers) */
146 NEComplexPixelWiseMultiplicationKernel &operator=(const NEComplexPixelWiseMultiplicationKernel &) = delete;
147 /** Allow instances of this class to be moved */
148 NEComplexPixelWiseMultiplicationKernel(NEComplexPixelWiseMultiplicationKernel &&) = default;
149 /** Allow instances of this class to be moved */
150 NEComplexPixelWiseMultiplicationKernel &operator=(NEComplexPixelWiseMultiplicationKernel &&) = default;
151 /** Initialise the kernel's input, output and border mode.
152 *
153 * @param[in] input1 An input tensor. Data types supported: F32. Number of channels supported: 2 (complex tensor).
154 * @param[in] input2 An input tensor. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
155 * @param[out] output The output tensor, Data types supported: same as @p input1. Number of channels supported: same as @p input1.
156 */
157 void configure(const ITensor *input1, const ITensor *input2, ITensor *output);
158 /** Static function to check if given info will lead to a valid configuration of @ref NEComplexPixelWiseMultiplicationKernel
159 *
160 * @param[in] input1 An input tensor info. Data types supported: F32. Number of channels supported: 2 (complex tensor).
161 * @param[in] input2 An input tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
162 * @param[in] output The output tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
163 *
164 * @return a status
165 */
166 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
167
168 // Inherited methods overridden:
169 void run(const Window &window, const ThreadInfo &info) override;
170 BorderSize border_size() const override;
171
172private:
173 const ITensor *_input1;
174 const ITensor *_input2;
175 ITensor *_output;
176};
177
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100178} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000179#endif /*ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H */