Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2019 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 | * |
| 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 Tello | 52ea9c2 | 2019-12-10 11:28:53 +0000 | [diff] [blame] | 59 | * @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). |
| 61 | * @param[out] output Output tensor. Data types supported: U8 (Only if both inputs are U8), QASYMM8 (only if both inputs are QASYMM8), QASYMM8_SIGNED (only if @p input1 is QASYMM8_SIGNED), S16, QSYMM16 (only if both inputs are QSYMM16), F16 (only if @p input1 is F16), F32 (only if both inputs are F32). |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 62 | * @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. |
Pablo Tello | 52ea9c2 | 2019-12-10 11:28:53 +0000 | [diff] [blame] | 64 | * @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] | 65 | * @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 Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 68 | /** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplicationKernel |
| 69 | * |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [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. |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 72 | * |
Pablo Tello | 52ea9c2 | 2019-12-10 11:28:53 +0000 | [diff] [blame] | 73 | * @param[in] input1 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/QSYMM16/S16/F16/F32 |
| 74 | * @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). |
| 75 | * @param[in] output Output tensor info. Data types supported: U8 (Only if both inputs are U8), QASYMM8 (only if both inputs are QASYMM8), QASYMM8_SIGNED (only if @p input1 is QASYMM8_SIGNED) , S16, QSYMM16 (only if both inputs are QSYMM16), F16 (only if @p input1 is F16), F32 (only if both inputs are F32). |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [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. |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 79 | * @param[in] rounding_policy Rounding policy. |
| 80 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 81 | * @return a status |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 82 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 83 | 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] | 84 | |
| 85 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 86 | void run(const Window &window, const ThreadInfo &info) override; |
Michalis Spyrou | 861f0db | 2018-02-26 16:47:58 +0000 | [diff] [blame] | 87 | BorderSize border_size() const override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 88 | |
| 89 | private: |
| 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 Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 95 | * @param[in] scale Integer scale factor. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 96 | */ |
| 97 | using MulFunctionInt = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, int scale); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 98 | /** 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 Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 103 | * @param[in] scale Float scale factor. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 104 | */ |
| 105 | using MulFunctionFloat = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, float scale); |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 106 | /** 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 Bottini | 7bb56c6 | 2019-06-26 15:17:09 +0100 | [diff] [blame] | 117 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 119 | |
Manuel Bottini | 7bb56c6 | 2019-06-26 15:17:09 +0100 | [diff] [blame] | 120 | MulFunctionFloat *_func_float; |
| 121 | MulFunctionInt *_func_int; |
| 122 | MulFunctionQuantized *_func_quantized; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 123 | |
| 124 | private: |
| 125 | const ITensor *_input1; |
| 126 | const ITensor *_input2; |
| 127 | ITensor *_output; |
| 128 | float _scale; |
| 129 | int _scale_exponent; |
Gian Marco Iodice | b19c55d | 2019-08-30 17:50:15 +0100 | [diff] [blame] | 130 | bool _run_optimized_qasymm8; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 131 | }; |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 132 | |
| 133 | /** Interface for the complex pixelwise multiplication kernel. */ |
| 134 | class NEComplexPixelWiseMultiplicationKernel : public INEKernel |
| 135 | { |
| 136 | public: |
| 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 | |
| 172 | private: |
| 173 | const ITensor *_input1; |
| 174 | const ITensor *_input2; |
| 175 | ITensor *_output; |
| 176 | }; |
| 177 | |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 178 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 179 | #endif /*ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H */ |