blob: f1a9145f7445630e637ec62c26165198f8fd63fa [file] [log] [blame]
Georgios Pinitasd9769582017-08-03 10:19:40 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
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
29using namespace arm_compute;
30
31namespace
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;
45 default:
46 ARM_COMPUTE_ERROR("Unsupported reduction axis");
47 }
48}
49BorderMode reduction_operation_border_mode(ReductionOperation op)
50{
51 switch(op)
52 {
53 case ReductionOperation::SUM_SQUARE:
54 return BorderMode::CONSTANT;
55 default:
56 return BorderMode::CONSTANT;
57 }
58}
59} // namespace
60
61NEReductionOperation::NEReductionOperation()
62 : _reduction_kernel(), _fill_border_kernel(), _window_split(0)
63{
64}
65
66void NEReductionOperation::configure(ITensor *input, ITensor *output, unsigned int axis, ReductionOperation op)
67{
68 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32);
69
70 // Configure reduction kernel
71 _reduction_kernel.configure(input, output, axis, op);
72 _window_split = reduction_window_split_dimension(axis);
73
74 // Configure fill border kernel
75 BorderSize fill_border_size = (axis == 0) ? _reduction_kernel.border_size() : BorderSize();
76 BorderMode fill_border_mode = reduction_operation_border_mode(op);
Michalis Spyrou490bf2e2017-09-29 11:24:55 +010077 _fill_border_kernel.configure(input, fill_border_size, fill_border_mode, PixelValue(static_cast<float>(0.f)));
Georgios Pinitasd9769582017-08-03 10:19:40 +010078}
79
80void NEReductionOperation::run()
81{
82 NEScheduler::get().schedule(&_fill_border_kernel, Window::DimY);
83 NEScheduler::get().schedule(&_reduction_kernel, _window_split);
84}