1

我想制作一个 python 包装的 GPU fft 函数,可以使用 scikits-cuda.cufft 计算任意大小的输入的变换。(我尝试了 PyFFT,它只需要 2 的幂)

我从 CUDA 代码建模了我的 skcuda.cufft 代码:

__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;
}

我的 skcuda.cufft 代码如下所示:

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(最近一次调用最后):

文件“”,第 1 行,在 runfile('/home/jesli/sk-cufft_test.py', wdir='/home/jesli')

文件“/home/jesli/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py”,第 580 行,运行文件 execfile(文件名,命名空间)

文件“/home/jesli/sk-cufft_test.py”,第 19 行,在 ft.cufftExecZ2Z(plan,x_gpu,xf_gpu,ft.CUFFT_FORWARD)

文件“/home/jesli/anaconda/lib/python2.7/site-packages/skcuda/cufft.py”,第 319 行,cufftExecZ2Z 方向)

ArgumentError:参数 2::错误类型

变换方向(CUFFT_FORWARDCUFFT_INVERSE)已在源代码中定义。

http://scikit-cuda.readthedocs.org/en/latest/_modules/skcuda/cufft.html

我想知道代码出了什么问题,或者函数需要什么参数。

4

0 回答 0