blob: 1aba6c039845bf51efade3b65640ff382f6d60fa [file] [log] [blame]
Gian Marco Iodice62251f72019-03-11 16:07:12 +00001/*
Michele Di Giorgiob54ba282020-01-14 15:31:55 +00002 * Copyright (c) 2019-2020 ARM Limited.
Gian Marco Iodice62251f72019-03-11 16:07:12 +00003 *
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 Giorgiof9179d32019-11-27 16:17:30 +000024#ifndef ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYRESHAPEDONLYRHSKERNEL_H
25#define ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYRESHAPEDONLYRHSKERNEL_H
Gian Marco Iodice62251f72019-03-11 16:07:12 +000026
27#include "arm_compute/core/CL/ICLKernel.h"
Michele Di Giorgiob54ba282020-01-14 15:31:55 +000028#include "arm_compute/core/KernelDescriptors.h"
Gian Marco Iodice62251f72019-03-11 16:07:12 +000029
30namespace arm_compute
31{
32class 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 Giorgiob54ba282020-01-14 15:31:55 +000037 * @note For fused output stage, only GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT type is supported
Gian Marco Iodice62251f72019-03-11 16:07:12 +000038 */
39class CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel : public ICLKernel
40{
41public:
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 Giorgiob54ba282020-01-14 15:31:55 +000054 * @param[in] input0 Input tensor containing the LHS matrix. Data type supported: QASYMM8/QASYMM8_SIGNED
Michele Di Giorgio1c1b3aa2020-04-02 17:35:42 +010055 * @param[in] input1 Input tensor containing the RHS reshaped matrix. Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8/QSYMM8_PER_CHANNEL
Michele Di Giorgiob54ba282020-01-14 15:31:55 +000056 * @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 Iodice62251f72019-03-11 16:07:12 +000075 */
Michele Di Giorgiob54ba282020-01-14 15:31:55 +000076 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 Bottini4c6bd512020-04-08 10:15:51 +010078 /** 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 Bottini679fc962020-04-21 16:08:53 +0100103 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 Bottini4c6bd512020-04-08 10:15:51 +0100104 const ICLTensor *vector_sum_row = nullptr, const ICLTensor *bias = nullptr, const ICLTensor *output_multipliers = nullptr, const ICLTensor *output_shifts = nullptr);
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000105 /** Static function to check if given info will lead to a valid configuration of @ref CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel
106 *
Michele Di Giorgiob54ba282020-01-14 15:31:55 +0000107 * @param[in] input0 Input tensor info for the LHS matrix. Data type supported: QASYMM8/QASYMM8_SIGNED
Michele Di Giorgio1c1b3aa2020-04-02 17:35:42 +0100108 * @param[in] input1 Input tensor info for the RHS reshaped matrix. Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8/QSYMM8_PER_CHANNEL
Michele Di Giorgiob54ba282020-01-14 15:31:55 +0000109 * @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 Iodice62251f72019-03-11 16:07:12 +0000128 *
129 * @return a status
130 */
Michele Di Giorgiob54ba282020-01-14 15:31:55 +0000131 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 Iodice62251f72019-03-11 16:07:12 +0000134
135 // Inherited methods overridden:
136 void run(const Window &window, cl::CommandQueue &queue) override;
137
138private:
139 const ICLTensor *_input0;
140 const ICLTensor *_input1;
141 ICLTensor *_output;
Michele Di Giorgiob54ba282020-01-14 15:31:55 +0000142 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 Iodice62251f72019-03-11 16:07:12 +0000147 bool _slide_matrix_b;
148 bool _reinterpret_input_as_3d;
149 bool _reinterpret_output_as_3d;
Gian Marco Iodice86cfffe2019-04-02 11:02:20 +0100150 bool _use_dummy_work_items;
Michele Di Giorgiob54ba282020-01-14 15:31:55 +0000151 bool _is_quantized_per_channel;
152 bool _fuse_output_stage;
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000153};
154} // namespace arm_compute
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000155#endif /* ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYRESHAPEDONLYRHSKERNEL_H */