1111from cuda .bindings import _nvml as nvml
1212
1313from . import util
14+ from .conftest import unsupported_before
1415
1516XFAIL_LEGACY_NVLINK_MSG = "Legacy NVLink test expected to fail."
1617
@@ -67,7 +68,8 @@ def test_device_get_handle_by_pci_bus_id(ngpus, pci_info):
6768def test_device_get_memory_affinity (handles , scope ):
6869 size = 1024
6970 for handle in handles :
70- node_set = nvml .device_get_memory_affinity (handle , size , scope )
71+ with unsupported_before (handle , nvml .DeviceArch .KEPLER ):
72+ node_set = nvml .device_get_memory_affinity (handle , size , scope )
7173 assert node_set is not None
7274 assert len (node_set ) == size
7375
@@ -77,7 +79,8 @@ def test_device_get_memory_affinity(handles, scope):
7779def test_device_get_cpu_affinity_within_scope (handles , scope ):
7880 size = 1024
7981 for handle in handles :
80- cpu_set = nvml .device_get_cpu_affinity_within_scope (handle , size , scope )
82+ with unsupported_before (handle , nvml .DeviceArch .KEPLER ):
83+ cpu_set = nvml .device_get_cpu_affinity_within_scope (handle , size , scope )
8184 assert cpu_set is not None
8285 assert len (cpu_set ) == size
8386
@@ -137,22 +140,22 @@ def test_device_get_p2p_status(handles, index):
137140
138141def test_device_get_power_usage (ngpus , handles ):
139142 for i in range (ngpus ):
140- try :
143+ # Note: documentation says this is supported on Fermi or newer,
144+ # but in practice it fails on some later architectures.
145+ with unsupported_before (handles [i ], None ):
141146 power_mwatts = nvml .device_get_power_usage (handles [i ])
142- except nvml .NotSupportedError :
143- pytest .skip ("device_get_power_usage not supported" )
144147 assert power_mwatts >= 0.0
145148
146149
147150def test_device_get_total_energy_consumption (ngpus , handles ):
148151 for i in range (ngpus ):
149- try :
152+ with unsupported_before ( handles [ i ], nvml . DeviceArch . VOLTA ) :
150153 energy_mjoules1 = nvml .device_get_total_energy_consumption (handles [i ])
151- except nvml .NotSupportedError :
152- pytest .skip ("device_get_total_energy_consumption not supported" )
154+
153155 for j in range (10 ): # idle for 150 ms
154156 time .sleep (0.015 ) # and check for increase every 15 ms
155- energy_mjoules2 = nvml .device_get_total_energy_consumption (handles [i ])
157+ with unsupported_before (handles [i ], nvml .DeviceArch .VOLTA ):
158+ energy_mjoules2 = nvml .device_get_total_energy_consumption (handles [i ])
156159 assert energy_mjoules2 >= energy_mjoules1
157160 if energy_mjoules2 > energy_mjoules1 :
158161 break
@@ -183,7 +186,8 @@ def test_device_get_memory_info(ngpus, handles):
183186
184187def test_device_get_utilization_rates (ngpus , handles ):
185188 for i in range (ngpus ):
186- urate = nvml .device_get_utilization_rates (handles [i ])
189+ with unsupported_before (handles [i ], "FERMI" ):
190+ urate = nvml .device_get_utilization_rates (handles [i ])
187191 assert urate .gpu >= 0
188192 assert urate .memory >= 0
189193
@@ -240,7 +244,8 @@ def test_device_get_utilization_rates(ngpus, handles):
240244
241245def test_device_get_pcie_throughput (ngpus , handles ):
242246 for i in range (ngpus ):
243- tx_bytes_tp = nvml .device_get_pcie_throughput (handles [i ], nvml .PcieUtilCounter .PCIE_UTIL_TX_BYTES )
247+ with unsupported_before (handles [i ], nvml .DeviceArch .MAXWELL ):
248+ tx_bytes_tp = nvml .device_get_pcie_throughput (handles [i ], nvml .PcieUtilCounter .PCIE_UTIL_TX_BYTES )
244249 assert tx_bytes_tp >= 0
245250 rx_bytes_tp = nvml .device_get_pcie_throughput (handles [i ], nvml .PcieUtilCounter .PCIE_UTIL_RX_BYTES )
246251 assert rx_bytes_tp >= 0
@@ -272,10 +277,10 @@ def test_device_get_pcie_throughput(ngpus, handles):
272277def test_device_get_nvlink_capability (ngpus , handles , cap_type ):
273278 for i in range (ngpus ):
274279 for j in range (nvml .NVLINK_MAX_LINKS ):
275- try :
280+ # By the documentation, this should be supported on PASCAL or newer,
281+ # but this also seems to fail on newer.
282+ with unsupported_before (handles [i ], None ):
276283 cap = nvml .device_get_nvlink_capability (handles [i ], j , cap_type )
277- except nvml .NotSupportedError :
278- pytest .skip ("NVLink capability not supported" )
279284 assert cap >= 0
280285
281286
0 commit comments