I want to make a python-wrapped GPU fft function that can compute the transforms of arbitrary sized inputs using scikits-cuda.cufft. (I tried PyFFT which only takes powers of 2)
I modeled my skcuda.cufft code from the CUDA code:
__host__ cuDoubleComplex* FFT(cuDoubleComplex *data, int NX){
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start, 0);
cuDoubleComplex *d_data;
cudaMalloc((void **)&d_data,NX*sizeof(cuDoubleComplex));
cufftHandle plan;
cufftPlan1d(&plan,NX,CUFFT_Z2Z,1);
cudaMemcpy(d_data, data, NX*sizeof(cuDoubleComplex), cudaMemcpyHostToDevice);
cufftExecZ2Z(plan,d_data,d_data,CUFFT_FORWARD);
cudaMemcpy(data,d_data,NX*sizeof(cuDoubleComplex),cudaMemcpyDeviceToHost);
cufftDestroy(plan);
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
float elapsedTime;
cudaEventElapsedTime(&elapsedTime, start, stop);
printf("\n Elapsed Time: %3.1f ms\n", elapsedTime);
cudaFree(d_data);
return data;
}
and my skcuda.cufft code looks like:
import skcuda.cufft as ft
import pycuda.autoinit
import pycuda.gpuarray as gpuarray
import numpy as np
N=100
x=np.array(np.random.random(N),np.float32)
x_gpu=gpuarray.to_gpu(x)
xf_gpu = gpuarray.empty(N,np.complex64)
plan=ft.cufftPlan1d(N,ft.CUFFT_Z2Z,1)
ft.cufftExecZ2Z(plan,x_gpu,xf_gpu,ft.CUFFT_FORWARD)
ft.cufftDestroy(plan)
xf=x_gpu.get()
but it gives the error:
runfile('/home/jesli/sk-cufft_test.py', wdir='/home/jesli') Traceback (most recent call last):
File "", line 1, in runfile('/home/jesli/sk-cufft_test.py', wdir='/home/jesli')
File "/home/jesli/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 580, in runfile execfile(filename, namespace)
File "/home/jesli/sk-cufft_test.py", line 19, in ft.cufftExecZ2Z(plan,x_gpu,xf_gpu,ft.CUFFT_FORWARD)
File "/home/jesli/anaconda/lib/python2.7/site-packages/skcuda/cufft.py", line 319, in cufftExecZ2Z direction)
ArgumentError: argument 2: : wrong type
The transform directions (CUFFT_FORWARD,CUFFT_INVERSE) are already defined in the source code.
http://scikit-cuda.readthedocs.org/en/latest/_modules/skcuda/cufft.html
I want to know what went wrong with the code, or what argument the function expects.