-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathram_usage.cu
32 lines (26 loc) · 863 Bytes
/
ram_usage.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#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);
break;
}
return 0;
}