Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion devito/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,14 @@ def _physical_deviceid(self):
if visible_devices is None:
return logical_deviceid
else:
return visible_devices[logical_deviceid]
try:
return visible_devices[logical_deviceid]
except IndexError:
errmsg = (f"A deviceid value of {logical_deviceid} is not valid "
f"with VISIBLE_DEVICES={visible_devices}. Note that "
Copy link
Contributor

Choose a reason for hiding this comment

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

since you're at it, fetch the self.platform and prefix it with CUDA_ or ROCM_ accordingly?

also, did you mean "with" or "within" ?

"deviceid corresponds to the logical index within the "
"visible devices, not the physical device index.")
raise ValueError(errmsg)
else:
return None

Expand Down
6 changes: 6 additions & 0 deletions tests/test_gpu_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ def test_visible_devices_with_devito_deviceid(self):
# So should be the second of the two visible devices specified (3)
assert argmap._physical_deviceid == 3

with switchenv({'CUDA_VISIBLE_DEVICES': "1"}), switchconfig(deviceid=0):
op1 = Operator(eq)

argmap1 = op1.arguments()
assert argmap1._physical_deviceid == 1

@pytest.mark.parallel(mode=2)
def test_deviceid_per_rank(self, mode):
"""
Expand Down
Loading