Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. 1) a.cpp for loading/saving the input/output data and doing FFT/IFFT
  2. 2) b.cu for multiplying some constant (my own code)
  3.  
  4. ....
  5.  
  6.  
  7. cufftHandle forward_plan, inverse_plan;
  8.  
  9. int rank = 2;
  10. int nCols = samples;
  11. int batch = frames;
  12. int nRows = 128;
  13. int n[2] = {nRows, nCols};
  14.  
  15. int idist = nRows*nCols;
  16. int odist = nRows*(nCols/2+1);
  17.  
  18. int inembed[] = {nRows, nCols};
  19. int onembed[] = {nRows, nCols/2+1};
  20.  
  21. int istride = 1;
  22. int ostride = 1;
  23.  
  24. cufftPlanMany(&forward_plan, rank, n,
  25. inembed, istride, idist,
  26. onembed, ostride, odist,
  27. CUFFT_R2C, batch);
  28.  
  29. cufftReal *d_in;
  30. cufftComplex *d_freq;
  31. cufftComplex *outputData = (cufftComplex *)malloc(nRows*(nCols/2+1)*batch*sizeof(cufftComplex));
  32.  
  33. cudaMalloc(&d_in, sizeof(cufftReal)*nRows*nCols*batch);
  34. cudaMAlloc(&d_freq, sizeof(cufftComplex)*nRows*(nCols/2+1)*batch);
  35.  
  36. cudaMemcpy(d_in, (cufftReal *)data, sizeof(cufftReal)*nRows*nCols*batch, cudaMemcpyHostToDevice);
  37.  
  38.  
  39. /* FFT */
  40. cufftExecR2C(forward_plan, d_in, d_freq);
  41.  
  42. cudaDeviceSynchronize();
  43.  
  44. /* multiply with H(f) */
  45. blockSize = 128;
  46. gridSize = ceil(128/(samples*batch));
  47. mulH<<<gridSize,blockSize>>>(d_freq, samples);
  48.  
  49. cudaDeviceSynchronize();
  50.  
  51. /* IFFT */
  52. cufftPlanMany(&inverse_plan, rank, n, onembed, ostride, odist,
  53. inembed, istride, idist, CUFFT_C2C, batch);
  54.  
  55. cufftExeC2C(inverse_plan, d_freq, d_freq, CUFFT_INVERSE);
  56.  
  57. cudaDeviceSynchronize();
  58.  
  59.  
  60. cudaMemcpy(outputData, d_in, sizeof(short)*nRows*nCols*batch,
  61. cudaMemcpyDeviceToHost);
  62.  
  63. .......
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement