Skip to content

Instantly share code, notes, and snippets.

@makaveli10
Last active February 12, 2021 05:50
Show Gist options
  • Save makaveli10/0fb0f684cfc239a136aa35f6cb5f0c00 to your computer and use it in GitHub Desktop.
Save makaveli10/0fb0f684cfc239a136aa35f6cb5f0c00 to your computer and use it in GitHub Desktop.
Check GPU Memory Usage (Jetson Nano)
#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