blob: bb27b5d47ae919abf6e2f16fa3be3269e1d8f895 [file] [log] [blame]
Georgios Pinitasd9769582017-08-03 10:19:40 +01001/*
John Richardson73d4aef2018-05-08 14:34:33 +01002 * Copyright (c) 2017-2018 ARM Limited.
Georgios Pinitasd9769582017-08-03 10:19:40 +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/NEReductionOperation.h"
25
26#include "arm_compute/core/Helpers.h"
27#include "arm_compute/runtime/NEON/NEScheduler.h"
28
Michalis Spyroubcf8a962018-10-12 10:51:31 +010029namespace arm_compute
30{
Georgios Pinitasd9769582017-08-03 10:19:40 +010031namespace
32{
33/** Define dimension to split the window
34 *
35 * @param[in] axis Reduction axis
36 *
37 * @return The dimension to split the window
38 */
39size_t reduction_window_split_dimension(unsigned int axis)
40{
41 switch(axis)
42 {
43 case 0:
44 return Window::DimY;
Michalis Spyroubcf8a962018-10-12 10:51:31 +010045 case 1:
46 case 2:
47 case 3:
48 return Window::DimX;
Georgios Pinitasd9769582017-08-03 10:19:40 +010049 default:
50 ARM_COMPUTE_ERROR("Unsupported reduction axis");
51 }
52}
53BorderMode reduction_operation_border_mode(ReductionOperation op)
54{
55 switch(op)
56 {
57 case ReductionOperation::SUM_SQUARE:
58 return BorderMode::CONSTANT;
59 default:
60 return BorderMode::CONSTANT;
61 }
62}
63} // namespace
64
65NEReductionOperation::NEReductionOperation()
Michalis Spyroubcf8a962018-10-12 10:51:31 +010066 : _reduction_kernel(), _fill_border_kernel(), _window_split(0), _reduction_axis()
Georgios Pinitasd9769582017-08-03 10:19:40 +010067{
68}
69
John Richardson73d4aef2018-05-08 14:34:33 +010070Status NEReductionOperation::validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op)
71{
72 ARM_COMPUTE_RETURN_ON_ERROR(NEReductionOperationKernel::validate(input, output, axis, op));
73
74 return Status{};
75}
76
Georgios Pinitasd9769582017-08-03 10:19:40 +010077void NEReductionOperation::configure(ITensor *input, ITensor *output, unsigned int axis, ReductionOperation op)
78{
Michalis Spyroubcf8a962018-10-12 10:51:31 +010079 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F16, DataType::F32);
Georgios Pinitasd9769582017-08-03 10:19:40 +010080
81 // Configure reduction kernel
82 _reduction_kernel.configure(input, output, axis, op);
Michalis Spyroubcf8a962018-10-12 10:51:31 +010083 _window_split = reduction_window_split_dimension(axis);
84 _reduction_axis = axis;
Georgios Pinitasd9769582017-08-03 10:19:40 +010085
Michalis Spyroubcf8a962018-10-12 10:51:31 +010086 if(axis == 0)
87 {
88 // Configure fill border kernel
Michalis Spyrou2897e612018-11-20 18:38:29 +000089 BorderSize fill_border_size = _reduction_kernel.border_size();
Michalis Spyroubcf8a962018-10-12 10:51:31 +010090 BorderMode fill_border_mode = reduction_operation_border_mode(op);
91 _fill_border_kernel.configure(input, fill_border_size, fill_border_mode, PixelValue(static_cast<float>(0.f)));
92 }
Georgios Pinitasd9769582017-08-03 10:19:40 +010093}
94
95void NEReductionOperation::run()
96{
Michalis Spyroubcf8a962018-10-12 10:51:31 +010097 if(_reduction_axis == 0)
98 {
99 NEScheduler::get().schedule(&_fill_border_kernel, Window::DimY);
100 }
Georgios Pinitasd9769582017-08-03 10:19:40 +0100101 NEScheduler::get().schedule(&_reduction_kernel, _window_split);
102}
Michalis Spyroubcf8a962018-10-12 10:51:31 +0100103} // namespace arm_compute