blob: 1ea948de63d778a979fb2c85be806a18007ae4c5 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michalis Spyrouebcebf12020-10-21 00:04:14 +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_NEGEMMMATRIXMULTIPLYKERNEL_H
25#define ARM_COMPUTE_NEGEMMMATRIXMULTIPLYKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
Michalis Spyrouebcebf12020-10-21 00:04:14 +010027#include "src/core/NEON/INEKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028
29namespace arm_compute
30{
31class ITensor;
32
33/** NEON kernel to multiply two input matrices "A" and "B". All elements of the output matrix/vector will be multiplied by alpha after the matrix multiplication
34 *
35 * @note If the output tensor is a matrix, the implementation assumes that the input tensors @p input0 and @p input1 are both matrices and reshaped respectively with @ref NEGEMMInterleave4x4Kernel" and @ref NEGEMMTranspose1xWKernel
36 * @note If the output tensor is a vector and the data type is F32, the implementation assumes that the first input tensor @p input0 is a vector and the second input tensor @p input1 a matrix. The implementation also assumes that both tensors have not been reshaped
37 *
38 */
39class NEGEMMMatrixMultiplyKernel : public INEKernel
40{
41public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000042 const char *name() const override
43 {
44 return "NEGEMMMatrixMultiplyKernel";
45 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046 /** Constructor */
47 NEGEMMMatrixMultiplyKernel();
48 /** Prevent instances of this class from being copied (As this class contains pointers) */
49 NEGEMMMatrixMultiplyKernel(const NEGEMMMatrixMultiplyKernel &) = delete;
50 /** Prevent instances of this class from being copied (As this class contains pointers) */
51 NEGEMMMatrixMultiplyKernel &operator=(const NEGEMMMatrixMultiplyKernel &) = delete;
52 /** Allow instances of this class to be moved */
53 NEGEMMMatrixMultiplyKernel(NEGEMMMatrixMultiplyKernel &&) = default;
54 /** Allow instances of this class to be moved */
55 NEGEMMMatrixMultiplyKernel &operator=(NEGEMMMatrixMultiplyKernel &&) = default;
56 /** Initialise the kernel's input and output.
57 *
58 * @note If the output tensor is a matrix, the input matrices @p input0 and @p input1 should be the output of the kernels: @ref NEGEMMInterleave4x4Kernel and @ref NEGEMMTranspose1xWKernel
59 * These two kernels change the layout of the original matrices to be more cache-friendly.
60 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010061 * @param[in] input0 Input tensor containing the interleaved Matrix A or the vector A. Data types supported: F16/F32
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000062 * @param[in] input1 Input tensor containing the transposed Matrix B if the first input tensor A is not a vector.
63 * If the output tensor is a vector, input1 must contain the matrix B not reshaped. Data type supported: same as @p input0
64 * @param[out] output Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0.
65 * @param[in] alpha Weight of the matrix product
66 * @param[in] is_interleaved (Optional) True if input0 and input1 have been reshaped respectively using @ref NEGEMMInterleave4x4Kernel and @ref NEGEMMTranspose1xWKernel
67 * @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 Barbier6ff3b192017-09-04 18:44:23 +010068 */
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000069 void configure(const ITensor *input0, const ITensor *input1, ITensor *output, float alpha, bool is_interleaved, const GEMMReshapeInfo &reshape_info = GEMMReshapeInfo());
Giorgio Arena7c23ad02017-11-30 15:08:38 +000070 /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMMatrixMultiplyKernel
71 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010072 * @param[in] input0 Input tensor containing the interleaved Matrix A or the vector A. Data types supported: F16/F32
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000073 * @param[in] input1 Input tensor containing the transposed Matrix B if the first input tensor A is not a vector.
74 * If the output tensor is a vector, input1 must contain the matrix B not reshaped. Data type supported: same as @p input0
75 * @param[in] output Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0.
76 * @param[in] alpha Weight of the matrix product
77 * @param[in] is_interleaved (Optional) True if input0 and input1 have been reshaped respectively using @ref NEGEMMInterleave4x4Kernel and @ref NEGEMMTranspose1xWKernel
78 * @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
Giorgio Arena7c23ad02017-11-30 15:08:38 +000079 *
80 * @return a status
81 */
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000082 static Status validate(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output, float alpha, bool is_interleaved, const GEMMReshapeInfo &reshape_info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010083
84 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010085 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010086
87private:
88 const ITensor *_input0;
89 const ITensor *_input1;
90 ITensor *_output;
91 float _alpha;
92};
Gian Marco Iodice356f6432017-09-22 11:32:21 +010093} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +000094#endif /*ARM_COMPUTE_NEGEMMMATRIXMULTIPLYKERNEL_H*/