MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / test2

Function test2

cpp/5_Domain_Specific/convolutionFFT2D/main.cpp:363–497  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361}
362
363bool test2(void)
364{
365 float *h_Data, *h_Kernel, *h_ResultCPU, *h_ResultGPU;
366
367 float *d_Data, *d_Kernel, *d_PaddedData, *d_PaddedKernel;
368
369 fComplex *d_DataSpectrum0, *d_KernelSpectrum0;
370
371 cufftHandle fftPlan;
372
373 bool bRetVal;
374 StopWatchInterface *hTimer = NULL;
375 sdkCreateTimer(&hTimer);
376
377 printf("Testing updated custom R2C / C2R FFT-based convolution\n");
378 const int kernelH = 7;
379 const int kernelW = 6;
380 const int kernelY = 3;
381 const int kernelX = 4;
382 const int dataH = 2000;
383 const int dataW = 2000;
384 const int fftH = snapTransformSize(dataH + kernelH - 1);
385 const int fftW = snapTransformSize(dataW + kernelW - 1);
386
387 printf("...allocating memory\n");
388 h_Data = (float *)malloc(dataH * dataW * sizeof(float));
389 h_Kernel = (float *)malloc(kernelH * kernelW * sizeof(float));
390 h_ResultCPU = (float *)malloc(dataH * dataW * sizeof(float));
391 h_ResultGPU = (float *)malloc(fftH * fftW * sizeof(float));
392
393 checkCudaErrors(cudaMalloc((void **)&d_Data, dataH * dataW * sizeof(float)));
394 checkCudaErrors(cudaMalloc((void **)&d_Kernel, kernelH * kernelW * sizeof(float)));
395
396 checkCudaErrors(cudaMalloc((void **)&d_PaddedData, fftH * fftW * sizeof(float)));
397 checkCudaErrors(cudaMalloc((void **)&d_PaddedKernel, fftH * fftW * sizeof(float)));
398
399 checkCudaErrors(cudaMalloc((void **)&d_DataSpectrum0, fftH * (fftW / 2) * sizeof(fComplex)));
400 checkCudaErrors(cudaMalloc((void **)&d_KernelSpectrum0, fftH * (fftW / 2) * sizeof(fComplex)));
401
402 printf("...generating random input data\n");
403 srand(2010);
404
405 for (int i = 0; i < dataH * dataW; i++) {
406 h_Data[i] = getRand();
407 }
408
409 for (int i = 0; i < kernelH * kernelW; i++) {
410 h_Kernel[i] = getRand();
411 }
412
413 printf("...creating C2C FFT plan for %i x %i\n", fftH, fftW / 2);
414 checkCudaErrors(cufftPlan2d(&fftPlan, fftH, fftW / 2, CUFFT_C2C));
415
416 printf("...uploading to GPU and padding convolution kernel and input data\n");
417 checkCudaErrors(cudaMemcpy(d_Data, h_Data, dataH * dataW * sizeof(float), cudaMemcpyHostToDevice));
418 checkCudaErrors(cudaMemcpy(d_Kernel, h_Kernel, kernelH * kernelW * sizeof(float), cudaMemcpyHostToDevice));
419 checkCudaErrors(cudaMemset(d_PaddedData, 0, fftH * fftW * sizeof(float)));
420 checkCudaErrors(cudaMemset(d_PaddedKernel, 0, fftH * fftW * sizeof(float)));

Callers 1

mainFunction · 0.85

Calls 10

sdkCreateTimerFunction · 0.85
snapTransformSizeFunction · 0.85
getRandFunction · 0.85
sdkResetTimerFunction · 0.85
sdkStartTimerFunction · 0.85
sdkStopTimerFunction · 0.85
sdkGetTimerValueFunction · 0.85
sqrtFunction · 0.85
sdkDeleteTimerFunction · 0.85

Tested by

no test coverage detected