blob: e926f5ed3645a562efab0dd0cfcc219bacb008bf [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Manuel Bottini4c6bd512020-04-08 10:15:51 +01002 * Copyright (c) 2017-2020 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYKERNEL_H
25#define ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/CL/ICLKernel.h"
28
29namespace arm_compute
30{
31class ICLTensor;
32
Gian Marco05288a22017-11-21 10:57:50 +000033/** OpenCL kernel to multiply matrices
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034 *
Gian Marco Iodice06be6f82019-06-24 17:47:51 +010035 * @note This kernel should be used ONLY for Midgard architectures
36 *
37 * This kernel performs the following computation:
Gian Marco05288a22017-11-21 10:57:50 +000038 *
39 * -# Convert a values from int8 to int32
40 * -# Convert b values from int8 to int32
41 * -# Compute the int32 matrix product of the resulting a * b and store the result as int32
42 *
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043 */
44class CLGEMMLowpMatrixMultiplyKernel : public ICLKernel
45{
46public:
47 /** Default Constructor */
48 CLGEMMLowpMatrixMultiplyKernel();
49 /** Prevent instances of this class from being copied (As this class contains pointers) */
50 CLGEMMLowpMatrixMultiplyKernel(const CLGEMMLowpMatrixMultiplyKernel &) = delete;
51 /** Prevent instances of this class from being copied (As this class contains pointers) */
52 CLGEMMLowpMatrixMultiplyKernel &operator=(const CLGEMMLowpMatrixMultiplyKernel &) = delete;
53 /** Allow instances of this class to be moved */
54 CLGEMMLowpMatrixMultiplyKernel(CLGEMMLowpMatrixMultiplyKernel &&) = default;
55 /** Allow instances of this class to be moved */
56 CLGEMMLowpMatrixMultiplyKernel &operator=(CLGEMMLowpMatrixMultiplyKernel &&) = default;
57 /** Initialise the kernel's input and output.
58 *
Gian Marco Iodice06be6f82019-06-24 17:47:51 +010059 * @note This kernel should be used ONLY for Midgard architectures
60 *
61 * @param[in] input0 Input tensor containing the LHS matrix. Data type supported: QASYMM8
62 * @param[in] input1 Input tensor containing the RHS matrix. Data type supported: same as @p input0
63 * @param[out] output Output tensor to store the result of matrix multiplication. Data type supported: S32
64 * @param[in] gemm_info (Optional) GEMM information used to retrieve the original dimensions of the input matrices
Anthony Barbier6ff3b192017-09-04 18:44:23 +010065 */
Gian Marco Iodice06be6f82019-06-24 17:47:51 +010066 void configure(const ICLTensor *input0, const ICLTensor *input1, ICLTensor *output, const GEMMReshapeInfo &gemm_info = GEMMReshapeInfo());
Manuel Bottini4c6bd512020-04-08 10:15:51 +010067 /** Initialise the kernel's input and output.
68 *
69 * @note This kernel should be used ONLY for Midgard architectures
70 *
71 * @param[in] compile_context The compile context to be used.
72 * @param[in] input0 Input tensor containing the LHS matrix. Data type supported: QASYMM8
73 * @param[in] input1 Input tensor containing the RHS matrix. Data type supported: same as @p input0
74 * @param[out] output Output tensor to store the result of matrix multiplication. Data type supported: S32
75 * @param[in] gemm_info (Optional) GEMM information used to retrieve the original dimensions of the input matrices
76 */
77 void configure(CLCompileContext &compile_context, const ICLTensor *input0, const ICLTensor *input1, ICLTensor *output, const GEMMReshapeInfo &gemm_info = GEMMReshapeInfo());
Georgios Pinitas358ca202017-12-07 16:47:52 +000078 /** Static function to check if given info will lead to a valid configuration of @ref CLGEMMLowpMatrixMultiplyKernel
79 *
Gian Marco Iodice06be6f82019-06-24 17:47:51 +010080 * @param[in] input0 Input tensor containing the LHS matrix. Data type supported: QASYMM8
81 * @param[in] input1 Input tensor containing the RHS matrix. Data type supported: same as @p input0
82 * @param[in] output Output tensor to store the result of matrix multiplication. Data type supported: S32
83 * @param[in] gemm_info (Optional) GEMM information used to retrieve the original dimensions of the input matrices
Georgios Pinitas358ca202017-12-07 16:47:52 +000084 *
85 * @return a status
86 */
Gian Marco Iodice06be6f82019-06-24 17:47:51 +010087 static Status validate(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output, const GEMMReshapeInfo &gemm_info = GEMMReshapeInfo());
Anthony Barbier6ff3b192017-09-04 18:44:23 +010088
89 // Inherited methods overridden:
90 void run(const Window &window, cl::CommandQueue &queue) override;
91
92private:
93 const ICLTensor *_input0;
94 const ICLTensor *_input1;
95 ICLTensor *_output;
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +010096 bool _slide_matrix_b;
97 bool _reinterpret_input_as_3d;
98 bool _reinterpret_output_as_3d;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010099};
Gian Marco Iodicef670a0a2017-09-18 12:20:45 +0100100} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000101#endif /*ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYKERNEL_H*/