blob: 3857046719d8e34f43336d7d6da1ab637b12c591 [file] [log] [blame]
Georgios Pinitas8be91482019-03-26 17:23:28 +00001/*
ramelg016d891572021-09-29 10:05:09 +01002 * Copyright (c) 2019-2021 Arm Limited.
Georgios Pinitas8be91482019-03-26 17:23:28 +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 */
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"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010029
30#include "src/common/utils/Log.h"
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010031#include "src/core/CL/kernels/CLFFTDigitReverseKernel.h"
32#include "src/core/CL/kernels/CLFFTRadixStageKernel.h"
33#include "src/core/CL/kernels/CLFFTScaleKernel.h"
Georgios Pinitas8be91482019-03-26 17:23:28 +000034
35namespace arm_compute
36{
37CLFFT2D::CLFFT2D(std::shared_ptr<IMemoryManager> memory_manager)
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010038 : _memory_group(memory_manager),
39 _first_pass_func(memory_manager),
40 _second_pass_func(memory_manager),
41 _first_pass_tensor()
Georgios Pinitas8be91482019-03-26 17:23:28 +000042{
43}
44
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010045CLFFT2D::~CLFFT2D() = default;
46
Georgios Pinitas8be91482019-03-26 17:23:28 +000047void CLFFT2D::configure(const ICLTensor *input, ICLTensor *output, const FFT2DInfo &config)
48{
Manuel Bottini2b84be52020-04-08 10:15:51 +010049 configure(CLKernelLibrary::get().get_compile_context(), input, output, config);
50}
51
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010052void CLFFT2D::configure(const CLCompileContext &compile_context,
53 const ICLTensor *input,
54 ICLTensor *output,
55 const FFT2DInfo &config)
Manuel Bottini2b84be52020-04-08 10:15:51 +010056{
Georgios Pinitas8be91482019-03-26 17:23:28 +000057 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
58 ARM_COMPUTE_ERROR_THROW_ON(CLFFT2D::validate(input->info(), output->info(), config));
ramelg016d891572021-09-29 10:05:09 +010059 ARM_COMPUTE_LOG_PARAMS(input, output, config);
Georgios Pinitas8be91482019-03-26 17:23:28 +000060
61 // Setup first pass
62 FFT1DInfo first_pass_config;
Georgios Pinitas0b192e82020-02-20 17:09:28 +000063 first_pass_config.axis = config.axis0;
Georgios Pinitas8be91482019-03-26 17:23:28 +000064 first_pass_config.direction = config.direction;
65 _memory_group.manage(&_first_pass_tensor);
Manuel Bottini2b84be52020-04-08 10:15:51 +010066 _first_pass_func.configure(compile_context, input, &_first_pass_tensor, first_pass_config);
Georgios Pinitas8be91482019-03-26 17:23:28 +000067
68 // Setup second pass
69 FFT1DInfo second_pass_config;
Georgios Pinitas0b192e82020-02-20 17:09:28 +000070 second_pass_config.axis = config.axis1;
Georgios Pinitas8be91482019-03-26 17:23:28 +000071 second_pass_config.direction = config.direction;
Manuel Bottini2b84be52020-04-08 10:15:51 +010072 _second_pass_func.configure(compile_context, &_first_pass_tensor, output, second_pass_config);
Georgios Pinitas8be91482019-03-26 17:23:28 +000073 _first_pass_tensor.allocator()->allocate();
74}
75
76Status CLFFT2D::validate(const ITensorInfo *input, const ITensorInfo *output, const FFT2DInfo &config)
77{
78 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output);
Giorgio Arenaea7de7b2020-12-10 16:49:39 +000079 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(input, DataType::F16, DataType::F32);
Georgios Pinitas8be91482019-03-26 17:23:28 +000080
81 // Create intermediate tensor info
82 TensorInfo first_pass_tensor(input->clone()->set_is_resizable(true).reset_padding().set_num_channels(2));
83
84 // Validate first pass
85 FFT1DInfo first_pass_config;
Georgios Pinitas0b192e82020-02-20 17:09:28 +000086 first_pass_config.axis = config.axis0;
Georgios Pinitas8be91482019-03-26 17:23:28 +000087 first_pass_config.direction = config.direction;
88 ARM_COMPUTE_RETURN_ON_ERROR(CLFFT1D::validate(input, &first_pass_tensor, first_pass_config));
89
90 // Validate second pass
91 FFT1DInfo second_pass_config;
Georgios Pinitas0b192e82020-02-20 17:09:28 +000092 second_pass_config.axis = config.axis1;
Georgios Pinitas8be91482019-03-26 17:23:28 +000093 second_pass_config.direction = config.direction;
94 ARM_COMPUTE_RETURN_ON_ERROR(CLFFT1D::validate(&first_pass_tensor, output, second_pass_config));
95
96 // Checks performed when output is configured
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010097 if ((output != nullptr) && (output->total_size() != 0))
Georgios Pinitas8be91482019-03-26 17:23:28 +000098 {
99 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output);
100 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
101 }
102
103 return Status{};
104}
105
106void CLFFT2D::run()
107{
Georgios Pinitas098516b2019-04-25 18:25:06 +0100108 MemoryGroupResourceScope scope_mg(_memory_group);
Georgios Pinitas8be91482019-03-26 17:23:28 +0000109
110 _first_pass_func.run();
111 _second_pass_func.run();
Georgios Pinitas8be91482019-03-26 17:23:28 +0000112}
113} // namespace arm_compute