Ooplace#

#include <hpk/fft/fft.hpp>

Declares a class template for computing Fast Fourier Transforms out of place, i.e., the input data is const and the output data is written to a distinct, non-overlapping region of memory. A free function for conveniently allocating scratch memory is also provided.


TYPEDEFS

template<typename fp_t>
using hpk::fft::OoplaceCC = Ooplace<fp_t, std::complex<fp_t>, std::complex<fp_t>>#

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

template<typename fp_t>
using hpk::fft::OoplaceRC = Ooplace<fp_t, fp_t, std::complex<fp_t>>#

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


CLASS

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

Abstract class for performing Fast Fourier Transforms out-of-place.

Instances of this class are returned by the makeOoplace() function of a Factory. Note that all member functions are const-qualified. An Ooplace 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 in_t, typename out_t>
inline void forwardCopy(const in_t *in, out_t *out, Allocator &&alloc = Allocator()) const#

Computes an unscaled out-of-place forward FFT.

Parameters:
  • in – Pointer to the input data. Its type can be timeType* or realTimeType* and can be const-qualified.

  • out – Pointer to the output data to be written. Its type can be freqType* or 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 in_t, typename out_t, typename Smartptr>
inline void forwardCopy(const in_t *in, out_t *out, const Smartptr &scratch) const noexcept#

Computes an unscaled out-of-place forward FFT.

Parameters:
  • in – Pointer to the input data. Its type can be timeType* or realTimeType* and can be const-qualified.

  • out – Pointer to the output data to be written. Its type can be freqType* or 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 in_t, typename out_t>
inline void forwardCopy(const in_t *in, out_t *out, mathType *scratch) const noexcept#

Computes an unscaled out-of-place forward FFT.

Parameters:
  • in – Pointer to the input data. Its type can be timeType* or realTimeType* and can be const-qualified.

  • out – Pointer to the output data to be written. Its type can be freqType* or realFreqType*.

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

template<typename Allocator = AlignedAllocator<mathType>, typename in_t, typename out_t>
inline void backwardCopy(const in_t *in, out_t *out, Allocator &&alloc = Allocator()) const#

Computes an unscaled out-of-place backward FFT.

Parameters:
  • in – Pointer to the input data. Its type can be freqType* or realFreqType* and can be const-qualified.

  • out – Pointer to the output data to be written. Its type can be timeType* or 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 in_t, typename out_t, typename Smartptr>
inline void backwardCopy(const in_t *in, out_t *out, const Smartptr &scratch) const noexcept#

Computes an unscaled out-of-place backward FFT.

Parameters:
  • in – Pointer to the input data. Its type can be freqType* or realFreqType* and can be const-qualified.

  • out – Pointer to the output data to be written. Its type can be timeType* or 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 in_t, typename out_t>
inline void backwardCopy(const in_t *in, out_t *out, mathType *scratch) const noexcept#

Computes an unscaled out-of-place backward FFT.

Parameters:
  • in – Pointer to the input data. Its type can be freqType* or realFreqType* and can be const-qualified.

  • out – Pointer to the output data to be written. Its type can be timeType* or realTimeType*.

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

template<typename Allocator = AlignedAllocator<mathType>, typename in_t, typename out_t>
inline void scaleForwardCopy(const mathType *scale, const in_t *in, out_t *out, Allocator &&alloc = Allocator()) const#

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

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

  • in – Pointer to the input data. Its type can be timeType* or realTimeType* and can be const-qualified.

  • out – Pointer to the output data to be written. Its type can be freqType* or 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 in_t, typename out_t, typename Smartptr>
inline void scaleForwardCopy(const mathType *scale, const in_t *in, out_t *out, const Smartptr &scratch) const noexcept#

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

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

  • in – Pointer to the input data. Its type can be timeType* or realTimeType* and can be const-qualified.

  • out – Pointer to the output data to be written. Its type can be freqType* or 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 in_t, typename out_t>
inline void scaleForwardCopy(const mathType *scale, const in_t *in, out_t *out, mathType *scratch) const noexcept#

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

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

  • in – Pointer to the input data. Its type can be timeType* or realTimeType* and can be const-qualified.

  • out – Pointer to the output data to be written. Its type can be freqType* or realFreqType*.

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

template<typename Allocator = AlignedAllocator<mathType>, typename in_t, typename out_t>
inline void scaleBackwardCopy(const mathType *scale, const in_t *in, out_t *out, Allocator &&alloc = Allocator()) const#

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

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

  • in – Pointer to the input data. Its type can be freqType* or realFreqType* and can be const-qualified.

  • out – Pointer to the output data to be written. Its type can be timeType* or 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 in_t, typename out_t, typename Smartptr>
inline void scaleBackwardCopy(const mathType *scale, const in_t *in, out_t *out, const Smartptr &scratch) const noexcept#

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

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

  • in – Pointer to the input data. Its type can be freqType* or realFreqType* and can be const-qualified.

  • out – Pointer to the output data to be written. Its type can be timeType* or 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 in_t, typename out_t>
inline void scaleBackwardCopy(const mathType *scale, const in_t *in, out_t *out, mathType *scratch) const noexcept#

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

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

  • in – Pointer to the input data. Its type can be freqType* or realFreqType* and can be const-qualified.

  • out – Pointer to the output data to be written. Its type can be timeType* or realTimeType*.

  • 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 Ooplace<fp_t, time_t, freq_t> &fft)#

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

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

Allocates scratch memory for an instance of Ooplace.

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

Example using an instance of an AlignedAllocator:

auto factory = hpk::fft::makeFactory<float>();
auto fft = factory->makeOoplace({1024});
auto alloc = hpk::AlignedAllocator<float, 128>();
auto scratch = allocateScratch(*fft, alloc);  // 128B-aligned

Returns:

std::unique_ptr that owns the allocated memory