Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 1 | /* |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2022 Arm Limited. |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [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 | */ |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 24 | #include "src/cpu/kernels/CpuFloorKernel.h" |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/Coordinates.h" |
| 27 | #include "arm_compute/core/Helpers.h" |
| 28 | #include "arm_compute/core/ITensor.h" |
| 29 | #include "arm_compute/core/Validate.h" |
| 30 | #include "src/core/CPP/Validate.h" |
| 31 | #include "src/core/helpers/AutoConfiguration.h" |
| 32 | #include "src/core/helpers/WindowHelpers.h" |
| 33 | |
| 34 | #include "src/core/common/Registrars.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 35 | #include "src/cpu/kernels/floor/list.h" |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace cpu |
| 40 | { |
| 41 | namespace kernels |
| 42 | { |
| 43 | namespace |
| 44 | { |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 45 | static const std::vector<CpuFloorKernel::FloorKernel> available_kernels = |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 46 | { |
| 47 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 48 | "neon_fp16_floor", |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 49 | [](const DataTypeISASelectorData & data) { return data.dt == DataType::F16 && data.isa.fp16; }, |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 50 | REGISTER_FP16_NEON(arm_compute::cpu::fp16_neon_floor) |
| 51 | }, |
| 52 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 53 | "neon_fp32_floor", |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 54 | [](const DataTypeISASelectorData & data) { return data.dt == DataType::F32; }, |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 55 | REGISTER_FP32_NEON(arm_compute::cpu::fp32_neon_floor) |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 56 | } |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 57 | }; |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 58 | |
| 59 | Status validate_arguments(const ITensorInfo *src, const ITensorInfo *dst) |
| 60 | { |
| 61 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src, dst); |
| 62 | |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 63 | const auto *uk = CpuFloorKernel::get_implementation(DataTypeISASelectorData{ src->data_type(), CPUInfo::get().get_isa() }); |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 64 | ARM_COMPUTE_RETURN_ERROR_ON(uk == nullptr || uk->ukernel == nullptr); |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 65 | |
| 66 | // Validate in case of configured output |
| 67 | if(dst->total_size() > 0) |
| 68 | { |
| 69 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, dst); |
| 70 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(src, dst); |
| 71 | } |
| 72 | |
| 73 | return Status{}; |
| 74 | } |
| 75 | } // namespace |
| 76 | |
| 77 | void CpuFloorKernel::configure(const ITensorInfo *src, ITensorInfo *dst) |
| 78 | { |
| 79 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst); |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 80 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst)); |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 81 | |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 82 | auto_init_if_empty(*dst, src->tensor_shape(), 1, src->data_type()); |
| 83 | |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 84 | const auto *uk = CpuFloorKernel::get_implementation(DataTypeISASelectorData{ src->data_type(), CPUInfo::get().get_isa() }); |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 85 | ARM_COMPUTE_ERROR_ON_NULLPTR(uk); |
| 86 | |
| 87 | _run_method = uk->ukernel; |
| 88 | _name = std::string("CpuFloorKernel").append("/").append(uk->name); |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 89 | |
| 90 | // Configure kernel window |
| 91 | const Window win = calculate_max_window(*src, Steps()); |
| 92 | |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 93 | ICPPKernel::configure(win); |
| 94 | } |
| 95 | |
| 96 | Window CpuFloorKernel::infer_window(const ITensorInfo *src, const ITensorInfo *dst) |
| 97 | { |
| 98 | ARM_COMPUTE_UNUSED(dst); |
| 99 | ARM_COMPUTE_ERROR_ON(!bool(validate_arguments(src, dst))); |
| 100 | |
| 101 | Window win; |
| 102 | win.use_tensor_dimensions(src->tensor_shape()); |
| 103 | return win; |
| 104 | } |
| 105 | |
| 106 | Status CpuFloorKernel::validate(const ITensorInfo *input, const ITensorInfo *output) |
| 107 | { |
| 108 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output)); |
| 109 | return Status{}; |
| 110 | } |
| 111 | |
| 112 | void CpuFloorKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) |
| 113 | { |
| 114 | ARM_COMPUTE_UNUSED(info); |
| 115 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 116 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 117 | |
| 118 | ARM_COMPUTE_ERROR_ON(tensors.empty()); |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 119 | ARM_COMPUTE_ERROR_ON(_run_method == nullptr); |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 120 | |
| 121 | const ITensor *src = tensors.get_const_tensor(TensorType::ACL_SRC); |
| 122 | ITensor *dst = tensors.get_tensor(TensorType::ACL_DST); |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 123 | const auto len = static_cast<int>(window.x().end()) - static_cast<int>(window.x().start()); |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 124 | |
| 125 | Window win{ window }; |
| 126 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 127 | |
| 128 | Iterator src_it(src, win); |
| 129 | Iterator dst_it(dst, win); |
| 130 | |
| 131 | execute_window_loop(win, [&](const Coordinates &) |
| 132 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 133 | _run_method(src_it.ptr(), dst_it.ptr(), len); |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 134 | }, |
| 135 | src_it, dst_it); |
| 136 | } |
| 137 | |
| 138 | const char *CpuFloorKernel::name() const |
| 139 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 140 | return _name.c_str(); |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 141 | } |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 142 | |
| 143 | const std::vector<CpuFloorKernel::FloorKernel> &CpuFloorKernel::get_available_kernels() |
| 144 | { |
| 145 | return available_kernels; |
| 146 | } |
| 147 | |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 148 | } // namespace kernels |
| 149 | } // namespace cpu |
| 150 | } // namespace arm_compute |