Last active
February 12, 2021 05:50
-
-
Save makaveli10/0fb0f684cfc239a136aa35f6cb5f0c00 to your computer and use it in GitHub Desktop.
Check GPU Memory Usage (Jetson Nano)
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
#include <iostream> | |
#include <unistd.h> | |
#include "cuda.h" | |
int main() | |
{ | |
// show memory usage of GPU | |
size_t free_byte ; | |
size_t total_byte ; | |
while (true ) | |
{ | |
cudaError_t cuda_status = cudaMemGetInfo( &free_byte, &total_byte ) ; | |
if ( cudaSuccess != cuda_status ){ | |
std::cout << "Error: cudaMemGetInfo fails, " << cudaGetErrorString(cuda_status) << std::endl; | |
exit(1); | |
} | |
double free_db = (double)free_byte ; | |
double total_db = (double)total_byte ; | |
double used_db = total_db - free_db ; | |
std::cout << "GPU memory usage: used = " << used_db/1024.0/1024.0 << ", free = " | |
<< free_db/1024.0/1024.0 << " MB, total = " << total_db/1024.0/1024.0 << " MB" << std::endl; | |
sleep(1); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment