Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +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/NEON/functions/NEDirectConvolutionLayer.h" |
| 25 | |
| 26 | #include "arm_compute/core/PixelValue.h" |
| 27 | #include "arm_compute/core/Utils.h" |
| 28 | #include "arm_compute/core/Validate.h" |
| 29 | #include "arm_compute/runtime/NEON/NEScheduler.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 30 | |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 31 | #include "src/cpu/operators/CpuDirectConv2d.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | |
Michele Di Giorgio | f29d1b7 | 2019-10-29 10:58:13 +0000 | [diff] [blame] | 33 | namespace arm_compute |
| 34 | { |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 35 | struct NEDirectConvolutionLayer::Impl |
| 36 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 37 | ITensor *src{nullptr}; |
| 38 | const ITensor *weights{nullptr}; |
| 39 | const ITensor *bias{nullptr}; |
| 40 | ITensor *dst{nullptr}; |
| 41 | std::unique_ptr<cpu::CpuDirectConv2d> op{nullptr}; |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 42 | }; |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 43 | |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 44 | NEDirectConvolutionLayer::NEDirectConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager) |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 45 | : _memory_manager(std::move(memory_manager)), _impl(std::make_unique<Impl>()) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 46 | { |
| 47 | } |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 48 | NEDirectConvolutionLayer::~NEDirectConvolutionLayer() = default; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 49 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 50 | void NEDirectConvolutionLayer::configure(ITensor *input, |
| 51 | const ITensor *weights, |
| 52 | const ITensor *bias, |
| 53 | ITensor *output, |
| 54 | const PadStrideInfo &conv_info, |
| 55 | const ActivationLayerInfo &act_info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 56 | { |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 57 | _impl->src = input; |
| 58 | _impl->weights = weights; |
| 59 | _impl->bias = bias; |
| 60 | _impl->dst = output; |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 61 | _impl->op = std::make_unique<cpu::CpuDirectConv2d>(_memory_manager); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 62 | _impl->op->configure(input->info(), weights->info(), (bias != nullptr ? bias->info() : nullptr), output->info(), |
| 63 | conv_info, act_info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 66 | Status NEDirectConvolutionLayer::validate(const ITensorInfo *input, |
| 67 | const ITensorInfo *weights, |
| 68 | const ITensorInfo *bias, |
| 69 | const ITensorInfo *output, |
| 70 | const PadStrideInfo &conv_info, |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 71 | const ActivationLayerInfo &act_info) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 72 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 73 | return cpu::CpuDirectConv2d::validate(input, weights, bias, output, conv_info, act_info); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 76 | void NEDirectConvolutionLayer::run() |
| 77 | { |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 78 | ITensorPack pack; |
| 79 | pack.add_tensor(TensorType::ACL_SRC_0, _impl->src); |
| 80 | pack.add_tensor(TensorType::ACL_SRC_1, _impl->weights); |
| 81 | pack.add_tensor(TensorType::ACL_SRC_2, _impl->bias); |
| 82 | pack.add_tensor(TensorType::ACL_DST, _impl->dst); |
| 83 | _impl->op->run(pack); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 84 | } |
Michele Di Giorgio | f29d1b7 | 2019-10-29 10:58:13 +0000 | [diff] [blame] | 85 | } // namespace arm_compute |