comparison toolbox/GPUselect.py @ 0:6bec4fef6b2e draft

"planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
author perssond
date Fri, 12 Mar 2021 00:17:29 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:6bec4fef6b2e
1 import subprocess, re
2 import numpy as np
3
4 def pick_gpu_lowest_memory():
5 output = subprocess.Popen("nvidia-smi", stdout=subprocess.PIPE, shell=True).communicate()[0]
6 output=output.decode("ascii")
7 gpu_output = output[output.find("Memory-Usage"):]
8 # lines of the form
9 # | 0 8734 C python 11705MiB |
10 memory_regex = re.compile(r"[|]\s+?\D+?.+[ ](?P<gpu_memory>\d+)MiB /")
11 rows = gpu_output.split("\n")
12 result=[]
13 for row in gpu_output.split("\n"):
14 m = memory_regex.search(row)
15 if not m:
16 continue
17 gpu_memory = int(m.group("gpu_memory"))
18 result.append(gpu_memory)
19 return np.argsort(result)[0]