blob: 9d54bab8683d44f7afd865634e9b822488d7f835 [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 */
Jakub Sujake9b3ee22023-04-17 12:08:48 +010024#ifndef ACL_ARM_COMPUTE_RUNTIME_CL_FUNCTIONS_CLMATMUL
25#define ACL_ARM_COMPUTE_RUNTIME_CL_FUNCTIONS_CLMATMUL
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000026
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010027#include "arm_compute/core/Types.h"
SiCong Li91295492023-07-21 18:16:13 +010028#include "arm_compute/function_info/ActivationLayerInfo.h"
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000029#include "arm_compute/runtime/IFunction.h"
30#include <memory>
Jakub Sujake9b3ee22023-04-17 12:08:48 +010031
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000032namespace arm_compute
33{
34// Forward declarations for used types instead of including their header, that could minimize compile time
35class CLCompileContext;
36class ICLTensor;
37class ITensorInfo;
38class MatMulInfo;
39class Status;
40
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000041/** Settings for MatMul OpenCL implementation */
42class GpuMatMulSettings
43{
44public:
45 /* Placeholder for operator parity between CPU/GPU */
46};
47
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000048/** Basic function to execute MatMul (Matrix Multiplication) on OpenCL */
49class CLMatMul : public IFunction
50{
51public:
52 /** Default constructor.*/
53 CLMatMul();
54 /** Default destructor */
55 ~CLMatMul();
56 /** Prevent instances of this class from being copied (As this class contains pointers) */
57 CLMatMul(const CLMatMul &) = delete;
58 /** Default move constructor */
59 CLMatMul(CLMatMul &&);
60 /** Prevent instances of this class from being copied (As this class contains pointers) */
61 CLMatMul &operator=(const CLMatMul &) = delete;
62 /** Default move assignment operator */
63 CLMatMul &operator=(CLMatMul &&);
64 /** Initialise the kernel's inputs and output
65 *
66 * Valid data layouts:
67 * - All
68 *
69 * Valid data type configurations:
Jakub Sujake9b3ee22023-04-17 12:08:48 +010070 * |lhs |rhs |dst |
71 * |:--------------|:--------------|:--------------|
72 * |F32 |F32 |F32 |
73 * |F16 |F16 |F16 |
74 * |QASYMM8_SIGNED |QASYMM8_SIGNED |QASYMM8_SIGNED |
75 * |QASYMM8 |QASYMM8 |QASYMM8 |
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000076 *
77 * @note BatchMatMul: Batched Matrix Multiply - [A * B], Multiplies all slices (slice is an element of a batch) of Tensors A and B
78 * and stores the result in the dst tensor of the same batch size.
79 * 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
80 * For NHWC for example: the batch is the higher dimensions H * N, and in general it is H * all higher dimensions.
81 * @note All tensors must have the same data type.
82 *
83 * @param[in] compile_context The compile context to be used.
Jakub Sujake9b3ee22023-04-17 12:08:48 +010084 * @param[in] lhs Left-hand side tensor info containing the input activations as Matrix A. Data types supported: F16/F32/QASYMM8_SIGNED/QASYMM8.
85 * @param[in] rhs Right-hand side tensor info containing the input weights as Matrix B. Data types supported: same as @p lhs.
86 * @param[out] dst Output tensor to store the result of the batched matrix multiplication. Data types supported: same as @p lhs.
87 * @param[in] matmul_info Contains MatMul operation information described in @ref MatMulInfo.
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010088 * @param[in] settings Contains flags for function level settings
89 * @param[in] act_info (Optional) Contains activation function and lower and upper bound values for bounded activation functions.
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000090 */
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010091 void configure(const CLCompileContext &compile_context, ICLTensor *rhs, ICLTensor *lhs, ICLTensor *dst, const MatMulInfo &matmul_info, const GpuMatMulSettings &settings = GpuMatMulSettings{}, const
92 ActivationLayerInfo &act_info = ActivationLayerInfo{});
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000093 /** Initialise the kernel's inputs and output
94 *
95 * Similar to @ref CLMatMul::configure()
96 */
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010097 void configure(ICLTensor *lhs, ICLTensor *rhs, ICLTensor *dst, const MatMulInfo &matmul_info, const GpuMatMulSettings &settings = GpuMatMulSettings{}, const ActivationLayerInfo &act_info =
98 ActivationLayerInfo{});
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000099 /** Static function to check if given info will lead to a valid configuration of @ref CLMatMul.
100 *
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000101 *
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100102 * @note All tensors must have the same data type.
103 *
104 * @param[in] lhs Left-hand side (Matrix A) tensor info. Data types supported: F16/F32/QASYMM8_SIGNED/QASYMM8.
105 * @param[in] rhs Right-hand side (Matrix B) tensor info. Data types supported: same as @p lhs.
106 * @param[out] output Output tensor info to store the result of the batched matrix multiplication. Data types supported: same as @p lhs.
107 * @param[in] matmul_info Contains MatMul operation information described in @ref MatMulInfo.
108 * @param[in] act_info (Optional) Contains activation function and lower and upper bound values for bounded activation functions.
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000109 */
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100110 static Status validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *output, const MatMulInfo &matmul_info, const ActivationLayerInfo &act_info = ActivationLayerInfo{});
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000111 // Inherited methods overridden:
112 void run() override;
113
114private:
115 struct Impl;
116 std::unique_ptr<Impl> _impl;
117};
118} // namespace arm_compute
119
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100120#endif /* ACL_ARM_COMPUTE_RUNTIME_CL_FUNCTIONS_CLMATMUL */