blob: 4dcae2e53676c38e996caa6833e20745e11fff12 [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Michalis Spyrouf4643372019-11-29 16:17:13 +00002 * Copyright (c) 2017-2019 ARM Limited.
Anthony Barbier7068f992017-10-26 15:23:08 +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_GCGEMMMATRIXMULTIPLYKERNEL_H
25#define ARM_COMPUTE_GCGEMMMATRIXMULTIPLYKERNEL_H
Anthony Barbier7068f992017-10-26 15:23:08 +010026
27#include "arm_compute/core/GLES_COMPUTE/IGCKernel.h"
Michele Di Giorgio164b65d2018-04-13 14:28:08 +010028#include "arm_compute/core/GPUTarget.h"
Anthony Barbier7068f992017-10-26 15:23:08 +010029
30namespace arm_compute
31{
32class IGCTensor;
33
34/** GLES Compute kernel to multiply two input matrices "A" and "B" or to multiply a vector "A" by a matrix "B". All elements of the output matrix/vector will be multiplied by alpha
35 *
Anthony Barbier7068f992017-10-26 15:23:08 +010036 * @attention The second input tensor must have at least 2 dimensions (matrix)
37 *
38 */
39class GCGEMMMatrixMultiplyKernel : public IGCKernel
40{
41public:
42 /** Default constructor */
43 GCGEMMMatrixMultiplyKernel();
44
45 /** Prevent instances of this class from being copied (As this class contains pointers) */
46 GCGEMMMatrixMultiplyKernel(const GCGEMMMatrixMultiplyKernel &) = delete;
47
48 /** Prevent instances of this class from being copied (As this class contains pointers) */
49 GCGEMMMatrixMultiplyKernel &operator=(const GCGEMMMatrixMultiplyKernel &) = delete;
50
51 /** Allow instances of this class to be moved */
52 GCGEMMMatrixMultiplyKernel(GCGEMMMatrixMultiplyKernel &&) = default;
53
54 /** Allow instances of this class to be moved */
55 GCGEMMMatrixMultiplyKernel &operator=(GCGEMMMatrixMultiplyKernel &&) = default;
56
57 /** Initialise the kernel's input, output and alpha
58 *
59 * @param[in] input0 Input tensor containing the interleaved Matrix A or the vector A. Data types supported: F16/F32
60 * @param[in] input1 Input tensor containing the transposed Matrix B if the first input tensor A is not a vector.
61 * If the output tensor is a vector, input1 must contain the matrix B not reshaped. Data type supported: same as @p input0
62 * @param[out] output Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0
63 * @param[in] alpha Weight of the matrix product
64 * @param[in] is_interleaved_transposed (Optional) True if input0 and input1 have been reshaped respectively using @ref GCGEMMInterleave4x4Kernel and @ref GCGEMMTranspose1xWKernel
Michele Di Giorgio164b65d2018-04-13 14:28:08 +010065 * @param[in] reshape_info (Optional) GEMM reshape info. If is_interleaved_transposed = true, this object must contain the information to understand how the matrix A and matrix B have been reshaped
Anthony Barbier7068f992017-10-26 15:23:08 +010066 */
Michele Di Giorgio164b65d2018-04-13 14:28:08 +010067 void configure(const IGCTensor *input0, const IGCTensor *input1, IGCTensor *output, float alpha, bool is_interleaved_transposed = true, const GEMMReshapeInfo &reshape_info = GEMMReshapeInfo());
68 /** Static function to check if given info will lead to a valid configuration of @ref GCGEMMMatrixMultiplyKernel
69 *
70 * @param[in] input0 Input tensor containing the Matrix A. Data types supported: F16/F32
71 * @param[in] input1 Input tensor containing the Matrix B. Data type supported: same as @p input0
72 * @param[in] output Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0
73 * @param[in] alpha Weight of the matrix product
74 * @param[in] is_interleaved_transposed True if input0 and input1 have been reshaped respectively using @ref GCGEMMInterleave4x4Kernel and @ref GCGEMMTranspose1xWKernel
75 * @param[in] reshape_info GEMM reshape info. If is_interleaved_transposed = true, this object must contain the information to understand how the matrix A and matrix B have been reshaped
76 * @param[in] gpu_target GPU Target
77 *
78 * @return a status
79 */
80 static Status validate(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output, float alpha, bool is_interleaved_transposed, const GEMMReshapeInfo &reshape_info,
81 GPUTarget gpu_target);
Anthony Barbier7068f992017-10-26 15:23:08 +010082
83 // Inherited methods overridden:
84 void run(const Window &window) override;
85
86private:
87 const IGCTensor *_input0;
88 const IGCTensor *_input1;
89 IGCTensor *_output;
90};
91}
Michalis Spyrouf4643372019-11-29 16:17:13 +000092#endif /* ARM_COMPUTE_GCGEMMMATRIXMULTIPLYKERNEL_H */