Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 Arm Limited. |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +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/core/NEON/kernels/NEFloorKernel.h" |
| 25 | |
| 26 | #include "arm_compute/core/Coordinates.h" |
| 27 | #include "arm_compute/core/Helpers.h" |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/ITensor.h" |
| 29 | #include "arm_compute/core/NEON/INEKernel.h" |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/Validate.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame^] | 31 | #include "src/core/CPP/Validate.h" |
| 32 | #include "src/core/helpers/AutoConfiguration.h" |
| 33 | #include "src/core/helpers/WindowHelpers.h" |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 34 | |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 35 | #include "src/core/NEON/kernels/floor/impl/list.h" |
| 36 | #include "src/core/common/Registrars.h" |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 37 | |
Georgios Pinitas | 565bf2d | 2018-08-31 11:46:49 +0100 | [diff] [blame] | 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace |
| 41 | { |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 42 | struct FloorSelectorData |
| 43 | { |
| 44 | DataType dt; |
| 45 | }; |
| 46 | using FloorSelectorPtr = std::add_pointer<bool(const FloorSelectorData &data)>::type; |
| 47 | using FloorUKernelPtr = std::add_pointer<void(const void *, void *, int)>::type; |
| 48 | |
| 49 | struct FloorKernel |
| 50 | { |
| 51 | const char *name; |
| 52 | const FloorSelectorPtr is_selected; |
| 53 | FloorUKernelPtr ukernel; |
| 54 | }; |
| 55 | |
| 56 | static const FloorKernel available_kernels[] = |
| 57 | { |
| 58 | { |
| 59 | "fp16_neon_floor", |
| 60 | [](const FloorSelectorData & data) { return data.dt == DataType::F16; }, |
| 61 | REGISTER_FP16_NEON(arm_compute::cpu::fp16_neon_floor) |
| 62 | }, |
| 63 | { |
| 64 | "f32_neon_floor", |
| 65 | [](const FloorSelectorData & data) { return data.dt == DataType::F32; }, |
| 66 | REGISTER_FP32_NEON(arm_compute::cpu::fp32_neon_floor) |
| 67 | }, |
| 68 | }; |
| 69 | |
| 70 | const FloorKernel *get_implementation(const FloorSelectorData &data) |
| 71 | { |
| 72 | for(const auto &uk : available_kernels) |
| 73 | { |
| 74 | if(uk.is_selected(data)) |
| 75 | { |
| 76 | return &uk; |
| 77 | } |
| 78 | } |
| 79 | return nullptr; |
| 80 | } |
| 81 | |
Georgios Pinitas | 565bf2d | 2018-08-31 11:46:49 +0100 | [diff] [blame] | 82 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output) |
| 83 | { |
| 84 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 85 | |
| 86 | const auto *uk = get_implementation(FloorSelectorData{ input->data_type() }); |
| 87 | ARM_COMPUTE_RETURN_ERROR_ON(uk == nullptr || uk->ukernel == nullptr); |
Georgios Pinitas | 565bf2d | 2018-08-31 11:46:49 +0100 | [diff] [blame] | 88 | |
| 89 | // Validate in case of configured output |
| 90 | if(output->total_size() > 0) |
| 91 | { |
| 92 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 93 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output); |
| 94 | } |
| 95 | |
| 96 | return Status{}; |
| 97 | } |
Georgios Pinitas | 565bf2d | 2018-08-31 11:46:49 +0100 | [diff] [blame] | 98 | } // namespace |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 99 | |
| 100 | void NEFloorKernel::configure(const ITensor *input, ITensor *output) |
| 101 | { |
| 102 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
| 103 | |
Michalis Spyrou | a4a9601 | 2017-10-09 15:46:30 +0100 | [diff] [blame] | 104 | // Auto initialize output |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 105 | auto_init_if_empty(*output->info(), input->info()->tensor_shape(), 1, input->info()->data_type()); |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 106 | |
Georgios Pinitas | 565bf2d | 2018-08-31 11:46:49 +0100 | [diff] [blame] | 107 | // Validate |
| 108 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info())); |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 109 | |
| 110 | _input = input; |
| 111 | _output = output; |
| 112 | |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 113 | // Configure kernel window |
Michalis Spyrou | ca8c0f7 | 2020-02-20 15:21:21 +0000 | [diff] [blame] | 114 | Window win = calculate_max_window(*input->info(), Steps()); |
| 115 | |
| 116 | Coordinates coord; |
| 117 | coord.set_num_dimensions(output->info()->num_dimensions()); |
| 118 | output->info()->set_valid_region(ValidRegion(coord, output->info()->tensor_shape())); |
| 119 | |
| 120 | INEKernel::configure(win); |
Georgios Pinitas | 565bf2d | 2018-08-31 11:46:49 +0100 | [diff] [blame] | 121 | } |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 122 | |
Georgios Pinitas | 565bf2d | 2018-08-31 11:46:49 +0100 | [diff] [blame] | 123 | Status NEFloorKernel::validate(const ITensorInfo *input, const ITensorInfo *output) |
| 124 | { |
| 125 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output)); |
Georgios Pinitas | 565bf2d | 2018-08-31 11:46:49 +0100 | [diff] [blame] | 126 | return Status{}; |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 129 | void NEFloorKernel::run(const Window &window, const ThreadInfo &info) |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 130 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 131 | ARM_COMPUTE_UNUSED(info); |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 132 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 133 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 134 | |
Michalis Spyrou | ca8c0f7 | 2020-02-20 15:21:21 +0000 | [diff] [blame] | 135 | Window win{ window }; |
| 136 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 137 | |
| 138 | const auto len = static_cast<int>(window.x().end()) - static_cast<int>(window.x().start()); |
| 139 | const auto *uk = get_implementation(FloorSelectorData{ _input->info()->data_type() }); |
| 140 | |
Michalis Spyrou | ca8c0f7 | 2020-02-20 15:21:21 +0000 | [diff] [blame] | 141 | Iterator input(_input, win); |
| 142 | Iterator output(_output, win); |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 143 | |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 144 | execute_window_loop(win, [&](const Coordinates &) |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 145 | { |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 146 | uk->ukernel(input.ptr(), output.ptr(), len); |
| 147 | }, |
| 148 | input, output); |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 149 | } |
Georgios Pinitas | 565bf2d | 2018-08-31 11:46:49 +0100 | [diff] [blame] | 150 | } // namespace arm_compute |