2016-04-14 10 views
1

現在、CUDA FFTルーチンを使用している私のコードをデバッグしています。CUDA FFTが期待した値を返さない

私はこのような何か(私は何をすべきかについて私の考えのためのコメントを参照してください)があります。だから私は今持っている問題はoutDblの結果が、私は彼らがあることを期待するものではないこと、である

#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 
} 

を。例えば、私はこの機能には以下の値を与える場合:

実= [0 -5.567702511594111 -5.595068807897317 -5.595068807897317 -5.567702511594111]

IMAG = [0 9.678604224870535 2.280007038673738 -2.280007038673738 -9.678604224870535]

は私が得ることを期待:

解像度をult = [-4.46511-3.09563 -0.29805 2.51837 5.34042]

しかし、私は全く別のものを手に入れます。

どうすればいいですか?私はFFT機能を誤解しましたか?基本的に複合FFTから実数への逆FFTではありませんか?データコピールーチンに問題はありますか?

私はこのことで少し失われていることを認めなければなりません。

答えて

1

うん、申し訳ありません。私は質問をした後、stackoverflowの答えが見つかりました。

here

基本的に参照:CUDAのFFTが正規化されていないので、私は正規化された値を取得するための要素の数でIが得る値を分割しなければなりません。

関連する問題