Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [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/NEPoolingLayer.h" |
| 25 | |
Michele Di Giorgio | 0c19cbd | 2021-05-11 17:41:32 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/TensorInfo.h" |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/Validate.h" |
Michele Di Giorgio | 0c19cbd | 2021-05-11 17:41:32 +0100 | [diff] [blame] | 28 | #include "arm_compute/runtime/Tensor.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 29 | |
Manuel Bottini | 94f799e | 2021-06-09 16:37:32 +0100 | [diff] [blame] | 30 | #include "src/core/helpers/MemoryHelpers.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 31 | #include "src/cpu/operators/CpuPool2d.h" |
Gian Marco Iodice | 1682430 | 2017-09-28 15:41:37 +0100 | [diff] [blame] | 32 | |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 33 | namespace arm_compute |
| 34 | { |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 35 | struct NEPoolingLayer::Impl |
| 36 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 37 | ITensor *src{nullptr}; |
| 38 | ITensor *dst{nullptr}; |
| 39 | ITensor *indices{nullptr}; |
| 40 | std::unique_ptr<cpu::CpuPool2d> op{nullptr}; |
Manuel Bottini | 94f799e | 2021-06-09 16:37:32 +0100 | [diff] [blame] | 41 | MemoryGroup memory_group{}; |
| 42 | ITensorPack run_pack{}; |
| 43 | WorkspaceData<Tensor> workspace_tensors{}; |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 46 | NEPoolingLayer::~NEPoolingLayer() = default; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 47 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 48 | NEPoolingLayer::NEPoolingLayer(std::shared_ptr<IMemoryManager> memory_manager) : _impl(std::make_unique<Impl>()) |
Gian Marco Iodice | 1682430 | 2017-09-28 15:41:37 +0100 | [diff] [blame] | 49 | { |
Manuel Bottini | 94f799e | 2021-06-09 16:37:32 +0100 | [diff] [blame] | 50 | _impl->memory_group = MemoryGroup(std::move(memory_manager)); |
Gian Marco Iodice | 1682430 | 2017-09-28 15:41:37 +0100 | [diff] [blame] | 51 | } |
| 52 | |
morgolock | cc1f6c9 | 2020-03-24 09:26:48 +0000 | [diff] [blame] | 53 | void NEPoolingLayer::configure(ITensor *input, ITensor *output, const PoolingLayerInfo &pool_info, ITensor *indices) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 54 | { |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 55 | _impl->src = input; |
| 56 | _impl->dst = output; |
| 57 | _impl->indices = indices; |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 58 | _impl->op = std::make_unique<cpu::CpuPool2d>(); |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 59 | _impl->op->configure(input->info(), output->info(), pool_info, (indices) ? indices->info() : nullptr); |
Michele Di Giorgio | 0c19cbd | 2021-05-11 17:41:32 +0100 | [diff] [blame] | 60 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 61 | _impl->run_pack = {{TensorType::ACL_SRC, _impl->src}, |
| 62 | {TensorType::ACL_DST_0, _impl->dst}, |
| 63 | {TensorType::ACL_DST_1, _impl->indices}}; |
Manuel Bottini | 94f799e | 2021-06-09 16:37:32 +0100 | [diff] [blame] | 64 | _impl->workspace_tensors = manage_workspace<Tensor>(_impl->op->workspace(), _impl->memory_group, _impl->run_pack); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 65 | } |
Gian Marco Iodice | 1682430 | 2017-09-28 15:41:37 +0100 | [diff] [blame] | 66 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 67 | Status NEPoolingLayer::validate(const ITensorInfo *input, |
| 68 | const ITensorInfo *output, |
| 69 | const PoolingLayerInfo &pool_info, |
| 70 | const ITensorInfo *indices) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 71 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 72 | return cpu::CpuPool2d::validate(input, output, pool_info, indices); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Gian Marco Iodice | 1682430 | 2017-09-28 15:41:37 +0100 | [diff] [blame] | 75 | void NEPoolingLayer::run() |
| 76 | { |
Manuel Bottini | 94f799e | 2021-06-09 16:37:32 +0100 | [diff] [blame] | 77 | MemoryGroupResourceScope scope_mg(_impl->memory_group); |
| 78 | ARM_COMPUTE_ERROR_ON_NULLPTR(_impl->src, _impl->dst); |
| 79 | _impl->op->run(_impl->run_pack); |
Sang-Hoon Park | 0cb3da6 | 2020-01-15 12:39:56 +0000 | [diff] [blame] | 80 | } |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 81 | } // namespace arm_compute |