Skip to content

Commit 3806f06

Browse files
committed
FFT cache disable support. Move czt from fft module.
1 parent ab2f457 commit 3806f06

File tree

4 files changed

+44
-28
lines changed

4 files changed

+44
-28
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ set(DSPLIB_SOURCES
4343
lib/resample/resample.cpp
4444
lib/fft.cpp
4545
lib/ifft.cpp
46+
lib/czt.cpp
4647
)
4748

4849
if (DSPLIB_EXCLUDE_FFT)
4950
message(STATUS "dsplib: use custom fft implementation")
5051
else()
5152
list(APPEND DSPLIB_SOURCES
52-
lib/fft/czt.cpp
5353
lib/fft/fact-fft.cpp
5454
lib/fft/factory.cpp
5555
lib/fft/pow2-fft.cpp

include/dsplib/czt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace dsplib {
77

88
class CztPlanImpl;
99

10-
class CztPlan : public BaseFftPlanC
10+
class CztPlan : public FftPlanC
1111
{
1212
public:
1313
explicit CztPlan(int n, int m, cmplx_t w, cmplx_t a = 1);
File renamed without changes.

lib/fft/factory.cpp

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace {
2121

2222
constexpr int FFT_CACHE_SIZE = DSPLIB_FFT_CACHE_SIZE;
2323

24-
static_assert(FFT_CACHE_SIZE > 0);
24+
static_assert(FFT_CACHE_SIZE >= 0);
2525

2626
//TODO: common plan for complex fft/ifft
2727

@@ -62,48 +62,64 @@ std::shared_ptr<FftPlanC> fft_plan_c(int n) {
6262
return std::make_shared<SmallFftC>(n);
6363
}
6464

65-
//TODO: use weak_ptr cache to prevent duplication
66-
thread_local LRUCache<int, std::shared_ptr<FftPlanC>> cache{FFT_CACHE_SIZE};
67-
if (!cache.exists(n)) {
68-
auto plan = _get_fft_plan(n);
69-
cache.put(n, plan);
70-
return plan;
65+
if constexpr (FFT_CACHE_SIZE > 0) {
66+
//TODO: use weak_ptr cache to prevent duplication
67+
thread_local LRUCache<int, std::shared_ptr<FftPlanC>> cache{FFT_CACHE_SIZE};
68+
if (!cache.exists(n)) {
69+
auto plan = _get_fft_plan(n);
70+
cache.put(n, plan);
71+
return plan;
72+
}
73+
return cache.get(n);
74+
} else {
75+
return _get_fft_plan(n);
7176
}
72-
return cache.get(n);
7377
}
7478

7579
std::shared_ptr<FftPlanR> fft_plan_r(int n) {
7680
if (SmallFftR::is_supported(n)) {
7781
return std::make_shared<SmallFftR>(n);
7882
}
7983

80-
thread_local LRUCache<int, std::shared_ptr<FftPlanR>> cache{FFT_CACHE_SIZE};
81-
if (!cache.exists(n)) {
82-
auto plan = _get_rfft_plan(n);
83-
cache.put(n, plan);
84-
return plan;
84+
if constexpr (FFT_CACHE_SIZE > 0) {
85+
thread_local LRUCache<int, std::shared_ptr<FftPlanR>> cache{FFT_CACHE_SIZE};
86+
if (!cache.exists(n)) {
87+
auto plan = _get_rfft_plan(n);
88+
cache.put(n, plan);
89+
return plan;
90+
}
91+
return cache.get(n);
92+
} else {
93+
return _get_rfft_plan(n);
8594
}
86-
return cache.get(n);
8795
}
8896

8997
std::shared_ptr<IfftPlanC> ifft_plan_c(int n) {
90-
thread_local LRUCache<int, std::shared_ptr<IfftPlanC>> cache{FFT_CACHE_SIZE};
91-
if (!cache.exists(n)) {
92-
auto plan = _get_ifft_plan(n);
93-
cache.put(n, plan);
94-
return plan;
98+
if constexpr (FFT_CACHE_SIZE > 0) {
99+
thread_local LRUCache<int, std::shared_ptr<IfftPlanC>> cache{FFT_CACHE_SIZE};
100+
if (!cache.exists(n)) {
101+
auto plan = _get_ifft_plan(n);
102+
cache.put(n, plan);
103+
return plan;
104+
}
105+
return cache.get(n);
106+
} else {
107+
return _get_ifft_plan(n);
95108
}
96-
return cache.get(n);
97109
}
98110

99111
std::shared_ptr<IfftPlanR> ifft_plan_r(int n) {
100-
thread_local LRUCache<int, std::shared_ptr<IfftPlanR>> cache{FFT_CACHE_SIZE};
101-
if (!cache.exists(n)) {
102-
auto plan = _get_irfft_plan(n);
103-
cache.put(n, plan);
104-
return plan;
112+
if constexpr (FFT_CACHE_SIZE > 0) {
113+
thread_local LRUCache<int, std::shared_ptr<IfftPlanR>> cache{FFT_CACHE_SIZE};
114+
if (!cache.exists(n)) {
115+
auto plan = _get_irfft_plan(n);
116+
cache.put(n, plan);
117+
return plan;
118+
}
119+
return cache.get(n);
120+
} else {
121+
return _get_irfft_plan(n);
105122
}
106-
return cache.get(n);
107123
}
108124

109125
} // namespace dsplib

0 commit comments

Comments
 (0)