Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +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/core/NEON/kernels/NEFloorKernel.h" |
| 25 | |
| 26 | #include "arm_compute/core/Coordinates.h" |
| 27 | #include "arm_compute/core/Helpers.h" |
| 28 | #include "arm_compute/core/IAccessWindow.h" |
| 29 | #include "arm_compute/core/ITensor.h" |
| 30 | #include "arm_compute/core/NEON/INEKernel.h" |
| 31 | #include "arm_compute/core/NEON/NEMath.h" |
| 32 | #include "arm_compute/core/Validate.h" |
| 33 | |
| 34 | #include <arm_neon.h> |
| 35 | |
| 36 | using namespace arm_compute; |
| 37 | |
| 38 | void NEFloorKernel::configure(const ITensor *input, ITensor *output) |
| 39 | { |
| 40 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
| 41 | |
Michalis Spyrou | a4a9601 | 2017-10-09 15:46:30 +0100 | [diff] [blame] | 42 | // Auto initialize output |
| 43 | auto_init_if_empty(*output->info(), input->info()->tensor_shape(), 1, input->info()->data_type(), input->info()->fixed_point_position()); |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 44 | |
| 45 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32); |
| 46 | ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(input, output); |
| 47 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 48 | |
| 49 | _input = input; |
| 50 | _output = output; |
| 51 | |
| 52 | constexpr unsigned int num_elems_processed_per_iteration = 4; |
| 53 | |
| 54 | // Configure kernel window |
| 55 | Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration)); |
| 56 | AccessWindowHorizontal input_access(input->info(), 0, num_elems_processed_per_iteration); |
| 57 | AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration); |
| 58 | |
| 59 | update_window_and_padding(win, input_access, output_access); |
| 60 | output_access.set_valid_region(win, input->info()->valid_region()); |
| 61 | |
| 62 | INEKernel::configure(win); |
| 63 | } |
| 64 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 65 | void NEFloorKernel::run(const Window &window, const ThreadInfo &info) |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 66 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 67 | ARM_COMPUTE_UNUSED(info); |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 68 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 69 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 70 | |
| 71 | Iterator input(_input, window); |
| 72 | Iterator output(_output, window); |
| 73 | |
| 74 | execute_window_loop(window, [&](const Coordinates & id) |
| 75 | { |
| 76 | const float32x4_t res = vfloorq_f32(vld1q_f32(reinterpret_cast<const float *>(input.ptr()))); |
| 77 | vst1q_f32(reinterpret_cast<float *>(output.ptr()), res); |
| 78 | }, |
| 79 | input, output); |
| 80 | } |