【发布时间】:2014-07-20 13:32:19
【问题描述】:
现在,我正在将我的 python 脚本移植到 CUDA 程序。 在我的 python 脚本中,使用了 scipy.fftpack.fft2。 为了验证 cufft 的结果,我使用 cufft 编写了示例程序。 但是,scipy.fftpack.fft2 和 cufft 之间似乎存在差异。
有什么建议吗?
python 脚本:
def test2():
g = [18,19,19,23,24,24,23,24,24]
g = numpy.array(g)
g.shape = [3,3]
G = fft2(g)
print "---------------"
print g
print G
return
python脚本的结果:
---------------
[[18 19 19]
[23 24 24]
[23 24 24]]
[[ 198.+0.j -3.+0.j -3.+0.j]
[ -15.+0.j 0.+0.j 0.+0.j]
[ -15.+0.j 0.+0.j 0.+0.j]]
cuda 程序:
cufftHandle plan;
int nRows = 3;
int nCols = 3;
cufftPlan2d(&plan, nRows, nCols, CUFFT_R2C);
float h_in[9] = {18,19,19,23,24,24,23,24,24};
float* d_in;
cudaMalloc(&d_in, sizeof(cufftComplex)*9);
cufftComplex* d_freq;
cudaMalloc(&d_freq, sizeof(cufftComplex)*9);
cudaMemcpy(d_in,h_in,sizeof( cufftComplex)*9,cudaMemcpyHostToDevice);
cufftExecR2C(inverse_plan, d_in, d_freq);
cufftComplex* h_freq = (float2*)malloc(sizeof( cufftComplex)*9);
cudaMemcpy(h_freq,d_freq,sizeof( cufftComplex)*9,cudaMemcpyDeviceToHost);
for(int i=0; i<9; i++) {
printf("%i %f %f\n", i, h_freq[i].x, h_freq[i].y);
}
cuda 程序的结果:
0 198.000000 -0.000001
1 -2.999996 -0.000001
2 -15.000000 0.000000
3 -0.000000 0.000000
4 -15.000000 0.000000
5 -0.000000 0.000000
6 497922732955248410000000000000.000000 8589934592.000000
7 572199135312371230000000000000.000000 8589934592.000000
8 -0.000000 0.000000
【问题讨论】: