blob: fe2b787c1208b383f2b576257e9d7fc45386cdbe [file] [log] [blame]
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +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 */
Jakub Sujak1ed6a142023-04-13 21:14:42 +010024#ifndef ACL_SRC_GPU_CL_KERNELS_CLMATMULNATIVEKERNEL
25#define ACL_SRC_GPU_CL_KERNELS_CLMATMULNATIVEKERNEL
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +000026
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +000027#include "arm_compute/core/KernelDescriptors.h"
28#include "src/core/common/Macros.h"
29#include "src/gpu/cl/ClCompileContext.h"
30#include "src/gpu/cl/IClKernel.h"
31
32namespace arm_compute
33{
34namespace opencl
35{
36namespace kernels
37{
Jakub Sujak1ed6a142023-04-13 21:14:42 +010038class ClMatMulNativeKernel : public IClKernel
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +000039{
40public:
Jakub Sujak1ed6a142023-04-13 21:14:42 +010041 ClMatMulNativeKernel();
42 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(ClMatMulNativeKernel);
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +000043 /** Initialise the kernel's input and output.
44 *
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010045 * @param[in] compile_context The compile context to be used.
Mohammed Suhail Munshi8e2dede2023-06-27 14:25:58 +010046 * @param[in] lhs Input tensor info for the LHS matrix. Data type supported: F32/F16.
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010047 * Dimensions above 2 are collapsed onto dimension 2 and represent the batch.
Mohammed Suhail Munshi8e2dede2023-06-27 14:25:58 +010048 * @param[in] rhs Input tensor info for the RHS matrix. Data type supported: same as @p lhs.
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010049 * Dimensions above 2 are collapsed onto dimension 2 and represent the batch.
Mohammed Suhail Munshi8e2dede2023-06-27 14:25:58 +010050 * @param[in] bias Bias tensor info for bias matrix. Can be nullptr. Data type supported: same as @p lhs.
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010051 * @param[out] dst Output tensor info. Data type supported: same as @p lhs
52 * @param[in] matmul_kernel_info Attributes for Batch MatMul Kernel
Mohammed Suhail Munshi8e2dede2023-06-27 14:25:58 +010053 * @param[in] act_info (Optional) Specifies activation function to use after Matrix multiplication. Default is Identity function.
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +000054 */
Mohammed Suhail Munshi8e2dede2023-06-27 14:25:58 +010055 void configure(const ClCompileContext &compile_context, ITensorInfo *lhs, ITensorInfo *rhs, ITensorInfo *bias, ITensorInfo *dst, const MatMulKernelInfo &matmul_kernel_info,
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010056 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +000057 /** Static function to check if given info will lead to a valid configuration
58 *
Jakub Sujak1ed6a142023-04-13 21:14:42 +010059 * Similar to @ref ClMatMulNativeKernel::configure()
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +000060 *
61 * @return a status
62 */
Mohammed Suhail Munshi8e2dede2023-06-27 14:25:58 +010063 static Status validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *bias, const ITensorInfo *dst, const MatMulKernelInfo &matmul_kernel_info,
64 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +000065
66 // Inherited methods overridden:
67 void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override;
Gunes Bayirbbeef722023-03-20 10:19:10 +000068
69private:
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000070 bool _export_rhs_to_cl_image{ false };
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +000071};
72} // namespace kernels
73} // namespace opencl
74} // namespace arm_compute
Jakub Sujak1ed6a142023-04-13 21:14:42 +010075#endif /* ACL_SRC_GPU_CL_KERNELS_CLMATMULNATIVEKERNEL */