Skip to content

Commit a537422

Browse files
committed
test: Enhance tests for interaction between deviceid and visible devices, and improve errors for invalid combinations
1 parent 3ce3395 commit a537422

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

devito/operator/operator.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,14 @@ def _physical_deviceid(self):
14021402
if visible_devices is None:
14031403
return logical_deviceid
14041404
else:
1405-
return visible_devices[logical_deviceid]
1405+
try:
1406+
return visible_devices[logical_deviceid]
1407+
except IndexError:
1408+
errmsg = (f"A deviceid value of {logical_deviceid} is not valid "
1409+
f"with VISIBLE_DEVICES={visible_devices}. Note that "
1410+
"deviceid corresponds to the logical index within the "
1411+
"visible devices, not the physical device index.")
1412+
raise ValueError(errmsg)
14061413
else:
14071414
return None
14081415

tests/test_gpu_common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ def test_visible_devices_with_devito_deviceid(self):
149149
# So should be the second of the two visible devices specified (3)
150150
assert argmap._physical_deviceid == 3
151151

152+
with switchenv({'CUDA_VISIBLE_DEVICES': "1"}), switchconfig(deviceid=0):
153+
op1 = Operator(eq)
154+
155+
argmap1 = op1.arguments()
156+
assert argmap1._physical_deviceid == 1
157+
152158
@pytest.mark.parallel(mode=2)
153159
def test_deviceid_per_rank(self, mode):
154160
"""

0 commit comments

Comments
 (0)