Created
February 7, 2016 07:38
-
-
Save InnovArul/f1af30c59bb5c2590c2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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