Mercurial > repos > perssond > unmicst
comparison toolbox/GPUselect.py @ 1:74fe58ff55a5 draft default tip
planemo upload for repository https://github.com/HMS-IDAC/UnMicst commit e14f76a8803cab0013c6dbe809bc81d7667f2ab9
author | goeckslab |
---|---|
date | Wed, 07 Sep 2022 23:10:14 +0000 |
parents | 6bec4fef6b2e |
children |
comparison
equal
deleted
inserted
replaced
0:6bec4fef6b2e | 1:74fe58ff55a5 |
---|---|
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] |