blob: 068e7c5ce8b646bc7da490e35b5d3e3069967893 [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_NEGEMM_H__
25#define __ARM_COMPUTE_NEGEMM_H__
26
27#include "arm_compute/core/NEON/kernels/NEFillBorderKernel.h"
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010028#include "arm_compute/core/NEON/kernels/NEGEMMAssemblyBaseKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029#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 Pinitas658039b2017-09-15 16:30:50 +010034#include "arm_compute/runtime/IMemoryManager.h"
35#include "arm_compute/runtime/MemoryGroup.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036#include "arm_compute/runtime/Tensor.h"
37
Georgios Pinitas658039b2017-09-15 16:30:50 +010038#include <memory>
39
Anthony Barbier6ff3b192017-09-04 18:44:23 +010040namespace 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 */
50class NEGEMM : public IFunction
51{
52public:
53 /** Constructor */
Georgios Pinitas658039b2017-09-15 16:30:50 +010054 NEGEMM(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010055
Anthony Barbier6ff3b192017-09-04 18:44:23 +010056 /** 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 Iodicebdb6b0b2017-06-30 12:21:00 +010061 * @param[in] a First input tensor (Matrix A or Vector A). Data type supported: QS8/QS16/F16/F32
Anthony Barbier6ff3b192017-09-04 18:44:23 +010062 * @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
73private:
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010074 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 Barbier6ff3b192017-09-04 18:44:23 +010085};
86}
87#endif /*__ARM_COMPUTE_NEGEMM_H__ */