Hi all, i’m new in cuda programming, i need to use CUFFT v 2.3 with number of points that are not a power of two (e.g 240). I need to pad the input array? If yes how?
this is my code :
[codebox]#include <stdio.h>
#include <math.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <cufft.h>
#define NX 240
#define NY 240
int main(int argc, char *argv)
{
cufftHandle plan;
cufftDoubleComplex *devPtr;
cufftDoubleComplex data[NX*NY];
cufftDoubleComplex** dataK;
int i;
/* source odata creation */
for(i= 0 ; i < NX*NY ; i++){
data[i].x = 1;
data[i].y = 1;
}
/* GPU memory allocation */
cudaMalloc((void**)&devPtr, sizeof(cufftDoubleComplex)*NX*NY);
/* transfer to GPU memory */
cudaMemcpy(devPtr, data, sizeof(cufftDoubleComplex)*NX*NY, cudaMemcpyHostToDevice);
/* creates 1D FFT plan */
cufftPlan2d(&plan, NX,NY, CUFFT_Z2Z);
/* executes FFT processes */
cufftExecZ2Z(plan, (cufftDoubleComplex *)devPtr, (cufftDoubleComplex *)devPtr, CUFFT_FORWARD);
/* transfer results from GPU memory */
cudaMemcpy(data,(cufftDoubleComplex *)devPtr, sizeof(cufftDoubleComplex)*NX*NY, cudaMemcpyDeviceToHost);
/* deletes CUFFT plan */
cufftDestroy(plan);
/* frees GPU memory */
cudaFree(devPtr);
for(i = 0 ; i < 10 ; i++){
printf("data[%d] %f %f\n", i, data[i].x, data[i].y);
}
return 0;
}
[/codebox]
With this input i’ve this output :
[codebox]data[0] 57600.000000 57600.000000
data[1] 0.000000 -0.000000
data[2] -0.000000 -0.000000
data[3] -0.000000 -0.000000
data[4] -0.000000 -0.000000
data[5] -0.000000 -0.000000
data[6] 0.000000 -0.000000
data[7] -0.000000 -0.000000
data[8] -0.000000 -0.000000
data[9] -0.000000 -0.000000
[/codebox]
with NX=NY=128 i got this :
[codebox]data[0] 16384.000000 16384.000000
data[1] 0.000000 0.000000
data[2] 0.000000 0.000000
data[3] 0.000000 0.000000
data[4] 0.000000 0.000000
data[5] 0.000000 0.000000
data[6] 0.000000 0.000000
data[7] 0.000000 0.000000
data[8] 0.000000 0.000000
data[9] 0.000000 0.000000
[/codebox]
And it seams to work
Thanks.