blob: 80448974c413cbba0da65f86e230c0f732cb1ce2 [file] [log] [blame]
SiCong Lia8d80582023-05-19 14:23:37 +01001/*
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 ACL_SRC_GPU_CL_KERNELS_CLMATMULNATIVEMMULKERNEL
25#define ACL_SRC_GPU_CL_KERNELS_CLMATMULNATIVEMMULKERNEL
26
27#include "src/core/common/Macros.h"
28#include "src/gpu/cl/ClCompileContext.h"
29#include "src/gpu/cl/IClKernel.h"
30
31namespace arm_compute
32{
33struct MatMulKernelInfo;
34namespace opencl
35{
36namespace kernels
37{
38class ClMatMulNativeMMULKernel : public IClKernel
39{
40public:
41 ClMatMulNativeMMULKernel();
42 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(ClMatMulNativeMMULKernel);
43 /** Initialize the kernel's input and output.
44 *
45 * This kernel performs matrix multiplication of lhs and rhs:
46 *
47 * dst = matmul(lhs, rhs)
48 *
49 * Valid data layouts:
50 * - All
51 *
52 * Valid data type configurations:
53 * |lhs |rhs |dst |
54 * |:--------------|:--------------|:--------------|
55 * |F32 |F32 |F32 |
56 * |F16 |F16 |F16 |
57 *
58 * Shape definitions:
59 * Dim0, Dim1, Dim2...
60 * lhs: [ K, M, Batch dims...]
61 * rhs: [ N, K, Batch dims...]
62 * dst: [ N, M, Batch dims...]
63 *
64 * Valid shape configurations:
65 * - K must be a multiple of 4 (MMUL_K0).
66 * - No broadcasting in batch dimensions. I.e. batch dims must be the same across lhs, rhs and dst
67 *
68 * @param[in] compile_context The compile context to be used.
Mohammed Suhail Munshi8e2dede2023-06-27 14:25:58 +010069 * @param[in] lhs Input tensor info for the LHS matrix.
70 * @param[in] rhs Input tensor info for the RHS matrix.
71 * @param[in] bias Bias tensor info. Can be nullptr. Data type supported: Same as @p lhs.
SiCong Lia8d80582023-05-19 14:23:37 +010072 * @param[out] dst Output tensor info.
73 * @param[in] matmul_info Attributes for Batch MatMul Kernel
74 */
Mohammed Suhail Munshi8e2dede2023-06-27 14:25:58 +010075 void configure(const ClCompileContext &compile_context, ITensorInfo *lhs, ITensorInfo *rhs, ITensorInfo *bias, ITensorInfo *dst, const MatMulKernelInfo &matmul_info);
SiCong Lia8d80582023-05-19 14:23:37 +010076 /** Static function to check if given info will lead to a valid configuration
77 *
78 * Similar to @ref ClMatMulNativeMMULKernel::configure()
79 *
80 * @return a status
81 */
Mohammed Suhail Munshi8e2dede2023-06-27 14:25:58 +010082 static Status validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *bias, const ITensorInfo *dst, const MatMulKernelInfo &matmul_info);
SiCong Lia8d80582023-05-19 14:23:37 +010083
84 // Inherited methods overridden:
85 void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override;
86
87private:
88 int _m{ 1 };
89 int _n{ 1 };
Ramy Elgammalc9525962023-05-19 14:23:37 +010090 int _k{ 1 };
SiCong Lia8d80582023-05-19 14:23:37 +010091};
92} // namespace kernels
93} // namespace opencl
94} // namespace arm_compute
95#endif /* ACL_SRC_GPU_CL_KERNELS_CLMATMULNATIVEMMULKERNEL */