Compute Library
 21.11
NEFFT2D.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 #include "src/common/utils/Log.h"
30 
31 namespace arm_compute
32 {
33 NEFFT2D::~NEFFT2D() = default;
34 
35 NEFFT2D::NEFFT2D(std::shared_ptr<IMemoryManager> memory_manager)
36  : _memory_group(memory_manager), _first_pass_func(memory_manager), _second_pass_func(memory_manager), _first_pass_tensor()
37 {
38 }
39 
40 void NEFFT2D::configure(const ITensor *input, ITensor *output, const FFT2DInfo &config)
41 {
42  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
43  ARM_COMPUTE_ERROR_THROW_ON(NEFFT2D::validate(input->info(), output->info(), config));
44  ARM_COMPUTE_LOG_PARAMS(input, output, config);
45 
46  // Setup first pass
47  FFT1DInfo first_pass_config;
48  first_pass_config.axis = config.axis0;
49  first_pass_config.direction = config.direction;
50  _memory_group.manage(&_first_pass_tensor);
51  _first_pass_func.configure(input, &_first_pass_tensor, first_pass_config);
52 
53  // Setup second pass
54  FFT1DInfo second_pass_config;
55  second_pass_config.axis = config.axis1;
56  second_pass_config.direction = config.direction;
57  _second_pass_func.configure(&_first_pass_tensor, output, second_pass_config);
58  _first_pass_tensor.allocator()->allocate();
59 }
60 
61 Status NEFFT2D::validate(const ITensorInfo *input, const ITensorInfo *output, const FFT2DInfo &config)
62 {
64 
65  // Create intermediate tensor info
66  TensorInfo first_pass_tensor(input->clone()->set_is_resizable(true).reset_padding().set_num_channels(2));
67 
68  // Validate first pass
69  FFT1DInfo first_pass_config;
70  first_pass_config.axis = config.axis0;
71  first_pass_config.direction = config.direction;
72  ARM_COMPUTE_RETURN_ON_ERROR(NEFFT1D::validate(input, &first_pass_tensor, first_pass_config));
73 
74  // Validate second pass
75  FFT1DInfo second_pass_config;
76  second_pass_config.axis = config.axis1;
77  second_pass_config.direction = config.direction;
78  ARM_COMPUTE_RETURN_ON_ERROR(NEFFT1D::validate(&first_pass_tensor, output, second_pass_config));
79 
80  // Checks performed when output is configured
81  if((output != nullptr) && (output->total_size() != 0))
82  {
85  }
86 
87  return Status{};
88 }
89 
91 {
92  _memory_group.acquire();
93 
94  _first_pass_func.run();
95  _second_pass_func.run();
96 
97  _memory_group.release();
98 }
99 } // namespace arm_compute
unsigned int axis
Axis to run the FFT on.
FFTDirection direction
Direction of the FFT.
NEFFT2D(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Default Constructor.
Definition: NEFFT2D.cpp:35
Descriptor used by the FFT1D function.
Descriptor used by the FFT2D function.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
Status class.
Definition: Error.h:52
Interface for CPU tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
TensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: Tensor.cpp:48
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
void run() override
Run the kernels contained in the function.
Definition: NEFFT1D.cpp:137
void release() override
Releases backing memory of the whole group.
Definition: MemoryGroup.h:115
void configure(const ITensor *input, ITensor *output, const FFT1DInfo &config)
Initialise the function&#39;s source and destinations.
Definition: NEFFT1D.cpp:44
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
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&#39;s metadata.
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 NEFFT2D.
Definition: NEFFT2D.cpp:61
void acquire() override
Acquires backing memory for the whole group.
Definition: MemoryGroup.h:105
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:439
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
void run() override
Run the kernels contained in the function.
Definition: NEFFT2D.cpp:90
unsigned int axis1
Axis to run second pass on.
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 NEFFT1D.
Definition: NEFFT1D.cpp:111
~NEFFT2D()
Default destructor.
#define ARM_COMPUTE_LOG_PARAMS(...)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:43
FFTDirection direction
Direction of the FFT.
void configure(const ITensor *input, ITensor *output, const FFT2DInfo &config)
Initialise the function&#39;s source and destinations.
Definition: NEFFT2D.cpp:40
unsigned int axis0
Axis to run first pass on.