Inplace#

#include <hpk/fft/fft.hpp>

Declares a class template for computing Fast Fourier Transforms in place, i.e., the output data overwrites the input. A free function for conveniently allocating scratch memory is also provided.


TYPEDEFS

template<typename fp_t>
using hpk::fft::InplaceCC = Inplace<fp_t, std::complex<fp_t>, std::complex<fp_t>>#

Convenience type alias for in-place transforms having complex time and complex frequency domains.

template<typename fp_t>
using hpk::fft::InplaceRC = Inplace<fp_t, fp_t, std::complex<fp_t>>#

Convenience type alias for in-place transforms having real time domain and complex frequency domain.


CLASS

template<typename fp_t, typename time_t, typename freq_t>
class Inplace#

Abstract class for performing Fast Fourier Transforms in-place.

Instances of this class are returned by the makeInplace() function of a Factory. Note that all member functions are const-qualified. An Inplace object is immutable and can be shared in a multithreaded environment.

Public Types

using mathType = fp_t#

Type of math computations and scale factor.

using timeType = time_t#

Type of data in the time domain.

using freqType = freq_t#

Type of data in the frequency domain.

using realTimeType = remove_complex_t<timeType>#

Real timeType.

using realFreqType = remove_complex_t<freqType>#

Real freqType.

Public Functions

template<typename Allocator = AlignedAllocator<mathType>, typename inout_t>
inline void forward(inout_t *inout, Allocator &&alloc = Allocator()) const#

Computes an unscaled in-place forward FFT.

Parameters:
  • inout – Pointer to the data to transform. Its type can be realTimeType* or std::complex<realTimeType>*.

  • alloc – Optionally provides an Allocator which will be used if scratch memory is needed. If omitted, an instance of the function’s first template parameter is constructed. If that also is not specified, the default is hpk::AlignedAllocator.

template<typename inout_t, typename Smartptr>
inline void forward(inout_t *inout, const Smartptr &scratch) const noexcept#

Computes an unscaled in-place forward FFT.

Parameters:
  • inout – Pointer to the data to transform. Its type can be realTimeType* or std::complex<realTimeType>*.

  • scratch – Smart pointer (e.g., std::unique_ptr) owning scratchSize() elements of mathType to be used as needed for temporary storage in computing the FFT.

template<typename inout_t>
inline void forward(inout_t *inout, mathType *scratch) const noexcept#

Computes an unscaled in-place forward FFT.

Parameters:
  • inout – Pointer to the data to transform. Its type can be realTimeType* or std::complex<realTimeType>*.

  • scratch – Raw pointer to scratchSize() elements of mathType to be used as needed for temporary storage.

template<typename Allocator = AlignedAllocator<mathType>, typename inout_t>
inline void backward(inout_t *inout, Allocator &&alloc = Allocator()) const#

Computes an unscaled in-place backward FFT.

Parameters:
  • inout – Pointer to the data to transform. Its type can be realFreqType* or std::complex<realFreqType>*.

  • alloc – Optionally provides an Allocator which will be used if scratch memory is needed. If omitted, an instance of the function’s first template parameter is constructed. If that also is not specified, the default is hpk::AlignedAllocator.

template<typename inout_t, typename Smartptr>
inline void backward(inout_t *inout, const Smartptr &scratch) const noexcept#

Computes an unscaled in-place backward FFT.

Parameters:
  • inout – Pointer to the data to transform. Its type can be realFreqType* or std::complex<realFreqType>*.

  • scratch – Smart pointer (e.g., std::unique_ptr) owning scratchSize() elements of mathType to be used as needed for temporary storage in computing the FFT.

template<typename inout_t>
inline void backward(inout_t *inout, mathType *scratch) const noexcept#

Computes an unscaled in-place backward FFT.

Parameters:
  • inout – Pointer to the data to transform. Its type can be realFreqType* or std::complex<realFreqType>*.

  • scratch – Raw pointer to scratchSize() elements of mathType to be used as needed for temporary storage.

template<typename Allocator = AlignedAllocator<mathType>, typename inout_t>
inline void scaleForward(const mathType *scale, inout_t *inout, Allocator &&alloc = Allocator()) const#

Computes a scaled (by a real value) in-place forward FFT.

