Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Matthew Bentham | f1aeab9 | 2023-05-30 13:35:34 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2016-2021, 2023 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_NEPIXELWISEMULTIPLICATION_H |
| 25 | #define ARM_COMPUTE_NEPIXELWISEMULTIPLICATION_H |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
Matthew Bentham | f1aeab9 | 2023-05-30 13:35:34 +0000 | [diff] [blame^] | 27 | #include "arm_compute/core/ActivationLayerInfo.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/Types.h" |
Matthew Bentham | f1aeab9 | 2023-05-30 13:35:34 +0000 | [diff] [blame^] | 29 | #include "arm_compute/core/Rounding.h" |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 30 | #include "arm_compute/runtime/IFunction.h" |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 31 | |
| 32 | #include <memory> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | class ITensor; |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 37 | class ITensorInfo; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 38 | |
Georgios Pinitas | 0dc0d8e | 2021-04-30 03:18:37 +0100 | [diff] [blame] | 39 | /** Basic function to run @ref cpu::CpuMul */ |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 40 | class NEPixelWiseMultiplication : public IFunction |
| 41 | { |
| 42 | public: |
| 43 | /** Default Constructor */ |
| 44 | NEPixelWiseMultiplication(); |
| 45 | /** Default Destructor */ |
| 46 | ~NEPixelWiseMultiplication(); |
| 47 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 48 | NEPixelWiseMultiplication(const NEPixelWiseMultiplication &) = delete; |
| 49 | /** Default move constructor */ |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 50 | NEPixelWiseMultiplication(NEPixelWiseMultiplication &&) = default; |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 51 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 52 | NEPixelWiseMultiplication &operator=(const NEPixelWiseMultiplication &) = delete; |
| 53 | /** Default move assignment operator */ |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 54 | NEPixelWiseMultiplication &operator=(NEPixelWiseMultiplication &&) = default; |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 55 | /** Initialise the kernel's inputs, output and convertion policy. |
| 56 | * |
Sheri Zhang | a47dcc2 | 2021-04-22 14:41:12 +0100 | [diff] [blame] | 57 | * Valid data layouts: |
| 58 | * - All |
| 59 | * |
| 60 | * Valid data type configurations: |
| 61 | * |src0 |src1 |dst | |
| 62 | * |:--------------|:--------------|:--------------| |
| 63 | * |QASYMM8 |QASYMM8 |QASYMM8 | |
| 64 | * |QASYMM8_SIGNED |QASYMM8_SIGNED |QASYMM8_SIGNED | |
| 65 | * |QSYMM16 |QSYMM16 |QASYMM16 | |
| 66 | * |QSYMM16 |QSYMM16 |S32 | |
| 67 | * |U8 |U8 |U8 | |
| 68 | * |U8 |U8 |S16 | |
| 69 | * |U8 |S16 |S16 | |
| 70 | * |S16 |U8 |S16 | |
| 71 | * |S16 |S16 |S16 | |
| 72 | * |F16 |F16 |F16 | |
| 73 | * |F32 |S32 |F32 | |
| 74 | * |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 75 | * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported. |
| 76 | * For all other scale values only round to zero (implemented as round towards minus infinity) is supported. |
| 77 | * |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 78 | * @param[in, out] input1 An input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32 |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 79 | * This input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 80 | * @param[in, out] 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, S32, QSYMM16 (only if @p input1 is QSYMM16), F16 (only if @p input1 is F16), F32 (only if @p input1 is F32). |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 81 | * This input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. |
| 82 | * @param[out] output Output tensor. Data types supported: |
| 83 | * - U8, only if both inputs are U8. |
| 84 | * - QASYMM8, only if both inputs are QASYMM8. |
| 85 | * - QASYMM8_SIGNED, only if @p input1 is QASYMM8_SIGNED. |
| 86 | * - S16. |
| 87 | * - QSYMM16, only if both inputs are QSYMM16. |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 88 | * - S32, only if both inputs are S32 or both are QSYMM16. |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 89 | * - F16, only if @p input1 is F16. |
| 90 | * - F32, only if both inputs are F32. |
| 91 | * @param[in] scale Scale to apply after multiplication. |
| 92 | * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15. |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 93 | * If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255 |
| 94 | * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 95 | * @param[in] rounding_policy Rounding policy. |
| 96 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
| 97 | */ |
| 98 | void configure(const ITensor *input1, const ITensor *input2, ITensor *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, |
| 99 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
| 100 | /** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplication |
| 101 | * |
| 102 | * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported. |
| 103 | * For all other scale values only round to zero (implemented as round towards minus infinity) is supported. |
| 104 | * |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 105 | * @param[in] input1 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32 |
| 106 | * @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, S32, QSYMM16 (only if both inputs are QSYMM16), F16 (only if @p input1 is F16), F32 (only if @p input1 is F32). |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 107 | * @param[in] output Output tensor info. Data types supported: |
| 108 | * - U8, only if both inputs are U8. |
| 109 | * - QASYMM8, only if both inputs are QASYMM8. |
| 110 | * - QASYMM8_SIGNED, only if @p input1 is QASYMM8_SIGNED. |
| 111 | * - S16. |
| 112 | * - QSYMM16, only if both inputs are QSYMM16. |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 113 | * - S32, only if both inputs are S32 or both are QSYMM16. |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 114 | * - F16, only if @p input1 is F16. |
| 115 | * - F32, only if both inputs are F32. |
| 116 | * @param[in] scale Scale to apply after multiplication. |
| 117 | * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15. |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 118 | * If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255 |
| 119 | * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 120 | * @param[in] rounding_policy Rounding policy. |
| 121 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
| 122 | * |
| 123 | * @return a status |
| 124 | */ |
| 125 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, |
| 126 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
| 127 | |
| 128 | // Inherited methods overridden: |
| 129 | void run() override; |
| 130 | |
| 131 | private: |
| 132 | struct Impl; |
| 133 | std::unique_ptr<Impl> _impl; |
| 134 | }; |
| 135 | |
Georgios Pinitas | 0dc0d8e | 2021-04-30 03:18:37 +0100 | [diff] [blame] | 136 | /** Basic function to run @ref cpu::CpuComplexMul. */ |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 137 | class NEComplexPixelWiseMultiplication : public IFunction |
| 138 | { |
| 139 | public: |
| 140 | /** Default Constructor */ |
| 141 | NEComplexPixelWiseMultiplication(); |
| 142 | /** Default Destructor */ |
| 143 | ~NEComplexPixelWiseMultiplication(); |
| 144 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 145 | NEComplexPixelWiseMultiplication(const NEComplexPixelWiseMultiplication &) = delete; |
| 146 | /** Default move constructor */ |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 147 | NEComplexPixelWiseMultiplication(NEComplexPixelWiseMultiplication &&) = default; |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 148 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 149 | NEComplexPixelWiseMultiplication &operator=(const NEComplexPixelWiseMultiplication &) = delete; |
| 150 | /** Default move assignment operator */ |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 151 | NEComplexPixelWiseMultiplication &operator=(NEComplexPixelWiseMultiplication &&) = default; |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 152 | /** Initialise the kernel's inputs, output. |
| 153 | * |
| 154 | * @param[in, out] input1 An input tensor. Data types supported: F32. Number of channels supported: 2 (complex tensor). |
| 155 | * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. |
| 156 | * @param[in, out] input2 An input tensor. Data types supported: same as @p input1. Number of channels supported: same as @p input1. |
| 157 | * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. |
| 158 | * @param[out] output The output tensor. Data types supported: same as @p input1. Number of channels: same as @p input1. |
| 159 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
| 160 | */ |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 161 | void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 162 | /** Static function to check if given info will lead to a valid configuration of @ref NEComplexPixelWiseMultiplication |
| 163 | * |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 164 | * @param[in] input1 An input tensor info. Data types supported: F32. Number of channels supported: 2 (complex tensor). |
| 165 | * @param[in] input2 An input tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1. |
| 166 | * @param[in] output The output tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1. |
| 167 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 168 | */ |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 169 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 170 | |
| 171 | // Inherited methods overridden: |
| 172 | void run() override; |
| 173 | |
| 174 | private: |
| 175 | struct Impl; |
| 176 | std::unique_ptr<Impl> _impl; |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 177 | }; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 178 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 179 | #endif /*ARM_COMPUTE_NEPIXELWISEMULTIPLICATION_H */ |