Skip to content

Commit 1d7c89e

Browse files
mdboomCopilot
andauthored
Skip NVML tests if the hardware doesn't support NVML (#1585)
* Skip NVML tests if the hardware doesn't support NVML * Also skip converting between Device types * Fix test_to_system_device test * Update cuda_bindings/cuda/bindings/_test_helpers/arch_check.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix test * Simplify check * Fix import when cuda_bindings is incompatible * Fix logic * Move over a single test from #1583 * Fix check --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent fd57180 commit 1d7c89e

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

cuda_bindings/cuda/bindings/_test_helpers/arch_check.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,30 @@
33

44

55
from contextlib import contextmanager
6+
from functools import cache
67

78
import pytest
89
from cuda.bindings import nvml
910

1011

12+
@cache
13+
def hardware_supports_nvml():
14+
"""
15+
Tries to call the simplest NVML API possible to see if just the basics
16+
works. If not we are probably on one of the platforms where NVML is not
17+
supported at all (e.g. Jetson Orin).
18+
"""
19+
nvml.init_v2()
20+
try:
21+
nvml.system_get_driver_branch()
22+
except (nvml.NotSupportedError, nvml.UnknownError):
23+
return False
24+
else:
25+
return True
26+
finally:
27+
nvml.shutdown()
28+
29+
1130
@contextmanager
1231
def unsupported_before(device: int, expected_device_arch: nvml.DeviceArch | str | None):
1332
device_arch = nvml.device_get_architecture(device)
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
3+
4+
5+
import pytest
6+
from cuda.bindings._test_helpers.arch_check import hardware_supports_nvml
7+
8+
if not hardware_supports_nvml():
9+
pytest.skip("NVML not supported on this platform", allow_module_level=True)

cuda_core/tests/system/conftest.py

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

55

66
import pytest
77
from cuda.core import system
88

9+
SHOULD_SKIP_NVML_TESTS = not system.CUDA_BINDINGS_NVML_IS_COMPATIBLE
10+
11+
12+
if system.CUDA_BINDINGS_NVML_IS_COMPATIBLE:
13+
from cuda.bindings._test_helpers.arch_check import hardware_supports_nvml
14+
15+
SHOULD_SKIP_NVML_TESTS |= not hardware_supports_nvml()
16+
17+
918
skip_if_nvml_unsupported = pytest.mark.skipif(
10-
not system.CUDA_BINDINGS_NVML_IS_COMPATIBLE, reason="NVML support requires cuda.bindings version 12.9.6+ or 13.1.2+"
19+
SHOULD_SKIP_NVML_TESTS,
20+
reason="NVML support requires cuda.bindings version 12.9.6+ or 13.1.2+, and hardware that supports NVML",
1121
)
1222

1323

cuda_core/tests/test_device.py

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

44
try:
@@ -35,6 +35,11 @@ def test_to_system_device(deinit_cuda):
3535
device.to_system_device()
3636
pytest.skip("NVML support requires cuda.bindings version 12.9.6+ or 13.1.2+")
3737

38+
from cuda.bindings._test_helpers.arch_check import hardware_supports_nvml
39+
40+
if not hardware_supports_nvml():
41+
pytest.skip("NVML not supported on this platform")
42+
3843
from cuda.core.system import Device as SystemDevice
3944

4045
system_device = device.to_system_device()

cuda_core/tests/test_graph_mem.py

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

@@ -13,6 +13,7 @@
1313
ProgramOptions,
1414
launch,
1515
)
16+
from cuda.core._utils.cuda_utils import CUDAError
1617
from helpers import IS_WINDOWS, IS_WSL
1718
from helpers.buffers import compare_buffer_to_constant, make_scratch_buffer, set_buffer
1819

@@ -166,7 +167,12 @@ def test_graph_alloc_with_output(mempool_device, mode):
166167
out.copy_from(in_, stream=gb)
167168
launch(gb, LaunchConfig(grid=1, block=1), add_one, out, NBYTES)
168169
options = GraphCompleteOptions(auto_free_on_launch=True)
169-
graph = gb.end_building().complete(options)
170+
try:
171+
graph = gb.end_building().complete(options)
172+
except CUDAError as exc:
173+
if "CUDA_ERROR_INVALID_VALUE" in str(exc):
174+
pytest.skip("auto_free_on_launch not supported on this platform")
175+
raise
170176

171177
# Launch the graph. The output buffer is allocated and set to one.
172178
graph.upload(stream)

0 commit comments

Comments
 (0)