Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 1 | /* |
Manuel Bottini | 1d4f385 | 2019-01-14 15:14:43 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 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 | |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 29 | namespace arm_compute |
| 30 | { |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 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; |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 45 | case 1: |
| 46 | case 2: |
| 47 | case 3: |
| 48 | return Window::DimX; |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 49 | default: |
| 50 | ARM_COMPUTE_ERROR("Unsupported reduction axis"); |
| 51 | } |
| 52 | } |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 53 | } // namespace |
| 54 | |
| 55 | NEReductionOperation::NEReductionOperation() |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 56 | : _reduction_kernel(), _fill_border_kernel(), _window_split(0), _reduction_axis() |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 57 | { |
| 58 | } |
| 59 | |
John Richardson | 73d4aef | 2018-05-08 14:34:33 +0100 | [diff] [blame] | 60 | Status 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 Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 67 | void NEReductionOperation::configure(ITensor *input, ITensor *output, unsigned int axis, ReductionOperation op) |
| 68 | { |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 69 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F16, DataType::F32); |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 70 | |
| 71 | // Configure reduction kernel |
| 72 | _reduction_kernel.configure(input, output, axis, op); |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 73 | _window_split = reduction_window_split_dimension(axis); |
| 74 | _reduction_axis = axis; |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 75 | |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 76 | if(axis == 0) |
| 77 | { |
| 78 | // Configure fill border kernel |
Manuel Bottini | 1d4f385 | 2019-01-14 15:14:43 +0000 | [diff] [blame^] | 79 | 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 Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 82 | } |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void NEReductionOperation::run() |
| 86 | { |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 87 | if(_reduction_axis == 0) |
| 88 | { |
| 89 | NEScheduler::get().schedule(&_fill_border_kernel, Window::DimY); |
| 90 | } |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 91 | NEScheduler::get().schedule(&_reduction_kernel, _window_split); |
| 92 | } |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 93 | } // namespace arm_compute |