blob: 712bac06bf6f3e99236343e90f959508af331257 [file] [log] [blame]
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +00001/*
2 * Copyright (c) 2023 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_RUNTIME_CL_FUNCTIONS_CLMATMUL
25#define ARM_COMPUTE_RUNTIME_CL_FUNCTIONS_CLMATMUL
26
27#include "arm_compute/runtime/IFunction.h"
28#include <memory>
29namespace arm_compute
30{
31// Forward declarations for used types instead of including their header, that could minimize compile time
32class CLCompileContext;
33class ICLTensor;
34class ITensorInfo;
35class MatMulInfo;
36class Status;
37
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000038/** Settings for MatMul OpenCL implementation */
39class GpuMatMulSettings
40{
41public:
42 /* Placeholder for operator parity between CPU/GPU */
43};
44
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000045/** Basic function to execute MatMul (Matrix Multiplication) on OpenCL */
46class CLMatMul : public IFunction
47{
48public:
49 /** Default constructor.*/
50 CLMatMul();
51 /** Default destructor */
52 ~CLMatMul();
53 /** Prevent instances of this class from being copied (As this class contains pointers) */
54 CLMatMul(const CLMatMul &) = delete;
55 /** Default move constructor */
56 CLMatMul(CLMatMul &&);
57 /** Prevent instances of this class from being copied (As this class contains pointers) */
58 CLMatMul &operator=(const CLMatMul &) = delete;
59 /** Default move assignment operator */
60 CLMatMul &operator=(CLMatMul &&);
61 /** Initialise the kernel's inputs and output
62 *
63 * Valid data layouts:
64 * - All
65 *
66 * Valid data type configurations:
67 * |lhs |rhs |output |
68 * |:------------|:------------|:--------------|
69 * |F32 |F32 |F32 |
70 * |F16 |F16 |F16 |
71 *
72 * @note BatchMatMul: Batched Matrix Multiply - [A * B], Multiplies all slices (slice is an element of a batch) of Tensors A and B
73 * and stores the result in the dst tensor of the same batch size.
74 * Batch here is number of slices from A and B multiplied at a time, do not confuse with the batch dimension 'N' of NHWC/NCHW
75 * For NHWC for example: the batch is the higher dimensions H * N, and in general it is H * all higher dimensions.
76 * @note All tensors must have the same data type.
77 *
78 * @param[in] compile_context The compile context to be used.
79 * @param[in] lhs LHS input tensor (Matrix or Vector A). Data types supported: F16/F32
80 * @param[in] rhs RHS input tensor (Matrix B). Data type supported: same as @p lhs.
81 * @param[out] output Output tensor. Data type supported: same as @p lhs.
82 * @param[in] matmul_info Attributes for MatMul
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000083 * @param[in] settings Class containing flags for function level settings
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000084 */
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000085 void configure(const CLCompileContext &compile_context, ICLTensor *rhs, ICLTensor *lhs, ICLTensor *output, const MatMulInfo &matmul_info, const GpuMatMulSettings &settings = GpuMatMulSettings{});
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000086 /** Initialise the kernel's inputs and output
87 *
88 * Similar to @ref CLMatMul::configure()
89 */
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000090 void configure(ICLTensor *lhs, ICLTensor *rhs, ICLTensor *output, const MatMulInfo &matmul_info, const GpuMatMulSettings &settings = GpuMatMulSettings{});
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000091 /** Static function to check if given info will lead to a valid configuration of @ref CLMatMul.
92 *
93 * Similar to @ref CLMatMul::configure()
94 *
95 * @return a status
96 */
97 static Status validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *output, const MatMulInfo &matmul_info);
98 // Inherited methods overridden:
99 void run() override;
100
101private:
102 struct Impl;
103 std::unique_ptr<Impl> _impl;
104};
105} // namespace arm_compute
106
107#endif /* ARM_COMPUTE_RUNTIME_CL_FUNCTIONS_CLMATMUL */