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