blob: 5a3b9c5e7edee8d17ca764301f075139f06dcf04 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +00002 * Copyright (c) 2017-2021 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 Giorgio0c19cbd2021-05-11 17:41:32 +010026#include "arm_compute/core/TensorInfo.h"
Michele Di Giorgio19289042021-02-03 16:05:00 +000027#include "arm_compute/core/Validate.h"
Michele Di Giorgio0c19cbd2021-05-11 17:41:32 +010028#include "arm_compute/runtime/Tensor.h"
Manuel Bottini94f799e2021-06-09 16:37:32 +010029#include "src/core/helpers/MemoryHelpers.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010030#include "src/cpu/operators/CpuPool2d.h"
Gian Marco Iodice16824302017-09-28 15:41:37 +010031
Michalis Spyrouebcebf12020-10-21 00:04:14 +010032namespace arm_compute
33{
Michele Di Giorgio19289042021-02-03 16:05:00 +000034struct NEPoolingLayer::Impl
35{
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010036 ITensor *src{ nullptr };
37 ITensor *dst{ nullptr };
38 ITensor *indices{ nullptr };
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010039 std::unique_ptr<cpu::CpuPool2d> op{ nullptr };
Manuel Bottini94f799e2021-06-09 16:37:32 +010040 MemoryGroup memory_group{};
41 ITensorPack run_pack{};
42 WorkspaceData<Tensor> workspace_tensors{};
Michele Di Giorgio19289042021-02-03 16:05:00 +000043};
44
Michalis Spyrouebcebf12020-10-21 00:04:14 +010045NEPoolingLayer::~NEPoolingLayer() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000047NEPoolingLayer::NEPoolingLayer(std::shared_ptr<IMemoryManager> memory_manager)
Manuel Bottini94f799e2021-06-09 16:37:32 +010048 : _impl(std::make_unique<Impl>())
Gian Marco Iodice16824302017-09-28 15:41:37 +010049{
Manuel Bottini94f799e2021-06-09 16:37:32 +010050 _impl->memory_group = MemoryGroup(std::move(memory_manager));
Gian Marco Iodice16824302017-09-28 15:41:37 +010051}
52
morgolockcc1f6c92020-03-24 09:26:48 +000053void NEPoolingLayer::configure(ITensor *input, ITensor *output, const PoolingLayerInfo &pool_info, ITensor *indices)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010054{
Michele Di Giorgio19289042021-02-03 16:05:00 +000055 _impl->src = input;
56 _impl->dst = output;
57 _impl->indices = indices;
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010058 _impl->op = std::make_unique<cpu::CpuPool2d>();
Michele Di Giorgio19289042021-02-03 16:05:00 +000059 _impl->op->configure(input->info(), output->info(), pool_info, (indices) ? indices->info() : nullptr);
Michele Di Giorgio0c19cbd2021-05-11 17:41:32 +010060
Manuel Bottini94f799e2021-06-09 16:37:32 +010061 _impl->run_pack = { { TensorType::ACL_SRC, _impl->src }, { TensorType::ACL_DST_0, _impl->dst }, { TensorType::ACL_DST_1, _impl->indices } };
62 _impl->workspace_tensors = manage_workspace<Tensor>(_impl->op->workspace(), _impl->memory_group, _impl->run_pack);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063}
Gian Marco Iodice16824302017-09-28 15:41:37 +010064
morgolockcc1f6c92020-03-24 09:26:48 +000065Status NEPoolingLayer::validate(const ITensorInfo *input, const ITensorInfo *output, const PoolingLayerInfo &pool_info, const ITensorInfo *indices)
Michalis Spyrouafa5d812017-11-30 14:25:57 +000066{
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010067 return cpu::CpuPool2d::validate(input, output, pool_info, indices);
Michalis Spyrouafa5d812017-11-30 14:25:57 +000068}
69
Gian Marco Iodice16824302017-09-28 15:41:37 +010070void NEPoolingLayer::run()
71{
Manuel Bottini94f799e2021-06-09 16:37:32 +010072 MemoryGroupResourceScope scope_mg(_impl->memory_group);
73 ARM_COMPUTE_ERROR_ON_NULLPTR(_impl->src, _impl->dst);
74 _impl->op->run(_impl->run_pack);
Sang-Hoon Park0cb3da62020-01-15 12:39:56 +000075}
Michalis Spyrouebcebf12020-10-21 00:04:14 +010076} // namespace arm_compute