Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2020 Arm Limited. |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +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 | */ |
Michele Di Giorgio | f9179d3 | 2019-11-27 16:17:30 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYRESHAPEDONLYRHSKERNEL_H |
| 25 | #define ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYRESHAPEDONLYRHSKERNEL_H |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 26 | |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/KernelDescriptors.h" |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 28 | #include "src/core/CL/ICLKernel.h" |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 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 |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 37 | * @note For fused output stage, only GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT type is supported |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 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 | * |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 54 | * @param[in] input0 Input tensor containing the LHS matrix. Data type supported: QASYMM8/QASYMM8_SIGNED |
Michele Di Giorgio | 1c1b3aa | 2020-04-02 17:35:42 +0100 | [diff] [blame] | 55 | * @param[in] input1 Input tensor containing the RHS reshaped matrix. Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8/QSYMM8_PER_CHANNEL |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 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. |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 75 | */ |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 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); |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 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 | */ |
Manuel Bottini | 679fc96 | 2020-04-21 16:08:53 +0100 | [diff] [blame] | 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, |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 104 | const ICLTensor *vector_sum_row = nullptr, const ICLTensor *bias = nullptr, const ICLTensor *output_multipliers = nullptr, const ICLTensor *output_shifts = nullptr); |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 105 | /** Static function to check if given info will lead to a valid configuration of @ref CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel |
| 106 | * |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 107 | * @param[in] input0 Input tensor info for the LHS matrix. Data type supported: QASYMM8/QASYMM8_SIGNED |
Michele Di Giorgio | 1c1b3aa | 2020-04-02 17:35:42 +0100 | [diff] [blame] | 108 | * @param[in] input1 Input tensor info for the RHS reshaped matrix. Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8/QSYMM8_PER_CHANNEL |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 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. |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 128 | * |
| 129 | * @return a status |
| 130 | */ |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 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); |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 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; |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 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; |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 147 | bool _slide_matrix_b; |
| 148 | bool _reinterpret_input_as_3d; |
| 149 | bool _reinterpret_output_as_3d; |
Gian Marco Iodice | 86cfffe | 2019-04-02 11:02:20 +0100 | [diff] [blame] | 150 | bool _use_dummy_work_items; |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 151 | bool _is_quantized_per_channel; |
| 152 | bool _fuse_output_stage; |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 153 | }; |
| 154 | } // namespace arm_compute |
Michele Di Giorgio | f9179d3 | 2019-11-27 16:17:30 +0000 | [diff] [blame] | 155 | #endif /* ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYRESHAPEDONLYRHSKERNEL_H */ |