blob: 1733def21c14169e3a4bf6c986e78021bdd3914e [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 */
Gunes Bayirc1204c72023-10-10 17:41:56 +010024#ifndef ACL_SRC_GPU_CL_OPERATORS_CLMATMUL_H
25#define ACL_SRC_GPU_CL_OPERATORS_CLMATMUL_H
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000026
SiCong Li91295492023-07-21 18:16:13 +010027#include "arm_compute/function_info/ActivationLayerInfo.h"
28#include "arm_compute/function_info/MatMulInfo.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010029
Gunes Bayirc1204c72023-10-10 17:41:56 +010030#include "src/gpu/cl/IClKernel.h"
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000031#include "src/gpu/cl/IClOperator.h"
Jakub Sujake9b3ee22023-04-17 12:08:48 +010032
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000033#include <memory>
34
35namespace arm_compute
36{
37namespace opencl
38{
39/** Basic operator to execute BatchMatMul on OpenCL. This operator calls the following OpenCL kernels:
40 *
Jakub Sujak1ed6a142023-04-13 21:14:42 +010041 * -# @ref kernels::ClMatMulNativeKernel
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000042 */
43class ClMatMul : public IClOperator
44{
45public:
46 /** Constructor */
47 ClMatMul();
Jakub Sujake9b3ee22023-04-17 12:08:48 +010048 /** Default destructor */
49 ~ClMatMul() = default;
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000050 /** Initialise the kernel's inputs and output
51 *
52 * Valid data layouts:
53 * - All
54 *
55 * Valid data type configurations:
Jakub Sujake9b3ee22023-04-17 12:08:48 +010056 * |lhs |rhs |dst |
57 * |:--------------|:--------------|:--------------|
58 * |F32 |F32 |F32 |
59 * |F16 |F16 |F16 |
60 * |QASYMM8_SIGNED |QASYMM8_SIGNED |QASYMM8_SIGNED |
61 * |QASYMM8 |QASYMM8 |QASYMM8 |
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000062 *
63 * @note BatchMatMul: Batched Matrix Multiply - [A * B], Multiplies all slices (slice is an element of a batch) of Tensors A and B
64 * and stores the result in the dst tensor of the same batch size.
65 * 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
66 * For NHWC for example: the batch is the higher dimensions H * N, and in general it is H * all higher dimensions.
67 * @note All tensors must have the same data type.
68 *
69 * @param[in] compile_context The compile context to be used.
Jakub Sujake9b3ee22023-04-17 12:08:48 +010070 * @param[in] lhs Left-hand side tensor info. Data types supported: F16/F32/QASYMM8_SIGNED/QASYMM8.
71 * @param[in] rhs Right-hand side tensor info. Data types supported: same as @p lhs.
72 * @param[out] dst Output tensor to store the result of the batched matrix multiplication. Data types supported: same as @p lhs.
73 * @param[in] matmul_info Contains MatMul operation information described in @ref MatMulInfo.
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010074 * @param[in] act_info Class containing information about fused activation function.
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000075 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010076 void configure(const CLCompileContext &compile_context,
77 ITensorInfo *lhs,
78 ITensorInfo *rhs,
79 ITensorInfo *dst,
80 const MatMulInfo &matmul_info,
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010081 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000082 /** Static function to check if given info will lead to a valid configuration
83 *
84 * Similar to @ref ClMatMul::configure()
85 *
86 * @return a status
87 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010088 static Status validate(const ITensorInfo *lhs,
89 const ITensorInfo *rhs,
90 const ITensorInfo *dst,
91 const MatMulInfo &matmul_info,
92 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000093 // Inherited methods overridden:
94 void run(ITensorPack &tensors) override;
95
96private:
Gunes Bayirc1204c72023-10-10 17:41:56 +010097 std::unique_ptr<opencl::IClKernel> _matmul_kernel{nullptr};
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000098};
99} // namespace opencl
100} // namespace arm_compute
Gunes Bayirc1204c72023-10-10 17:41:56 +0100101#endif // ACL_SRC_GPU_CL_OPERATORS_CLMATMUL_H