blob: 3ec8ef145ee75b20b748b8f1080be4a43548cdd7 [file] [log] [blame]
Georgios Pinitasd9769582017-08-03 10:19:40 +01001/*
Manuel Bottini1d4f3852019-01-14 15:14:43 +00002 * Copyright (c) 2017-2019 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}
Georgios Pinitasd9769582017-08-03 10:19:40 +010053} // namespace
54
55NEReductionOperation::NEReductionOperation()
Michalis Spyroubcf8a962018-10-12 10:51:31 +010056 : _reduction_kernel(), _fill_border_kernel(), _window_split(0), _reduction_axis()
Georgios Pinitasd9769582017-08-03 10:19:40 +010057{
58}
59
John Richardson73d4aef2018-05-08 14:34:33 +010060Status NEReductionOperation::validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op)
61{
62 ARM_COMPUTE_RETURN_ON_ERROR(NEReductionOperationKernel::validate(input, output, axis, op));
63
64 return Status{};
65}
66
Georgios Pinitasd9769582017-08-03 10:19:40 +010067void NEReductionOperation::configure(ITensor *input, ITensor *output, unsigned int axis, ReductionOperation op)
68{
Michalis Spyroubcf8a962018-10-12 10:51:31 +010069 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F16, DataType::F32);
Georgios Pinitasd9769582017-08-03 10:19:40 +010070
71 // Configure reduction kernel
72 _reduction_kernel.configure(input, output, axis, op);
Michalis Spyroubcf8a962018-10-12 10:51:31 +010073 _window_split = reduction_window_split_dimension(axis);
74 _reduction_axis = axis;
Georgios Pinitasd9769582017-08-03 10:19:40 +010075
Michalis Spyroubcf8a962018-10-12 10:51:31 +010076 if(axis == 0)
77 {
78 // Configure fill border kernel
Manuel Bottini1d4f3852019-01-14 15:14:43 +000079 const BorderSize fill_border_size = _reduction_kernel.border_size();
80 const PixelValue pixelValue = PixelValue((op == ReductionOperation::PROD) ? 1 : 0, input->info()->data_type(), input->info()->quantization_info());
81 _fill_border_kernel.configure(input, fill_border_size, BorderMode::CONSTANT, pixelValue);
Michalis Spyroubcf8a962018-10-12 10:51:31 +010082 }
Georgios Pinitasd9769582017-08-03 10:19:40 +010083}
84
85void NEReductionOperation::run()
86{
Michalis Spyroubcf8a962018-10-12 10:51:31 +010087 if(_reduction_axis == 0)
88 {
89 NEScheduler::get().schedule(&_fill_border_kernel, Window::DimY);
90 }
Georgios Pinitasd9769582017-08-03 10:19:40 +010091 NEScheduler::get().schedule(&_reduction_kernel, _window_split);
92}
Michalis Spyroubcf8a962018-10-12 10:51:31 +010093} // namespace arm_compute