Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 29 | using namespace arm_compute; |
| 30 | |
| 31 | namespace |
| 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 | */ |
| 39 | size_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 | } |
| 49 | BorderMode 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 | |
| 61 | NEReductionOperation::NEReductionOperation() |
| 62 | : _reduction_kernel(), _fill_border_kernel(), _window_split(0) |
| 63 | { |
| 64 | } |
| 65 | |
| 66 | void 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); |
| 77 | _fill_border_kernel.configure(input, fill_border_size, fill_border_mode, PixelValue(0)); |
| 78 | } |
| 79 | |
| 80 | void NEReductionOperation::run() |
| 81 | { |
| 82 | NEScheduler::get().schedule(&_fill_border_kernel, Window::DimY); |
| 83 | NEScheduler::get().schedule(&_reduction_kernel, _window_split); |
| 84 | } |