I’m the basic user about nvidia. Sorry to my short English.
These days I tried to 2d cufft using rawfile but failed to do the fft.
Raw file’s inpormation : data type : unsigned char
size:256*256
I followed CUDA CUFFT Library pdf file…
Is there anyone who can solve my problem?
Below is my code. I hope somebody help me. Thank you for reading this.
(When I checked a odata, that is not correct…)
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cufft.h>
#include <cutil_inline.h>
void runTest(int argc, char** argv);
int main(int argc, char** argv)
{
runTest(argc, argv);
cutilExit(argc, argv);
}
void runTest(int argc, char** argv)
{
if( cutCheckCmdLineFlag(argc, (const char**)argv, “device”) )
cutilDeviceInit(argc, argv);
else
cudaSetDevice( cutGetMaxGflopsDeviceId() );
cufftComplex *idata=(cufftComplex*)malloc(sizeof(cufftComplex)*NX*NY);
cufftComplex *odata=(cufftComplex*)malloc(sizeof(cufftComplex)*NX*NY);
cufftComplex *d_idata;
cufftComplex *d_odata;
cutilSafeCall(cudaMalloc((void**)&d_odata,sizeof(cufftComplex)*NX*NY));
cufftHandle plan;
unsigned char *rawdata= (unsigned char*)malloc(sizeof(unsigned char) * NX*NY);
FILE *infile;
infile=fopen("Lena_256.raw","rb");
if(infile==NULL){
printf("File not found! \n");
}
fread(rawdata,sizeof(unsigned char),NX*NY,infile);
fclose(infile);
for(int i=0; i<NX*NY; i++)
{
idata[i].x=float(rawdata[i]);
idata[i].y=0.0f;
}
unsigned int timer = 0;
cutilCheckError(cutCreateTimer(&timer));
cutilCheckError(cutStartTimer(timer));
cufftPlan2d(&plan,NX,NY,CUFFT_C2C);
cufftExecC2C(plan,d_idata,odata,CUFFT_FORWARD);
cutilCheckError(cutStopTimer(timer));
printf("Processing time: %f (ms) \n", cutGetTimerValue(timer));
cutilCheckError(cutDeleteTimer(timer));
cufftDestroy(plan);
free(idata);
free(odata);
cudaThreadExit();
}