From 3d5e9290ff75326709185a564096fc236857b756 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Sun, 1 Mar 2020 15:04:51 +0100 Subject: [PATCH] Wrapped the functions of FFTW to load and store wisdom. --- lasp/c/lasp_fft.c | 20 ++++++++++++++++++++ lasp/c/lasp_fft.h | 17 +++++++++++++++++ lasp/wrappers.pyx | 23 +++++++++++++++++++++-- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/lasp/c/lasp_fft.c b/lasp/c/lasp_fft.c index 4a05be7..b1673fd 100644 --- a/lasp/c/lasp_fft.c +++ b/lasp/c/lasp_fft.c @@ -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) { diff --git a/lasp/c/lasp_fft.h b/lasp/c/lasp_fft.h index 5da9e1d..701f658 100644 --- a/lasp/c/lasp_fft.h +++ b/lasp/c/lasp_fft.h @@ -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. * diff --git a/lasp/wrappers.pyx b/lasp/wrappers.pyx index 5fb4920..bd6c53e 100644 --- a/lasp/wrappers.pyx +++ b/lasp/wrappers.pyx @@ -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( &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