1010from cuda .bindings import _nvml as nvml
1111
1212from . import util
13+ from .conftest import unsupported_before
1314
1415XFAIL_LEGACY_NVLINK_MSG = "Legacy NVLink test expected to fail."
1516
@@ -66,7 +67,8 @@ def test_device_get_handle_by_pci_bus_id(ngpus, pci_info):
6667def test_device_get_memory_affinity (handles , scope ):
6768 size = 1024
6869 for handle in handles :
69- node_set = nvml .device_get_memory_affinity (handle , size , scope )
70+ with unsupported_before (handle , nvml .DeviceArch .KEPLER ):
71+ node_set = nvml .device_get_memory_affinity (handle , size , scope )
7072 assert node_set is not None
7173 assert len (node_set ) == size
7274
@@ -76,7 +78,8 @@ def test_device_get_memory_affinity(handles, scope):
7678def test_device_get_cpu_affinity_within_scope (handles , scope ):
7779 size = 1024
7880 for handle in handles :
79- cpu_set = nvml .device_get_cpu_affinity_within_scope (handle , size , scope )
81+ with unsupported_before (handle , nvml .DeviceArch .KEPLER ):
82+ cpu_set = nvml .device_get_cpu_affinity_within_scope (handle , size , scope )
8083 assert cpu_set is not None
8184 assert len (cpu_set ) == size
8285
@@ -136,22 +139,22 @@ def test_device_get_p2p_status(handles, index):
136139
137140def test_device_get_power_usage (ngpus , handles ):
138141 for i in range (ngpus ):
139- try :
142+ # Note: documentation says this is supported on Fermi or newer,
143+ # but in practice it fails on some later architectures.
144+ with unsupported_before (handles [i ], None ):
140145 power_mwatts = nvml .device_get_power_usage (handles [i ])
141- except nvml .NotSupportedError :
142- pytest .skip ("device_get_power_usage not supported" )
143146 assert power_mwatts >= 0.0
144147
145148
146149def test_device_get_total_energy_consumption (ngpus , handles ):
147150 for i in range (ngpus ):
148- try :
151+ with unsupported_before ( handles [ i ], nvml . DeviceArch . VOLTA ) :
149152 energy_mjoules1 = nvml .device_get_total_energy_consumption (handles [i ])
150- except nvml .NotSupportedError :
151- pytest .skip ("device_get_total_energy_consumption not supported" )
153+
152154 for j in range (10 ): # idle for 150 ms
153155 time .sleep (0.015 ) # and check for increase every 15 ms
154- energy_mjoules2 = nvml .device_get_total_energy_consumption (handles [i ])
156+ with unsupported_before (handles [i ], nvml .DeviceArch .VOLTA ):
157+ energy_mjoules2 = nvml .device_get_total_energy_consumption (handles [i ])
155158 assert energy_mjoules2 >= energy_mjoules1
156159 if energy_mjoules2 > energy_mjoules1 :
157160 break
@@ -182,7 +185,8 @@ def test_device_get_memory_info(ngpus, handles):
182185
183186def test_device_get_utilization_rates (ngpus , handles ):
184187 for i in range (ngpus ):
185- urate = nvml .device_get_utilization_rates (handles [i ])
188+ with unsupported_before (handles [i ], "FERMI" ):
189+ urate = nvml .device_get_utilization_rates (handles [i ])
186190 assert urate .gpu >= 0
187191 assert urate .memory >= 0
188192
@@ -239,7 +243,8 @@ def test_device_get_utilization_rates(ngpus, handles):
239243
240244def test_device_get_pcie_throughput (ngpus , handles ):
241245 for i in range (ngpus ):
242- tx_bytes_tp = nvml .device_get_pcie_throughput (handles [i ], nvml .PcieUtilCounter .PCIE_UTIL_TX_BYTES )
246+ with unsupported_before (handles [i ], nvml .DeviceArch .MAXWELL ):
247+ tx_bytes_tp = nvml .device_get_pcie_throughput (handles [i ], nvml .PcieUtilCounter .PCIE_UTIL_TX_BYTES )
243248 assert tx_bytes_tp >= 0
244249 rx_bytes_tp = nvml .device_get_pcie_throughput (handles [i ], nvml .PcieUtilCounter .PCIE_UTIL_RX_BYTES )
245250 assert rx_bytes_tp >= 0
@@ -271,10 +276,10 @@ def test_device_get_pcie_throughput(ngpus, handles):
271276def test_device_get_nvlink_capability (ngpus , handles , cap_type ):
272277 for i in range (ngpus ):
273278 for j in range (nvml .NVLINK_MAX_LINKS ):
274- try :
279+ # By the documentation, this should be supported on PASCAL or newer,
280+ # but this also seems to fail on newer.
281+ with unsupported_before (handles [i ], None ):
275282 cap = nvml .device_get_nvlink_capability (handles [i ], j , cap_type )
276- except nvml .NotSupportedError :
277- pytest .skip ("NVLink capability not supported" )
278283 assert cap >= 0
279284
280285
0 commit comments