Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 4a578b9 | 2021-06-25 12:13:49 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 Arm Limited. |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 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/CLGEMMLowpOutputStage.h" |
| 25 | |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/CL/CLHelpers.h" |
| 27 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/CL/ICLTensor.h" |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/Helpers.h" |
| 30 | #include "arm_compute/core/KernelDescriptors.h" |
| 31 | #include "arm_compute/core/TensorInfo.h" |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 32 | #include "arm_compute/core/Types.h" |
Georgios Pinitas | 4a578b9 | 2021-06-25 12:13:49 +0100 | [diff] [blame] | 33 | |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 34 | #include "src/core/CL/ICLKernel.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 35 | #include "src/gpu/cl/operators/ClGemmLowpOutputStage.h" |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 36 | |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 37 | #include <algorithm> |
| 38 | |
Georgios Pinitas | 932491f | 2018-09-21 16:33:15 +0100 | [diff] [blame] | 39 | namespace arm_compute |
| 40 | { |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 41 | struct CLGEMMLowpOutputStage::Impl |
| 42 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 43 | const ICLTensor *src{nullptr}; |
| 44 | const ICLTensor *bias{nullptr}; |
| 45 | ICLTensor *dst{nullptr}; |
| 46 | std::unique_ptr<opencl::ClGemmLowpOutputStage> op{nullptr}; |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 47 | ITensorPack run_pack{}; |
| 48 | }; |
| 49 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 50 | CLGEMMLowpOutputStage::CLGEMMLowpOutputStage() : _impl(std::make_unique<Impl>()) |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 51 | { |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 52 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 53 | CLGEMMLowpOutputStage::CLGEMMLowpOutputStage(CLGEMMLowpOutputStage &&) = default; |
Georgios Pinitas | 4a578b9 | 2021-06-25 12:13:49 +0100 | [diff] [blame] | 54 | CLGEMMLowpOutputStage &CLGEMMLowpOutputStage::operator=(CLGEMMLowpOutputStage &&) = default; |
| 55 | CLGEMMLowpOutputStage::~CLGEMMLowpOutputStage() = default; |
Manuel Bottini | 9c9b70b | 2019-07-01 17:35:56 +0100 | [diff] [blame] | 56 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 57 | void CLGEMMLowpOutputStage::configure(const ICLTensor *input, |
| 58 | const ICLTensor *bias, |
| 59 | ICLTensor *output, |
| 60 | const GEMMLowpOutputStageInfo &info) |
Sheri Zhang | 0cdbda5 | 2020-02-25 15:57:21 +0000 | [diff] [blame] | 61 | { |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 62 | configure(CLKernelLibrary::get().get_compile_context(), input, bias, output, info); |
| 63 | } |
| 64 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 65 | void CLGEMMLowpOutputStage::configure(const CLCompileContext &compile_context, |
| 66 | const ICLTensor *input, |
| 67 | const ICLTensor *bias, |
| 68 | ICLTensor *output, |
| 69 | const GEMMLowpOutputStageInfo &info) |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 70 | { |
Sheri Zhang | 0cdbda5 | 2020-02-25 15:57:21 +0000 | [diff] [blame] | 71 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Sheri Zhang | 0cdbda5 | 2020-02-25 15:57:21 +0000 | [diff] [blame] | 72 | |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 73 | _impl->src = input; |
| 74 | _impl->bias = bias; |
| 75 | _impl->dst = output; |
Georgios Pinitas | 4a578b9 | 2021-06-25 12:13:49 +0100 | [diff] [blame] | 76 | |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 77 | _impl->op = std::make_unique<opencl::ClGemmLowpOutputStage>(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 78 | _impl->op->configure(compile_context, input->info(), bias != nullptr ? bias->info() : nullptr, output->info(), |
| 79 | info); |
| 80 | _impl->run_pack = {{ACL_SRC, _impl->src}, {ACL_BIAS, _impl->bias}, {ACL_DST, _impl->dst}}; |
Sheri Zhang | 0cdbda5 | 2020-02-25 15:57:21 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 83 | Status CLGEMMLowpOutputStage::validate(const ITensorInfo *input, |
| 84 | const ITensorInfo *bias, |
| 85 | const ITensorInfo *output, |
| 86 | const GEMMLowpOutputStageInfo &info) |
Sheri Zhang | 0cdbda5 | 2020-02-25 15:57:21 +0000 | [diff] [blame] | 87 | { |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 88 | return opencl::ClGemmLowpOutputStage::validate(input, bias, output, info); |
Sheri Zhang | 0cdbda5 | 2020-02-25 15:57:21 +0000 | [diff] [blame] | 89 | } |
Georgios Pinitas | 4a578b9 | 2021-06-25 12:13:49 +0100 | [diff] [blame] | 90 | |
| 91 | void CLGEMMLowpOutputStage::run() |
| 92 | { |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 93 | _impl->op->run(_impl->run_pack); |
Georgios Pinitas | 4a578b9 | 2021-06-25 12:13:49 +0100 | [diff] [blame] | 94 | } |
Sang-Hoon Park | a45abfd | 2020-08-17 13:50:15 +0100 | [diff] [blame] | 95 | } // namespace arm_compute |