1 /*
2 * Copyright (c) 2019-2021 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/runtime/CL/functions/CLFFT2D.h"
25
26 #include "arm_compute/core/CL/ICLTensor.h"
27 #include "arm_compute/core/Validate.h"
28 #include "arm_compute/runtime/CL/CLScheduler.h"
29 #include "src/core/CL/kernels/CLFFTDigitReverseKernel.h"
30 #include "src/core/CL/kernels/CLFFTRadixStageKernel.h"
31 #include "src/core/CL/kernels/CLFFTScaleKernel.h"
32
33 #include "src/common/utils/Log.h"
34
35 namespace arm_compute
36 {
CLFFT2D(std::shared_ptr<IMemoryManager> memory_manager)37 CLFFT2D::CLFFT2D(std::shared_ptr<IMemoryManager> memory_manager)
38 : _memory_group(memory_manager), _first_pass_func(memory_manager), _second_pass_func(memory_manager), _first_pass_tensor()
39 {
40 }
41
42 CLFFT2D::~CLFFT2D() = default;
43
configure(const ICLTensor * input,ICLTensor * output,const FFT2DInfo & config)44 void CLFFT2D::configure(const ICLTensor *input, ICLTensor *output, const FFT2DInfo &config)
45 {
46 configure(CLKernelLibrary::get().get_compile_context(), input, output, config);
47 }
48
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output,const FFT2DInfo & config)49 void CLFFT2D::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, const FFT2DInfo &config)
50 {
51 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
52 ARM_COMPUTE_ERROR_THROW_ON(CLFFT2D::validate(input->info(), output->info(), config));
53 ARM_COMPUTE_LOG_PARAMS(input, output, config);
54
55 // Setup first pass
56 FFT1DInfo first_pass_config;
57 first_pass_config.axis = config.axis0;
58 first_pass_config.direction = config.direction;
59 _memory_group.manage(&_first_pass_tensor);
60 _first_pass_func.configure(compile_context, input, &_first_pass_tensor, first_pass_config);
61
62 // Setup second pass
63 FFT1DInfo second_pass_config;
64 second_pass_config.axis = config.axis1;
65 second_pass_config.direction = config.direction;
66 _second_pass_func.configure(compile_context, &_first_pass_tensor, output, second_pass_config);
67 _first_pass_tensor.allocator()->allocate();
68 }
69
validate(const ITensorInfo * input,const ITensorInfo * output,const FFT2DInfo & config)70 Status CLFFT2D::validate(const ITensorInfo *input, const ITensorInfo *output, const FFT2DInfo &config)
71 {
72 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output);
73 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(input, DataType::F16, DataType::F32);
74
75 // Create intermediate tensor info
76 TensorInfo first_pass_tensor(input->clone()->set_is_resizable(true).reset_padding().set_num_channels(2));
77
78 // Validate first pass
79 FFT1DInfo first_pass_config;
80 first_pass_config.axis = config.axis0;
81 first_pass_config.direction = config.direction;
82 ARM_COMPUTE_RETURN_ON_ERROR(CLFFT1D::validate(input, &first_pass_tensor, first_pass_config));
83
84 // Validate second pass
85 FFT1DInfo second_pass_config;
86 second_pass_config.axis = config.axis1;
87 second_pass_config.direction = config.direction;
88 ARM_COMPUTE_RETURN_ON_ERROR(CLFFT1D::validate(&first_pass_tensor, output, second_pass_config));
89
90 // Checks performed when output is configured
91 if((output != nullptr) && (output->total_size() != 0))
92 {
93 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output);
94 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
95 }
96
97 return Status{};
98 }
99
run()100 void CLFFT2D::run()
101 {
102 MemoryGroupResourceScope scope_mg(_memory_group);
103
104 _first_pass_func.run();
105 _second_pass_func.run();
106 }
107 } // namespace arm_compute
108