Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2020 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 3 | * |
| 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 Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H |
| 25 | #define ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/NEON/INEKernel.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | class ITensor; |
| 33 | |
| 34 | /** Interface for the kernel to perform addition between two tensors */ |
| 35 | class NEPixelWiseMultiplicationKernel : public INEKernel |
| 36 | { |
| 37 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 38 | const char *name() const override |
| 39 | { |
| 40 | return "NEPixelWiseMultiplicationKernel"; |
| 41 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 42 | /** 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 Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame^] | 56 | * Valid configurations (Input1,Input2) -> Output : |
| 57 | * |
| 58 | * - (U8,U8) -> U8 |
| 59 | * - (U8,U8) -> S16 |
| 60 | * - (U8,S16) -> S16 |
| 61 | * - (S16,U8) -> S16 |
| 62 | * - (S16,S16) -> S16 |
| 63 | * - (F16,F16) -> F16 |
| 64 | * - (F32,F32) -> F32 |
| 65 | * - (QASYMM8,QASYMM8) -> QASYMM8 |
| 66 | * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED |
| 67 | * - (QSYMM16,QSYMM16) -> QSYMM16 |
| 68 | * - (QSYMM16,QSYMM16) -> S32 |
| 69 | * |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 70 | * @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 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame^] | 73 | * @param[in] input1 First input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32 |
| 74 | * @param[in] input2 Second input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32 |
| 75 | * @param[out] output Output tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32/S32 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 76 | * @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. |
Pablo Tello | 52ea9c2 | 2019-12-10 11:28:53 +0000 | [diff] [blame] | 78 | * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if datatype is QASYMM8, QASYMM8_SIGNED or QSYMM16. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 79 | * @param[in] rounding_policy Rounding policy. |
| 80 | */ |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 81 | void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy); |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 82 | /** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplicationKernel |
| 83 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame^] | 84 | * Valid configurations (Input1,Input2) -> Output : |
| 85 | * |
| 86 | * - (U8,U8) -> U8 |
| 87 | * - (U8,U8) -> S16 |
| 88 | * - (U8,S16) -> S16 |
| 89 | * - (S16,U8) -> S16 |
| 90 | * - (S16,S16) -> S16 |
| 91 | * - (F16,F16) -> F16 |
| 92 | * - (F32,F32) -> F32 |
| 93 | * - (QASYMM8,QASYMM8) -> QASYMM8 |
| 94 | * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED |
| 95 | * - (QSYMM16,QSYMM16) -> QSYMM16 |
| 96 | * - (QSYMM16,QSYMM16) -> S32 |
| 97 | * |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 98 | * @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 Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 100 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame^] | 101 | * @param[in] input1 First input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32 |
| 102 | * @param[in] input2 Second input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32 |
| 103 | * @param[in] output Output tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32/S32 |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 104 | * @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. |
Pablo Tello | 52ea9c2 | 2019-12-10 11:28:53 +0000 | [diff] [blame] | 106 | * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if datatype is QASYMM8, QASYMM8_SIGNED or QSYMM16. |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 107 | * @param[in] rounding_policy Rounding policy. |
| 108 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 109 | * @return a status |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 110 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 111 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 112 | |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 113 | // Inherited methods overridden |
| 114 | void run_op(const InputTensorMap &inputs, const OutputTensorMap &outputs, const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 115 | |
| 116 | private: |
| 117 | /** Common signature for all the specialised multiplication functions with integer scaling factor |
| 118 | * |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 119 | * @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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 124 | */ |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 125 | using MulFunctionInt = void(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, int scale); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 126 | /** Common signature for all the specialised multiplication functions with float scaling factor |
| 127 | * |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 128 | * @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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 133 | */ |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 134 | using MulFunctionFloat = void(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, float scale); |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 135 | /** Common signature for all the specialised QASYMM8 multiplication functions with float scaling factor |
| 136 | * |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 137 | * @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 Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 142 | * |
| 143 | */ |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 144 | using MulFunctionQuantized = void(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, float scale); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 145 | |
Manuel Bottini | 7bb56c6 | 2019-06-26 15:17:09 +0100 | [diff] [blame] | 146 | MulFunctionFloat *_func_float; |
| 147 | MulFunctionInt *_func_int; |
| 148 | MulFunctionQuantized *_func_quantized; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 149 | |
| 150 | private: |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 151 | float _scale; |
| 152 | int _scale_exponent; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 153 | }; |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 154 | |
| 155 | /** Interface for the complex pixelwise multiplication kernel. */ |
| 156 | class NEComplexPixelWiseMultiplicationKernel : public INEKernel |
| 157 | { |
| 158 | public: |
| 159 | const char *name() const override |
| 160 | { |
| 161 | return "NEComplexPixelWiseMultiplicationKernel"; |
| 162 | } |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 163 | /** 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 Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 169 | void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 170 | /** 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: |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 181 | void run_op(const InputTensorMap &inputs, const OutputTensorMap &outputs, const Window &window, const ThreadInfo &info) override; |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 182 | }; |
| 183 | |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 184 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 185 | #endif /*ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H */ |