Wrapped the functions of FFTW to load and store wisdom.

This commit is contained in:
Anne de Jong 2020-03-01 15:04:51 +01:00
parent 82e077ec3a
commit 3d5e9290ff
3 changed files with 58 additions and 2 deletions

View File

@ -28,6 +28,26 @@ typedef struct Fft_s {
#endif
void load_fft_wisdom(const char* wisdom) {
#ifdef LASP_FFT_BACKEND_FFTPACK
#elif defined LASP_FFT_BACKEND_FFTW
if(wisdom) {
int rv= fftw_import_wisdom_from_string(wisdom);
if(rv != 1) {
fprintf(stderr, "Error loading FFTW wisdom");
}
}
#endif
}
char* store_fft_wisdom() {
#ifdef LASP_FFT_BACKEND_FFTPACK
return NULL;
#elif defined LASP_FFT_BACKEND_FFTW
return fftw_export_wisdom_to_string();
#endif
}
Fft* Fft_create(const us nfft) {
fsTRACE(15);
if(nfft == 0) {

View File

@ -11,6 +11,23 @@
#include "lasp_types.h"
#include "lasp_mat.h"
/**
* Load wisdom data from a NULL-terminated character string. Note that at this
* point in time this is only used by the FFTW fft backend.
*
* @param[in] wisdom: Wisdom string
*/
void load_fft_wisdom(const char* wisdom);
/**
* Creates a NULL-terminated string containing FFTW wisdom, or state knowledge
* from other libraries.
*
* @returns A NULL-terminated string. *Should be deallocated after being used*
*/
char* store_fft_wisdom(void);
/**
* Perform forward FFT's on real time data.
*

View File

@ -67,14 +67,15 @@ cdef extern from "lasp_python.h":
__all__ = ['AvPowerSpectra', 'SosFilterBank', 'FilterBank', 'Siggen',
'sweep_flag_forward', 'sweep_flag_backward', 'sweep_flag_linear',
'sweep_flag_exponential', 'sweep_flag_hyperbolic']
'sweep_flag_exponential', 'sweep_flag_hyperbolic',
'load_fft_wisdom', 'store_fft_wisdom']
setTracerLevel(15)
cdef extern from "cblas.h":
int openblas_get_num_threads()
void openblas_set_num_threads(int)
# If we touch this variable: we get segfaults when running from
# Spyder!
# openblas_set_num_threads(8)
@ -86,6 +87,8 @@ def cls():
# cls()
cdef extern from "lasp_fft.h":
void c_load_fft_wisdom "load_fft_wisdom" (const char* wisdom)
char* c_store_fft_wisdom "store_fft_wisdom" ()
ctypedef struct c_Fft "Fft"
c_Fft* Fft_create(us nfft)
void Fft_free(c_Fft*)
@ -93,8 +96,24 @@ cdef extern from "lasp_fft.h":
void Fft_ifft(c_Fft*,cmat * freqdata,dmat* timedata) nogil
us Fft_nfft(c_Fft*)
def load_fft_wisdom(const unsigned char[::1] wisdom):
c_load_fft_wisdom(<const char*> &wisdom[0])
from cpython cimport PyBytes_FromString
from libc.stdlib cimport free
def store_fft_wisdom():
cdef char* wisdom = c_store_fft_wisdom()
if wisdom != NULL:
try:
bts = PyBytes_FromString(wisdom)
finally:
free(wisdom)
return bts
else:
return None
cdef class Fft:
cdef:
c_Fft* _fft