blob: 15833216bb85b08e37173ee1dadf6d2d6d8791c8 [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#include "src/gpu/cl/operators/ClMatMul.h"
25#include "arm_compute/core/Error.h"
26#include "arm_compute/runtime/CL/CLScheduler.h"
27#include "src/common/utils/Log.h"
Jakub Sujak1ed6a142023-04-13 21:14:42 +010028#include "src/gpu/cl/kernels/ClMatMulNativeKernel.h"
Gian Marco Iodice352c07d2023-05-03 12:21:38 +010029#include "src/runtime/heuristics/matmul_native/ClMatMulNativeDefaultConfigValhall.h"
30#include "src/runtime/heuristics/matmul_native/ClMatMulNativeKernelConfig.h"
31#include "src/runtime/heuristics/matmul_native/IClMatMulNativeKernelConfig.h"
32
33using namespace arm_compute::cl_matmul;
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000034
35namespace arm_compute
36{
37namespace opencl
38{
39using namespace arm_compute::opencl::kernels;
40ClMatMul::ClMatMul()
Jakub Sujak1ed6a142023-04-13 21:14:42 +010041 : _native_matmul_kernel(std::make_unique<ClMatMulNativeKernel>())
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000042{
43}
44ClMatMul::~ClMatMul()
45{
46}
47Status ClMatMul::validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *output, const MatMulInfo &matmul_info)
48{
Gian Marco Iodice352c07d2023-05-03 12:21:38 +010049 const GPUTarget gpu_target = CLScheduler::get().target();
50
51 std::unique_ptr<IClMatMulNativeKernelConfig> t = ClMatMulNativeKernelConfigurationFactory::create(gpu_target);
52
53 MatMulKernelInfo kernel_info = t->configure(lhs, rhs, matmul_info);
54
Jakub Sujak1ed6a142023-04-13 21:14:42 +010055 return ClMatMulNativeKernel::validate(lhs, rhs, output, kernel_info);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000056}
57void ClMatMul::configure(const CLCompileContext &compile_context, ITensorInfo *lhs, ITensorInfo *rhs, ITensorInfo *output, const MatMulInfo &matmul_info)
58{
59 ARM_COMPUTE_ERROR_ON_NULLPTR(lhs, rhs, output);
60 ARM_COMPUTE_LOG_PARAMS(lhs, rhs, output, matmul_info);
61
62 // Perform validation step
63 ARM_COMPUTE_ERROR_THROW_ON(validate(lhs, rhs, output, matmul_info));
64 const GPUTarget gpu_target = CLScheduler::get().target();
65
Gian Marco Iodice352c07d2023-05-03 12:21:38 +010066 std::unique_ptr<IClMatMulNativeKernelConfig> t = ClMatMulNativeKernelConfigurationFactory::create(gpu_target);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000067
Gian Marco Iodice352c07d2023-05-03 12:21:38 +010068 MatMulKernelInfo kernel_info = t->configure(lhs, rhs, matmul_info);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000069
70 // Set the target for the kernels
71 _native_matmul_kernel->set_target(gpu_target);
72
73 // Configure the native matrix multiply kernel
74 _native_matmul_kernel->configure(compile_context, lhs, rhs, output, kernel_info);
75}
76void ClMatMul::run(ITensorPack &tensors)
77{
78 CLScheduler::get().enqueue_op(*_native_matmul_kernel, tensors, true);
79}
80} // namespace opencl
81} // namespace arm_compute