Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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 | |
| 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 | */ |
| 39 | class NEGEMMMatrixMultiplyKernel : public INEKernel |
| 40 | { |
| 41 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 42 | const char *name() const override |
| 43 | { |
| 44 | return "NEGEMMMatrixMultiplyKernel"; |
| 45 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 46 | /** 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 Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 61 | * @param[in] input0 Input tensor containing the interleaved Matrix A or the vector A. Data types supported: F16/F32 |
Ioan-Cristian Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 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 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 68 | */ |
Ioan-Cristian Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 69 | void configure(const ITensor *input0, const ITensor *input1, ITensor *output, float alpha, bool is_interleaved, const GEMMReshapeInfo &reshape_info = GEMMReshapeInfo()); |
Giorgio Arena | 7c23ad0 | 2017-11-30 15:08:38 +0000 | [diff] [blame] | 70 | /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMMatrixMultiplyKernel |
| 71 | * |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 72 | * @param[in] input0 Input tensor containing the interleaved Matrix A or the vector A. Data types supported: F16/F32 |
Ioan-Cristian Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 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 |
Giorgio Arena | 7c23ad0 | 2017-11-30 15:08:38 +0000 | [diff] [blame] | 79 | * |
| 80 | * @return a status |
| 81 | */ |
Ioan-Cristian Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 82 | static Status validate(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output, float alpha, bool is_interleaved, const GEMMReshapeInfo &reshape_info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 83 | |
| 84 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 85 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 86 | |
| 87 | private: |
| 88 | const ITensor *_input0; |
| 89 | const ITensor *_input1; |
| 90 | ITensor *_output; |
| 91 | float _alpha; |
| 92 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 93 | } // namespace arm_compute |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 94 | #endif /*__ARM_COMPUTE_NEGEMMMATRIXMULTIPLYKERNEL_H__*/ |