GPU FFT

最近用到FFT了。cuda里有GPUFFT的函数,不过是C的。最近找了个封装,还挺好用。具体效率没测过,主要是内存和显存之间来回传递比较费时间吧。代码如下:

CudafyModule km = CudafyTranslator.Cudafy();
 
            GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target);
            gpu.LoadModule(km);
 
            ComplexD[] cm = new ComplexD[4];
            cm[0] = new ComplexD(1.5, 1);
            cm[1] = new ComplexD(2.5, 2);
            cm[2] = new ComplexD(3.5, 3);
            cm[3] = new ComplexD(4.5, 4);
            ComplexD[] dev_cm = gpu.CopyToDevice(cm);
 
            ComplexD[] ifftData = new ComplexD[4];
            ComplexD[] dev_ifftData = gpu.CopyToDevice(ifftData);
 
            Cudafy.Maths.FFT.GPGPUFFT gpuFFT = Cudafy.Maths.FFT.GPGPUFFT.Create(gpu);
            Cudafy.Maths.FFT.FFTPlan1D fft_1d = gpuFFT.Plan1D(Cudafy.Maths.FFT.eFFTType.Complex2Complex, Cudafy.Maths.FFT.eDataType.Double, 4, 1);
 
            fft_1d.Execute<ComplexD, ComplexD>(dev_cm, dev_ifftData, true);
            gpu.CopyFromDevice(dev_ifftData, ifftData);
 
            gpu.FreeAll();

你可能感兴趣的:(GPU;FFT)