Georgios Pinitas | 4a578b9 | 2021-06-25 12:13:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020-2021 Arm Limited. |
| 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 | */ |
| 24 | #ifndef ARM_COMPUTE_CL_GEMMLOWP_QUANTIZEDOWN_INT32_SCALE_BY_FIXEDPOINT_KERNEL_H |
| 25 | #define ARM_COMPUTE_CL_GEMMLOWP_QUANTIZEDOWN_INT32_SCALE_BY_FIXEDPOINT_KERNEL_H |
| 26 | |
| 27 | #include "src/core/common/Macros.h" |
| 28 | #include "src/core/gpu/cl/ClCompileContext.h" |
| 29 | #include "src/core/gpu/cl/IClKernel.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | namespace opencl |
| 34 | { |
| 35 | namespace kernels |
| 36 | { |
| 37 | /** OpenCL kernel used to quantize down the int32 accumulator values of GEMMLowp to QASYMM8/QASYMM8_SIGNED/QSYMM16 |
| 38 | * |
| 39 | * This kernel takes a final int32 accumulator value (the output of the matrix multiplication), and processes it to obtain the final quantized value. |
| 40 | * The following computations will be performed by the kernel: |
| 41 | * |
| 42 | * -# Compute fixed point multiplication between each entry of input by gemmlowp_multiplier |
| 43 | * -# Add bias to final result if bias tensor is not a nullptr |
| 44 | * -# Round to nearest division by a power-of-two using result_shift |
| 45 | * -# Add offset to each result |
| 46 | * -# Clamp the value between the specified min and max bounds |
| 47 | * -# Clamp the resulting int32 values to the proper quantized range and cast to QASYMM8/QASYMM8_SIGNED/QSYMM16. |
| 48 | */ |
| 49 | class ClGemmLowpQuantizeDownInt32ScaleByFixedPointKernel : public IClKernel |
| 50 | { |
| 51 | public: |
| 52 | ClGemmLowpQuantizeDownInt32ScaleByFixedPointKernel(); |
| 53 | ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(ClGemmLowpQuantizeDownInt32ScaleByFixedPointKernel); |
| 54 | /** Initialise the kernel's source and destination. |
| 55 | * |
| 56 | * @param[in] compile_context The compile context to be used. |
| 57 | * @param[in] src Source tensor. Data type supported: S32 |
| 58 | * @param[in] bias Biases tensor. Only shared biases supported and it can be a nullptr if the biases addition is not required. |
| 59 | * Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p src. |
| 60 | * @param[out] dst Destination tensor. Data type supported: Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM16. |
| 61 | * @param[in] info Output stage info. Used to pass the quantized output data type |
| 62 | */ |
| 63 | void configure(const CLCompileContext &compile_context, const ITensorInfo *src, const ITensorInfo *bias, ITensorInfo *dst, const GEMMLowpOutputStageInfo *info); |
| 64 | /** Static function to check if given info will lead to a valid configuration |
| 65 | * |
| 66 | * Similar to @ref ClGemmLowpQuantizeDownInt32ScaleByFixedPointKernel::configure() |
| 67 | * |
| 68 | * @return a status |
| 69 | */ |
| 70 | static Status validate(const ITensorInfo *src, const ITensorInfo *bias, const ITensorInfo *dst, const GEMMLowpOutputStageInfo *info); |
| 71 | |
| 72 | // Inherited methods overridden: |
| 73 | void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override; |
| 74 | }; |
| 75 | } // namespace kernels |
| 76 | } // namespace opencl |
| 77 | } // namespace arm_compute |
| 78 | #endif /* ARM_COMPUTE_CL_GEMMLOWP_QUANTIZEDOWN_INT32_SCALE_BY_FIXEDPOINT_KERNEL_H */ |