Compute Library
 19.08
CLFFT2D.cpp
Go to the documentation of this file.
1 /*
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  */
25 
29 
30 namespace arm_compute
31 {
32 CLFFT2D::CLFFT2D(std::shared_ptr<IMemoryManager> memory_manager)
33  : _memory_group(memory_manager), _first_pass_func(memory_manager), _second_pass_func(memory_manager), _first_pass_tensor()
34 {
35 }
36 
37 void CLFFT2D::configure(const ICLTensor *input, ICLTensor *output, const FFT2DInfo &config)
38 {
39  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
40  ARM_COMPUTE_ERROR_THROW_ON(CLFFT2D::validate(input->info(), output->info(), config));
41 
42  // Setup first pass
43  FFT1DInfo first_pass_config;
44  first_pass_config.axis = config.axes.first;
45  first_pass_config.direction = config.direction;
46  _memory_group.manage(&_first_pass_tensor);
47  _first_pass_func.configure(input, &_first_pass_tensor, first_pass_config);
48 
49  // Setup second pass
50  FFT1DInfo second_pass_config;
51  second_pass_config.axis = config.axes.second;
52  second_pass_config.direction = config.direction;
53  _second_pass_func.configure(&_first_pass_tensor, output, second_pass_config);
54  _first_pass_tensor.allocator()->allocate();
55 }
56 
57 Status CLFFT2D::validate(const ITensorInfo *input, const ITensorInfo *output, const FFT2DInfo &config)
58 {
60 
61  // Create intermediate tensor info
62  TensorInfo first_pass_tensor(input->clone()->set_is_resizable(true).reset_padding().set_num_channels(2));
63 
64  // Validate first pass
65  FFT1DInfo first_pass_config;
66  first_pass_config.axis = config.axes.first;
67  first_pass_config.direction = config.direction;
68  ARM_COMPUTE_RETURN_ON_ERROR(CLFFT1D::validate(input, &first_pass_tensor, first_pass_config));
69 
70  // Validate second pass
71  FFT1DInfo second_pass_config;
72  second_pass_config.axis = config.axes.second;
73  second_pass_config.direction = config.direction;
74  ARM_COMPUTE_RETURN_ON_ERROR(CLFFT1D::validate(&first_pass_tensor, output, second_pass_config));
75 
76  // Checks performed when output is configured
77  if((output != nullptr) && (output->total_size() != 0))
78  {
81  }
82 
83  return Status{};
84 }
85 
87 {
88  MemoryGroupResourceScope scope_mg(_memory_group);
89 
90  _first_pass_func.run();
91  _second_pass_func.run();
92 }
93 } // namespace arm_compute
unsigned int axis
Axis to run the FFT on.
FFTDirection direction
Direction of the FFT.
void configure(const ICLTensor *input, ICLTensor *output, const FFT2DInfo &config)
Initialise the function's source, destinations and border mode.
Definition: CLFFT2D.cpp:37
void configure(const ICLTensor *input, ICLTensor *output, const FFT1DInfo &config)
Initialise the function's source, destinations and border mode.
Definition: CLFFT1D.cpp:38
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:545
Descriptor used by the FFT1D function.
Descriptor used by the FFT2D function.
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:100
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
void run() override
Run the kernels contained in the function.
Definition: CLFFT2D.cpp:86
Store the tensor's metadata.
Definition: ITensorInfo.h:40
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: CLTensor.cpp:55
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
Status class.
Definition: Error.h:52
Copyright (c) 2017-2018 ARM Limited.
void manage(TensorType *obj)
Sets a object to be managed by the given memory group.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:443
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
std::pair< unsigned int, unsigned int > axes
Axes to run on.
CLFFT2D(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Default Constructor.
Definition: CLFFT2D.cpp:32
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
Memory group resources scope handling class.
Definition: IMemoryGroup.h:46
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.
Store the tensor's metadata.
Definition: TensorInfo.h:45
FFTDirection direction
Direction of the FFT.
void run() override
Run the kernels contained in the function.
Definition: CLFFT1D.cpp:125
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:57