Skip to content

Commit bab66ba

Browse files
committed
added new nvidia-smi query to list gpus
1 parent 0dd68be commit bab66ba

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

nvdocker/nvdocker.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,16 @@ def exec_run(self, cid, cmd):
152152

153153
@staticmethod
154154
def list_gpus():
155-
output = check_output(["nvidia-smi", "-L"]).decode("utf-8")
156-
regex = re.compile(r"GPU (?P<id>\d+):")
157-
gpus = []
158-
for line in output.strip().split("\n"):
159-
m = regex.match(line)
160-
assert m, "unable to parse " + line
161-
gpus.append(int(m.group("id")))
155+
#output = check_output(["nvidia-smi", "-L"]).decode("utf-8")
156+
query_gpu = check_output("nvidia-smi", "--query-gpu=memory.free,memory.used,memory.total --format=csv,noheader")
157+
#regex = re.compile(r"GPU (?P<id>\d+):")
158+
gpus = {}
159+
id = 0;
160+
for gpu in query_gpu.split("\n"):
161+
gpu_info = []
162+
for info in gpu:
163+
gpu_info.append(info.split(" ")[0]);
164+
gpus[id] = gpu_info;
162165
return gpus
163166

164167
@staticmethod
@@ -175,4 +178,4 @@ def gpu_memory_usage():
175178
id = int(gpu.group("id"))
176179
memory = int(gpu.group("usage"))
177180
usage[id] += memory
178-
return usage
181+
return usage

0 commit comments

Comments
 (0)