Skip to content

Commit 7598449

Browse files
committed
Adapt CUDA 12 NVML tests for current CI runners
Relocate the established hardware, driver, visibility and timing accommodations from the source-integration layer. Preserve their contents exactly; the FieldId correction moves with the test maintenance. Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
1 parent 71b17a0 commit 7598449

4 files changed

Lines changed: 36 additions & 24 deletions

File tree

‎cuda_bindings_12/tests/nvml/test_cuda.py‎

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

4+
import pytest
5+
46
import cuda.bindings.driver as cuda
57
from cuda.bindings import nvml
68

@@ -15,10 +17,15 @@ def get_nvml_device_names():
1517
for idx in range(num_devices):
1618
handle = nvml.device_get_handle_by_index_v2(idx)
1719
name = nvml.device_get_name(handle)
18-
info = nvml.device_get_pci_info_v3(handle)
19-
assert isinstance(info.bus, int)
20+
try:
21+
info = nvml.device_get_pci_info_v3(handle)
22+
except nvml.NotSupportedError:
23+
bus_id = -1
24+
else:
25+
bus_id = info.bus
26+
assert isinstance(bus_id, int)
2027
assert isinstance(name, str)
21-
result.append({"name": name, "id": info.bus})
28+
result.append({"name": name, "id": bus_id})
2229

2330
return result
2431

@@ -54,4 +61,15 @@ def test_cuda_device_order():
5461
cuda_devices = get_cuda_device_names()
5562
nvml_devices = get_nvml_device_names()
5663

57-
assert cuda_devices == nvml_devices, "CUDA and NVML device lists do not match"
64+
for kind in ("Orin", "Thor"):
65+
if any(kind in device["name"] for device in nvml_devices):
66+
pytest.skip(f"Skipping test on {kind}, which has non-standard device naming")
67+
68+
def compare(cuda_device, nvml_device):
69+
return cuda_device["name"] == nvml_device["name"] and (
70+
nvml_device["id"] == -1 or cuda_device["id"] == nvml_device["id"]
71+
)
72+
73+
assert len(cuda_devices) <= len(nvml_devices)
74+
for cuda_device in cuda_devices:
75+
assert any(compare(cuda_device, nvml_device) for nvml_device in nvml_devices)

‎cuda_bindings_12/tests/nvml/test_init.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66

77
import pytest
88

9-
from cuda.bindings import nvml
9+
from cuda.bindings import driver, nvml
10+
11+
12+
def _driver_version_at_least_13_4():
13+
(status,) = driver.cuInit(0)
14+
assert status == driver.CUresult.CUDA_SUCCESS
15+
status, version = driver.cuDriverGetVersion()
16+
assert status == driver.CUresult.CUDA_SUCCESS
17+
return version >= 13040
1018

1119

1220
def assert_nvml_is_initialized():
@@ -36,10 +44,14 @@ def test_devices_are_the_same_architecture(all_devices):
3644

3745

3846
@pytest.mark.skipif(sys.platform == "win32", reason="Test not supported on Windows")
47+
@pytest.mark.thread_unsafe(reason="nvml init affects other threads")
3948
def test_init_ref_count():
4049
"""
4150
Verifies that we can call NVML shutdown and init(2) multiple times, and that ref counting works
4251
"""
52+
if _driver_version_at_least_13_4():
53+
pytest.skip("Init behavior changed in CUDA 13.4")
54+
4355
with pytest.raises(nvml.UninitializedError):
4456
nvml.shutdown()
4557

‎cuda_bindings_12/tests/nvml/test_pynvml.py‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# A set of tests ported from https://github.com/gpuopenanalytics/pynvml/blob/11.5.3/pynvml/tests/test_nvml.py
55

66
import os
7-
import time
8-
97
import pytest
108

119
from cuda.bindings import nvml
@@ -147,22 +145,6 @@ def test_device_get_power_usage(ngpus, handles):
147145
assert power_mwatts >= 0.0
148146

149147

150-
def test_device_get_total_energy_consumption(ngpus, handles):
151-
for i in range(ngpus):
152-
with unsupported_before(handles[i], nvml.DeviceArch.VOLTA):
153-
energy_mjoules1 = nvml.device_get_total_energy_consumption(handles[i])
154-
155-
for j in range(10): # idle for 150 ms
156-
time.sleep(0.015) # and check for increase every 15 ms
157-
with unsupported_before(handles[i], nvml.DeviceArch.VOLTA):
158-
energy_mjoules2 = nvml.device_get_total_energy_consumption(handles[i])
159-
assert energy_mjoules2 >= energy_mjoules1
160-
if energy_mjoules2 > energy_mjoules1:
161-
break
162-
else:
163-
raise AssertionError("energy did not increase across 150 ms interval")
164-
165-
166148
# [Skipping] pynvml.nvmlDeviceGetGpuOperationMode
167149
# [Skipping] pynvml.nvmlDeviceGetCurrentGpuOperationMode
168150
# [Skipping] pynvml.nvmlDeviceGetPendingGpuOperationMode

‎cuda_bindings_12/tests/nvml/util.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ def supports_ecc(device):
4343

4444
def supports_nvlink(device):
4545
fields = nvml.FieldValue(1)
46-
fields[0].field_id = nvml.FI.DEV_NVLINK_GET_STATE
46+
fields[0].field_id = nvml.FieldId.DEV_NVLINK_GET_STATE
4747
return nvml.device_get_field_values(device, fields)[0].nvml_return == nvml.Return.SUCCESS

0 commit comments

Comments
 (0)