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 "arm_compute/runtime/CL/functions/CLMatMul.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 25 | |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 26 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 27 | #include "arm_compute/runtime/CL/CLTypes.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 28 | |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 29 | #include "src/gpu/cl/operators/ClMatMul.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | using OperatorType = opencl::ClMatMul; |
| 34 | |
| 35 | struct CLMatMul::Impl |
| 36 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 37 | std::unique_ptr<OperatorType> op{nullptr}; |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 38 | ITensorPack run_pack{}; |
| 39 | }; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 40 | CLMatMul::CLMatMul() : _impl(std::make_unique<Impl>()) |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 41 | { |
| 42 | } |
| 43 | |
| 44 | CLMatMul::~CLMatMul() = default; |
| 45 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 46 | void CLMatMul::configure(ICLTensor *lhs, |
| 47 | ICLTensor *rhs, |
| 48 | ICLTensor *output, |
| 49 | const MatMulInfo &matmul_info, |
| 50 | const GpuMatMulSettings &settings, |
| 51 | const ActivationLayerInfo &act_info) |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 52 | { |
Mohammed Suhail Munshi | a1b1e41 | 2023-03-23 22:21:31 +0000 | [diff] [blame] | 53 | ARM_COMPUTE_UNUSED(settings); |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 54 | configure(CLKernelLibrary::get().get_compile_context(), lhs, rhs, output, matmul_info, settings, act_info); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 57 | void CLMatMul::configure(const CLCompileContext &compile_context, |
| 58 | ICLTensor *lhs, |
| 59 | ICLTensor *rhs, |
| 60 | ICLTensor *output, |
| 61 | const MatMulInfo &matmul_info, |
| 62 | const GpuMatMulSettings &settings, |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 63 | const ActivationLayerInfo &act_info) |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 64 | { |
| 65 | ARM_COMPUTE_ERROR_ON_NULLPTR(lhs, rhs, output); |
Mohammed Suhail Munshi | a1b1e41 | 2023-03-23 22:21:31 +0000 | [diff] [blame] | 66 | ARM_COMPUTE_UNUSED(settings); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 67 | |
| 68 | _impl->op = std::make_unique<OperatorType>(); |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 69 | _impl->op->configure(compile_context, lhs->info(), rhs->info(), output->info(), matmul_info, act_info); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 70 | _impl->run_pack = {{ACL_SRC_0, lhs}, {ACL_SRC_1, rhs}, {ACL_DST, output}}; |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 73 | Status CLMatMul::validate(const ITensorInfo *lhs, |
| 74 | const ITensorInfo *rhs, |
| 75 | const ITensorInfo *output, |
| 76 | const MatMulInfo &matmul_info, |
| 77 | const ActivationLayerInfo &act_info) |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 78 | { |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 79 | return OperatorType::validate(lhs, rhs, output, matmul_info, act_info); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void CLMatMul::run() |
| 83 | { |
| 84 | _impl->op->run(_impl->run_pack); |
| 85 | } |
| 86 | |
| 87 | } // namespace arm_compute |