22 #include <lal/LALDatatypes.h>
23 #include <lal/LALMalloc.h>
24 #include <lal/RealFFT.h>
25 #include <lal/XLALError.h>
26 #include <lal/FFTWMutex.h>
33 #define UNUSED __attribute__ ((unused))
88 if( size == 1 ) createSize = 2;
89 else createSize = size;
92 cufftPlan1d( &plan->plan, createSize, CUFFT_R2C, 1 );
94 cufftPlan1d( &plan->plan, createSize, CUFFT_C2R, 1 );
114 plan->sign = ( fwdflg ? -1 : 1 );
153 cufftDestroy( plan->plan );
156 memset( plan, 0,
sizeof( *plan ) );
163 if ( !
output || ! input || ! plan )
168 if ( ! plan->size || plan->sign != -1 )
172 if ( input->
length != plan->size ||
output->length != plan->size/2 + 1 )
179 if( plan->size == 1 )
185 (cufftComplex *)(
output->data), (cufftReal *)(input->
data),
186 (cufftComplex *)plan->d_complex, (cufftReal *)plan->d_real, plan->size );
189 if( plan->size%2 == 0 )
200 if ( !
output || ! input || ! plan )
205 if ( ! plan->size || plan->sign != 1 )
209 if (
output->length != plan->size || input->
length != plan->size/2 + 1 )
211 if ( cimagf(input->
data[0]) != 0.0 )
213 if ( ! plan->size % 2 && cimagf(input->
data[plan->size/2]) != 0.0 )
220 if( plan->size == 1 )
226 (cufftReal *)(
output->data), (cufftComplex *)(input->
data),
227 (cufftReal *)plan->d_real, (cufftComplex *)plan->d_complex, plan->size );
238 if ( !
output || ! input || ! plan )
245 if ( !
output->data || ! input->data ||
output->data == input->data )
247 if (
output->length != plan->size || input->length != plan->size )
250 if( plan->size == 1 )
252 output->data[0] = input->data[0];
256 tmp =
XLALMalloc( plan->size *
sizeof(*tmp) );
258 if( plan->sign == -1 )
261 (cufftComplex *)tmp, (cufftReal *)(input->data),
262 (cufftComplex *)plan->d_complex, (cufftReal *)plan->d_real, plan->size );
263 output->data[0] = crealf(tmp[0]);
265 for( k = 1; k < (plan->size + 1)/2; k++ )
267 output->data[k] = crealf(tmp[k]);
268 output->data[plan->size - k] = cimagf(tmp[k]);
271 if( plan->size % 2 == 0 )
273 output->data[plan->size/2] = crealf(tmp[plan->size/2]);
278 tmp[0] =
crectf( input->data[0], 0.0 );
280 for( k = 1; k < (plan->size + 1)/2; k++ )
282 tmp[k] =
crectf( input->data[k], input->data[plan->size - k] );
285 if( plan->size%2 == 0 )
287 tmp[plan->size/2] =
crectf( input->data[plan->size/2], 0.0 );
291 (cufftReal *)(
output->data), (cufftComplex *)tmp,
292 (cufftReal *)plan->d_real, (cufftComplex *)plan->d_complex, plan->size );
302 const REAL4FFTPlan *plan )
307 if ( ! spec || ! data || ! plan )
316 if ( data->
length != plan->size || spec->
length != plan->size/2 + 1 )
320 tmp =
XLALMalloc( (plan->size/2 + 1) *
sizeof( *tmp ) );
325 if( plan->size == 1 )
326 tmp[0] =
crectf( data->
data[0], cimagf(tmp[0]) );
330 (cufftComplex *)(tmp), (cufftReal *)(data->
data),
331 (cufftComplex *)plan->d_complex, (cufftReal *)plan->d_real, plan->size );
336 spec->
data[0] = crealf(tmp[0]) * crealf(tmp[0]);
339 for (k = 1; k < (plan->size + 1)/2; ++k)
341 REAL4 re = crealf(tmp[k]);
342 REAL4 im = cimagf(tmp[k]);
343 spec->
data[k] = re * re + im * im;
344 spec->
data[k] *= 2.0;
348 if ( plan->size%2 == 0 )
349 spec->
data[k] = crealf(tmp[k]) * crealf(tmp[k]);
371 int flags = FFTW_UNALIGNED;
378 switch ( measurelvl )
381 flags |= FFTW_ESTIMATE;
384 flags |= FFTW_EXHAUSTIVE;
387 flags |= FFTW_PATIENT;
390 flags |= FFTW_MEASURE;
398 if ( ! plan || ! tmp1 || ! tmp2 )
408 plan->plan = fftw_plan_r2r_1d( size, tmp1, tmp2, FFTW_R2HC, flags );
410 plan->plan = fftw_plan_r2r_1d( size, tmp1, tmp2, FFTW_HC2R, flags );
428 plan->sign = ( fwdflg ? -1 : 1 );
463 fftw_destroy_plan( plan->plan );
465 memset( plan, 0,
sizeof( *plan ) );
476 if ( !
output || ! input || ! plan )
481 if ( ! plan->size || plan->sign != -1 )
485 if ( input->
length != plan->size ||
output->length != plan->size/2 + 1 )
489 tmp =
XLALMalloc( plan->size *
sizeof( *tmp ) );
494 fftw_execute_r2r( plan->plan, input->
data, tmp );
502 for ( k = 1; k < (plan->size + 1)/2; ++k )
504 output->data[k] =
crect( tmp[k], tmp[plan->size - k] );
508 if ( plan->size%2 == 0 )
510 output->data[plan->size/2] =
crect( tmp[plan->size/2], 0.0 );
523 if ( !
output || ! input || ! plan )
528 if ( ! plan->size || plan->sign != 1 )
532 if (
output->length != plan->size || input->
length != plan->size/2 + 1 )
534 if ( cimag(input->
data[0]) != 0.0 )
536 if ( ! plan->size % 2 && cimag(input->
data[plan->size/2]) != 0.0 )
540 tmp =
XLALMalloc( plan->size *
sizeof( *tmp ) );
547 tmp[0] = creal(input->
data[0]);
550 for ( k = 1; k < (plan->size + 1)/2; ++k )
552 tmp[k] = creal(input->
data[k]);
553 tmp[plan->size - k] = cimag(input->
data[k]);
557 if ( plan->size%2 == 0 )
558 tmp[plan->size/2] = creal(input->
data[plan->size/2]);
561 fftw_execute_r2r( plan->plan, tmp,
output->data );
571 if ( !
output || ! input || ! plan )
578 if ( !
output->data || ! input->data ||
output->data == input->data )
580 if (
output->length != plan->size || input->length != plan->size )
584 fftw_execute_r2r( plan->plan, input->data,
output->data );
590 const REAL8FFTPlan *plan )
595 if ( ! spec || ! data || ! plan )
604 if ( data->
length != plan->size || spec->
length != plan->size/2 + 1 )
608 tmp =
XLALMalloc( plan->size *
sizeof( *tmp ) );
613 fftw_execute_r2r( plan->plan, data->
data, tmp );
618 spec->
data[0] = tmp[0] * tmp[0];
621 for (k = 1; k < (plan->size + 1)/2; ++k)
624 REAL8 im = tmp[plan->size - k];
625 spec->
data[k] = re * re + im * im;
626 spec->
data[k] *= 2.0;
630 if ( plan->size%2 == 0 )
631 spec->
data[plan->size/2] = tmp[plan->size/2] * tmp[plan->size/2];
int cudafft_execute_c2r(cufftHandle plan, cufftReal *output, const cufftComplex *input, cufftReal *d_output, cufftComplex *d_input, UINT4 size)
int cudafft_execute_r2c(cufftHandle plan, cufftComplex *output, const cufftReal *input, cufftComplex *d_output, cufftReal *d_input, UINT4 size)
COMPLEX8 * XLALCudaMallocComplex(UINT4 size)
void XLALCudaFree(void *d_data)
REAL4 * XLALCudaMallocReal(UINT4 size)
int XLALREAL4PowerSpectrum(REAL4Vector *spec, const REAL4Vector *data, const REAL4FFTPlan *plan)
int XLALREAL8VectorFFT(REAL8Vector *_LAL_RESTRICT_ output, const REAL8Vector *_LAL_RESTRICT_ input, const REAL8FFTPlan *plan)
REAL4FFTPlan * XLALCreateREAL4FFTPlan(UINT4 size, int fwdflg, UNUSED int measurelvl)
#define LAL_FFTW_WISDOM_UNLOCK
#define LAL_FFTW_WISDOM_LOCK
#define crect(re, im)
Construct a COMPLEX16 from real and imaginary parts.
double REAL8
Double precision real floating-point number (8 bytes).
#define crectf(re, im)
Construct a COMPLEX8 from real and imaginary parts.
uint32_t UINT4
Four-byte unsigned integer.
float complex COMPLEX8
Single-precision floating-point complex number (8 bytes total)
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
int XLALREAL8ForwardFFT(COMPLEX16Vector *output, const REAL8Vector *input, const REAL8FFTPlan *plan)
Performs a forward FFT of REAL8 data.
int XLALREAL8ReverseFFT(REAL8Vector *output, const COMPLEX16Vector *input, const REAL8FFTPlan *plan)
Performs a reverse FFT of REAL8 data.
REAL4FFTPlan * XLALCreateReverseREAL4FFTPlan(UINT4 size, int measurelvl)
Returns a new REAL4FFTPlan for a reverse transform.
void XLALDestroyREAL8FFTPlan(REAL8FFTPlan *plan)
Destroys a REAL8FFTPlan.
REAL4FFTPlan * XLALCreateForwardREAL4FFTPlan(UINT4 size, int measurelvl)
Returns a new REAL4FFTPlan for a forward transform.
REAL8FFTPlan * XLALCreateReverseREAL8FFTPlan(UINT4 size, int measurelvl)
Returns a new REAL8FFTPlan for a reverse transform.
int XLALREAL8PowerSpectrum(REAL8Vector *spec, const REAL8Vector *data, const REAL8FFTPlan *plan)
Computes the power spectrum of REAL8 data.
void XLALDestroyREAL4FFTPlan(REAL4FFTPlan *plan)
Destroys a REAL4FFTPlan.
REAL8FFTPlan * XLALCreateREAL8FFTPlan(UINT4 size, int fwdflg, int measurelvl)
Returns a new REAL8FFTPlan.
int XLALREAL4VectorFFT(REAL4Vector *_LAL_RESTRICT_ output, const REAL4Vector *_LAL_RESTRICT_ input, const REAL4FFTPlan *plan)
Perform a REAL4Vector to REAL4Vector FFT.
int XLALREAL4ReverseFFT(REAL4Vector *output, const COMPLEX8Vector *input, const REAL4FFTPlan *plan)
Performs a reverse FFT of REAL4 data.
REAL8FFTPlan * XLALCreateForwardREAL8FFTPlan(UINT4 size, int measurelvl)
Returns a new REAL8FFTPlan for a forward transform.
int XLALREAL4ForwardFFT(COMPLEX8Vector *output, const REAL4Vector *input, const REAL4FFTPlan *plan)
Performs a forward FFT of REAL4 data.
#define XLAL_ERROR_VOID(...)
Macro to invoke a failure from a XLAL routine returning void.
#define XLAL_ERROR_NULL(...)
Macro to invoke a failure from a XLAL routine returning a pointer.
#define XLAL_ERROR(...)
Macro to invoke a failure from a XLAL routine returning an integer.
@ XLAL_EBADLEN
Inconsistent or invalid length.
@ XLAL_ENOMEM
Memory allocation error.
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EDOM
Input domain error.
@ XLAL_EINVAL
Invalid argument.
Vector of type COMPLEX16, see DATATYPE-Vector types for more details.
UINT4 length
Number of elements in array.
COMPLEX16 * data
Pointer to the data array.
Vector of type COMPLEX8, see DATATYPE-Vector types for more details.
UINT4 length
Number of elements in array.
COMPLEX8 * data
Pointer to the data array.
Vector of type REAL4, see DATATYPE-Vector types for more details.
REAL4 * data
Pointer to the data array.
UINT4 length
Number of elements in array.
Vector of type REAL8, see DATATYPE-Vector types for more details.
REAL8 * data
Pointer to the data array.
UINT4 length
Number of elements in array.
Plan to perform FFT of REAL4 data.
INT4 sign
sign in transform exponential, -1 for forward, +1 for reverse
UINT4 size
length of the real data vector for this plan
Plan to perform FFT of REAL8 data.
UINT4 size
length of the real data vector for this plan
fftw_plan plan
the FFTW plan
INT4 sign
sign in transform exponential, -1 for forward, +1 for reverse
void output(int gps_sec, int output_type)