Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 1 | /* |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2022 Arm Limited. |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +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 | */ |
Georgios Pinitas | 9fb1159 | 2018-04-26 20:34:58 +0100 | [diff] [blame] | 24 | #include "arm_compute/runtime/NEON/functions/NEWinogradConvolutionLayer.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 25 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/Error.h" |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/ITensorPack.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/Utils.h" |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/Validate.h" |
| 31 | |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 32 | #include "src/core/CPP/Validate.h" |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 33 | #include "src/core/helpers/MemoryHelpers.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 34 | #include "src/core/NEON/kernels/convolution/common/utils.hpp" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 35 | #include "src/cpu/kernels/CpuWinogradConv2dKernel.h" |
| 36 | #include "src/cpu/operators/CpuWinogradConv2d.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 37 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 38 | namespace arm_compute |
| 39 | { |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 40 | using namespace arm_compute::experimental; |
| 41 | |
| 42 | struct NEWinogradConvolutionLayer::Impl |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 43 | { |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 44 | MemoryGroup memory_group{}; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 45 | std::unique_ptr<cpu::CpuWinogradConv2d> op{nullptr}; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 46 | ITensorPack run_pack{}; |
| 47 | ITensorPack prep_pack{}; |
| 48 | WorkspaceData<Tensor> workspace{}; |
| 49 | experimental::MemoryRequirements aux_mem_req{}; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 50 | const ITensor *original_weights{nullptr}; |
| 51 | bool is_prepared{false}; |
| 52 | bool is_activationlayer_enabled{false}; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 53 | DataLayout data_layout{}; |
| 54 | }; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 55 | |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 56 | NEWinogradConvolutionLayer::NEWinogradConvolutionLayer(const std::shared_ptr<IMemoryManager> &memory_manager) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 57 | : _impl(std::make_unique<Impl>()) |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 58 | { |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 59 | _impl->memory_group = MemoryGroup(std::move(memory_manager)); |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 60 | } |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 61 | |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 62 | NEWinogradConvolutionLayer::~NEWinogradConvolutionLayer() = default; |
| 63 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 64 | void NEWinogradConvolutionLayer::configure(const ITensor *input, |
| 65 | const ITensor *weights, |
| 66 | const ITensor *biases, |
| 67 | ITensor *output, |
| 68 | const PadStrideInfo &conv_info, |
| 69 | const ActivationLayerInfo &act_info, |
| 70 | bool enable_fast_math) |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 71 | { |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 72 | _impl->original_weights = weights; |
| 73 | _impl->op = std::make_unique<cpu::CpuWinogradConv2d>(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 74 | _impl->op->configure(input->info(), weights->info(), biases != nullptr ? biases->info() : nullptr, output->info(), |
| 75 | conv_info, act_info, enable_fast_math); |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 76 | |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 77 | _impl->aux_mem_req = _impl->op->workspace(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 78 | _impl->run_pack = {{ACL_SRC_0, input}, {ACL_SRC_1, weights}, {ACL_SRC_2, biases}, {ACL_DST, output}}; |
| 79 | _impl->prep_pack = {{ACL_SRC_1, weights}, {ACL_SRC_2, biases}}; |
| 80 | _impl->workspace = |
| 81 | manage_workspace<Tensor>(_impl->aux_mem_req, _impl->memory_group, _impl->run_pack, _impl->prep_pack); |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Georgios Pinitas | 9fb1159 | 2018-04-26 20:34:58 +0100 | [diff] [blame] | 84 | void NEWinogradConvolutionLayer::run() |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 85 | { |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 86 | prepare(); |
| 87 | |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 88 | MemoryGroupResourceScope scope_mg(_impl->memory_group); |
| 89 | _impl->op->run(_impl->run_pack); |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 90 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 91 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 92 | Status NEWinogradConvolutionLayer::validate(const ITensorInfo *input, |
| 93 | const ITensorInfo *weights, |
| 94 | const ITensorInfo *biases, |
| 95 | const ITensorInfo *output, |
| 96 | const PadStrideInfo &conv_info, |
| 97 | const ActivationLayerInfo &act_info, |
| 98 | bool enable_fast_math) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 99 | { |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 100 | return cpu::CpuWinogradConv2d::validate(input, weights, biases, output, conv_info, act_info, enable_fast_math); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 103 | void NEWinogradConvolutionLayer::prepare() |
| 104 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 105 | if (!_impl->is_prepared) |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 106 | { |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 107 | _impl->op->prepare(_impl->prep_pack); |
| 108 | _impl->original_weights->mark_as_unused(); |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 109 | |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 110 | // Release temporary tensors that are only used in prepare stage |
Michele Di Giorgio | d9cdf14 | 2021-07-02 15:17:08 +0100 | [diff] [blame] | 111 | release_temporaries<Tensor>(_impl->aux_mem_req, _impl->workspace); |
Georgios Pinitas | ddd79f5 | 2021-01-15 09:42:26 +0000 | [diff] [blame] | 112 | |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 113 | _impl->is_prepared = true; |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 114 | } |
| 115 | } |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 116 | } // namespace arm_compute |