c++ - CUDA FFT 不返回我期望的值

标签 c++ cuda fft cufft

<分区>

我目前正在调试我的代码,我在其中使用 CUDA FFT 例程。

我有这样的事情(请参阅评论了解我对我所做的事情的看法):

#include <cufft.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <cuComplex.h>

void foo(double* real, double* imag, size_t size)
{
    cufftHandle plan;
    cufftDoubleComplex* inputData;
    cufftDoubleReal* outputReal;

    //Allocation of arrays:
    size_t allocSizeInput = sizeof(cufftDoubleComplex) * size;
    size_t allocSizeOutput = sizeof(cufftDoubleReal) * (size - 1) * 2;

    cudaMalloc((void**)&outputReal, allocSizeOutput);
    cudaMalloc((void**)&inputData, allocSizeInput);

    //Now I put the data in the arrays real and imag into input data by 
    //interleaving it
    cudaMemcpy2D(static_cast<void*>(inputData),
            2 * sizeof (double),
            static_cast<const void*>(real),
            sizeof(double),
            sizeof(double),
            size,
            cudaMemcpyHostToDevice);

    cudaMemcpy2D(static_cast<void*>(inputData) + sizeof(double),
            2 * sizeof (double),
            static_cast<const void*>(imag),
            sizeof(double),
            sizeof(double),
            size,
            cudaMemcpyHostToDevice);

    //I checked inputData at this point and it does indeed look like i expect it to.

    //Now I create the plan
    cufftPlan1d(&plan, size, CUFFT_Z2D, 1);

    //Now I execute the plan
    cufftExecZ2D(plan, inputData, outputReal);

    //Now I wait for device sync
    cudaDeviceSynchronize();

    //Now I fetch up the data from device
    double* outDbl = new double[(size-1)*2]
    cudaMemcpy(static_cast<void*>(outDbl),
            static_cast<void*>(outputReal),
            allocSizeOutput,
            cudaMemcpyDeviceToHost);

    //Here I am doing other fancy stuff which is not important
}

所以我现在遇到的问题是,outDbl 中的结果不是我期望的那样。例如,如果我将以下值赋给此函数:

真实 = [0 -5.567702511594111 -5.595068807897317 -5.595068807897317 -5.567702511594111]

图片 = [0 9.678604224870535 2.280007038673738 -2.280007038673738 -9.678604224870535]

我希望得到:

结果 = [-4.46511 -3.09563 -0.29805 2.51837 5.34042]

但我得到了完全不同的东西。

我做错了什么?我误解了 FFT 功能吗?基本上不是从复数到实数的逆FFT吗?我的数据复制例程有问题吗?

我必须承认我在这方面有点迷茫。

最佳答案

是的..对不起。问完问题后,我在stackoverflow上找到了答案。

参见 here

基本上:cuda fft 未标准化,因此我必须将获得的值除以元素数量以获得标准化值。

关于c++ - CUDA FFT 不返回我期望的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36617275/

相关文章:

javascript - 是否可以捕获音频并将其存储在阵列中?

c++ - MSVC++2010 中带有默认值的部分模板特化

c++ - 为什么模板化的右值引用接受左值?

c++ - 父进程和子进程的切换发生在这里?

c++ - 字符串 vector ,每个字符串的长度和 C++ 中的 strlen

c++ - CUDA 计算后数组中的重复值

cuda - 您已成功使用GPGPU吗?

Ubuntu 11.10/12.04 上的 CUDA "No compatible Device"错误

xcode - constUnsafePointer Swift FFT 中未解析的标识符

c++ - C++ 中的 FFT 和 IFFT