Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix max fft size fiasco #281

Merged
merged 3 commits into from
Oct 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions include/algorithms/util/FFT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ under the European Union’s Horizon 2020 research and innovation programme
#include "../../data/FluidMemory.hpp"
#include <Eigen/Core>
#include <fft/fft.hpp>
#include <optional>

namespace fluid {
namespace algorithm {
Expand All @@ -38,8 +39,8 @@ class FFTSetup
FFTSetup(FFTSetup const&) = delete;
FFTSetup& operator=(FFTSetup const&) = delete;

FFTSetup(FFTSetup&& other) { *this = std::move(other); };
FFTSetup& operator=(FFTSetup&& other)
FFTSetup(FFTSetup&& other) noexcept { *this = std::move(other); };
FFTSetup& operator=(FFTSetup&& other) noexcept
{
using std::swap;
swap(mMaxSize, other.mMaxSize);
Expand All @@ -62,13 +63,13 @@ class FFT
public:
using MapXcd = Eigen::Map<Eigen::ArrayXcd>;

static void setup() { getFFTSetup(); }

FFT() = delete;

FFT(index size, Allocator& alloc = FluidDefaultAllocator()) noexcept
: mMaxSize(size), mSize(size), mFrameSize(size / 2 + 1),
mLog2Size(static_cast<index>(std::log2(size))), mSetup(getFFTSetup()),
mLog2Size(static_cast<index>(std::log2(size))),
mSetup(getFFTSetup(*this, size)),
mRealBuffer(asUnsigned(mFrameSize), alloc),
mImagBuffer(asUnsigned(mFrameSize), alloc),
mOutputBuffer(asUnsigned(mFrameSize), alloc)
Expand Down Expand Up @@ -106,11 +107,18 @@ class FFT
return {mOutputBuffer.data(), mFrameSize};
}

private:
std::optional<impl::FFTSetup> mLocalSetup;
protected:
static htl::setup_type<double> getFFTSetup()
{
static const impl::FFTSetup static_setup(65536);
return static_setup();
static constexpr index default_max = 65536;
static htl::setup_type<double> getFFTSetup(FFT& _this, index size)
{
static const impl::FFTSetup static_setup(default_max);
if(size <= default_max) return static_setup();
else {
_this.mLocalSetup = std::optional<impl::FFTSetup>(size);
return _this.mLocalSetup->operator()();
}
}

index mMaxSize{16384};
Expand All @@ -127,6 +135,7 @@ class FFT
rt::vector<std::complex<double>> mOutputBuffer;
};


class IFFT : public FFT
{

Expand Down
Loading