Fourier transform-fft (Cuda implementation)

Source: Internet
Author: User

Background:

Inadvertently see Cuda solution FFT has a Cufft function library, a general view of the relevant knowledge of Cufft, wrote a solution to a one-dimensional cuda code, according to the investigation know Cufft in the resolution of the situation 1d,2d,3d the complexity of the time is O (Nlogn), attached to solve One-dimensional code, ready to find some detailed information to learn about Cuda's library of functions.

#include"stdio.h"#include"cuda_runtime.h"#include"cufft.h"#include"Device_launch_parameters.h"#defineLENGTH 4intMain () {
floatData[length] = {1,2,3,4}; Cufftcomplex*compdata= (cufftcomplex*)malloc(length*sizeof(Cufftcomplex)); inti; for(i=0; i<length;i++) {compdata[i].x=Data[i]; Compdata[i].y=0; }Cufftcomplex*D_fftdata; Cudamalloc ((void* *) &d_fftdata,length*sizeof(Cufftcomplex)); cudamemcpy (D_fftdata,compdata,length*sizeof(Cufftcomplex), cudamemcpyhosttodevice); Cuffthandle plan; CUFFTPLAN1D (&AMP;PLAN,LENGTH,CUFFT_C2C,1); CUFFTEXECC2C (Plan, (Cufftcomplex*) D_fftdata, (cufftcomplex*) D_fftdata,cufft_forward); Cudadevicesynchronize (); cudamemcpy (Compdata,d_fftdata,length*sizeof(Cufftcomplex), cudamemcpydevicetohost); for(i=0; i<length;i++) { if(compdata[i].x! =0) {printf ("%3.1f", compdata[i].x); } if(Compdata[i].y! =0) {printf ("+%3.1fi", COMPDATA[I].Y); } printf ("\ n"); } Cufftdestroy (plan); Free(Compdata); Cudafree (D_fftdata);}

This code that runs under Linux:

Compile command: Nvcc-o fftcu fft.cu-i/usr/local/cuda/include-l/usr/local/cuda/lib64-lcufft

Run command:./FFTCU

Note: There are cufft.h header files in/usr/local/cuda/include, libcufft.so library files in/usr/local/cuda/lib64

Fourier transform-fft (Cuda implementation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.