Compute Library
 23.11
CLFFT2D.cpp
Go to the documentation of this file.
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  */
25 
29 
30 #include "src/common/utils/Log.h"
34 
35 namespace arm_compute
36 {
37 CLFFT2D::CLFFT2D(std::shared_ptr<IMemoryManager> memory_manager)
38  : _memory_group(memory_manager),
39  _first_pass_func(memory_manager),
40  _second_pass_func(memory_manager),
41  _first_pass_tensor()
42 {
43 }
44 
45 CLFFT2D::~CLFFT2D() = default;
46 
47 void CLFFT2D::configure(const ICLTensor *input, ICLTensor *output, const FFT2DInfo &config)
48 {
49  configure(CLKernelLibrary::get().get_compile_context(), input, output, config);
50 }
51 
52 void CLFFT2D::configure(const CLCompileContext &compile_context,
53  const ICLTensor *input,
54  ICLTensor *output,
55  const FFT2DInfo &config)
56 {
58  ARM_COMPUTE_ERROR_THROW_ON(CLFFT2D::validate(input->info(), output->info(), config));
59  ARM_COMPUTE_LOG_PARAMS(input, output, config);
60 
61  // Setup first pass
62  FFT1DInfo first_pass_config;
63  first_pass_config.axis = config.axis0;
64  first_pass_config.direction = config.direction;
65  _memory_group.manage(&_first_pass_tensor);
66  _first_pass_func.configure(compile_context, input, &_first_pass_tensor, first_pass_config);
67 
68  // Setup second pass
69  FFT1DInfo second_pass_config;
70  second_pass_config.axis = config.axis1;
71  second_pass_config.direction = config.direction;
72  _second_pass_func.configure(compile_context, &_first_pass_tensor, output, second_pass_config);
73  _first_pass_tensor.allocator()->allocate();
74 }
75 
76 Status CLFFT2D::validate(const ITensorInfo *input, const ITensorInfo *output, const FFT2DInfo &config)
77 {
80 
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;
86  first_pass_config.axis = config.axis0;
87  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;
92  second_pass_config.axis = config.axis1;
93  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
97  if ((output != nullptr) && (output->total_size() != 0))
98  {
101  }
102 
103  return Status{};
104 }
105 
107 {
108  MemoryGroupResourceScope scope_mg(_memory_group);
109 
110  _first_pass_func.run();
111  _second_pass_func.run();
112 }
113 } // namespace arm_compute
ICLTensor.h
arm_compute::MemoryGroup::manage
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:76
arm_compute::CLFFT1D::run
void run() override
Run the kernels contained in the function.
Definition: CLFFT1D.cpp:152
arm_compute::CLFFT2D::validate
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const FFT2DInfo &config)
Static function to check if given info will lead to a valid configuration of CLFFT2D.
Definition: CLFFT2D.cpp:76
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:574
arm_compute::ICLTensor
Interface for OpenCL tensor.
Definition: ICLTensor.h:41
arm_compute::CLKernelLibrary::get
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Definition: CLKernelLibrary.cpp:41
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:677
arm_compute::CLFFT2D::~CLFFT2D
~CLFFT2D()
Default destructor.
ARM_COMPUTE_RETURN_ON_ERROR
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:205
ARM_COMPUTE_ERROR_ON_NULLPTR
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
arm_compute::FFT2DInfo::direction
FFTDirection direction
Direction of the FFT.
Definition: FunctionDescriptors.h:53
arm_compute::ITensor::info
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
ARM_COMPUTE_ERROR_THROW_ON
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(t,...)
Definition: Validate.h:838
arm_compute::CLCompileContext
CLCompileContext class.
Definition: CLCompileContext.h:204
arm_compute::CLFFT2D::run
void run() override
Run the kernels contained in the function.
Definition: CLFFT2D.cpp:106
CLFFTDigitReverseKernel.h
arm_compute::Status
Status class.
Definition: Error.h:52
arm_compute::FFT2DInfo::axis0
unsigned int axis0
Axis to run first pass on.
Definition: FunctionDescriptors.h:51
CLScheduler.h
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
arm_compute::FFT1DInfo::axis
unsigned int axis
Axis to run the FFT on.
Definition: FunctionDescriptors.h:44
arm_compute::CLTensorAllocator::allocate
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
Definition: CLTensorAllocator.cpp:131
arm_compute::CLTensor::allocator
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: CLTensor.cpp:61
arm_compute::FFT2DInfo
Descriptor used by the FFT2D function.
Definition: FunctionDescriptors.h:49
arm_compute::FFT1DInfo
Descriptor used by the FFT1D function.
Definition: FunctionDescriptors.h:42
arm_compute::TensorInfo
Store the tensor's metadata.
Definition: TensorInfo.h:41
arm_compute::FFT1DInfo::direction
FFTDirection direction
Direction of the FFT.
Definition: FunctionDescriptors.h:45
arm_compute::MemoryGroupResourceScope
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::DataType::F16
@ F16
16-bit floating-point number
arm_compute::CLFFT2D::CLFFT2D
CLFFT2D(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Default Constructor.
Definition: CLFFT2D.cpp:37
Log.h
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
arm_compute::ITensorInfo
Store the tensor's metadata.
Definition: ITensorInfo.h:44
arm_compute::DataType::F32
@ F32
32-bit floating-point number
arm_compute::FFT2DInfo::axis1
unsigned int axis1
Axis to run second pass on.
Definition: FunctionDescriptors.h:52
ARM_COMPUTE_LOG_PARAMS
#define ARM_COMPUTE_LOG_PARAMS(...)
Definition: Log.h:35
Validate.h
arm_compute::ITensorInfo::total_size
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.
CLFFTScaleKernel.h
CLFFTRadixStageKernel.h
arm_compute::CLFFT2D::configure
void configure(const ICLTensor *input, ICLTensor *output, const FFT2DInfo &config)
Initialise the function's source, destinations and border mode.
Definition: CLFFT2D.cpp:47
CLFFT2D.h
arm_compute::CLFFT1D::validate
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const FFT1DInfo &config)
Static function to check if given info will lead to a valid configuration of CLFFT1D.
Definition: CLFFT1D.cpp:127
arm_compute::test::validation::input
auto input
Definition: LSTMLayerQuantized.cpp:486
arm_compute::CLFFT1D::configure
void configure(const ICLTensor *input, ICLTensor *output, const FFT1DInfo &config)
Initialise the function's source, destinations and border mode.
Definition: CLFFT1D.cpp:52