Skip to content

Commit 392f4e9

Browse files
mdboomrwgk
andauthored
Fix nvbug6563848: Make tests properly skip on unsupported devices. (#2742)
* Fix nvbug6563848: Make tests properly skip on unsupported devices. * Update cuda_bindings/tests/nvml/test_cuda.py * test(nvml): skip unsupported Orin UUID lookups --------- Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
1 parent e606d08 commit 392f4e9

4 files changed

Lines changed: 26 additions & 55 deletions

File tree

cuda_bindings/tests/nvml/conftest.py

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
from collections import namedtuple
54

65
import pytest
76
from cuda_python_test_helpers.arch_check import unsupported_before # noqa: F401
@@ -26,56 +25,19 @@ def nvml_init():
2625
yield
2726

2827

29-
@pytest.fixture(scope="session", autouse=True)
30-
def device_info():
31-
dev_count = None
32-
bus_id_to_board_details = {}
33-
34-
with NVMLInitializer():
35-
dev_count = nvml.device_get_count_v2()
36-
37-
# Store some details for each device now when we know NVML is in known state
38-
for i in range(dev_count):
39-
try:
40-
dev = nvml.device_get_handle_by_index_v2(i)
41-
except nvml.NoPermissionError:
42-
continue
43-
pci_info = nvml.device_get_pci_info_v3(dev)
44-
45-
name = nvml.device_get_name(dev)
46-
# Get architecture name ex: Ampere, Kepler
47-
arch_id = nvml.device_get_architecture(dev)
48-
49-
BoardCfg = namedtuple("BoardCfg", "name, ids_arr")
50-
board = BoardCfg(name, ids_arr=[(pci_info.pci_device_id, pci_info.pci_sub_system_id)])
51-
52-
try:
53-
serial = nvml.device_get_serial(dev)
54-
except nvml.NvmlError:
55-
serial = None
56-
57-
bus_id = pci_info.bus_id
58-
device_id = pci_info.device_
59-
uuid = nvml.device_get_uuid(dev)
60-
61-
BoardDetails = namedtuple("BoardDetails", "name, board, arch_id, bus_id, device_id, serial")
62-
bus_id_to_board_details[uuid] = BoardDetails(name, board, arch_id, bus_id, device_id, serial)
63-
64-
return bus_id_to_board_details
65-
66-
67-
def get_devices(device_info):
68-
for uuid in list(device_info.keys()):
28+
def get_devices():
29+
dev_count = nvml.device_get_count_v2()
30+
for i in range(dev_count):
6931
try:
70-
yield nvml.device_get_handle_by_uuid(uuid)
32+
yield nvml.device_get_handle_by_index_v2(i)
7133
except nvml.NoPermissionError:
7234
continue # ignore devices that can't be accessed
7335

7436

7537
@pytest.fixture
76-
def all_devices(device_info):
38+
def all_devices():
7739
with NVMLInitializer():
78-
yield sorted(set(get_devices(device_info)))
40+
yield sorted(set(get_devices()))
7941

8042

8143
@pytest.fixture

cuda_bindings/tests/nvml/test_cuda.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ def test_cuda_device_order():
5858
cuda_devices = get_cuda_device_names()
5959
nvml_devices = get_nvml_device_names()
6060

61-
if any("Thor" in device["name"] for device in nvml_devices):
62-
pytest.skip("Skipping test on Thor, which has non-standard device naming")
61+
for kind in ("Orin", "Thor"):
62+
if any(kind in device["name"] for device in nvml_devices):
63+
pytest.skip(f"Skipping test on {kind}, which has non-standard device naming")
6364
return
6465

6566
if "CUDA_VISIBLE_DEVICES" not in os.environ:

cuda_bindings/tests/nvml/test_device.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ def test_grid_licensable_features(all_devices):
6363
nvml.GridLicenseExpiry(feature.license_expiry)
6464

6565

66-
def test_get_handle_by_uuidv(all_devices):
66+
def test_get_handle_by_uuidv(all_devices, subtests):
6767
for device in all_devices:
68-
uuid = nvml.device_get_uuid(device)
69-
new_handle = nvml.device_get_handle_by_uuidv(nvml.UUIDType.ASCII, uuid.encode("ascii"))
70-
assert new_handle == device
68+
with subtests.test(device_index=nvml.device_get_index(device)):
69+
uuid = nvml.device_get_uuid(device)
70+
if "Orin" in nvml.device_get_name(device) and len(uuid) == 36:
71+
pytest.skip("UUID lookup is unsupported on Orin, which reports a UUID without a GPU- prefix")
72+
with unsupported_before(device, None):
73+
new_handle = nvml.device_get_handle_by_uuidv(nvml.UUIDType.ASCII, uuid.encode("ascii"))
74+
assert new_handle == device
7175

7276

7377
def test_get_nv_link_supported_bw_modes(all_devices, subtests):

cuda_bindings/tests/nvml/test_pynvml.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@ def test_device_get_attributes(mig_handles):
5252
pytest.skip("No MIG devices found")
5353

5454

55-
def test_device_get_handle_by_uuid(ngpus, uuids):
56-
handles = [nvml.device_get_handle_by_uuid(uuids[i]) for i in range(ngpus)]
57-
assert len(handles) == ngpus
55+
def test_device_get_handle_by_uuid(ngpus, handles, uuids, subtests):
56+
for i in range(ngpus):
57+
with subtests.test(device_index=i):
58+
uuid = uuids[i]
59+
if "Orin" in nvml.device_get_name(handles[i]) and len(uuid) == 36:
60+
pytest.skip("UUID lookup is unsupported on Orin, which reports a UUID without a GPU- prefix")
61+
assert nvml.device_get_handle_by_uuid(uuid) == handles[i]
5862

5963

6064
def test_device_get_handle_by_pci_bus_id(ngpus, pci_info):
@@ -68,7 +72,7 @@ def test_device_get_memory_affinity(handles, scope, subtests):
6872
size = 1024
6973
for device_index, handle in enumerate(handles):
7074
with subtests.test(device_index=device_index):
71-
with unsupported_before(handle, nvml.DeviceArch.KEPLER):
75+
with unsupported_before(handle, None):
7276
node_set = nvml.device_get_memory_affinity(handle, size, scope)
7377
assert node_set is not None
7478
assert len(node_set) == size
@@ -80,7 +84,7 @@ def test_device_get_cpu_affinity_within_scope(handles, scope, subtests):
8084
size = 1024
8185
for device_index, handle in enumerate(handles):
8286
with subtests.test(device_index=device_index):
83-
with unsupported_before(handle, nvml.DeviceArch.KEPLER):
87+
with unsupported_before(handle, None):
8488
cpu_set = nvml.device_get_cpu_affinity_within_scope(handle, size, scope)
8589
assert cpu_set is not None
8690
assert len(cpu_set) == size

0 commit comments

Comments
 (0)