blob: 7845d244eb6759e011655c7dcb99bc64672ca1fb [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
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 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);
Gian Marco Iodice62251f72019-03-11 16:07:12 +000078 /** Static function to check if given info will lead to a valid configuration of @ref CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel
79 *
Michele Di Giorgiob54ba282020-01-14 15:31:55 +000080 * @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 Iodice62251f72019-03-11 16:07:12 +0000101 *
102 * @return a status
103 */
Michele Di Giorgiob54ba282020-01-14 15:31:55 +0000104 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 Iodice62251f72019-03-11 16:07:12 +0000107
108 // Inherited methods overridden:
109 void run(const Window &window, cl::CommandQueue &queue) override;
110
111private:
112 const ICLTensor *_input0;
113 const ICLTensor *_input1;
114 ICLTensor *_output;
Michele Di Giorgiob54ba282020-01-14 15:31:55 +0000115 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 Iodice62251f72019-03-11 16:07:12 +0000120 bool _slide_matrix_b;
121 bool _reinterpret_input_as_3d;
122 bool _reinterpret_output_as_3d;
Gian Marco Iodice86cfffe2019-04-02 11:02:20 +0100123 bool _use_dummy_work_items;
Michele Di Giorgiob54ba282020-01-14 15:31:55 +0000124 bool _is_quantized_per_channel;
125 bool _fuse_output_stage;
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000126};
127} // namespace arm_compute
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000128#endif /* ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYRESHAPEDONLYRHSKERNEL_H */