Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2013
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. cudaEvent_t startGPU, stopGPU, startCPU, stopCPU;
  2. float GPUtime, CPUtime;
  3.  
  4. CUDA_CALL(cudaEventCreate(&startGPU));
  5. CUDA_CALL(cudaEventCreate(&stopGPU));
  6. CUDA_CALL(cudaEventRecord(startGPU, 0));
  7. for (int a = 0; a < 100; a++)
  8. {
  9. //do stuff
  10. }
  11. CUDA_CALL(cudaEventRecord(stopGPU, 0));
  12. CUDA_CALL(cudaEventSynchronize(stopGPU));
  13. cudaEventElapsedTime(&GPUtime, startGPU, stopGPU);
  14.  
  15.  
  16. CUDA_CALL(cudaEventCreate(&startCPU));
  17. CUDA_CALL(cudaEventCreate(&stopCPU));
  18. CUDA_CALL(cudaEventRecord(startCPU, 0));
  19. for (int a = 0; a < 100; a++)
  20. {
  21. //do stuff again
  22. }
  23. CUDA_CALL(cudaEventRecord(stopCPU, 0));
  24. CUDA_CALL(cudaEventSynchronize(stopCPU));
  25. cudaEventElapsedTime(&CPUtime, startCPU, stopCPU);
  26.  
  27. printf("%f\n", GPUtime);
  28. printf("%f\n", CPUtime);
  29.  
  30. CUDA_CALL(cudaEventDestroy(startGPU));
  31. CUDA_CALL(cudaEventDestroy(stopGPU));
  32. CUDA_CALL(cudaEventDestroy(startCPU));
  33. CUDA_CALL(cudaEventDestroy(stopCPU));
  34. getchar();
  35. exit(EXIT_SUCCESS);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement