Skip to content

Instantly share code, notes, and snippets.

@waltner
Created October 5, 2017 12:12
Show Gist options
  • Save waltner/f7fd25bee8ba3708578f99a76b29e492 to your computer and use it in GitHub Desktop.
Save waltner/f7fd25bee8ba3708578f99a76b29e492 to your computer and use it in GitHub Desktop.
CUDA timing
// GPU timing example
// uses CUDA_SAFE_CALL [https://gist.github.com/waltner/ece68738c42d38c5e9bd1862c43b1146.js]
float elapsed_time = 0.0;
cudaEvent_t start, stop;
CUDA_SAFE_CALL(cudaEventCreate(&start));
CUDA_SAFE_CALL(cudaEventCreate(&stop));
CUDA_SAFE_CALL(cudaEventRecord(start,0));
// DO STUFF ...
CUDA_SAFE_CALL(cudaEventRecord(stop,0));
CUDA_SAFE_CALL(cudaEventSynchronize(stop));
CUDA_SAFE_CALL(cudaEventElapsedTime(&elapsedTime,start,stop));
printf("Runtime (GPU): %3.1f ms\n", elapsed_time);
CUDA_SAFE_CALL(cudaEventDestroy(start));
CUDA_SAFE_CALL(cudaEventDestroy(stop));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment