Skip to content

Commit f4ff22e

Browse files
committed
add regex
1 parent b43fd07 commit f4ff22e

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

codalab/worker/docker_utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,14 @@ def get_nvidia_devices(self, use_docker=True):
165165
remove=True,
166166
)
167167
gpu_info = output.decode()
168-
if gpu_info.find("==========") != -1: # need to remove header
169-
gpus = gpu_info.split("\n")[15:-1]
170-
else:
171-
gpus = gpu_info.split("\n")[:-1]
168+
GPU_REGEX = r"(\d+), (?:GPU-)?([a-fA-F0-9-]+)"
169+
gpus = {}
170+
for line in gpu_info.splitlines():
171+
match = re.match(GPU_REGEX, line)
172+
if match:
173+
idx = match.group(1)
174+
uuid = match.group(2)
175+
gpus[idx] = uuid
172176

173177
else:
174178
# use the singularity runtime to run nvidia-smi
@@ -177,10 +181,10 @@ def get_nvidia_devices(self, use_docker=True):
177181
# if output['return_code'] != 0:
178182
# raise SingularityError
179183
# gpus = output['message']
180-
gpus = []
184+
gpus = {}
181185
# Get newline delimited gpu-index, gpu-uuid list
182186
logger.info("GPUs: " + str(gpus))
183-
return {gpu.split(',')[0].strip(): gpu.split(',')[1].strip() for gpu in gpus}
187+
return gpus
184188

185189
@wrap_exception('Unable to fetch Docker container ip')
186190
def get_container_ip(self, network_name: str, container_id: str):

0 commit comments

Comments
 (0)