blob: 31ad0abaa0a6215409aef39a30a38dded395559b [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Gian Marco1aede362018-02-05 15:07:36 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier7068f992017-10-26 15:23:08 +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
25#ifndef __ARM_COMPUTE_GCGEMM_H__
26#define __ARM_COMPUTE_GCGEMM_H__
27
28#include "arm_compute/core/GLES_COMPUTE/kernels/GCGEMMInterleave4x4Kernel.h"
29#include "arm_compute/core/GLES_COMPUTE/kernels/GCGEMMMatrixAdditionKernel.h"
30#include "arm_compute/core/GLES_COMPUTE/kernels/GCGEMMMatrixMultiplyKernel.h"
31#include "arm_compute/core/GLES_COMPUTE/kernels/GCGEMMTranspose1xWKernel.h"
Michalis Spyrou9e9cbaf2018-03-15 14:41:34 +000032#include "arm_compute/runtime/GLES_COMPUTE/GCMemoryGroup.h"
Anthony Barbier7068f992017-10-26 15:23:08 +010033#include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h"
34#include "arm_compute/runtime/IFunction.h"
35
36namespace arm_compute
37{
38class IGCTensor;
39
40/** Basic function to execute GEMM on OpenGLES Compute. This function calls the following kernels:
41 *
42 * -# @ref GCGEMMInterleave4x4Kernel (if the output tensor is a matrix)
43 * -# @ref GCGEMMTranspose1xWKernel (if the output tensor is a matrix)
44 * -# @ref GCGEMMMatrixMultiplyKernel
45 * -# @ref GCGEMMMatrixAdditionKernel (if c != nullptr and beta != 0.0)
46 *
47 */
48class GCGEMM : public IFunction
49{
50public:
51 /** Default constructor. */
Michalis Spyrou9e9cbaf2018-03-15 14:41:34 +000052 GCGEMM(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Anthony Barbier7068f992017-10-26 15:23:08 +010053
54 /** Initialise the kernel's inputs and output
55 *
56 * @note GEMM: General Matrix Multiply - [alpha * A * B + beta * C].
57 *
58 * @note All tensors must have the same data type.
59 *
60 * @note Whilst the first input tensor can be a vector, the second input tensor must be at least a matrix
61 *
Gian Marco1aede362018-02-05 15:07:36 +000062 * @param[in] a First input tensor (Matrix or Vector A). Data types supported: 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] output 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 Barbier7068f992017-10-26 15:23:08 +010070 */
Gian Marco1aede362018-02-05 15:07:36 +000071 void configure(const IGCTensor *a, const IGCTensor *b, const IGCTensor *c, IGCTensor *output, float alpha, float beta, const GEMMInfo &gemm_info = GEMMInfo());
Anthony Barbier7068f992017-10-26 15:23:08 +010072
73 // Inherited methods overridden:
74 void run() override;
75
76private:
Michalis Spyrou9e9cbaf2018-03-15 14:41:34 +000077 GCMemoryGroup _memory_group;
Anthony Barbier7068f992017-10-26 15:23:08 +010078 GCGEMMInterleave4x4Kernel _interleave_kernel;
79 GCGEMMTranspose1xWKernel _transpose_kernel;
80 GCGEMMMatrixMultiplyKernel _mm_kernel;
81 GCGEMMMatrixAdditionKernel _ma_kernel;
82 GCTensor _tmp_a;
83 GCTensor _tmp_b;
84 bool _is_interleaved_transposed;
85 bool _run_addition;
86};
87}
88
89#endif /* __ARM_COMPUTE_GCGEMM_H__ */