blob: 1aeb896325c7da48537edf4b34529d9a4510b956 [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 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010075 void configure(const ClCompileContext &compile_context,
76 ITensorInfo *lhs,
77 ITensorInfo *rhs,
78 ITensorInfo *bias,
79 ITensorInfo *dst,
80 const MatMulKernelInfo &matmul_info);
SiCong Lia8d80582023-05-19 14:23:37 +010081 /** Static function to check if given info will lead to a valid configuration
82 *
83 * Similar to @ref ClMatMulNativeMMULKernel::configure()
84 *
85 * @return a status
86 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010087 static Status validate(const ITensorInfo *lhs,
88 const ITensorInfo *rhs,
89 const ITensorInfo *bias,
90 const ITensorInfo *dst,
91 const MatMulKernelInfo &matmul_info);
SiCong Lia8d80582023-05-19 14:23:37 +010092
93 // Inherited methods overridden:
94 void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override;
95
96private:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010097 int _m{1};
98 int _n{1};
99 int _k{1};
SiCong Lia8d80582023-05-19 14:23:37 +0100100};
101} // namespace kernels
102} // namespace opencl
103} // namespace arm_compute
104#endif /* ACL_SRC_GPU_CL_KERNELS_CLMATMULNATIVEMMULKERNEL */