blob: 5483fae56539c77f15a0cf2371ed48aad6fd6697 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgio9428a182020-03-30 14:10:20 +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 *
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 *
Pablo Tello52ea9c22019-12-10 11:28:53 +000059 * @param[in] input1 An input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32
60 * @param[in] 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, QSYMM16 (only if @p input1 is QSYMM16), F16 (only if @p input1 is F16), F32 (only if @p input1 is F32).
Michele Di Giorgio9428a182020-03-30 14:10:20 +010061 * @param[out] output Output tensor. Data types supported:
62 * - U8, only if both inputs are U8.
63 * - QASYMM8, only if both inputs are QASYMM8.
64 * - QASYMM8_SIGNED, only if @p input1 is QASYMM8_SIGNED.
65 * - S16.
66 * - QSYMM16, only if both inputs are QSYMM16.
67 * - S32, only if both inputs are QSYMM16.
68 * - F16, only if @p input1 is F16.
69 * - F32, only if both inputs are F32.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070 * @param[in] scale Scale to apply after multiplication.
71 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
Pablo Tello52ea9c22019-12-10 11:28:53 +000072 * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if datatype is QASYMM8, QASYMM8_SIGNED or QSYMM16.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010073 * @param[in] rounding_policy Rounding policy.
74 */
Michalis Spyrou6eb73452020-07-02 17:39:25 +010075 void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy);
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000076 /** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplicationKernel
77 *
Michalis Spyrouafa5d812017-11-30 14:25:57 +000078 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
79 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000080 *
Pablo Tello52ea9c22019-12-10 11:28:53 +000081 * @param[in] input1 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/QSYMM16/S16/F16/F32
82 * @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, QSYMM16 (only if @p input1 is QSYMM16), F16 (only if @p input1 is F16), F32 (only if @p input1 is F32).
Michele Di Giorgio9428a182020-03-30 14:10:20 +010083 * @param[in] output Output tensor info. Data types supported:
84 * - U8, only if both inputs are U8.
85 * - QASYMM8, only if both inputs are QASYMM8.
86 * - QASYMM8_SIGNED, only if @p input1 is QASYMM8_SIGNED.
87 * - S16.
88 * - QSYMM16, only if both inputs are QSYMM16.
89 * - S32, only if both inputs are QSYMM16.
90 * - F16, only if @p input1 is F16.
91 * - F32, only if both inputs are F32.
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000092 * @param[in] scale Scale to apply after multiplication.
93 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
Pablo Tello52ea9c22019-12-10 11:28:53 +000094 * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if datatype is QASYMM8, QASYMM8_SIGNED or QSYMM16.
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000095 * @param[in] rounding_policy Rounding policy.
96 *
Georgios Pinitas631c41a2017-12-06 11:53:03 +000097 * @return a status
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000098 */
Georgios Pinitas631c41a2017-12-06 11:53:03 +000099 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 +0100100
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100101 // Inherited methods overridden
102 void run_op(const InputTensorMap &inputs, const OutputTensorMap &outputs, const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100103
104private:
105 /** Common signature for all the specialised multiplication functions with integer scaling factor
106 *
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100107 * @param[in] in1 Input1 tensor object.
108 * @param[in] in2 Input2 tensor object.
109 * @param[out] out Output tensor object.
110 * @param[in] window Region on which to execute the kernel
111 * @param[in] scale Integer scale factor.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100112 */
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100113 using MulFunctionInt = void(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, int scale);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100114 /** Common signature for all the specialised multiplication functions with float scaling factor
115 *
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100116 * @param[in] in1 Input1 tensor object.
117 * @param[in] in2 Input2 tensor object.
118 * @param[out] out Output tensor object.
119 * @param[in] window Region on which to execute the kernel
120 * @param[in] scale Float scale factor.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100121 */
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100122 using MulFunctionFloat = void(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, float scale);
Manuel Bottini79fa9a22019-02-22 17:54:22 +0000123 /** Common signature for all the specialised QASYMM8 multiplication functions with float scaling factor
124 *
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100125 * @param[in] in1 Input1 tensor object.
126 * @param[in] in2 Input2 tensor object.
127 * @param[out] out Output tensor object.
128 * @param[in] window Region on which to execute the kernel
129 * @param[in] scale Float scale factor.
Manuel Bottini79fa9a22019-02-22 17:54:22 +0000130 *
131 */
Sheri Zhangfcf6f4e2020-06-25 20:01:00 +0100132 using MulFunctionQuantized = void(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, float scale);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100133
Manuel Bottini7bb56c62019-06-26 15:17:09 +0100134 MulFunctionFloat *_func_float;
135 MulFunctionInt *_func_int;
136 MulFunctionQuantized *_func_quantized;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100137
138private:
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100139 float _scale;
140 int _scale_exponent;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100141};
giuros01154bc1c2019-03-26 17:44:40 +0000142
143/** Interface for the complex pixelwise multiplication kernel. */
144class NEComplexPixelWiseMultiplicationKernel : public INEKernel
145{
146public:
147 const char *name() const override
148 {
149 return "NEComplexPixelWiseMultiplicationKernel";
150 }
giuros01154bc1c2019-03-26 17:44:40 +0000151 /** 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 */
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100157 void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output);
giuros01154bc1c2019-03-26 17:44:40 +0000158 /** 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:
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100169 void run_op(const InputTensorMap &inputs, const OutputTensorMap &outputs, const Window &window, const ThreadInfo &info) override;
giuros01154bc1c2019-03-26 17:44:40 +0000170};
171
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100172} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000173#endif /*ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H */