Skip to content

Commit

Permalink
fix(api/device): further isolate the CUDA_VISIBLE_DEVICE parser in …
Browse files Browse the repository at this point in the history
…a subprocess (#70)
  • Loading branch information
XuehaiPan authored Apr 11, 2023
1 parent 5a0da92 commit 7fca245
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

-
- Further isolate the `CUDA_VISIBLE_DEVICE` parser in a subprocess by [@XuehaiPan](https://github.com/XuehaiPan) in [#70](https://github.com/XuehaiPan/nvitop/pull/70).

### Removed

Expand Down
31 changes: 29 additions & 2 deletions nvitop/api/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
import multiprocessing as mp
import os
import re
import subprocess
import sys
import textwrap
import threading
from collections import OrderedDict
from typing import Any, Callable, Iterable, NamedTuple
Expand Down Expand Up @@ -2488,8 +2491,32 @@ def _parse_cuda_visible_devices( # pylint: disable=too-many-branches,too-many-s
gpu_uuids = set(physical_device_attrs)

try:
raw_uuids = _parse_cuda_visible_devices_to_uuids(cuda_visible_devices, verbose=False)
except libcuda.CUDAError:
raw_uuids = (
subprocess.check_output(
[
sys.executable,
'-c',
textwrap.dedent(
f"""
import nvitop.api.device
print(
','.join(
nvitop.api.device._parse_cuda_visible_devices_to_uuids(
{cuda_visible_devices!r},
verbose=False,
),
),
)
""",
),
],
)
.decode('utf-8')
.strip()
.split(',')
)
except subprocess.CalledProcessError:
pass
else:
uuids = [
Expand Down

0 comments on commit 7fca245

Please sign in to comment.