Skip to content

Commit 978d282

Browse files
committed
Use stable identifiers for device subtests
1 parent 3e8d151 commit 978d282

5 files changed

Lines changed: 57 additions & 46 deletions

File tree

‎cuda_bindings/tests/nvml/test_device.py‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_clk_mon_status_t():
4040

4141
def test_current_clock_freqs(all_devices, subtests):
4242
for device in all_devices:
43-
with subtests.test(device=device):
43+
with subtests.test(device_index=nvml.device_get_index(device)):
4444
with unsupported_before(device, None):
4545
clk_freqs = nvml.device_get_current_clock_freqs(device)
4646
assert isinstance(clk_freqs, str)
@@ -72,7 +72,7 @@ def test_get_handle_by_uuidv(all_devices):
7272

7373
def test_get_nv_link_supported_bw_modes(all_devices, subtests):
7474
for device in all_devices:
75-
with subtests.test(device=device):
75+
with subtests.test(device_index=nvml.device_get_index(device)):
7676
with unsupported_before(device, None):
7777
modes = nvml.device_get_nvlink_supported_bw_modes(device)
7878
assert isinstance(modes, nvml.NvlinkSupportedBwModes_v1)
@@ -92,7 +92,7 @@ def test_device_get_pdi(all_devices):
9292

9393
def test_device_get_performance_modes(all_devices, subtests):
9494
for device in all_devices:
95-
with subtests.test(device=device):
95+
with subtests.test(device_index=nvml.device_get_index(device)):
9696
with unsupported_before(device, None):
9797
modes = nvml.device_get_performance_modes(device)
9898
assert isinstance(modes, str)
@@ -101,15 +101,15 @@ def test_device_get_performance_modes(all_devices, subtests):
101101
@pytest.mark.skipif(cuda_version_less_than(13010), reason="Introduced in 13.1")
102102
def test_device_get_unrepairable_memory_flag(all_devices, subtests):
103103
for device in all_devices:
104-
with subtests.test(device=device):
104+
with subtests.test(device_index=nvml.device_get_index(device)):
105105
with unsupported_before(device, None):
106106
status = nvml.device_get_unrepairable_memory_flag_v1(device)
107107
assert isinstance(status, int)
108108

109109

110110
def test_device_vgpu_get_heterogeneous_mode(all_devices, subtests):
111111
for device in all_devices:
112-
with subtests.test(device=device):
112+
with subtests.test(device_index=nvml.device_get_index(device)):
113113
with unsupported_before(device, None):
114114
mode = nvml.device_get_vgpu_heterogeneous_mode(device)
115115
assert isinstance(mode, int)
@@ -118,7 +118,7 @@ def test_device_vgpu_get_heterogeneous_mode(all_devices, subtests):
118118
@pytest.mark.skipif(cuda_version_less_than(13010), reason="Introduced in 13.1")
119119
def test_read_prm_counters(all_devices, subtests):
120120
for device in all_devices:
121-
with subtests.test(device=device):
121+
with subtests.test(device_index=nvml.device_get_index(device)):
122122
counters = nvml.PRMCounter_v1(5)
123123
with unsupported_before(device, None):
124124
read_counters = nvml.device_read_prm_counters_v1(device, counters)
@@ -129,7 +129,7 @@ def test_read_prm_counters(all_devices, subtests):
129129
@pytest.mark.thread_unsafe(reason="API appears to be thread-unsafe (2026-06)")
130130
def test_read_write_prm(all_devices, subtests):
131131
for device in all_devices:
132-
with subtests.test(device=device):
132+
with subtests.test(device_index=nvml.device_get_index(device)):
133133
# Docs say supported in BLACKWELL or later
134134
with unsupported_before(device, None):
135135
try:
@@ -144,13 +144,16 @@ def test_read_write_prm(all_devices, subtests):
144144
def test_get_power_management_limit(all_devices, subtests):
145145
for device in all_devices:
146146
# Docs say supported on FERMI or later
147-
with subtests.test(device=device), unsupported_before(device, "FERMI"):
147+
with subtests.test(device_index=nvml.device_get_index(device)), unsupported_before(device, "FERMI"):
148148
nvml.device_get_power_management_limit(device)
149149

150150

151151
def test_set_power_management_limit(all_devices, subtests):
152152
for device in all_devices:
153-
with subtests.test(device=device), unsupported_before(device, nvml.DeviceArch.KEPLER):
153+
with (
154+
subtests.test(device_index=nvml.device_get_index(device)),
155+
unsupported_before(device, nvml.DeviceArch.KEPLER),
156+
):
154157
try:
155158
nvml.device_set_power_management_limit_v2(device, nvml.PowerScope.GPU, 10000)
156159
except nvml.NoPermissionError:
@@ -161,7 +164,7 @@ def test_set_power_management_limit(all_devices, subtests):
161164

162165
def test_set_temperature_threshold(all_devices, subtests):
163166
for device in all_devices:
164-
with subtests.test(device=device):
167+
with subtests.test(device_index=nvml.device_get_index(device)):
165168
# Docs say supported on MAXWELL or newer
166169
with unsupported_before(device, None):
167170
temp = nvml.device_get_temperature_threshold(

‎cuda_bindings/tests/nvml/test_gpu.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def test_gpu_get_module_id(nvml_init, subtests):
2121
if util.is_vgpu(device):
2222
continue
2323

24-
with subtests.test(i=i):
24+
with subtests.test(device_index=i):
2525
with unsupported_before(device, None):
2626
module_id = nvml.device_get_module_id(device)
2727
assert isinstance(module_id, int)
2828

2929

3030
def test_gpu_get_platform_info(all_devices, subtests):
3131
for device in all_devices:
32-
with subtests.test(device=device):
32+
with subtests.test(device_index=nvml.device_get_index(device)):
3333
if util.is_vgpu(device):
3434
pytest.skip(f"Not supported on vGPU device {device}")
3535

@@ -63,7 +63,11 @@ def test_conf_compute_attestation_report_t(all_devices):
6363
def test_gpu_conf_compute_attestation_report(all_devices, subtests):
6464
for device in all_devices:
6565
# Documentation says AMPERE or newer
66-
with subtests.test(device=device), unsupported_before(device, None), pytest.raises(nvml.UnknownError):
66+
with (
67+
subtests.test(device_index=nvml.device_get_index(device)),
68+
unsupported_before(device, None),
69+
pytest.raises(nvml.UnknownError),
70+
):
6771
# The nonce string is nonsensical, so if this "works", we expect an UnknownError
6872
nvml.device_get_conf_compute_gpu_attestation_report(device, nonce=b"12345678")
6973

@@ -79,6 +83,10 @@ def test_conf_compute_gpu_certificate_t():
7983
def test_conf_compute_gpu_certificate(all_devices, subtests):
8084
for device in all_devices:
8185
# Documentation says AMPERE or newer
82-
with subtests.test(device=device), unsupported_before(device, None), pytest.raises(nvml.UnknownError):
86+
with (
87+
subtests.test(device_index=nvml.device_get_index(device)),
88+
unsupported_before(device, None),
89+
pytest.raises(nvml.UnknownError),
90+
):
8391
# This is expected to fail if the device doesn't have a proper certificate
8492
nvml.device_get_conf_compute_gpu_certificate(device)

‎cuda_bindings/tests/nvml/test_pci.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def test_discover_gpus(all_devices, subtests):
1313
for device in all_devices:
14-
with subtests.test(device=device):
14+
with subtests.test(device_index=nvml.device_get_index(device)):
1515
pci_info = nvml.device_get_pci_info_v3(device)
1616
# Docs say this should be supported on PASCAL and later
1717
with unsupported_before(device, None), contextlib.suppress(nvml.OperatingSystemError):
@@ -27,7 +27,7 @@ def test_bridge_chip_hierarchy_t():
2727

2828
def test_bridge_chip_info(all_devices, subtests):
2929
for device in all_devices:
30-
with subtests.test(device=device):
30+
with subtests.test(device_index=nvml.device_get_index(device)):
3131
with unsupported_before(device, None):
3232
info = nvml.device_get_bridge_chip_info(device)
3333
assert isinstance(info, nvml.BridgeChipHierarchy)

‎cuda_bindings/tests/nvml/test_pynvml.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def test_device_get_handle_by_pci_bus_id(ngpus, pci_info):
6767
@pytest.mark.skipif(util.is_wsl() or util.is_windows(), reason="Not supported on WSL or Windows")
6868
def test_device_get_memory_affinity(handles, scope, subtests):
6969
size = 1024
70-
for handle in handles:
71-
with subtests.test(handle=handle):
70+
for device_index, handle in enumerate(handles):
71+
with subtests.test(device_index=device_index):
7272
with unsupported_before(handle, nvml.DeviceArch.KEPLER):
7373
node_set = nvml.device_get_memory_affinity(handle, size, scope)
7474
assert node_set is not None
@@ -79,8 +79,8 @@ def test_device_get_memory_affinity(handles, scope, subtests):
7979
@pytest.mark.skipif(util.is_wsl() or util.is_windows(), reason="Not supported on WSL or Windows")
8080
def test_device_get_cpu_affinity_within_scope(handles, scope, subtests):
8181
size = 1024
82-
for handle in handles:
83-
with subtests.test(handle=handle):
82+
for device_index, handle in enumerate(handles):
83+
with subtests.test(device_index=device_index):
8484
with unsupported_before(handle, nvml.DeviceArch.KEPLER):
8585
cpu_set = nvml.device_get_cpu_affinity_within_scope(handle, size, scope)
8686
assert cpu_set is not None
@@ -142,7 +142,7 @@ def test_device_get_p2p_status(handles, index):
142142

143143
def test_device_get_power_usage(ngpus, handles, subtests):
144144
for i in range(ngpus):
145-
with subtests.test(i=i):
145+
with subtests.test(device_index=i):
146146
# Note: documentation says this is supported on Fermi or newer,
147147
# but in practice it fails on some later architectures.
148148
with unsupported_before(handles[i], None):
@@ -152,7 +152,7 @@ def test_device_get_power_usage(ngpus, handles, subtests):
152152

153153
def test_device_get_total_energy_consumption(ngpus, handles, subtests):
154154
for i in range(ngpus):
155-
with subtests.test(i=i):
155+
with subtests.test(device_index=i):
156156
with unsupported_before(handles[i], None):
157157
energy_mjoules1 = nvml.device_get_total_energy_consumption(handles[i])
158158

@@ -174,7 +174,7 @@ def test_device_get_total_energy_consumption(ngpus, handles, subtests):
174174

175175
def test_device_get_memory_info(ngpus, handles, subtests):
176176
for i in range(ngpus):
177-
with subtests.test(i=i):
177+
with subtests.test(device_index=i):
178178
with unsupported_before(handles[i], None):
179179
meminfo = nvml.device_get_memory_info_v2(handles[i])
180180
assert (meminfo.used <= meminfo.total) and (meminfo.free <= meminfo.total)
@@ -192,7 +192,7 @@ def test_device_get_memory_info(ngpus, handles, subtests):
192192

193193
def test_device_get_utilization_rates(ngpus, handles, subtests):
194194
for i in range(ngpus):
195-
with subtests.test(i=i):
195+
with subtests.test(device_index=i):
196196
with unsupported_before(handles[i], None):
197197
urate = nvml.device_get_utilization_rates(handles[i])
198198
assert urate.gpu >= 0
@@ -251,7 +251,7 @@ def test_device_get_utilization_rates(ngpus, handles, subtests):
251251

252252
def test_device_get_pcie_throughput(ngpus, handles, subtests):
253253
for i in range(ngpus):
254-
with subtests.test(i=i):
254+
with subtests.test(device_index=i):
255255
with unsupported_before(handles[i], None):
256256
tx_bytes_tp = nvml.device_get_pcie_throughput(handles[i], nvml.PcieUtilCounter.PCIE_UTIL_TX_BYTES)
257257
assert tx_bytes_tp >= 0

0 commit comments

Comments
 (0)