[Beginner] Simple CUDAFFT

Hi!

I’m tried to write simple FFT test, but ran into some troubles. Here, the code:

void runTest(int argc, char** argv) 

{

	int signal_size = 128;

	cufftReal* sinus_signal;

	cutilSafeCall(cudaMalloc((void**)&sinus_signal, signal_size*sizeof(cufftReal)));

	cufftReal* cpu_sinus_signal = (cufftReal *)malloc(signal_size*sizeof(cufftReal));

	for(int i=0; i<signal_size; i++)

	{

		*(cpu_sinus_signal + i) = 100*sin(2*3.14*i/360);

	}

	cutilSafeCall(cudaMemcpy(sinus_signal, cpu_sinus_signal, signal_size*sizeof(cufftReal), cudaMemcpyHostToDevice));

	// CUFFT plan

	cufftHandle plan;

	cufftSafeCall(cufftPlan1d(&plan, signal_size, CUFFT_R2C, 1));

	cufftComplex* out_signal;

	cutilSafeCall(cudaMalloc((void**)&out_signal, signal_size*sizeof(cufftComplex)));

	// Transform signal

	cufftSafeCall(cufftExecR2C(plan, sinus_signal, out_signal));

	

	cufftComplex* cout_signal = (cufftComplex *)malloc(signal_size*sizeof(cufftComplex));

	cutilSafeCall(cudaMemcpy(cout_signal, out_signal, signal_size*sizeof(cufftComplex), cudaMemcpyDeviceToHost));

	for (int i=0; i<signal_size; i++)

	{  

        printf("Test %f \n", cout_signal[i].x);

	}

	// Destroy CUFFT context

	cufftSafeCall(cufftDestroy(plan));

	// Cleanup memory

	free(cpu_sinus_signal);

	cutilSafeCall(cudaFree(sinus_signal));

	cutilSafeCall(cudaFree(out_signal));

	cudaThreadExit();

}

It seems that cufftPlan1d function returns 0 in “plan” variable. I can’t get why this happens. I will be grateful to anyone who could explain to me where I was wrong.

Win7 x64, cuda SDK 3.2, 9600GT

Hi

When you call the plan function, does it return with an error?

My first function call to the plan also returns a 0 in the plan variable, but I simply thinks that this is because the array index of your plan will be 0. All subsequent calls are incremented by 1. Do not think of it as a pointer, it is simply a handle.

Cheers

Henrik