Compute Library
 22.05
NEFFT1D Class Reference

Basic function to execute one dimensional FFT. More...

#include <NEFFT1D.h>

Collaboration diagram for NEFFT1D:
[legend]

Public Member Functions

 NEFFT1D (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Default Constructor. More...
 
 NEFFT1D (const NEFFT1D &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEFFT1Doperator= (const NEFFT1D &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEFFT1D (NEFFT1D &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
NEFFT1Doperator= (NEFFT1D &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
 ~NEFFT1D ()
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, const FFT1DInfo &config)
 Initialise the function's source and destinations. More...
 
void run () override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
 
virtual void prepare ()
 Prepare the function for executing. More...
 

Static Public Member Functions

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. More...
 

Detailed Description

Basic function to execute one dimensional FFT.

This function calls the following kernels:

  1. NEFFTDigitReverseKernel Performs digit reverse
  2. NEFFTRadixStageKernel A list of FFT kernels depending on the radix decomposition
  3. NEFFTScaleKernel Performs output scaling in case of in inverse FFT

Definition at line 49 of file NEFFT1D.h.

Constructor & Destructor Documentation

◆ NEFFT1D() [1/3]

NEFFT1D ( std::shared_ptr< IMemoryManager memory_manager = nullptr)

Default Constructor.

Definition at line 39 of file NEFFT1D.cpp.

40  : _memory_group(std::move(memory_manager)), _digit_reverse_kernel(), _fft_kernels(), _scale_kernel(), _digit_reversed_input(), _digit_reverse_indices(), _num_ffts(0), _axis(0), _run_scale(false)
41 {
42 }

◆ NEFFT1D() [2/3]

NEFFT1D ( const NEFFT1D )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ NEFFT1D() [3/3]

NEFFT1D ( NEFFT1D &&  )
delete

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ ~NEFFT1D()

~NEFFT1D ( )
default

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
const FFT1DInfo config 
)

Initialise the function's source and destinations.

Valid data layouts:

  • All

Valid data type configurations:

src dst
F32 F32
Parameters
[in]inputSource tensor. Data types supported: F32. Number of channels supported: 1 (real tensor) or 2 (complex tensor).
[out]outputDestination tensor. Data types and data layouts supported: Same as input. Number of channels supported: 1 (real tensor) or 2 (complex tensor).If input is real, output must be complex.
[in]configFFT related configuration

Definition at line 44 of file NEFFT1D.cpp.

References TensorAllocator::allocate(), Tensor::allocator(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ARM_COMPUTE_LOG_PARAMS, FFT1DInfo::axis, FFTDigitReverseKernelInfo::axis, FFTRadixStageKernelInfo::axis, Tensor::buffer(), FFTScaleKernelInfo::conjugate, FFTDigitReverseKernelInfo::conjugate, arm_compute::helpers::fft::decompose_stages(), arm_compute::helpers::fft::digit_reverse_indices(), FFT1DInfo::direction, ITensor::info(), TensorAllocator::init(), arm_compute::Inverse, FFTRadixStageKernelInfo::is_first_stage, MemoryGroup::manage(), N, ITensorInfo::num_channels(), FFTRadixStageKernelInfo::Nx, FFTRadixStageKernelInfo::radix, FFTScaleKernelInfo::scale, NEFFTRadixStageKernel::supported_radix(), ITensorInfo::tensor_shape(), arm_compute::U32, and NEFFT1D::validate().

Referenced by NEFFT2D::configure().

45 {
47  ARM_COMPUTE_ERROR_THROW_ON(NEFFT1D::validate(input->info(), output->info(), config));
48  ARM_COMPUTE_LOG_PARAMS(input, output, config);
49 
50  // Decompose size to radix factors
51  const auto supported_radix = NEFFTRadixStageKernel::supported_radix();
52  const unsigned int N = input->info()->tensor_shape()[config.axis];
53  const auto decomposed_vector = arm_compute::helpers::fft::decompose_stages(N, supported_radix);
54  ARM_COMPUTE_ERROR_ON(decomposed_vector.empty());
55 
56  // Flags
57  _run_scale = config.direction == FFTDirection::Inverse;
58 
59  const bool is_c2r = input->info()->num_channels() == 2 && output->info()->num_channels() == 1;
60 
61  // Configure digit reverse
62  FFTDigitReverseKernelInfo digit_reverse_config;
63  digit_reverse_config.axis = config.axis;
64  digit_reverse_config.conjugate = config.direction == FFTDirection::Inverse;
65  TensorInfo digit_reverse_indices_info(TensorShape(input->info()->tensor_shape()[config.axis]), 1, DataType::U32);
66  _digit_reverse_indices.allocator()->init(digit_reverse_indices_info);
67  _memory_group.manage(&_digit_reversed_input);
68  _digit_reverse_kernel = std::make_unique<NEFFTDigitReverseKernel>();
69  _digit_reverse_kernel->configure(input, &_digit_reversed_input, &_digit_reverse_indices, digit_reverse_config);
70 
71  // Create and configure FFT kernels
72  unsigned int Nx = 1;
73  _num_ffts = decomposed_vector.size();
74  _fft_kernels.resize(_num_ffts);
75  _axis = config.axis;
76 
77  for(unsigned int i = 0; i < _num_ffts; ++i)
78  {
79  const unsigned int radix_for_stage = decomposed_vector.at(i);
80 
81  FFTRadixStageKernelInfo fft_kernel_info;
82  fft_kernel_info.axis = config.axis;
83  fft_kernel_info.radix = radix_for_stage;
84  fft_kernel_info.Nx = Nx;
85  fft_kernel_info.is_first_stage = (i == 0);
86  _fft_kernels[i] = std::make_unique<NEFFTRadixStageKernel>();
87  _fft_kernels[i]->configure(&_digit_reversed_input, ((i == (_num_ffts - 1)) && !is_c2r) ? output : nullptr, fft_kernel_info);
88 
89  Nx *= radix_for_stage;
90  }
91 
92  // Configure scale kernel
93  if(_run_scale)
94  {
95  FFTScaleKernelInfo scale_config;
96  scale_config.scale = static_cast<float>(N);
97  scale_config.conjugate = config.direction == FFTDirection::Inverse;
98  _scale_kernel = std::make_unique<NEFFTScaleKernel>();
99  is_c2r ? _scale_kernel->configure(&_digit_reversed_input, output, scale_config) : _scale_kernel->configure(output, nullptr, scale_config);
100  }
101 
102  // Allocate tensors
103  _digit_reversed_input.allocator()->allocate();
104  _digit_reverse_indices.allocator()->allocate();
105 
106  // Init digit reverse indices
107  const auto digit_reverse_cpu = arm_compute::helpers::fft::digit_reverse_indices(N, decomposed_vector);
108  std::copy_n(digit_reverse_cpu.data(), N, reinterpret_cast<unsigned int *>(_digit_reverse_indices.buffer()));
109 }
void init(const TensorAllocator &allocator, const Coordinates &coords, TensorInfo &sub_info)
Shares the same backing memory with another tensor allocator, while the tensor info might be differen...
std::vector< unsigned int > decompose_stages(unsigned int N, const std::set< unsigned int > &supported_factors)
Decompose a given 1D input size using the provided supported factors.
Definition: fft.cpp:34
std::vector< unsigned int > digit_reverse_indices(unsigned int N, const std::vector< unsigned int > &fft_stages)
Calculate digit reverse index vector given fft size and the decomposed stages.
Definition: fft.cpp:79
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
TensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: Tensor.cpp:48
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
1 channel, 1 U32 per channel
unsigned int N
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
static std::set< unsigned int > supported_radix()
Returns the radix that are support by the FFT kernel.
uint8_t * buffer() const override
Interface to be implemented by the child class to return a pointer to CPU memory. ...
Definition: Tensor.cpp:43
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
#define ARM_COMPUTE_LOG_PARAMS(...)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ operator=() [1/2]

NEFFT1D& operator= ( const NEFFT1D )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ operator=() [2/2]

NEFFT1D& operator= ( NEFFT1D &&  )
delete

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For CPU kernels:

  • Multi-threading is used for the kernels which are parallelisable.
  • By default std::thread::hardware_concurrency() threads are used.
Note
CPPScheduler::set_num_threads() can be used to manually set the number of threads

For OpenCL kernels:

  • All the kernels are enqueued on the queue associated with CLScheduler.
  • The queue is then flushed.
Note
The function will not block until the kernels are executed. It is the user's responsibility to wait.
Will call prepare() on first run if hasn't been done

Implements IFunction.

Definition at line 137 of file NEFFT1D.cpp.

References Window::DimX, Window::DimY, Window::DimZ, Scheduler::get(), and IScheduler::schedule().

Referenced by NEFFT2D::run().

138 {
139  MemoryGroupResourceScope scope_mg(_memory_group);
140 
141  NEScheduler::get().schedule(_digit_reverse_kernel.get(), (_axis == 0 ? Window::DimY : Window::DimZ));
142 
143  for(unsigned int i = 0; i < _num_ffts; ++i)
144  {
145  NEScheduler::get().schedule(_fft_kernels[i].get(), (_axis == 0 ? Window::DimY : Window::DimX));
146  }
147 
148  // Run output scaling
149  if(_run_scale)
150  {
151  NEScheduler::get().schedule(_scale_kernel.get(), Window::DimY);
152  }
153 }
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
virtual void schedule(ICPPKernel *kernel, const Hints &hints)=0
Runs the kernel in the same thread as the caller synchronously.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const FFT1DInfo config 
)
static

Static function to check if given info will lead to a valid configuration of NEFFT1D.

Parameters
[in]inputSource tensor info. Data types supported: F32.
[in]outputDestination tensor info. Data types and data layouts supported: Same as input.
[in]configFFT related configuration
Returns
a status

Definition at line 111 of file NEFFT1D.cpp.

References ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, FFT1DInfo::axis, ITensorInfo::data_type(), arm_compute::helpers::fft::decompose_stages(), arm_compute::F32, N, ITensorInfo::num_channels(), NEFFTRadixStageKernel::supported_radix(), ITensorInfo::tensor_shape(), and ITensorInfo::total_size().

Referenced by NEFFT1D::configure(), and NEFFT2D::validate().

112 {
115  ARM_COMPUTE_RETURN_ERROR_ON(input->num_channels() > 2);
116  ARM_COMPUTE_RETURN_ERROR_ON(std::set<unsigned int>({ 0, 1 }).count(config.axis) == 0);
117 
118  // Check if FFT is decomposable
119  const auto supported_radix = NEFFTRadixStageKernel::supported_radix();
120  const unsigned int N = input->tensor_shape()[config.axis];
121  const auto decomposed_vector = arm_compute::helpers::fft::decompose_stages(N, supported_radix);
122  ARM_COMPUTE_RETURN_ERROR_ON(decomposed_vector.empty());
123 
124  // Checks performed when output is configured
125  if((output != nullptr) && (output->total_size() != 0))
126  {
127  // All combinations are supported except real input with real output (i.e., both input channels set to 1)
128  ARM_COMPUTE_RETURN_ERROR_ON(output->num_channels() == 1 && input->num_channels() == 1);
129  ARM_COMPUTE_RETURN_ERROR_ON(output->num_channels() > 2);
132  }
133 
134  return Status{};
135 }
std::vector< unsigned int > decompose_stages(unsigned int N, const std::set< unsigned int > &supported_factors)
Decompose a given 1D input size using the provided supported factors.
Definition: fft.cpp:34
1 channel, 1 F32 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
unsigned int N
static std::set< unsigned int > supported_radix()
Returns the radix that are support by the FFT kernel.
#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

The documentation for this class was generated from the following files: