blob: 043b2b811550512cb906a235c73e05a9de852d6f [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 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_CLGEMM_H__
25#define __ARM_COMPUTE_CLGEMM_H__
26
27#include "arm_compute/core/CL/kernels/CLFillBorderKernel.h"
28#include "arm_compute/core/CL/kernels/CLGEMMInterleave4x4Kernel.h"
29#include "arm_compute/core/CL/kernels/CLGEMMMatrixAdditionKernel.h"
30#include "arm_compute/core/CL/kernels/CLGEMMMatrixMultiplyKernel.h"
31#include "arm_compute/core/CL/kernels/CLGEMMTranspose1xWKernel.h"
32#include "arm_compute/runtime/CL/CLTensor.h"
33#include "arm_compute/runtime/IFunction.h"
34
35namespace arm_compute
36{
37class ICLTensor;
38
39/** Basic function to execute GEMM on OpenCL. Data types supported: F32, F16. This function calls the following OpenCL kernels:
40 *
41 * -# @ref CLGEMMInterleave4x4Kernel (if the output tensor is a matrix)
42 * -# @ref CLGEMMTranspose1xWKernel (if the output tensor is a matrix)
43 * -# @ref CLGEMMMatrixMultiplyKernel
44 * -# @ref CLGEMMMatrixAdditionKernel (if c != nullptr and beta != 0.0)
45 *
46 */
47class CLGEMM : public IFunction
48{
49public:
50 /** Default constructor. */
51 CLGEMM();
52 /** Initialise the kernel's inputs and output
53 *
54 * @note GEMM: General Matrix Multiply - [alpha * A * B + beta * C].
55 *
56 * @note All tensors must have the same data type. Data types supported: F32, F16
57 *
58 * @note Whilst the first input tensor can be a vector, the second input tensor must be at least a matrix
59 *
60 * @param[in] a First input tensor (Matrix or Vector A). Data types supported: F32, F16
61 * @param[in] b Second input tensor (Matrix B). Data type supported: same as @p a.
62 * @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.
63 * @param[out] output Output tensor. Data type supported: same as @p a
64 * @param[in] alpha Weight of the matrix product
65 * @param[in] beta Weight of matrix C
66 */
67 void configure(const ICLTensor *a, const ICLTensor *b, const ICLTensor *c, ICLTensor *output, float alpha, float beta);
68
69 // Inherited methods overridden:
70 void run() override;
71
72private:
73 CLGEMMInterleave4x4Kernel _interleave_kernel;
74 CLGEMMTranspose1xWKernel _transpose_kernel;
75 CLGEMMMatrixMultiplyKernel _mm_kernel;
76 CLGEMMMatrixAdditionKernel _ma_kernel;
77 CLTensor _tmp_a;
78 CLTensor _tmp_b;
79 bool _run_vector_matrix_multiplication;
80 bool _run_addition;
81};
82}
83
84#endif /* __ARM_COMPUTE_CLGEMM_H__ */