blob: dd85ac1fd6420b8edbcf6fb599fe080f3f04dbb3 [file] [log] [blame]
Georgios Pinitasd8e765b2017-08-02 13:44:33 +01001/*
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
36using namespace arm_compute;
37
38void NEFloorKernel::configure(const ITensor *input, ITensor *output)
39{
40 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
41
42 set_shape_if_empty(*output->info(), input->info()->tensor_shape());
43
44 set_data_type_if_unknown(*input->info(), DataType::F32);
45 set_data_type_if_unknown(*output->info(), DataType::F32);
46
47 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32);
48 ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(input, output);
49 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
50
51 _input = input;
52 _output = output;
53
54 constexpr unsigned int num_elems_processed_per_iteration = 4;
55
56 // Configure kernel window
57 Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
58 AccessWindowHorizontal input_access(input->info(), 0, num_elems_processed_per_iteration);
59 AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
60
61 update_window_and_padding(win, input_access, output_access);
62 output_access.set_valid_region(win, input->info()->valid_region());
63
64 INEKernel::configure(win);
65}
66
Moritz Pflanzerc186b572017-09-07 09:48:04 +010067void NEFloorKernel::run(const Window &window, const ThreadInfo &info)
Georgios Pinitasd8e765b2017-08-02 13:44:33 +010068{
Moritz Pflanzerc186b572017-09-07 09:48:04 +010069 ARM_COMPUTE_UNUSED(info);
Georgios Pinitasd8e765b2017-08-02 13:44:33 +010070 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
71 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
72
73 Iterator input(_input, window);
74 Iterator output(_output, window);
75
76 execute_window_loop(window, [&](const Coordinates & id)
77 {
78 const float32x4_t res = vfloorq_f32(vld1q_f32(reinterpret_cast<const float *>(input.ptr())));
79 vst1q_f32(reinterpret_cast<float *>(output.ptr()), res);
80 },
81 input, output);
82}