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