Please Help,
I have been going around with this issue for a couple of days and can’t seem to understand why it is not working. I have a C-code struct which has a cufftHandle variable (fftHandle) and is defined in a separate C file (defines.cu). However when I try to access the fftHandle variable from a different C file it doesn’t work. There are no compile errors, but it doesn’t seem to work - i.e., after calling functions declared in my header file (defines.cuh) from another C file (other.cu) the values returned from GPU are always zero.
Can anyone offer any help?
The code follows:
defines.cuh
// includes for cuffs here
typedef struct{
cufftHandle fftHandle;
} myFFT;
void initFFT(myFFT *fft, const int n);
void execFFT(myFFT *fft, cuComplex *d_in, cuComplex *d_out);
defines.cu
#include "defines.cuh"
void initFFT(myFFT *fft, const int n){
cufftPlan1d(&cufft->fftHandle, n, CUFFT_C2C, 1);
}
void execFFT(myFFT *fft, cuComplex *d_in, cuComplex *d_out){
cufftExecC2C(fft->fftHandle, d_in, d_out, CUFFT_FORWARD);
}
other file: other.cu
#include "defines.cuh"
...
myFFT myfft;
const int n = 10;
cuComplex *d_in;
cuComplex *d_out;
cudaMalloc((void**)&d_in, n*sizeof(cuComplex));
cudaMalloc((void**)&d_out, n*sizeof(cuComplex));
// HOST
cuComplex *h_in;
cuComplex *h_out;
h_in = (cuComplex*)malloc(n*sizeof(cuComplex));
h_out = (cuComplex*)malloc(n*sizeof(cuComplex));
// load some data into HOST array h_in, e.g. random numbers [1-10]
// copy to DEVICE
cudaMemcpy(d_in, h_in, n*sizeof(cuComplex), cudaMemcpyHostToDevice);
// create a plan
initFFT(&myfft, n);
// execute
execFFT(&myfft, d_in, d_out);
// get result from DEVICE
cudaMemcpy(h_out, d_out, n*sizeof(cuComplex) cudaMemcpyDeviceToHost);
// at this stage h_out always has all zeros