Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1) a.cpp for loading/saving the input/output data and doing FFT/IFFT
- 2) b.cu for multiplying some constant (my own code)
- ....
- cufftHandle forward_plan, inverse_plan;
- int rank = 2;
- int nCols = samples;
- int batch = frames;
- int nRows = 128;
- int n[2] = {nRows, nCols};
- int idist = nRows*nCols;
- int odist = nRows*(nCols/2+1);
- int inembed[] = {nRows, nCols};
- int onembed[] = {nRows, nCols/2+1};
- int istride = 1;
- int ostride = 1;
- cufftPlanMany(&forward_plan, rank, n,
- inembed, istride, idist,
- onembed, ostride, odist,
- CUFFT_R2C, batch);
- cufftReal *d_in;
- cufftComplex *d_freq;
- cufftComplex *outputData = (cufftComplex *)malloc(nRows*(nCols/2+1)*batch*sizeof(cufftComplex));
- cudaMalloc(&d_in, sizeof(cufftReal)*nRows*nCols*batch);
- cudaMAlloc(&d_freq, sizeof(cufftComplex)*nRows*(nCols/2+1)*batch);
- cudaMemcpy(d_in, (cufftReal *)data, sizeof(cufftReal)*nRows*nCols*batch, cudaMemcpyHostToDevice);
- /* FFT */
- cufftExecR2C(forward_plan, d_in, d_freq);
- cudaDeviceSynchronize();
- /* multiply with H(f) */
- blockSize = 128;
- gridSize = ceil(128/(samples*batch));
- mulH<<<gridSize,blockSize>>>(d_freq, samples);
- cudaDeviceSynchronize();
- /* IFFT */
- cufftPlanMany(&inverse_plan, rank, n, onembed, ostride, odist,
- inembed, istride, idist, CUFFT_C2C, batch);
- cufftExeC2C(inverse_plan, d_freq, d_freq, CUFFT_INVERSE);
- cudaDeviceSynchronize();
- cudaMemcpy(outputData, d_in, sizeof(short)*nRows*nCols*batch,
- cudaMemcpyDeviceToHost);
- .......
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement