我想做一个python包装的GPU fft函数,可以使用sciket计算任意大小输入的变换-库达·库夫特. (我试过只取2次方幂的PyFFT)
我模仿我的斯库达·库夫特CUDA代码:
__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;
}
还有我的斯库达·库夫特代码如下所示:
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()
但它给出了一个错误:
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
变换方向(CUFFT\u FORWARD,CUFFT\u INVERSE)已经在源代码中定义。你知道吗
http://scikit-cuda.readthedocs.org/en/latest/_modules/skcuda/cufft.html
我想知道代码出了什么问题,或者函数需要什么参数。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