@@ -18,11 +18,23 @@ def exclude_gpus(lines):
1818
1919
2020def gpustat (machine , stat ):
21- lines = stat .split ("\n " )
21+ # Example of stat:
22+ # chitu Fri Dec 31 01:33:24 2021 470.74
23+ # [0] NVIDIA GeForce RTX 3080 | 70'C, 67 % | 3637 / 10018 MB | shuaim:python3/3589(689M)
24+ # [1] NVIDIA GeForce RTX 3080 | 66'C, 37 % | 6412 / 10014 MB | shuaim:python3/3589(361M)
25+ lines = stat .strip ().split ("\n " )
2226 lines = exclude_gpus (lines )
2327 avail = None
24- for l in lines :
25- if l != "" and l .split ("|" )[- 1 ] == "" :
28+ for l in lines [1 :]:
29+ contents = l .split ("|" )
30+ utilization = int (contents [1 ].split ("," , 1 )[1 ].split ("%" )[0 ]) / 100
31+ memory = contents [2 ].split ("/" , 1 )
32+ memory_used = int (memory [0 ])
33+ memory_total = int (memory [1 ].split ("MB" )[0 ])
34+ if (
35+ 1 - utilization >= config .gpu_utilization
36+ and memory_total - memory_used >= config .gpu_memory * 1024
37+ ):
2638 avail = int (l [1 ])
2739 return machine , "\n " .join (lines ), avail
2840
@@ -46,6 +58,7 @@ def gpu_available(first_only=False, verbose=0):
4658 for m , stat , avail in gpuresource ():
4759 if verbose == 2 :
4860 print (stat )
61+ print ("" )
4962 if gavail is None and avail is not None :
5063 gm , gavail = m , avail
5164 if first_only :
0 commit comments