blob: 56703bafcc56b29895fe0ac3b487df58bd681701 [file] [log] [blame]
giuros0105fb4482019-03-26 17:44:40 +00001/*
2 * Copyright (c) 2019 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/NEFFTScaleKernel.h"
25
26#include "arm_compute/core/ITensor.h"
27#include "arm_compute/core/NEON/wrapper/wrapper.h"
28#include "arm_compute/core/TensorInfo.h"
29#include "arm_compute/core/Types.h"
30#include "arm_compute/core/Validate.h"
31#include "arm_compute/core/Window.h"
32
33#include <arm_neon.h>
34
35namespace arm_compute
36{
37namespace
38{
39void scale_complex(float *c_in, float *c_out, bool is_conjugate, float scale)
40{
41 const auto a = wrapper::vload(c_in);
42 auto b = wrapper::vdiv(a, float32x2_t{ scale, scale });
43 if(is_conjugate)
44 {
45 const float img_part = wrapper::vgetlane(b, 1);
46 b = wrapper::vsetlane(-img_part, b, 1);
47 }
48
49 wrapper::vstore(c_out, b);
50}
51
52Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output)
53{
54 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 2, DataType::F32);
55
56 // Checks performed when output is configured
57 if((output != nullptr) && (output->total_size() != 0))
58 {
59 ARM_COMPUTE_RETURN_ERROR_ON(output->num_channels() != 1 && output->num_channels() != 2);
60 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output);
61 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
62 }
63
64 return Status{};
65}
66
67std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output)
68{
69 // Configure kernel window
70 Window win = calculate_max_window(*input, Steps());
71
72 if(output != nullptr)
73 {
74 // Output auto inizialitation if not yet initialized
75 auto_init_if_empty(*output, *input->clone());
76
77 // NEFFTScaleKernel doesn't need padding so update_window_and_padding() can be skipped
78 Coordinates coord;
79 coord.set_num_dimensions(output->num_dimensions());
80 output->set_valid_region(ValidRegion(coord, output->tensor_shape()));
81 }
82
83 return std::make_pair(Status{}, win);
84}
85} // namespace
86
87NEFFTScaleKernel::NEFFTScaleKernel()
88 : _input(nullptr), _output(nullptr), _scale(), _run_in_place(false), _is_conj(false)
89{
90}
91
92void NEFFTScaleKernel::configure(ITensor *input, ITensor *output, const FFTScaleKernelInfo &config)
93{
94 ARM_COMPUTE_ERROR_ON_NULLPTR(input);
95 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), (output != nullptr) ? output->info() : nullptr));
96
97 _input = input;
98 _output = output;
99 _run_in_place = (output == nullptr) || (output == input);
100 _is_conj = config.conjugate;
101 _scale = config.scale;
102
103 // Configure kernel window
104 auto win_config = validate_and_configure_window(input->info(), _run_in_place ? nullptr : output->info());
105 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
106 INEKernel::configure(win_config.second);
107}
108
109Status NEFFTScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const FFTScaleKernelInfo &config)
110{
111 ARM_COMPUTE_UNUSED(config);
112 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output));
113 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get()).first);
114
115 return Status{};
116}
117
118void NEFFTScaleKernel::run(const Window &window, const ThreadInfo &info)
119{
120 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
121 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
122 ARM_COMPUTE_UNUSED(info);
123
124 Window input_window = window;
125 input_window.set(Window::DimX, 0);
126
127 Iterator in(_input, input_window);
128 Iterator out(_run_in_place ? _input : _output, input_window);
129
130 execute_window_loop(window, [&](const Coordinates &)
131 {
giuros01154bc1c2019-03-26 17:44:40 +0000132 scale_complex(reinterpret_cast<float *>(in.ptr()), reinterpret_cast<float *>(out.ptr()), _is_conj, _scale);
giuros0105fb4482019-03-26 17:44:40 +0000133 },
134 in, out);
135}
136} // namespace arm_compute