blob: cbfd68485f5bf22ed828fff282177c23ac3d8253 [file] [log] [blame]
Anthony Barbier871448e2017-03-24 14:54:29 +00001/*
Anthony Barbierf45d5a92018-01-24 16:23:15 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier871448e2017-03-24 14:54:29 +00003 *
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
Kaizenbf8b01d2017-10-12 14:26:51 +010026#include "arm_compute/core/ITensor.h"
27#include "arm_compute/runtime/NEON/NEScheduler.h"
28
Kaizen8938bd32017-09-28 14:38:23 +010029#include "support/ToolchainSupport.h"
Anthony Barbier871448e2017-03-24 14:54:29 +000030
31using namespace arm_compute;
32
Kaizenbf8b01d2017-10-12 14:26:51 +010033NEPoolingLayer::NEPoolingLayer()
Jenkinsb3a371b2018-05-23 11:36:53 +010034 : _pooling_layer_kernel(), _border_handler(), _is_global_pooling_layer(false), _data_layout(DataLayout::NCHW)
Kaizenbf8b01d2017-10-12 14:26:51 +010035{
36}
37
Anthony Barbier871448e2017-03-24 14:54:29 +000038void NEPoolingLayer::configure(ITensor *input, ITensor *output, const PoolingLayerInfo &pool_info)
39{
Kaizenbf8b01d2017-10-12 14:26:51 +010040 // Check if we have Global Pooling Layer
Anthony Barbier06ea0482018-02-22 15:45:35 +000041 _is_global_pooling_layer = (input->info()->dimension(0) == pool_info.pool_size().width) && (input->info()->dimension(1) == pool_info.pool_size().height);
Kaizenbf8b01d2017-10-12 14:26:51 +010042
Jenkinsb3a371b2018-05-23 11:36:53 +010043 // Get data layout
44 _data_layout = input->info()->data_layout();
45
Anthony Barbier871448e2017-03-24 14:54:29 +000046 // Configure pooling kernel
Kaizenbf8b01d2017-10-12 14:26:51 +010047 _pooling_layer_kernel.configure(input, output, pool_info);
Anthony Barbier871448e2017-03-24 14:54:29 +000048
Jenkinsb3a371b2018-05-23 11:36:53 +010049 switch(_data_layout)
Anthony Barbierf45d5a92018-01-24 16:23:15 +000050 {
Jenkinsb3a371b2018-05-23 11:36:53 +010051 case DataLayout::NCHW:
52 {
53 // Configure border depending on operation required (quantize border in case of asymmetric data_type)
54 BorderMode border_mode = (pool_info.pool_type() == PoolingType::MAX) ? BorderMode::REPLICATE : BorderMode::CONSTANT;
55 PixelValue zero_value(0.f);
56 if(is_data_type_quantized_asymmetric(input->info()->data_type()) && !pool_info.exclude_padding())
57 {
58 zero_value = PixelValue(static_cast<uint32_t>(input->info()->quantization_info().offset));
59 }
60 _border_handler.configure(input, _pooling_layer_kernel.border_size(), border_mode, zero_value);
61 break;
62 }
63 case DataLayout::NHWC:
64 break;
65 default:
66 ARM_COMPUTE_ERROR("Data layout not supported");
Anthony Barbierf45d5a92018-01-24 16:23:15 +000067 }
Anthony Barbier871448e2017-03-24 14:54:29 +000068}
Kaizenbf8b01d2017-10-12 14:26:51 +010069
Anthony Barbier8140e1e2017-12-14 23:48:46 +000070Status NEPoolingLayer::validate(const ITensorInfo *input, const ITensorInfo *output, const PoolingLayerInfo &pool_info)
71{
72 return NEPoolingLayerKernel::validate(input, output, pool_info);
73}
74
Kaizenbf8b01d2017-10-12 14:26:51 +010075void NEPoolingLayer::run()
76{
Jenkinsb3a371b2018-05-23 11:36:53 +010077 switch(_data_layout)
78 {
79 case DataLayout::NCHW:
80 // Fill border
81 NEScheduler::get().schedule(&_border_handler, Window::DimY);
Kaizenbf8b01d2017-10-12 14:26:51 +010082
Jenkinsb3a371b2018-05-23 11:36:53 +010083 // Run pooling layer
84 NEScheduler::get().schedule(&_pooling_layer_kernel, _is_global_pooling_layer ? Window::DimZ : Window::DimY);
85 break;
86 case DataLayout::NHWC:
87 // Run pooling layer
88 NEScheduler::get().schedule(&_pooling_layer_kernel, Window::DimX);
89 break;
90 default:
91 ARM_COMPUTE_ERROR("Data layout not supported");
92 }
Kaizenbf8b01d2017-10-12 14:26:51 +010093}