Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit GPU metrics to visible devices only #3810

Merged
merged 8 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 11 additions & 1 deletion distributed/diagnostics/nvml.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pynvml

handles = None
Expand All @@ -8,7 +9,16 @@ def _pynvml_handles():
if handles is None:
pynvml.nvmlInit()
count = pynvml.nvmlDeviceGetCount()
handles = [pynvml.nvmlDeviceGetHandleByIndex(i) for i in range(count)]
cuda_visible_devices = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As dask cuda just reorder the devices to change cuda device enumeration. This is still getting all the devices like what nvml does right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that I undrstand this comment. My understanding is that pynvml doesn't respect the CUDA_VISIBLE_DEVICES environment variable, and so we need to handle this manually.

int(idx) for idx in os.environ.get("CUDA_VISIBLE_DEVICES", "").split(",")
]
if not cuda_visible_devices:
cuda_visible_devices = list(range(count))
handles = [
pynvml.nvmlDeviceGetHandleByIndex(i)
for i in range(count)
if i in cuda_visible_devices
]
return handles


Expand Down
26 changes: 26 additions & 0 deletions distributed/diagnostics/tests/test_nvml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest
import os

pytest.importorskip("pynvml")

from distributed.diagnostics import nvml


def test_one_time():
output = nvml.one_time()
assert "memory-total" in output
assert "name" in output

assert len(output["name"]) > 0


def test_1_visible_devices():
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
output = nvml.one_time()
assert len(output["memory-total"]) == 1


def test_2_visible_devices():
os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"
output = nvml.one_time()
assert len(output["memory-total"]) == 2