blob: 9923c31018d102961109b789539469a9cca15f2a [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
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 */
24#ifndef __ARM_COMPUTE_NEGEMMMATRIXMULTIPLYKERNEL_H__
25#define __ARM_COMPUTE_NEGEMMMATRIXMULTIPLYKERNEL_H__
26
27#include "arm_compute/core/NEON/INEKernel.h"
28
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:
42 /** Constructor */
43 NEGEMMMatrixMultiplyKernel();
44 /** Prevent instances of this class from being copied (As this class contains pointers) */
45 NEGEMMMatrixMultiplyKernel(const NEGEMMMatrixMultiplyKernel &) = delete;
46 /** Prevent instances of this class from being copied (As this class contains pointers) */
47 NEGEMMMatrixMultiplyKernel &operator=(const NEGEMMMatrixMultiplyKernel &) = delete;
48 /** Allow instances of this class to be moved */
49 NEGEMMMatrixMultiplyKernel(NEGEMMMatrixMultiplyKernel &&) = default;
50 /** Allow instances of this class to be moved */
51 NEGEMMMatrixMultiplyKernel &operator=(NEGEMMMatrixMultiplyKernel &&) = default;
52 /** Initialise the kernel's input and output.
53 *
54 * @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
55 * These two kernels change the layout of the original matrices to be more cache-friendly.
56 *
Gian Marco Iodicebdb6b0b2017-06-30 12:21:00 +010057 * @param[in] input0 Input tensor containing the interleaved Matrix A or the vector A. Data types supported: QS8/QS16/F16/F32
Anthony Barbier6ff3b192017-09-04 18:44:23 +010058 * @param[in] input1 Input tensor containing the transposed Matrix B if the first input tensor A is not a vector.
59 * If the output tensor is a vector, input1 must contain the matrix B not reshaped. Data type supported: same as @p input0
60 * @param[out] output Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0.
61 * @param[in] alpha Weight of the matrix product
62 */
63 void configure(const ITensor *input0, const ITensor *input1, ITensor *output, float alpha);
Giorgio Arena7c23ad02017-11-30 15:08:38 +000064 /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMMatrixMultiplyKernel
65 *
66 * @param[in] input0 Input tensor containing the Matrix A. Data types supported: QS8/QS16/F16/F32
67 * @param[in] input1 Input tensor containing the Matrix B. Data type supported: same as @p input0
68 * @param[in] output Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0
69 *
70 * @return a status
71 */
72 static Status validate(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010073
74 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010075 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010076
77private:
78 const ITensor *_input0;
79 const ITensor *_input1;
80 ITensor *_output;
81 float _alpha;
82};
Gian Marco Iodice356f6432017-09-22 11:32:21 +010083} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +010084#endif /*__ARM_COMPUTE_NEGEMMMATRIXMULTIPLYKERNEL_H__*/