I described my problem here: Instability of CUFFT_R2C and CUFFT_C2R | Medical Imaging Solution
My testing codes for ifft (C2R) are attached.
using namespace std;
#include <stdio.h>
#include
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <cufft.h>
#define INFILE “x.DAT”
#define OUTFILE1 “X.DAT”
#define OUTFILE2 “xx.DAT”
#define NO_x1 (1024)
#define NO_x2 (1024)
#define NO_X1 (1024)// Run faster
#define NO_X2 (1024)
int main(int argc, char**argv){
int device,nx1,nx2;
FILE *fp;
if (cudaSetDevice(0)!=cudaSuccess){
cout<<“Error when initializing device2!”<<endl;
exit(-1);
}
cudaGetDevice(&device);
cout<<“I am occupying device-”<<device<<"; "<<endl;
float x = (cufftReal)malloc(NO_x1NO_x2sizeof(float));
cufftReal d_x;
cudaMalloc((void*)&d_x,sizeof(cufftReal)NO_x1NO_x2);
cufftComplex d_X;
cudaMalloc((void*)&d_X,sizeof(cufftComplex)NO_X1NO_X2);
cufftComplex X = (cufftComplex )malloc(NO_X1NO_X2sizeof(cufftComplex));
cufftHandle plan_cr;
if (cufftPlan2d(&plan_cr, NO_x1, NO_x2, CUFFT_C2R) != CUFFT_SUCCESS){
cout<<“CUFFT error: Plan creation failed???”<<endl;
return (1);
}
if((fp=fopen(“X.DAT”,“rb”))==NULL){
printf(“Can not open file %s.\n”,INFILE);
exit(1);
}
if (fread(X,sizeof(cufftComplex),NO_X1NO_X2,fp)!=NO_X1NO_X2){
printf(“Can not read file &s.\n”,INFILE);
exit(1);
}
fclose(fp);
cudaMemset(d_X,0,sizeof(cufftComplex)NO_X1NO_X2); // This line is for testing only
cudaMemcpy(d_X,X,sizeof(cufftComplex)513512,cudaMemcpyHostToDevice);
cudaMemset(d_x,0,sizeof(float)NO_x1NO_x2);
if (cufftExecC2R(plan_cr, d_X, d_x) != CUFFT_SUCCESS){
cout<<“CUFFT error: ExecR2C forward failed”<<endl;
return;
}
cudaMemcpy(x,d_x,sizeof(float)NO_x1NO_x2,cudaMemcpyDeviceToHost);
if ((fp=fopen(“xestimate.DAT”,“wb”))==NULL){
cout<<"Can not open file "<<OUTFILE1<<endl;
exit(0);
}
fwrite(x,sizeof(float),NO_x1*NO_x2,fp);
fclose(fp);
free(x);
free(X);
cudaFree(d_X);cudaFree(d_x);
cufftDestroy(plan_cr);
cudaThreadExit();
return(0);
}