Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 1 | /* |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 Arm Limited. |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [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_NEGEMMLOWPOUTPUTSTAGE_H |
| 25 | #define ARM_COMPUTE_NEGEMMLOWPOUTPUTSTAGE_H |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 26 | |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/Types.h" |
Michalis Spyrou | 95abfdd | 2018-11-28 14:59:47 +0000 | [diff] [blame] | 28 | #include "arm_compute/runtime/NEON/INESimpleFunctionNoBorder.h" |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 29 | |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 30 | /** This file contains all available output stages for GEMMLowp. |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 31 | * |
| 32 | * In gemmlowp, the "output stage" is the process that takes a final int32 accumulator value (the output of @ref NEGEMMLowpMatrixMultiplyCore), |
| 33 | * and processes it to obtain the final ASYMM8 value. |
| 34 | * |
| 35 | * More information about the GEMMLowp output stage can be found at https://github.com/google/gemmlowp/blob/master/doc/output.md |
| 36 | */ |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | class ITensor; |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 41 | class ITensorInfo; |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 42 | |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 43 | /** Basic function to execute NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint. |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 44 | * |
| 45 | * NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint depends on 3 parameters: |
| 46 | * |
| 47 | * result_fixedpoint_multiplier, result_shift, result_offset_after_shift |
| 48 | * |
| 49 | * The final result is: |
| 50 | * |
| 51 | * (FixedPointMul(input[i][k], result_fixedpoint_multiplier) >> result_shift) + result_offset_after_shift |
| 52 | * |
| 53 | * where FixedPointMul(x, y) is the nearest integer to the following |
| 54 | * mathematical expression, evaluated without overflow or intermediate rounding: |
| 55 | * |
| 56 | * (x * y) / 2^31 |
| 57 | * |
| 58 | * For more information: https://github.com/google/gemmlowp/blob/master/public/output_stages.h#L68 |
| 59 | * |
| 60 | * In case the bias tensor is provided, the final result is: |
| 61 | * |
| 62 | * ((FixedPointMul(input[i][k] + bias[k], result_fixedpoint_multiplier)) >> result_shift) + result_offset_after_shift |
| 63 | * |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 64 | * This function calls the following kernels: |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 65 | * |
| 66 | * -# @ref NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel |
| 67 | * |
| 68 | * @note The function accepts also 2 optional input arguments (min and max) which can be used to implement "rectified linear unit" activation functions |
| 69 | * after the result is shifted right by result_shift |
| 70 | */ |
Michalis Spyrou | 95abfdd | 2018-11-28 14:59:47 +0000 | [diff] [blame] | 71 | class NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint : public INESimpleFunctionNoBorder |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 72 | { |
| 73 | public: |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 74 | /** Constructor */ |
| 75 | NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint() = default; |
| 76 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 77 | NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint(const NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint &) = delete; |
| 78 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 79 | NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint &operator=(const NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint &) = delete; |
| 80 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 81 | NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint(NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint &&) = delete; |
| 82 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 83 | NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint &operator=(NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint &&) = delete; |
| 84 | /** Default destructor */ |
| 85 | ~NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint(); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 86 | /** Initialise the kernel's inputs, output |
| 87 | * |
| 88 | * @param[in] input Input tensor. Data type supported: S32 |
| 89 | * @param[in] bias Biases tensor. Only shared biases supported and it can be a nullptr if the biases addition is not required. |
| 90 | * Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p input. |
| 91 | * @param[out] output Output tensor. Data type supported: Data type supported: QASYMM8 |
| 92 | * @param[in] result_fixedpoint_multiplier Fixed point value to be multiplied to each element of the input matrix when once the result_offset has been add |
| 93 | * @param[in] result_shift Number of bits to shift right the result after the fixed point multiplication |
| 94 | * @param[in] result_offset_after_shift Offset to be applied to result before converting it back to QASYMM8 |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 95 | * @param[in] min (Optional) Min value used to saturate down the output result before converting back to QASYMM8. Defaults to the minimum possible 32-bit signed integer. |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 96 | * @param[in] max (Optional) Max value used to saturate up the output result before converting back to QASYMM8, |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 97 | * Along with @p min, this value can be used to implement "rectified linear unit" activation functions. Defaults to the maximum possible 32-bit signed integer. |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 98 | */ |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 99 | void configure(const ITensor *input, const ITensor *bias, ITensor *output, int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift, |
| 100 | int min = std::numeric_limits<int32_t>::lowest(), int max = std::numeric_limits<int32_t>::max()); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 101 | /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint |
| 102 | * |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 103 | * @param[in] input Input tensor. It is the output of @ref NEGEMMLowpMatrixMultiplyCore function. Data type supported: S32 |
| 104 | * @param[in] bias Biases tensor. Only shared biases supported and it can be a nullptr if the addition of biases is not required. |
| 105 | * Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p input. |
| 106 | * @param[in] output Output tensor. Data type supported: Data type supported: QASYMM8 |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 107 | * @param[in] min (Optional) Min value used to saturate down the output result before converting back to QASYMM8. Defaults to the minimum possible 32-bit signed integer. |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 108 | * @param[in] max (Optional) Max value used to saturate up the output result before converting back to QASYMM8, |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 109 | * Along with @p min, this value can be used to implement "rectified linear unit" activation functions. Defaults to the maximum possible 32-bit signed integer. |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 110 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 111 | * @return a status |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 112 | */ |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 113 | static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, int min = std::numeric_limits<int32_t>::lowest(), int max = std::numeric_limits<int32_t>::max()); |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 114 | }; |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 115 | /** Basic function to execute NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint. |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 116 | * |
| 117 | * NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint depends on 3 parameters: |
| 118 | * |
| 119 | * result_fixedpoint_multiplier, result_shift, result_offset_after_shift |
| 120 | * |
| 121 | * The final result is: |
| 122 | * |
| 123 | * (FixedPointMul(input[i][k], result_fixedpoint_multiplier) >> result_shift) + result_offset_after_shift |
| 124 | * |
| 125 | * where FixedPointMul(x, y) is the nearest integer to the following |
| 126 | * mathematical expression, evaluated without overflow or intermediate rounding: |
| 127 | * |
| 128 | * (x * y) / 2^31 |
| 129 | * |
| 130 | * For more information: https://github.com/google/gemmlowp/blob/master/public/output_stages.h#L68 |
| 131 | * |
| 132 | * In case the bias tensor is provided, the final result is: |
| 133 | * |
| 134 | * ((FixedPointMul(input[i][k] + bias[k], result_fixedpoint_multiplier)) >> result_shift) + result_offset_after_shift |
| 135 | * |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 136 | * This function calls the following kernels: |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 137 | * |
| 138 | * -# @ref NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel |
| 139 | * |
| 140 | * @note The function accepts also 2 optional input arguments (min and max) which can be used to implement "rectified linear unit" activation functions |
| 141 | * after the result is shifted right by result_shift |
| 142 | */ |
| 143 | class NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint : public INESimpleFunctionNoBorder |
| 144 | { |
| 145 | public: |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 146 | /** Constructor */ |
| 147 | NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint() = default; |
| 148 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 149 | NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint(const NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint &) = delete; |
| 150 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 151 | NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint &operator=(const NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint &) = delete; |
| 152 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 153 | NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint(NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint &&) = delete; |
| 154 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 155 | NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint &operator=(NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint &&) = delete; |
| 156 | /** Default destructor */ |
| 157 | ~NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint(); |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 158 | /** Initialise the kernel's inputs, output |
| 159 | * |
| 160 | * @param[in] input Input tensor. Data type supported: S32 |
| 161 | * @param[in] bias Biases tensor. Only shared biases supported and it can be a nullptr if the biases addition is not required. |
| 162 | * Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p input. |
| 163 | * @param[out] output Output tensor. Data type supported: Data type supported: QASYMM8_SIGNED |
| 164 | * @param[in] result_fixedpoint_multiplier Fixed point value to be multiplied to each element of the input matrix when once the result_offset has been add |
| 165 | * @param[in] result_shift Number of bits to shift right the result after the fixed point multiplication |
| 166 | * @param[in] result_offset_after_shift Offset to be applied to result before converting it back to QASYMM8_SIGNED |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 167 | * @param[in] min (Optional) Min value used to saturate down the output result before converting back to QASYMM8_SIGNED. Defaults to the minimum possible 32-bit signed integer. |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 168 | * @param[in] max (Optional) Max value used to saturate up the output result before converting back to QASYMM8_SIGNED, |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 169 | * Along with @p min, this value can be used to implement "rectified linear unit" activation functions. Defaults to the maximum possible 32-bit signed integer. |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 170 | */ |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 171 | void configure(const ITensor *input, const ITensor *bias, ITensor *output, int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift, |
| 172 | int min = std::numeric_limits<int32_t>::lowest(), int max = std::numeric_limits<int32_t>::max()); |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 173 | /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint |
| 174 | * |
| 175 | * @param[in] input Input tensor. It is the output of @ref NEGEMMLowpMatrixMultiplyCore function. Data type supported: S32 |
| 176 | * @param[in] bias Biases tensor. Only shared biases supported and it can be a nullptr if the addition of biases is not required. |
| 177 | * Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p input. |
| 178 | * @param[in] output Output tensor. Data type supported: Data type supported: QASYMM8_SIGNED |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 179 | * @param[in] min (Optional) Min value used to saturate down the output result before converting back to QASYMM8_SIGNED. Defaults to the minimum possible 32-bit signed integer. |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 180 | * @param[in] max (Optional) Max value used to saturate up the output result before converting back to QASYMM8_SIGNED, |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 181 | * Along with @p min, this value can be used to implement "rectified linear unit" activation functions. Defaults to the maximum possible 32-bit signed integer. |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 182 | * |
| 183 | * @return a status |
| 184 | */ |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 185 | static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, int min = std::numeric_limits<int32_t>::lowest(), int max = std::numeric_limits<int32_t>::max()); |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 186 | }; |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 187 | /** Basic function to execute NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint. |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 188 | * |
| 189 | * NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint depends on 2 parameters: |
| 190 | * |
| 191 | * result_fixedpoint_multiplier, result_shift |
| 192 | * |
| 193 | * The final result is: |
| 194 | * |
| 195 | * (FixedPointMul(input[i][k], result_fixedpoint_multiplier) >> result_shift) |
| 196 | * |
| 197 | * where FixedPointMul(x, y) is the nearest integer to the following |
| 198 | * mathematical expression, evaluated without overflow or intermediate rounding: |
| 199 | * |
| 200 | * (x * y) / 2^31 |
| 201 | * |
| 202 | * For more information: https://github.com/google/gemmlowp/blob/master/public/output_stages.h#L68 |
| 203 | * |
| 204 | * In case the bias tensor is provided, the final result is: |
| 205 | * |
| 206 | * ((FixedPointMul(input[i][k] + bias[k], result_fixedpoint_multiplier)) >> result_shift) + result_offset_after_shift |
| 207 | * |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 208 | * This function calls the following kernels: |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 209 | * |
| 210 | * -# @ref NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointKernel |
| 211 | * |
| 212 | * @note The function accepts also 2 optional input arguments (min and max) which can be used to implement "rectified linear unit" activation functions |
| 213 | * after the result is shifted right by result_shift |
| 214 | */ |
| 215 | class NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint : public INESimpleFunctionNoBorder |
| 216 | { |
| 217 | public: |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 218 | /** Constructor */ |
| 219 | NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint() = default; |
| 220 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 221 | NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint(const NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint &) = delete; |
| 222 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 223 | NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint &operator=(const NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint &) = delete; |
| 224 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 225 | NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint(NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint &&) = delete; |
| 226 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 227 | NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint &operator=(NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint &&) = delete; |
| 228 | /** Default destructor */ |
| 229 | ~NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint(); |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 230 | /** Initialise the kernel's inputs, output |
| 231 | * |
| 232 | * @param[in] input Input tensor. Data type supported: S32 |
| 233 | * @param[in] bias Biases tensor. Only shared biases supported and it can be a nullptr if the biases addition is not required. |
| 234 | * Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p input. |
| 235 | * @param[out] output Output tensor. Data type supported: Data type supported: QSYMM16 |
| 236 | * @param[in] result_fixedpoint_multiplier Fixed point value to be multiplied to each element of the input matrix when once the result_offset has been add |
| 237 | * @param[in] result_shift Number of bits to shift right the result after the fixed point multiplication |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 238 | * @param[in] min (Optional) Min value used to saturate down the output result before converting back to QSYMM16. Defaults to the minimum possible 32-bit signed integer. |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 239 | * @param[in] max (Optional) Max value used to saturate up the output result before converting back to QSYMM16. |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 240 | * Along with @p min, this value can be used to implement "rectified linear unit" activation functions. Defaults to the maximum possible 32-bit signed integer. |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 241 | */ |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 242 | void configure(const ITensor *input, const ITensor *bias, ITensor *output, int result_fixedpoint_multiplier, int result_shift, int min = std::numeric_limits<int32_t>::lowest(), |
| 243 | int max = std::numeric_limits<int32_t>::max()); |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 244 | /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint |
| 245 | * |
| 246 | * @param[in] input Input tensor info. It is the output of @ref NEGEMMLowpMatrixMultiplyCore function. Data type supported: S32 |
| 247 | * @param[in] bias Biases tensor info. Only shared biases supported and it can be a nullptr if the addition of biases is not required. |
| 248 | * Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p input. |
| 249 | * @param[in] output Output tensor info. Data type supported: Data type supported: QSYMM16 |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 250 | * @param[in] min (Optional) Min value used to saturate down the output result before converting back to QSYMM16. Defaults to the minimum possible 32-bit signed integer. |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 251 | * @param[in] max (Optional) Max value used to saturate up the output result before converting back to QSYMM16, |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 252 | * Along with @p min, this value can be used to implement "rectified linear unit" activation functions. Defaults to the maximum possible 32-bit signed integer. |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 253 | * |
| 254 | * @return a status |
| 255 | */ |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 256 | static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, int min = std::numeric_limits<int32_t>::lowest(), int max = std::numeric_limits<int32_t>::max()); |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 257 | }; |
Michele Di Giorgio | 9c70037 | 2020-01-08 11:33:44 +0000 | [diff] [blame] | 258 | |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 259 | /** Basic function to execute GEMMLowpQuantizeDown kernels. |
Michele Di Giorgio | 9c70037 | 2020-01-08 11:33:44 +0000 | [diff] [blame] | 260 | * |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 261 | * This function calls the following kernels: |
Michele Di Giorgio | 9c70037 | 2020-01-08 11:33:44 +0000 | [diff] [blame] | 262 | * |
Luca Foschiani | 4b86953 | 2020-02-13 15:07:36 +0000 | [diff] [blame] | 263 | * -# @ref NEGEMMLowpQuantizeDownInt32ScaleKernel |
Michele Di Giorgio | 9c70037 | 2020-01-08 11:33:44 +0000 | [diff] [blame] | 264 | * -# @ref NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel |
| 265 | * -# @ref NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel |
| 266 | * -# @ref NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointKernel |
| 267 | */ |
| 268 | class NEGEMMLowpOutputStage : public INESimpleFunctionNoBorder |
| 269 | { |
| 270 | public: |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 271 | /** Constructor */ |
| 272 | NEGEMMLowpOutputStage() = default; |
| 273 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 274 | NEGEMMLowpOutputStage(const NEGEMMLowpOutputStage &) = delete; |
| 275 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 276 | NEGEMMLowpOutputStage &operator=(const NEGEMMLowpOutputStage &) = delete; |
| 277 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 278 | NEGEMMLowpOutputStage(NEGEMMLowpOutputStage &&) = delete; |
| 279 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 280 | NEGEMMLowpOutputStage &operator=(NEGEMMLowpOutputStage &&) = delete; |
| 281 | /** Default destructor */ |
| 282 | ~NEGEMMLowpOutputStage(); |
Michele Di Giorgio | 9c70037 | 2020-01-08 11:33:44 +0000 | [diff] [blame] | 283 | /** Initialise the kernel's inputs, output |
| 284 | * |
Sheri Zhang | 6124ce6 | 2021-05-04 14:03:13 +0100 | [diff] [blame] | 285 | * Valid data layouts: |
| 286 | * - All |
| 287 | * |
| 288 | * Valid data type configurations: |
| 289 | * |src0 |src1 |dst | |
| 290 | * |:--------------|:-------------|:-------------| |
| 291 | * |S32 |S32 |QASYMM8 | |
| 292 | * |S32 |S32 |QASYMM8_SIGNED| |
| 293 | * |S32 |S32 |QSYMM16 | |
| 294 | * |
Michele Di Giorgio | 9c70037 | 2020-01-08 11:33:44 +0000 | [diff] [blame] | 295 | * @param[in] input Input tensor. Data type supported: S32 |
| 296 | * @param[in] bias Biases tensor. Only shared biases supported and it can be a nullptr if the biases addition is not required. |
| 297 | * Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p input. |
| 298 | * @param[out] output Output tensor. Data type supported: Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM16 |
| 299 | * @param[in] info GEMMLowp output stage metadata. |
| 300 | */ |
| 301 | void configure(const ITensor *input, const ITensor *bias, ITensor *output, const GEMMLowpOutputStageInfo &info); |
| 302 | /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMLowpOutputStage |
| 303 | * |
| 304 | * @param[in] input Input tensor info. It is the output of @ref NEGEMMLowpMatrixMultiplyCore function. Data type supported: S32 |
| 305 | * @param[in] bias Biases tensor info. Only shared biases supported and it can be a nullptr if the addition of biases is not required. |
| 306 | * Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p input. |
| 307 | * @param[in] output Output tensor info. Data type supported: Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM16 |
| 308 | * @param[in] info GEMMLowp output stage metadata. |
| 309 | * |
| 310 | * @return a status |
| 311 | */ |
| 312 | static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo &info); |
| 313 | }; |
Georgios Pinitas | 041f36d | 2018-09-18 18:38:37 +0100 | [diff] [blame] | 314 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 315 | #endif /*ARM_COMPUTE_NEGEMMLOWPOUTPUTSTAGE_H */ |