Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [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 | |
| 27 | #include "arm_compute/core/CL/ICLKernel.h" |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/KernelDescriptors.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 |
| 55 | * @param[in] input1 Input tensor containing the RHS reshaped matrix. Data type supported: same as @p input0 |
| 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); |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 78 | /** Static function to check if given info will lead to a valid configuration of @ref CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel |
| 79 | * |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 80 | * @param[in] input0 Input tensor info for the LHS matrix. Data type supported: QASYMM8/QASYMM8_SIGNED |
| 81 | * @param[in] input1 Input tensor info for the RHS reshaped matrix. Data type supported: same as @p input0 |
| 82 | * @param[in] output Output tensor info. Data type supported: QASYMM8/QASYMM8_SIGNED/S32. |
| 83 | * @param[in] gemm_info GEMM information used to retrieve the original dimensions of the input matrices, output stage information and RHS/LHS info. |
| 84 | * Only the following values are supported for LHS info: |
| 85 | * lhs_info.m0: 2,3,4,5,6,7,8 |
| 86 | * lhs_info.k0: 2,3,4,8,16 |
| 87 | * Only the following values are supported for RHS info: |
| 88 | * rhs_info.n0: 2,3,4,8,16 |
| 89 | * rhs_info.k0: same as lhs_info.k0 |
| 90 | * rhs_info.transpose: true |
| 91 | * @param[in] vector_sum_col (Optional) Input row-vector info of sums of all the entries in each column of matrix B. |
| 92 | * Note: vector_sum_col can be a nullptr in case a_offset = 0. Data type supported: S32 |
| 93 | * @param[in] vector_sum_row (Optional) Input row-vector info of sums of all the entries in each row of matrix A. |
| 94 | * Note: vector_sum_row can be a nullptr in case b_offset = 0. Data type supported: S32 |
| 95 | * @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. |
| 96 | * Biases are 1D tensor with dimensions [OFM]. Data type supported: S32. |
| 97 | * @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). |
| 98 | * Supported data types: S32. |
| 99 | * @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). |
| 100 | * Supported data types: S32. |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 101 | * |
| 102 | * @return a status |
| 103 | */ |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 104 | static Status validate(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output, const GEMMKernelInfo &gemm_info, const ITensorInfo *vector_sum_col = nullptr, |
| 105 | const ITensorInfo *vector_sum_row = nullptr, const ITensorInfo *bias = nullptr, const ITensorInfo *output_multipliers = nullptr, |
| 106 | const ITensorInfo *output_shifts = nullptr); |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 107 | |
| 108 | // Inherited methods overridden: |
| 109 | void run(const Window &window, cl::CommandQueue &queue) override; |
| 110 | |
| 111 | private: |
| 112 | const ICLTensor *_input0; |
| 113 | const ICLTensor *_input1; |
| 114 | ICLTensor *_output; |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 115 | const ICLTensor *_vector_sum_col; |
| 116 | const ICLTensor *_vector_sum_row; |
| 117 | const ICLTensor *_bias; |
| 118 | const ICLTensor *_output_multipliers; |
| 119 | const ICLTensor *_output_shifts; |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 120 | bool _slide_matrix_b; |
| 121 | bool _reinterpret_input_as_3d; |
| 122 | bool _reinterpret_output_as_3d; |
Gian Marco Iodice | 86cfffe | 2019-04-02 11:02:20 +0100 | [diff] [blame] | 123 | bool _use_dummy_work_items; |
Michele Di Giorgio | b54ba28 | 2020-01-14 15:31:55 +0000 | [diff] [blame] | 124 | bool _is_quantized_per_channel; |
| 125 | bool _fuse_output_stage; |
Gian Marco Iodice | 62251f7 | 2019-03-11 16:07:12 +0000 | [diff] [blame] | 126 | }; |
| 127 | } // namespace arm_compute |
Michele Di Giorgio | f9179d3 | 2019-11-27 16:17:30 +0000 | [diff] [blame] | 128 | #endif /* ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYRESHAPEDONLYRHSKERNEL_H */ |