blob: df7e6aad46538aa97dca8f0738feff1e45ad1eed [file] [log] [blame]
Georgios Pinitas70eb53b2021-01-06 19:42:21 +00001/*
Giorgio Arena5ae8d802021-11-18 18:02:13 +00002 * Copyright (c) 2017-2022 Arm Limited.
Georgios Pinitas70eb53b2021-01-06 19:42:21 +00003 *
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 Pinitas7891a732021-08-20 21:39:25 +010024#include "src/cpu/kernels/CpuFloorKernel.h"
Georgios Pinitas70eb53b2021-01-06 19:42:21 +000025
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"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010030
31#include "src/core/common/Registrars.h"
Georgios Pinitas70eb53b2021-01-06 19:42:21 +000032#include "src/core/CPP/Validate.h"
33#include "src/core/helpers/AutoConfiguration.h"
34#include "src/core/helpers/WindowHelpers.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010035#include "src/cpu/kernels/floor/list.h"
Georgios Pinitas70eb53b2021-01-06 19:42:21 +000036
37namespace arm_compute
38{
39namespace cpu
40{
41namespace kernels
42{
43namespace
44{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010045static const std::vector<CpuFloorKernel::FloorKernel> available_kernels = {
46 {"neon_fp16_floor", [](const DataTypeISASelectorData &data) { return data.dt == DataType::F16 && data.isa.fp16; },
47 REGISTER_FP16_NEON(arm_compute::cpu::fp16_neon_floor)},
48 {"neon_fp32_floor", [](const DataTypeISASelectorData &data) { return data.dt == DataType::F32; },
49 REGISTER_FP32_NEON(arm_compute::cpu::fp32_neon_floor)}};
Georgios Pinitas70eb53b2021-01-06 19:42:21 +000050
51Status validate_arguments(const ITensorInfo *src, const ITensorInfo *dst)
52{
53 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src, dst);
54
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010055 const auto *uk =
56 CpuFloorKernel::get_implementation(DataTypeISASelectorData{src->data_type(), CPUInfo::get().get_isa()});
Georgios Pinitas5fdde992021-06-25 05:42:57 +010057 ARM_COMPUTE_RETURN_ERROR_ON(uk == nullptr || uk->ukernel == nullptr);
Georgios Pinitas70eb53b2021-01-06 19:42:21 +000058
59 // Validate in case of configured output
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010060 if (dst->total_size() > 0)
Georgios Pinitas70eb53b2021-01-06 19:42:21 +000061 {
62 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, dst);
63 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(src, dst);
64 }
65
66 return Status{};
67}
68} // namespace
69
70void CpuFloorKernel::configure(const ITensorInfo *src, ITensorInfo *dst)
71{
72 ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst);
Georgios Pinitas5fdde992021-06-25 05:42:57 +010073 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst));
Georgios Pinitas70eb53b2021-01-06 19:42:21 +000074
Georgios Pinitas70eb53b2021-01-06 19:42:21 +000075 auto_init_if_empty(*dst, src->tensor_shape(), 1, src->data_type());
76
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010077 const auto *uk =
78 CpuFloorKernel::get_implementation(DataTypeISASelectorData{src->data_type(), CPUInfo::get().get_isa()});
Georgios Pinitas5fdde992021-06-25 05:42:57 +010079 ARM_COMPUTE_ERROR_ON_NULLPTR(uk);
80
81 _run_method = uk->ukernel;
82 _name = std::string("CpuFloorKernel").append("/").append(uk->name);
Georgios Pinitas70eb53b2021-01-06 19:42:21 +000083
84 // Configure kernel window
85 const Window win = calculate_max_window(*src, Steps());
86
Georgios Pinitas70eb53b2021-01-06 19:42:21 +000087 ICPPKernel::configure(win);
88}
89
90Window CpuFloorKernel::infer_window(const ITensorInfo *src, const ITensorInfo *dst)
91{
92 ARM_COMPUTE_UNUSED(dst);
93 ARM_COMPUTE_ERROR_ON(!bool(validate_arguments(src, dst)));
94
95 Window win;
96 win.use_tensor_dimensions(src->tensor_shape());
97 return win;
98}
99
100Status CpuFloorKernel::validate(const ITensorInfo *input, const ITensorInfo *output)
101{
102 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output));
103 return Status{};
104}
105
106void CpuFloorKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info)
107{
108 ARM_COMPUTE_UNUSED(info);
109 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
110 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window);
111
112 ARM_COMPUTE_ERROR_ON(tensors.empty());
Georgios Pinitas5fdde992021-06-25 05:42:57 +0100113 ARM_COMPUTE_ERROR_ON(_run_method == nullptr);
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000114
115 const ITensor *src = tensors.get_const_tensor(TensorType::ACL_SRC);
116 ITensor *dst = tensors.get_tensor(TensorType::ACL_DST);
Georgios Pinitas5fdde992021-06-25 05:42:57 +0100117 const auto len = static_cast<int>(window.x().end()) - static_cast<int>(window.x().start());
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000118
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100119 Window win{window};
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000120 win.set(Window::DimX, Window::Dimension(0, 1, 1));
121
122 Iterator src_it(src, win);
123 Iterator dst_it(dst, win);
124
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100125 execute_window_loop(
126 win, [&](const Coordinates &) { _run_method(src_it.ptr(), dst_it.ptr(), len); }, src_it, dst_it);
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000127}
128
129const char *CpuFloorKernel::name() const
130{
Georgios Pinitas5fdde992021-06-25 05:42:57 +0100131 return _name.c_str();
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000132}
Giorgio Arena5ae8d802021-11-18 18:02:13 +0000133
134const std::vector<CpuFloorKernel::FloorKernel> &CpuFloorKernel::get_available_kernels()
135{
136 return available_kernels;
137}
138
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000139} // namespace kernels
140} // namespace cpu
141} // namespace arm_compute