MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _query_visible_devices

Function _query_visible_devices

tensorflow/python/distribute/launch.py:38–63  ·  view source on GitHub ↗

r"""Query visible devices.

()

Source from the content-addressed store, hash-verified

36
37
38def _query_visible_devices():
39 r"""Query visible devices."""
40 visible_devices_str = os.getenv("CUDA_VISIBLE_DEVICES", "")
41 if not visible_devices_str:
42 visible_devices_str = os.getenv("NVIDIA_VISIBLE_DEVICES", "")
43 if not visible_devices_str or visible_devices_str == "void":
44 return []
45 if visible_devices_str != "all":
46 try:
47 return visible_devices_str.split(",")
48 except: # pylint: disable=bare-except
49 logging.exception("Parse NVIDIA_VISIBLE_DEVICES failed:")
50 return []
51 query_devices_command = (
52 "nvidia-smi --query-gpu=uuid --format=csv,noheader 2>/dev/null"
53 )
54 try:
55 with subprocess.Popen(
56 query_devices_command,
57 shell=True,
58 stderr=subprocess.STDOUT,
59 stdout=subprocess.PIPE,
60 ) as proc:
61 return [d for d in iter(proc.stdout.readline, b"") if d]
62 except (OSError, ValueError):
63 return []
64
65
66def launch(command):

Callers 1

launchFunction · 0.85

Calls 2

exceptionMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected