現在、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]
imag = [0 9.678604224870535 2.280007038673738 -2.280007038673738 -9.678604224870535]
私は得ることを期待しています:
結果 = [-4.46511 -3.09563 -0.29805 2.51837 5.34042]
しかし、私はまったく違うものを手に入れます。
私は何を間違っていますか?FFT関数を誤解していませんか?基本的には複素数から実数への逆FFTではないでしょうか? データ コピー ルーチンに問題はありますか?
私はこれについて少し迷っていることを認めなければなりません。