Skip to content

Instantly share code, notes, and snippets.

@InnovArul
Created February 7, 2016 07:38
Show Gist options
  • Save InnovArul/f1af30c59bb5c2590c2f to your computer and use it in GitHub Desktop.
Save InnovArul/f1af30c59bb5c2590c2f to your computer and use it in GitHub Desktop.
/**
* API to report the memory usage of the GPU
*/
static void reportMemStatus() {
// show memory usage of GPU
size_t free_byte;
size_t total_byte;
size_t malloc_byte;
cudaError_t cuda_status = cudaMemGetInfo(&free_byte, &total_byte);
if (cudaSuccess != cuda_status) {
printf("Error: cudaMemGetInfo fails, %s \n",
cudaGetErrorString(cuda_status));
return;
}
cuda_status = cudaDeviceGetLimit(&malloc_byte, cudaLimitMallocHeapSize);
if (cudaSuccess != cuda_status) {
printf("Error: cudaDeviceGetLimit fails, %s \n",
cudaGetErrorString(cuda_status));
return;
}
double free_db = (double) free_byte;
double total_db = (double) total_byte;
double used_db = total_db - free_db;
printf("GPU memory usage: used = %f, free = %f MB, total = %f MB, malloc limit = %f MB\n",
used_db / 1024.0 / 1024.0, free_db / 1024.0 / 1024.0,
total_db / 1024.0 / 1024.0, malloc_byte / 1024.0 / 1024.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment