Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 1 | /* |
| 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 Sujak | 1ed6a14 | 2023-04-13 21:14:42 +0100 | [diff] [blame] | 28 | #include "src/gpu/cl/kernels/ClMatMulNativeKernel.h" |
Gian Marco Iodice | 352c07d | 2023-05-03 12:21:38 +0100 | [diff] [blame^] | 29 | #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 | |
| 33 | using namespace arm_compute::cl_matmul; |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace opencl |
| 38 | { |
| 39 | using namespace arm_compute::opencl::kernels; |
| 40 | ClMatMul::ClMatMul() |
Jakub Sujak | 1ed6a14 | 2023-04-13 21:14:42 +0100 | [diff] [blame] | 41 | : _native_matmul_kernel(std::make_unique<ClMatMulNativeKernel>()) |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | ClMatMul::~ClMatMul() |
| 45 | { |
| 46 | } |
| 47 | Status ClMatMul::validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *output, const MatMulInfo &matmul_info) |
| 48 | { |
Gian Marco Iodice | 352c07d | 2023-05-03 12:21:38 +0100 | [diff] [blame^] | 49 | 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 Sujak | 1ed6a14 | 2023-04-13 21:14:42 +0100 | [diff] [blame] | 55 | return ClMatMulNativeKernel::validate(lhs, rhs, output, kernel_info); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 56 | } |
| 57 | void 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 Iodice | 352c07d | 2023-05-03 12:21:38 +0100 | [diff] [blame^] | 66 | std::unique_ptr<IClMatMulNativeKernelConfig> t = ClMatMulNativeKernelConfigurationFactory::create(gpu_target); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 67 | |
Gian Marco Iodice | 352c07d | 2023-05-03 12:21:38 +0100 | [diff] [blame^] | 68 | MatMulKernelInfo kernel_info = t->configure(lhs, rhs, matmul_info); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 69 | |
| 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 | } |
| 76 | void ClMatMul::run(ITensorPack &tensors) |
| 77 | { |
| 78 | CLScheduler::get().enqueue_op(*_native_matmul_kernel, tensors, true); |
| 79 | } |
| 80 | } // namespace opencl |
| 81 | } // namespace arm_compute |