Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 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_NEGEMM_H__ |
| 25 | #define __ARM_COMPUTE_NEGEMM_H__ |
| 26 | |
| 27 | #include "arm_compute/core/NEON/kernels/NEFillBorderKernel.h" |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/NEON/kernels/NEGEMMAssemblyBaseKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/NEON/kernels/NEGEMMInterleave4x4Kernel.h" |
| 30 | #include "arm_compute/core/NEON/kernels/NEGEMMMatrixAdditionKernel.h" |
| 31 | #include "arm_compute/core/NEON/kernels/NEGEMMMatrixMultiplyKernel.h" |
| 32 | #include "arm_compute/core/NEON/kernels/NEGEMMTranspose1xWKernel.h" |
| 33 | #include "arm_compute/runtime/IFunction.h" |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 34 | #include "arm_compute/runtime/IMemoryManager.h" |
| 35 | #include "arm_compute/runtime/MemoryGroup.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | #include "arm_compute/runtime/Tensor.h" |
| 37 | |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 38 | #include <memory> |
| 39 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 40 | namespace arm_compute |
| 41 | { |
| 42 | /** Basic function to execute GEMM on NEON. This function calls the following NEON kernels: |
| 43 | * |
| 44 | * -# @ref NEGEMMInterleave4x4Kernel (if the output tensor is a matrix) |
| 45 | * -# @ref NEGEMMTranspose1xWKernel (if the output tensor is a matrix) |
| 46 | * -# @ref NEGEMMMatrixMultiplyKernel |
| 47 | * -# @ref NEGEMMMatrixAdditionKernel (if c != nullptr and beta != 0.0) |
| 48 | * |
| 49 | */ |
| 50 | class NEGEMM : public IFunction |
| 51 | { |
| 52 | public: |
| 53 | /** Constructor */ |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 54 | NEGEMM(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 55 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 56 | /** Initialise the kernel's inputs, output |
| 57 | * |
| 58 | * @note GEMM: General Matrix Multiply - [alpha * A * B + beta * C]. |
| 59 | * @note GEMM: The tensors a, b, c, d must have the same data type. You should not mix data types when calling this function. |
| 60 | * |
Gian Marco Iodice | bdb6b0b | 2017-06-30 12:21:00 +0100 | [diff] [blame] | 61 | * @param[in] a First input tensor (Matrix A or Vector A). Data type supported: QS8/QS16/F16/F32 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 62 | * @param[in] b Second input tensor (Matrix B). Data type supported: same as @p a |
| 63 | * @param[in] c Third input tensor (Matrix C). It can be a nullptr if just the multiplication between @p a and @p b is needed. Data type supported: same as @p a |
| 64 | * @param[out] d Output tensor. Data type supported: same as @p a |
| 65 | * @param[in] alpha Weight of the matrix product |
| 66 | * @param[in] beta Weight of matrix C |
| 67 | */ |
| 68 | void configure(const ITensor *a, const ITensor *b, const ITensor *c, ITensor *d, float alpha, float beta); |
| 69 | |
| 70 | // Inherited methods overridden: |
| 71 | void run() override; |
| 72 | |
| 73 | private: |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 74 | MemoryGroup _memory_group; |
| 75 | NEGEMMInterleave4x4Kernel _interleave_kernel; |
| 76 | NEGEMMTranspose1xWKernel _transpose_kernel; |
| 77 | NEGEMMMatrixMultiplyKernel _mm_kernel; |
| 78 | std::unique_ptr<NEGEMMAssemblyBaseKernel> _mm_optimised_kernel; |
| 79 | NEGEMMMatrixAdditionKernel _ma_kernel; |
| 80 | Tensor _tmp_a; |
| 81 | Tensor _tmp_b; |
| 82 | Tensor _workspace; |
| 83 | bool _run_vector_matrix_multiplication; |
| 84 | bool _run_addition; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 85 | }; |
| 86 | } |
| 87 | #endif /*__ARM_COMPUTE_NEGEMM_H__ */ |