blob: a0aed96521342fd853fde62a6a917562f68aa033 [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{
giuros01154bc1c2019-03-26 17:44:40 +000069 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
70 ARM_COMPUTE_ERROR_THROW_ON(NEReductionOperation::validate(input->info(), output->info(), axis, op));
Georgios Pinitasd9769582017-08-03 10:19:40 +010071
72 // Configure reduction kernel
73 _reduction_kernel.configure(input, output, axis, op);
Michalis Spyroubcf8a962018-10-12 10:51:31 +010074 _window_split = reduction_window_split_dimension(axis);
75 _reduction_axis = axis;
Georgios Pinitasd9769582017-08-03 10:19:40 +010076
Michalis Spyroubcf8a962018-10-12 10:51:31 +010077 if(axis == 0)
78 {
79 // Configure fill border kernel
Manuel Bottini1d4f3852019-01-14 15:14:43 +000080 const BorderSize fill_border_size = _reduction_kernel.border_size();
Georgios Pinitas804aafb2019-02-21 14:29:02 +000081 const PixelValue pixelValue = (op == ReductionOperation::PROD) ? PixelValue(1, input->info()->data_type(), input->info()->quantization_info()) : PixelValue(0, input->info()->data_type());
Manuel Bottini1d4f3852019-01-14 15:14:43 +000082 _fill_border_kernel.configure(input, fill_border_size, BorderMode::CONSTANT, pixelValue);
Michalis Spyroubcf8a962018-10-12 10:51:31 +010083 }
Georgios Pinitasd9769582017-08-03 10:19:40 +010084}
85
86void NEReductionOperation::run()
87{
Michalis Spyroubcf8a962018-10-12 10:51:31 +010088 if(_reduction_axis == 0)
89 {
90 NEScheduler::get().schedule(&_fill_border_kernel, Window::DimY);
91 }
Georgios Pinitasd9769582017-08-03 10:19:40 +010092 NEScheduler::get().schedule(&_reduction_kernel, _window_split);
93}
Michalis Spyroubcf8a962018-10-12 10:51:31 +010094} // namespace arm_compute