1 /* 2 * Copyright (c) 2019-2020 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_CLGEMMLOWPMATRIXMULTIPLYRESHAPEDONLYRHSKERNEL_H 25 #define ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYRESHAPEDONLYRHSKERNEL_H 26 27 #include "arm_compute/core/KernelDescriptors.h" 28 #include "src/core/CL/ICLKernel.h" 29 30 namespace arm_compute 31 { 32 class ICLTensor; 33 34 /** OpenCL kernel to multiply matrices with QASYMM8 data type when only the input matrix RHS (input1) has been reshaped 35 * 36 * @note The input matrix input1 must be reshaped through @ref CLGEMMReshapeRHSMatrixKernel 37 * @note For fused output stage, only GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT type is supported 38 */ 39 class CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel : public ICLKernel 40 { 41 public: 42 /** Default Constructor */ 43 CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel(); 44 /** Prevent instances of this class from being copied (As this class contains pointers) */ 45 CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel(const CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel &) = delete; 46 /** Prevent instances of this class from being copied (As this class contains pointers) */ 47 CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel &operator=(const CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel &) = delete; 48 /** Allow instances of this class to be moved */ 49 CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel(CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel &&) = default; 50 /** Allow instances of this class to be moved */ 51 CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel &operator=(CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel &&) = default; 52 /** Initialise the kernel's input and output. 53 * 54 * @param[in] input0 Input tensor containing the LHS matrix. Data type supported: QASYMM8/QASYMM8_SIGNED 55 * @param[in] input1 Input tensor containing the RHS reshaped matrix. Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8/QSYMM8_PER_CHANNEL 56 * @param[out] output Output tensor. Data type supported: QASYMM8/QASYMM8_SIGNED/S32. 57 * @param[in] gemm_info GEMM information used to retrieve the original dimensions of the input matrices, output stage information and RHS/LHS info. 58 * Only the following values are supported for LHS info: 59 * lhs_info.m0: 2,3,4,5,6,7,8 60 * lhs_info.k0: 2,3,4,8,16 61 * Only the following values are supported for RHS info: 62 * rhs_info.n0: 2,3,4,8,16 63 * rhs_info.k0: same as lhs_info.k0 64 * rhs_info.transpose: true 65 * @param[in] vector_sum_col (Optional) Input row-vector of sums of all the entries in each column of matrix B. 66 * Note: vector_sum_col can be a nullptr in case a_offset = 0. Data type supported: S32 67 * @param[in] vector_sum_row (Optional) Input row-vector of sums of all the entries in each row of matrix A. 68 * Note: vector_sum_row can be a nullptr in case b_offset = 0. Data type supported: S32 69 * @param[in] bias (Optional) Biases tensor. Only shared biases supported and it can be a nullptr if the addition of biases is not required. 70 * Biases are 1D tensor with dimensions [OFM]. Data type supported: S32. 71 * @param[in] output_multipliers (Optional) Output multipliers tensor. In case of per-channel quantization, the number of multipliers must be equal to the number of filters (OFM). 72 * Supported data types: S32. 73 * @param[in] output_shifts (Optional) Output shifts tensor. In case of per-channel quantization, the number of multipliers must be equal to the number of filters (OFM). 74 * Supported data types: S32. 75 */ 76 void configure(const ICLTensor *input0, const ICLTensor *input1, ICLTensor *output, const GEMMKernelInfo &gemm_info, const ICLTensor *vector_sum_col = nullptr, 77 const ICLTensor *vector_sum_row = nullptr, const ICLTensor *bias = nullptr, const ICLTensor *output_multipliers = nullptr, const ICLTensor *output_shifts = nullptr); 78 /** Initialise the kernel's input and output. 79 * 80 * @param[in] compile_context The compile context to be used. 81 * @param[in] input0 Input tensor containing the LHS matrix. Data type supported: QASYMM8/QASYMM8_SIGNED 82 * @param[in] input1 Input tensor containing the RHS reshaped matrix. Data type supported: same as @p input0 83 * @param[out] output Output tensor. Data type supported: QASYMM8/QASYMM8_SIGNED/S32. 84 * @param[in] gemm_info GEMM information used to retrieve the original dimensions of the input matrices, output stage information and RHS/LHS info. 85 * Only the following values are supported for LHS info: 86 * lhs_info.m0: 2,3,4,5,6,7,8 87 * lhs_info.k0: 2,3,4,8,16 88 * Only the following values are supported for RHS info: 89 * rhs_info.n0: 2,3,4,8,16 90 * rhs_info.k0: same as lhs_info.k0 91 * rhs_info.transpose: true 92 * @param[in] vector_sum_col (Optional) Input row-vector of sums of all the entries in each column of matrix B. 93 * Note: vector_sum_col can be a nullptr in case a_offset = 0. Data type supported: S32 94 * @param[in] vector_sum_row (Optional) Input row-vector of sums of all the entries in each row of matrix A. 95 * Note: vector_sum_row can be a nullptr in case b_offset = 0. Data type supported: S32 96 * @param[in] bias (Optional) Biases tensor. Only shared biases supported and it can be a nullptr if the addition of biases is not required. 97 * Biases are 1D tensor with dimensions [OFM]. Data type supported: S32. 98 * @param[in] output_multipliers (Optional) Output multipliers tensor. In case of per-channel quantization, the number of multipliers must be equal to the number of filters (OFM). 99 * Supported data types: S32. 100 * @param[in] output_shifts (Optional) Output shifts tensor. In case of per-channel quantization, the number of multipliers must be equal to the number of filters (OFM). 101 * Supported data types: S32. 102 */ 103 void configure(const CLCompileContext &compile_context, const ICLTensor *input0, const ICLTensor *input1, ICLTensor *output, const GEMMKernelInfo &gemm_info, const ICLTensor *vector_sum_col = nullptr, 104 const ICLTensor *vector_sum_row = nullptr, const ICLTensor *bias = nullptr, const ICLTensor *output_multipliers = nullptr, const ICLTensor *output_shifts = nullptr); 105 /** Static function to check if given info will lead to a valid configuration of @ref CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel 106 * 107 * @param[in] input0 Input tensor info for the LHS matrix. Data type supported: QASYMM8/QASYMM8_SIGNED 108 * @param[in] input1 Input tensor info for the RHS reshaped matrix. Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8/QSYMM8_PER_CHANNEL 109 * @param[in] output Output tensor info. Data type supported: QASYMM8/QASYMM8_SIGNED/S32. 110 * @param[in] gemm_info GEMM information used to retrieve the original dimensions of the input matrices, output stage information and RHS/LHS info. 111 * Only the following values are supported for LHS info: 112 * lhs_info.m0: 2,3,4,5,6,7,8 113 * lhs_info.k0: 2,3,4,8,16 114 * Only the following values are supported for RHS info: 115 * rhs_info.n0: 2,3,4,8,16 116 * rhs_info.k0: same as lhs_info.k0 117 * rhs_info.transpose: true 118 * @param[in] vector_sum_col (Optional) Input row-vector info of sums of all the entries in each column of matrix B. 119 * Note: vector_sum_col can be a nullptr in case a_offset = 0. Data type supported: S32 120 * @param[in] vector_sum_row (Optional) Input row-vector info of sums of all the entries in each row of matrix A. 121 * Note: vector_sum_row can be a nullptr in case b_offset = 0. Data type supported: S32 122 * @param[in] bias (Optional) Biases tensor info. Only shared biases supported and it can be a nullptr if the addition of biases is not required. 123 * Biases are 1D tensor with dimensions [OFM]. Data type supported: S32. 124 * @param[in] output_multipliers (Optional) Output multipliers tensor info. In case of per-channel quantization, the number of multipliers must be equal to the number of filters (OFM). 125 * Supported data types: S32. 126 * @param[in] output_shifts (Optional) Output shifts tensor info. In case of per-channel quantization, the number of multipliers must be equal to the number of filters (OFM). 127 * Supported data types: S32. 128 * 129 * @return a status 130 */ 131 static Status validate(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output, const GEMMKernelInfo &gemm_info, const ITensorInfo *vector_sum_col = nullptr, 132 const ITensorInfo *vector_sum_row = nullptr, const ITensorInfo *bias = nullptr, const ITensorInfo *output_multipliers = nullptr, 133 const ITensorInfo *output_shifts = nullptr); 134 135 // Inherited methods overridden: 136 void run(const Window &window, cl::CommandQueue &queue) override; 137 138 private: 139 const ICLTensor *_input0; 140 const ICLTensor *_input1; 141 ICLTensor *_output; 142 const ICLTensor *_vector_sum_col; 143 const ICLTensor *_vector_sum_row; 144 const ICLTensor *_bias; 145 const ICLTensor *_output_multipliers; 146 const ICLTensor *_output_shifts; 147 bool _slide_matrix_b; 148 bool _reinterpret_input_as_3d; 149 bool _reinterpret_output_as_3d; 150 bool _use_dummy_work_items; 151 bool _is_quantized_per_channel; 152 bool _fuse_output_stage; 153 }; 154 } // namespace arm_compute 155 #endif /* ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYRESHAPEDONLYRHSKERNEL_H */