Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/somd2/runner/_repex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,10 @@ def _check_device_memory(device=0):
the visible set, whereas pynvml and pyopencl enumerate all devices
on the machine, so the two only agree when the visible set starts
at zero and is contiguous. CUDA_VISIBLE_DEVICES entries may be
either an index or a UUID.
either an index or a UUID. In containerized or cgroup-isolated
environments where only a subset of GPU device nodes is mounted,
OpenCL may expose fewer devices than the physical index and will
fall back to pynvml.
"""

device = str(device).strip()
Expand Down Expand Up @@ -1117,11 +1120,11 @@ def _check_device_memory(device=0):
ocl_device = all_devices[device_index]
vendor = ocl_device.vendor
else:
msg = f"Device index {device_index} out of range. Found {len(all_devices)} GPU(s)."
_logger.error(msg)
raise IndexError(msg)
except IndexError:
raise
msg = (
f"Device index {device_index} out of range for OpenCL "
f"(found {len(all_devices)} GPU(s)); falling back to pynvml."
)
_logger.warning(msg)
except Exception:
_logger.warning(
"Could not query GPU platform via OpenCL; falling back to pynvml for NVIDIA detection."
Expand All @@ -1133,13 +1136,15 @@ def _check_device_memory(device=0):
import pynvml

pynvml.nvmlInit()
if is_uuid:
handle = pynvml.nvmlDeviceGetHandleByUUID(device.encode())
else:
handle = pynvml.nvmlDeviceGetHandleByIndex(device_index)
memory = pynvml.nvmlDeviceGetMemoryInfo(handle)
pynvml.nvmlShutdown()
return (memory.used, memory.free, memory.total)
try:
if is_uuid:
handle = pynvml.nvmlDeviceGetHandleByUUID(device.encode())
else:
handle = pynvml.nvmlDeviceGetHandleByIndex(device_index)
memory = pynvml.nvmlDeviceGetMemoryInfo(handle)
return (memory.used, memory.free, memory.total)
finally:
pynvml.nvmlShutdown()
except Exception as e:
if vendor is None:
msg = f"Could not get GPU memory info for device {device} via OpenCL or pynvml: {e}"
Expand Down