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 | { |
| 43 | const ICLTensor *src{ nullptr }; |
| 44 | const ICLTensor *bias{ nullptr }; |
| 45 | ICLTensor *dst{ nullptr }; |
| 46 | std::unique_ptr<opencl::ClGemmLowpOutputStage> op{ nullptr }; |
| 47 | ITensorPack run_pack{}; |
| 48 | }; |
| 49 | |
Georgios Pinitas | 4a578b9 | 2021-06-25 12:13:49 +0100 | [diff] [blame] | 50 | CLGEMMLowpOutputStage::CLGEMMLowpOutputStage() |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 51 | : _impl(std::make_unique<Impl>()) |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 52 | { |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 53 | } |
Georgios Pinitas | 4a578b9 | 2021-06-25 12:13:49 +0100 | [diff] [blame] | 54 | CLGEMMLowpOutputStage::CLGEMMLowpOutputStage(CLGEMMLowpOutputStage &&) = default; |
| 55 | CLGEMMLowpOutputStage &CLGEMMLowpOutputStage::operator=(CLGEMMLowpOutputStage &&) = default; |
| 56 | CLGEMMLowpOutputStage::~CLGEMMLowpOutputStage() = default; |
Manuel Bottini | 9c9b70b | 2019-07-01 17:35:56 +0100 | [diff] [blame] | 57 | |
Sheri Zhang | 0cdbda5 | 2020-02-25 15:57:21 +0000 | [diff] [blame] | 58 | void CLGEMMLowpOutputStage::configure(const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, const GEMMLowpOutputStageInfo &info) |
| 59 | { |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 60 | configure(CLKernelLibrary::get().get_compile_context(), input, bias, output, info); |
| 61 | } |
| 62 | |
| 63 | void CLGEMMLowpOutputStage::configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, const GEMMLowpOutputStageInfo &info) |
| 64 | { |
Sheri Zhang | 0cdbda5 | 2020-02-25 15:57:21 +0000 | [diff] [blame] | 65 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Sheri Zhang | 0cdbda5 | 2020-02-25 15:57:21 +0000 | [diff] [blame] | 66 | |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 67 | _impl->src = input; |
| 68 | _impl->bias = bias; |
| 69 | _impl->dst = output; |
Georgios Pinitas | 4a578b9 | 2021-06-25 12:13:49 +0100 | [diff] [blame] | 70 | |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 71 | _impl->op = std::make_unique<opencl::ClGemmLowpOutputStage>(); |
| 72 | _impl->op->configure(compile_context, input->info(), bias != nullptr ? bias->info() : nullptr, output->info(), info); |
| 73 | _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] | 74 | } |
| 75 | |
| 76 | Status CLGEMMLowpOutputStage::validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo &info) |
| 77 | { |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 78 | return opencl::ClGemmLowpOutputStage::validate(input, bias, output, info); |
Sheri Zhang | 0cdbda5 | 2020-02-25 15:57:21 +0000 | [diff] [blame] | 79 | } |
Georgios Pinitas | 4a578b9 | 2021-06-25 12:13:49 +0100 | [diff] [blame] | 80 | |
| 81 | void CLGEMMLowpOutputStage::run() |
| 82 | { |
Georgios Pinitas | 399f623 | 2021-06-29 15:31:58 +0100 | [diff] [blame] | 83 | _impl->op->run(_impl->run_pack); |
Georgios Pinitas | 4a578b9 | 2021-06-25 12:13:49 +0100 | [diff] [blame] | 84 | } |
Sang-Hoon Park | a45abfd | 2020-08-17 13:50:15 +0100 | [diff] [blame] | 85 | } // namespace arm_compute |