LAL  7.5.0.1-ec27e42
CudaFFT.cu
Go to the documentation of this file.
1 #include <lal/LALDatatypes.h>
2 #include "CudaFunctions.h"
3 
4 void XLALCudaError(cudaError_t error, const char *file, int line)
5 {
6  if(error != cudaSuccess)
7  {
8  fprintf( stderr, "%s:%d %s\n", file, line, cudaGetErrorString(error));
9  exit(1);
10  }
11 }
12 
13 void XLALCudaFFTError(cufftResult_t error, const char *file, int line)
14 {
15  if(error != CUFFT_SUCCESS)
16  {
17  /* As there are no GetErrorString function available for CUDA FFT,
18  * the error messages had to be hard-coded,
19  * and needs to be updated with new CUDA releases.
20  */
21  switch( error )
22  {
23  case CUFFT_INVALID_PLAN:
24  fprintf( stderr, "%s:%d The plan handle is invalid\n", file, line );
25  break;
26 
27  case CUFFT_INVALID_VALUE:
28  fprintf( stderr, "%s:%d The input data and/or output data is not valid\n", file, line );
29  break;
30 
31  case CUFFT_INTERNAL_ERROR:
32  fprintf( stderr, "%s:%d Internal driver error is detected\n", file, line );
33  break;
34 
35  case CUFFT_EXEC_FAILED:
36  fprintf( stderr, "%s:%d CUFFT failed to execute the transform on GPU\n", file, line );
37  break;
38 
39  case CUFFT_SETUP_FAILED:
40  fprintf( stderr, "%s:%d CUFFT library failed to initialize\n", file, line );
41  break;
42 
43  default:
44  fprintf( stderr, "%s:%d Cuda FFT Error: %d\n", file, line, error);
45  }
46  exit(1);
47  }
48 }
49 
50 int cudafft_execute_r2c(cufftHandle plan,
51  cufftComplex *output, const cufftReal *input,
52  cufftComplex *d_output, cufftReal *d_input,UINT4 size)
53 {
54  UINT4 inputBytes = size * sizeof(cufftReal);
55  UINT4 outputBytes = (size/2 + 1) * sizeof(cufftComplex);
56 
57  XLALCUDACHECK(cudaMemcpy( d_input, input, inputBytes, cudaMemcpyHostToDevice ));
58 
59  XLALCUDAFFTCHECK(cufftExecR2C(plan, d_input, d_output));
60 
61  XLALCUDACHECK(cudaMemcpy( output, d_output, outputBytes, cudaMemcpyDeviceToHost ));
62 
63  return 0;
64 }
65 
66 int cudafft_execute_c2r(cufftHandle plan,
67  cufftReal *output, const cufftComplex *input,
68  cufftReal *d_output, cufftComplex *d_input, UINT4 size)
69 {
70  UINT4 inputBytes = (size/2 + 1) * sizeof(cufftComplex);
71  UINT4 outputBytes = size * sizeof(cufftReal);
72 
73  XLALCUDACHECK(cudaMemcpy( d_input, input, inputBytes, cudaMemcpyHostToDevice ));
74 
75  XLALCUDAFFTCHECK(cufftExecC2R(plan, d_input, d_output));
76 
77  XLALCUDACHECK(cudaMemcpy( output, d_output, outputBytes, cudaMemcpyDeviceToHost ));
78 
79  return 0;
80 }
81 
82 int cudafft_execute_c2c(cufftHandle plan,
83  cufftComplex *output, const cufftComplex *input,
84  cufftComplex *d_output, cufftComplex *d_input,
85  INT4 direction, UINT4 size)
86 {
87  UINT4 nBytes = size * sizeof(cufftComplex);
88 
89  XLALCUDACHECK(cudaMemcpy( d_input, input, nBytes, cudaMemcpyHostToDevice ));
90 
91  XLALCUDAFFTCHECK(cufftExecC2C(plan, d_input, d_output, direction));
92 
93  XLALCUDACHECK(cudaMemcpy( output, d_output, nBytes, cudaMemcpyDeviceToHost ));
94 
95  return 0;
96 }
int cudafft_execute_c2r(cufftHandle plan, cufftReal *output, const cufftComplex *input, cufftReal *d_output, cufftComplex *d_input, UINT4 size)
Definition: CudaFFT.cu:66
int cudafft_execute_c2c(cufftHandle plan, cufftComplex *output, const cufftComplex *input, cufftComplex *d_output, cufftComplex *d_input, INT4 direction, UINT4 size)
Definition: CudaFFT.cu:82
void XLALCudaFFTError(cufftResult_t error, const char *file, int line)
Definition: CudaFFT.cu:13
int cudafft_execute_r2c(cufftHandle plan, cufftComplex *output, const cufftReal *input, cufftComplex *d_output, cufftReal *d_input, UINT4 size)
Definition: CudaFFT.cu:50
void XLALCudaError(cudaError_t error, const char *file, int line)
Definition: CudaFFT.cu:4
#define XLALCUDAFFTCHECK(e)
Definition: CudaFunctions.h:16
#define XLALCUDACHECK(e)
Definition: CudaFunctions.h:15
#define fprintf
static REAL8TimeSeries * error(const REAL8TimeSeries *s1, const REAL8TimeSeries *s0)
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
void output(int gps_sec, int output_type)
Definition: tconvert.c:440