blob: 20beda91cefc50c43d92493dc618fe966e7dbeef [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 */
24#ifndef ARM_COMPUTE_SRC_GPU_CL_OPERATORS_ClMatMul
25#define ARM_COMPUTE_SRC_GPU_CL_OPERATORS_ClMatMul
26
27#include "src/gpu/cl/IClOperator.h"
Jakub Sujak1ed6a142023-04-13 21:14:42 +010028#include "src/gpu/cl/kernels/ClMatMulNativeKernel.h"
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000029#include <memory>
30
31namespace arm_compute
32{
33namespace opencl
34{
35/** Basic operator to execute BatchMatMul on OpenCL. This operator calls the following OpenCL kernels:
36 *
Jakub Sujak1ed6a142023-04-13 21:14:42 +010037 * -# @ref kernels::ClMatMulNativeKernel
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000038 */
39class ClMatMul : public IClOperator
40{
41public:
42 /** Constructor */
43 ClMatMul();
44 ~ClMatMul();
45 /** Initialise the kernel's inputs and output
46 *
47 * Valid data layouts:
48 * - All
49 *
50 * Valid data type configurations:
51 * |lhs |rhs |output |
52 * |:------------|:------------|:------------|
53 * |F32 |F32 |F32 |
54 * |F16 |F16 |F16 |
55 *
56 * @note BatchMatMul: Batched Matrix Multiply - [A * B], Multiplies all slices (slice is an element of a batch) of Tensors A and B
57 * and stores the result in the dst tensor of the same batch size.
58 * 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
59 * For NHWC for example: the batch is the higher dimensions H * N, and in general it is H * all higher dimensions.
60 * @note All tensors must have the same data type.
61 *
62 * @param[in] compile_context The compile context to be used.
63 * @param[in] lhs LHS input tensor info (Matrix A). Data types supported: F16/F32
64 * @param[in] rhs RHS input tensor info (Matrix B). Data types supported: same as @p lhs.
65 * @param[out] output Output tensor info. Data types supported: same as @p lhs
66 * @param[in] matmul_info Attributes for MatMul
67 */
68 void configure(const CLCompileContext &compile_context, ITensorInfo *lhs, ITensorInfo *rhs, ITensorInfo *output, const MatMulInfo &matmul_info);
69 /** Static function to check if given info will lead to a valid configuration
70 *
71 * Similar to @ref ClMatMul::configure()
72 *
73 * @return a status
74 */
75 static Status validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *output, const MatMulInfo &matmul_info);
76 // Inherited methods overridden:
77 void run(ITensorPack &tensors) override;
78
79private:
Jakub Sujak1ed6a142023-04-13 21:14:42 +010080 std::unique_ptr<kernels::ClMatMulNativeKernel> _native_matmul_kernel;
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000081};
82} // namespace opencl
83} // namespace arm_compute
84#endif // ARM_COMPUTE_SRC_GPU_CL_OPERATORS_ClMatMul