CUDA fft 1d 来自 MATLAB fft 的不同结果
CUDA fft 1d different results from MATLAB fft
我想使用 GPU 来加速我的 matlab 程序,但我发现了一个问题。
fft 结果从 CUDA 到 matlab 是不同的。
我已经尝试了很多次,但无法解决。
所以我来这里寻求帮助。
原始数据: name:cj1;size:1*8
在 matlab 中使用代码:
a1=fft(cj1)';
得到结果:
the fft result of matlab
和cuda代码:
cuFloatComplex *idata_m;
idata_m = (cuFloatComplex*)malloc(M * sizeof(cuFloatComplex));
for (int i = 0; i < 8; i++)
{
idata_m[i].x = initA[i];
idata_m[i].y = initB[i];
}
cuComplex *dev_test;
cudaMalloc((void**)&dev_test, M * sizeof(cuFloatComplex));
cudaMemcpy(dev_test, idata_m, M * sizeof(cuFloatComplex), cudaMemcpyHostToDevice);
cufftHandle plantest;
cufftPlan1d(&plantest, 8, CUFFT_C2C, 1);
cufftExecC2C(plantest, dev_test, dev_test, CUFFT_FORWARD);//forward
cuComplex *test_out;
test_out = (cuFloatComplex*)malloc( M * sizeof(cuFloatComplex));
cudaMemcpy(test_out, dev_test, 8 * sizeof(cuFloatComplex), cudaMemcpyDeviceToHost);
the input data is the same to the original data in matlab
the fft result of cuda
最有趣的是这两个结果非常相似但是顺序错误。
那我该怎么做才能使结果与matlab的结果相同呢?
用于 CUDA 代码的输入数据的虚部是用于 Matlab 的负数。所以你真的在计算复数共轭输入的 FFT,inverts the order of the result。要使用 CUDA 获得相同的结果,您应该使用相同的输入。
另外值得注意的是,在 Matlab 中,'
运算符计算 complex-conjugate 转置,因此您可能希望将 CUDA 结果与 a1=transpose(fft(cj1));
进行比较。
我想使用 GPU 来加速我的 matlab 程序,但我发现了一个问题。 fft 结果从 CUDA 到 matlab 是不同的。 我已经尝试了很多次,但无法解决。 所以我来这里寻求帮助。
原始数据: name:cj1;size:1*8
在 matlab 中使用代码:
a1=fft(cj1)';
得到结果: the fft result of matlab
和cuda代码:
cuFloatComplex *idata_m;
idata_m = (cuFloatComplex*)malloc(M * sizeof(cuFloatComplex));
for (int i = 0; i < 8; i++)
{
idata_m[i].x = initA[i];
idata_m[i].y = initB[i];
}
cuComplex *dev_test;
cudaMalloc((void**)&dev_test, M * sizeof(cuFloatComplex));
cudaMemcpy(dev_test, idata_m, M * sizeof(cuFloatComplex), cudaMemcpyHostToDevice);
cufftHandle plantest;
cufftPlan1d(&plantest, 8, CUFFT_C2C, 1);
cufftExecC2C(plantest, dev_test, dev_test, CUFFT_FORWARD);//forward
cuComplex *test_out;
test_out = (cuFloatComplex*)malloc( M * sizeof(cuFloatComplex));
cudaMemcpy(test_out, dev_test, 8 * sizeof(cuFloatComplex), cudaMemcpyDeviceToHost);
the input data is the same to the original data in matlab
the fft result of cuda
最有趣的是这两个结果非常相似但是顺序错误。 那我该怎么做才能使结果与matlab的结果相同呢?
用于 CUDA 代码的输入数据的虚部是用于 Matlab 的负数。所以你真的在计算复数共轭输入的 FFT,inverts the order of the result。要使用 CUDA 获得相同的结果,您应该使用相同的输入。
另外值得注意的是,在 Matlab 中,'
运算符计算 complex-conjugate 转置,因此您可能希望将 CUDA 结果与 a1=transpose(fft(cj1));
进行比较。