【问题标题】:CUDA FFT does not return the values I expect [duplicate]CUDA FFT 不返回我期望的值[重复]
【发布时间】:2016-04-14 16:23:40
【问题描述】:

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

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

#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吗?我的数据复制例程有问题吗?

我必须承认我对这个有点迷茫。

【问题讨论】:

    标签: c++ cuda fft cufft


    【解决方案1】:

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

    here

    基本上:cuda fft 没有标准化,所以我必须将得到的值除以元素的数量才能得到标准化的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-07
      • 2014-05-02
      • 2020-12-24
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 2016-11-22
      • 1970-01-01
      相关资源
      最近更新 更多