Parameters:
  • scale – Pointer to a real-valued scaling factor.

  • inout – Pointer to the data to transform. Its type can be realTimeType* or std::complex<realTimeType>*.

  • alloc – Optionally provides an Allocator which will be used if scratch memory is needed. If omitted, an instance of the function’s first template parameter is constructed. If that also is not specified, the default is hpk::AlignedAllocator.

template<typename inout_t, typename Smartptr>
inline void scaleForward(const mathType *scale, inout_t *inout, const Smartptr &scratch) const noexcept#

Computes a scaled (by a real value) in-place forward FFT.

Parameters:
  • scale – Pointer to a real-valued scaling factor.

  • inout – Pointer to the data to transform. Its type can be realTimeType* or std::complex<realTimeType>*.

  • scratch – Smart pointer (e.g., std::unique_ptr) owning scratchSize() elements of mathType to be used as needed for temporary storage in computing the FFT.

template<typename inout_t>
inline void scaleForward(const mathType *scale, inout_t *inout, mathType *scratch) const noexcept#

Computes a scaled (by a real value) in-place forward FFT.

Parameters:
  • scale – Pointer to a real-valued scaling factor.

  • inout – Pointer to the data to transform. Its type can be realTimeType* or std::complex<realTimeType>*.

  • scratch – Raw pointer to scratchSize() elements of mathType to be used as needed for temporary storage.

template<typename Allocator = AlignedAllocator<mathType>, typename inout_t>
inline void scaleBackward(const mathType *scale, inout_t *inout, Allocator &&alloc = Allocator()) const#

Computes a scaled (by a real value) in-place backward FFT.

Parameters:
  • scale – Pointer to a real-valued scaling factor.

  • inout – Pointer to the data to transform. Its type can be realFreqType* or std::complex<realFreqType>*.

  • alloc – Optionally provides an Allocator which will be used if scratch memory is needed. If omitted, an instance of the function’s first template parameter is constructed. If that also is not specified, the default is hpk::AlignedAllocator.

template<typename inout_t, typename Smartptr>
inline void scaleBackward(const mathType *scale, inout_t *inout, const Smartptr &scratch) const noexcept#

Computes a scaled (by a real value) in-place backward FFT.

Parameters:
  • scale – Pointer to a real-valued scaling factor.

  • inout – Pointer to the data to transform. Its type can be realFreqType* or std::complex<realFreqType>*.

  • scratch – Smart pointer (e.g., std::unique_ptr) owning scratchSize() elements of mathType to be used as needed for temporary storage in computing the FFT.

template<typename inout_t>
inline void scaleBackward(const mathType *scale, inout_t *inout, mathType *scratch) const noexcept#

Computes a scaled (by a real value) in-place backward FFT.

Parameters:
  • scale – Pointer to a real-valued scaling factor.

  • inout – Pointer to the data to transform. Its type can be realFreqType* or std::complex<realFreqType>*.

  • scratch – Raw pointer to scratchSize() elements of mathType to be used as needed for temporary storage.

virtual std::size_t scratchSize() const noexcept = 0#

Returns the number of mathType real elements needed as scratch space.

inline std::size_t scratchSizeBytes() const noexcept#

Returns the number of bytes needed as scratch space, sizeof(mathType) * scratchSize().

virtual int maxThreads() const = 0#

Returns an upper bound on the number of threads that could be used.

virtual std::string toString() const = 0#

Returns a short string describing the transform.

template<typename fp_t, typename time_t, typename freq_t>
inline std::ostream &operator<<(std::ostream &os, const Inplace<fp_t, time_t, freq_t> &fft)#

Overload for ostream’s << operator for an Inplace.

template<typename fp_t, typename Allocator = AlignedAllocator<fp_t>, typename time_t, typename freq_t>
inline auto allocateScratch(const Inplace<fp_t, time_t, freq_t> &fft, Allocator &&alloc = Allocator())#

Allocates scratch memory for an instance of Inplace.

Convenience function for allocating the scratch memory needed when using an instance of hpk::fft::Inplace to compute an FFT. The required memory size is obtained from fft.scratchSize(), and the return value is constructed using allocateMemory().

Example using the default AlignedAllocator:

auto factory = hpk::fft::makeFactory<float>();
auto fft = factory->makeInplace({1024});
auto scratch = allocateScratch(*fft);  // default 64B-aligned

Returns:

std::unique_ptr that owns the allocated memory