blob: 5279995be4aaeae7eb3a3f5b717a83106b1f84d0 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitas78c00902018-01-09 17:33:11 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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"
28#include "arm_compute/core/NEON/kernels/NEGEMMInterleave4x4Kernel.h"
29#include "arm_compute/core/NEON/kernels/NEGEMMMatrixAdditionKernel.h"
30#include "arm_compute/core/NEON/kernels/NEGEMMMatrixMultiplyKernel.h"
31#include "arm_compute/core/NEON/kernels/NEGEMMTranspose1xWKernel.h"
32#include "arm_compute/runtime/IFunction.h"
Georgios Pinitas658039b2017-09-15 16:30:50 +010033#include "arm_compute/runtime/IMemoryManager.h"
34#include "arm_compute/runtime/MemoryGroup.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010035#include "arm_compute/runtime/Tensor.h"
36
Pablo Telloeb82fd22018-02-23 13:43:50 +000037#include "arm_compute/runtime/NEON/AssemblyHelper.h"
38
Georgios Pinitas658039b2017-09-15 16:30:50 +010039#include <memory>
40
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041namespace arm_compute
42{
43/** Basic function to execute GEMM on NEON. This function calls the following NEON kernels:
44 *
45 * -# @ref NEGEMMInterleave4x4Kernel (if the output tensor is a matrix)
46 * -# @ref NEGEMMTranspose1xWKernel (if the output tensor is a matrix)
47 * -# @ref NEGEMMMatrixMultiplyKernel
48 * -# @ref NEGEMMMatrixAdditionKernel (if c != nullptr and beta != 0.0)
49 *
50 */
51class NEGEMM : public IFunction
52{
53public:
54 /** Constructor */
Georgios Pinitas658039b2017-09-15 16:30:50 +010055 NEGEMM(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010056
Anthony Barbier6ff3b192017-09-04 18:44:23 +010057 /** Initialise the kernel's inputs, output
58 *
59 * @note GEMM: General Matrix Multiply - [alpha * A * B + beta * C].
60 * @note GEMM: The tensors a, b, c, d must have the same data type. You should not mix data types when calling this function.
61 *
Gian Marco1d25ed52017-12-16 19:33:50 +000062 * @param[in] a First input tensor (Matrix A or Vector A). Data type supported: QS8/QS16/F16/F32
63 * @param[in] b Second input tensor (Matrix B). Data type supported: same as @p a
64 * @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
65 * @param[out] d Output tensor. Data type supported: same as @p a
66 * @param[in] alpha Weight of the matrix product
67 * @param[in] beta Weight of matrix C
68 * @param[in] gemm_info (Optional) Specifies if the matrix A and/or matrix B have been reshaped and
69 * if the reshape of matrix B should happen only for the first run
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070 */
Gian Marco1d25ed52017-12-16 19:33:50 +000071 void configure(const ITensor *a, const ITensor *b, const ITensor *c, ITensor *d, float alpha, float beta, const GEMMInfo &gemm_info = GEMMInfo());
Anthony Barbier6ff3b192017-09-04 18:44:23 +010072
73 // Inherited methods overridden:
74 void run() override;
75
76private:
Pablo Telloeb82fd22018-02-23 13:43:50 +000077 MemoryGroup _memory_group;
78 NEGEMMInterleave4x4Kernel _interleave_kernel;
79 NEGEMMTranspose1xWKernel _transpose_kernel;
80 NEGEMMMatrixMultiplyKernel _mm_kernel;
81 AssemblyKernelGlueF32 _asm_glue;
82 NEGEMMMatrixAdditionKernel _ma_kernel;
83 Tensor _tmp_a;
84 Tensor _tmp_b;
85 Tensor _workspace;
86 bool _run_vector_matrix_multiplication;
87 bool _run_addition;
88 bool _is_first_run;
89 bool _reshape_b_only_on_first_run;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010090};
91}
92#endif /*__ARM_COMPUTE_NEGEMM_H__ */