steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 1 | /* |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 Arm Limited. |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [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/CLDirectConvolutionLayer.h" |
| 25 | |
Georgios Pinitas | 6fdfaa8 | 2017-11-29 14:27:24 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/CL/ICLTensor.h" |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/PixelValue.h" |
| 28 | #include "arm_compute/core/Utils.h" |
| 29 | #include "arm_compute/core/Validate.h" |
| 30 | #include "arm_compute/runtime/CL/CLScheduler.h" |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 31 | #include "src/runtime/gpu/cl/operators/ClActivation.h" |
| 32 | #include "src/runtime/gpu/cl/operators/ClDirectConvolution.h" |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 33 | |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 34 | namespace arm_compute |
| 35 | { |
| 36 | struct CLDirectConvolutionLayer::Impl |
| 37 | { |
| 38 | const ICLTensor *src{ nullptr }; |
| 39 | const ICLTensor *weights{ nullptr }; |
| 40 | const ICLTensor *biases{ nullptr }; |
| 41 | ICLTensor *dst{ nullptr }; |
| 42 | std::unique_ptr<opencl::ClDirectConvolution> op{ nullptr }; |
| 43 | }; |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 44 | |
| 45 | CLDirectConvolutionLayer::CLDirectConvolutionLayer() |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 46 | : _impl(std::make_unique<Impl>()) |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 47 | { |
| 48 | } |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 49 | CLDirectConvolutionLayer::CLDirectConvolutionLayer(CLDirectConvolutionLayer &&) = default; |
| 50 | CLDirectConvolutionLayer &CLDirectConvolutionLayer::operator=(CLDirectConvolutionLayer &&) = default; |
| 51 | CLDirectConvolutionLayer::~CLDirectConvolutionLayer() = default; |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 52 | |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 53 | void CLDirectConvolutionLayer::configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info) |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 54 | { |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 55 | configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, conv_info, act_info); |
| 56 | } |
| 57 | |
| 58 | void CLDirectConvolutionLayer::configure(const CLCompileContext &compile_context, ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 59 | const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info) |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 60 | { |
Michele Di Giorgio | 97e2580 | 2021-03-25 12:37:45 +0000 | [diff] [blame] | 61 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 62 | |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 63 | _impl->src = input; |
| 64 | _impl->weights = weights; |
| 65 | _impl->biases = biases; |
| 66 | _impl->dst = output; |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 67 | |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 68 | _impl->op = std::make_unique<opencl::ClDirectConvolution>(); |
Michele Di Giorgio | 97e2580 | 2021-03-25 12:37:45 +0000 | [diff] [blame] | 69 | _impl->op->configure(compile_context, input->info(), weights->info(), (biases != nullptr) ? biases->info() : nullptr, output->info(), conv_info, act_info); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 72 | Status CLDirectConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 73 | const ActivationLayerInfo &act_info) |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 74 | { |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 75 | return opencl::ClDirectConvolution::validate(input, weights, biases, output, conv_info, act_info); |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 76 | } |
| 77 | |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 78 | void CLDirectConvolutionLayer::run() |
| 79 | { |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 80 | ITensorPack pack; |
| 81 | pack.add_tensor(TensorType::ACL_SRC, _impl->src); |
| 82 | pack.add_tensor(TensorType::ACL_SRC_1, _impl->weights); |
| 83 | pack.add_tensor(TensorType::ACL_SRC_2, _impl->biases); |
| 84 | pack.add_tensor(TensorType::ACL_DST, _impl->dst); |
| 85 | _impl->op->run(pack); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 86 | } |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 87 | } |