Compute Library
 21.02
NEGEMMMatrixMultiplyKernel.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2021 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 
28 
29 namespace arm_compute
30 {
31 class 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  */
40 {
41 public:
42  const char *name() const override
43  {
44  return "NEGEMMMatrixMultiplyKernel";
45  }
46  /** Constructor */
48  /** Prevent instances of this class from being copied (As this class contains pointers) */
50  /** Prevent instances of this class from being copied (As this class contains pointers) */
52  /** Allow instances of this class to be moved */
54  /** Allow instances of this class to be moved */
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  *
61  * @param[in] input0 Input tensor containing the interleaved Matrix A or the vector A. Data types supported: F16/F32
62  * @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
68  */
69  void configure(const ITensor *input0, const ITensor *input1, ITensor *output, float alpha, bool is_interleaved, const GEMMReshapeInfo &reshape_info = GEMMReshapeInfo());
70  /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMMatrixMultiplyKernel
71  *
72  * @param[in] input0 Input tensor containing the interleaved Matrix A or the vector A. Data types supported: F16/F32
73  * @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
79  *
80  * @return a status
81  */
82  static Status validate(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output, float alpha, bool is_interleaved, const GEMMReshapeInfo &reshape_info);
83 
84  // Inherited methods overridden:
85  void run(const Window &window, const ThreadInfo &info) override;
86 
87 private:
88  const ITensor *_input0;
89  const ITensor *_input1;
90  ITensor *_output;
91  float _alpha;
92 };
93 } // namespace arm_compute
94 #endif /*ARM_COMPUTE_NEGEMMMATRIXMULTIPLYKERNEL_H*/
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
Common interface for all kernels implemented in C++.
Definition: ICPPKernel.h:38
GEMM reshape information class.
Definition: Types.h:1831
Store the tensor's metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
Interface for Neon tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
Definition: CPPTypes.h:235
void configure(const ITensor *input0, const ITensor *input1, ITensor *output, float alpha, bool is_interleaved, const GEMMReshapeInfo &reshape_info=GEMMReshapeInfo())
Initialise the kernel's input and output.
static Status validate(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output, float alpha, bool is_interleaved, const GEMMReshapeInfo &reshape_info)
Static function to check if given info will lead to a valid configuration of NEGEMMMatrixMultiplyKern...
NEGEMMMatrixMultiplyKernel & operator=(const NEGEMMMatrixMultiplyKernel &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
const char * name() const override
Name of the kernel.
Describe a multidimensional execution window.
Definition: Window.h:39
Neon kernel to multiply two input matrices "A" and "B".