blob: 48f964c6a2af509f54f255f483170f186123a238 [file] [log] [blame]
Georgios Pinitasd8e765b2017-08-02 13:44:33 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Georgios Pinitasd8e765b2017-08-02 13:44:33 +01003 *
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 Pinitasd8e765b2017-08-02 13:44:33 +010028#include "arm_compute/core/ITensor.h"
29#include "arm_compute/core/NEON/INEKernel.h"
Georgios Pinitasd8e765b2017-08-02 13:44:33 +010030#include "arm_compute/core/Validate.h"
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010031#include "src/core/CPP/Validate.h"
32#include "src/core/helpers/AutoConfiguration.h"
33#include "src/core/helpers/WindowHelpers.h"
Georgios Pinitasd8e765b2017-08-02 13:44:33 +010034
Georgios Pinitasff4fca02020-10-02 21:00:00 +010035#include "src/core/NEON/kernels/floor/impl/list.h"
36#include "src/core/common/Registrars.h"
Georgios Pinitasd8e765b2017-08-02 13:44:33 +010037
Georgios Pinitas565bf2d2018-08-31 11:46:49 +010038namespace arm_compute
39{
40namespace
41{
Georgios Pinitasff4fca02020-10-02 21:00:00 +010042struct FloorSelectorData
43{
44 DataType dt;
45};
46using FloorSelectorPtr = std::add_pointer<bool(const FloorSelectorData &data)>::type;
47using FloorUKernelPtr = std::add_pointer<void(const void *, void *, int)>::type;
48
49struct FloorKernel
50{
51 const char *name;
52 const FloorSelectorPtr is_selected;
53 FloorUKernelPtr ukernel;
54};
55
56static 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
70const 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 Pinitas565bf2d2018-08-31 11:46:49 +010082Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output)
83{
84 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output);
Georgios Pinitasff4fca02020-10-02 21:00:00 +010085
86 const auto *uk = get_implementation(FloorSelectorData{ input->data_type() });
87 ARM_COMPUTE_RETURN_ERROR_ON(uk == nullptr || uk->ukernel == nullptr);
Georgios Pinitas565bf2d2018-08-31 11:46:49 +010088
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 Pinitas565bf2d2018-08-31 11:46:49 +010098} // namespace
Georgios Pinitasd8e765b2017-08-02 13:44:33 +010099
100void NEFloorKernel::configure(const ITensor *input, ITensor *output)
101{
102 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
103
Michalis Spyroua4a96012017-10-09 15:46:30 +0100104 // Auto initialize output
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100105 auto_init_if_empty(*output->info(), input->info()->tensor_shape(), 1, input->info()->data_type());
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100106
Georgios Pinitas565bf2d2018-08-31 11:46:49 +0100107 // Validate
108 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info()));
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100109
110 _input = input;
111 _output = output;
112
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100113 // Configure kernel window
Michalis Spyrouca8c0f72020-02-20 15:21:21 +0000114 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 Pinitas565bf2d2018-08-31 11:46:49 +0100121}
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100122
Georgios Pinitas565bf2d2018-08-31 11:46:49 +0100123Status NEFloorKernel::validate(const ITensorInfo *input, const ITensorInfo *output)
124{
125 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output));
Georgios Pinitas565bf2d2018-08-31 11:46:49 +0100126 return Status{};
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100127}
128
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100129void NEFloorKernel::run(const Window &window, const ThreadInfo &info)
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100130{
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100131 ARM_COMPUTE_UNUSED(info);
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100132 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
133 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
134
Michalis Spyrouca8c0f72020-02-20 15:21:21 +0000135 Window win{ window };
136 win.set(Window::DimX, Window::Dimension(0, 1, 1));
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100137
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 Spyrouca8c0f72020-02-20 15:21:21 +0000141 Iterator input(_input, win);
142 Iterator output(_output, win);
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100143
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100144 execute_window_loop(win, [&](const Coordinates &)
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100145 {
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100146 uk->ukernel(input.ptr(), output.ptr(), len);
147 },
148 input, output);
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100149}
Georgios Pinitas565bf2d2018-08-31 11:46:49 +0100150} // namespace arm_compute