From 0a3df4f84fc7d138a91efa090c626f80ca3a3650 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 6 Feb 2026 13:14:23 -0500 Subject: [PATCH] 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> --- .../cuda/bindings/_test_helpers/arch_check.py | 19 +++++++++++++++++++ cuda_bindings/tests/nvml/__init__.py | 10 +++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cuda_bindings/cuda/bindings/_test_helpers/arch_check.py b/cuda_bindings/cuda/bindings/_test_helpers/arch_check.py index f4e99aaeca..9b1e5e23a7 100644 --- a/cuda_bindings/cuda/bindings/_test_helpers/arch_check.py +++ b/cuda_bindings/cuda/bindings/_test_helpers/arch_check.py @@ -3,12 +3,31 @@ from contextlib import contextmanager +from functools import cache import pytest from cuda.bindings import nvml +@cache +def hardware_supports_nvml(): + """ + Tries to call the simplest NVML API possible to see if just the basics + works. If not we are probably on one of the platforms where NVML is not + supported at all (e.g. Jetson Orin). + """ + nvml.init_v2() + try: + nvml.system_get_driver_branch() + except (nvml.NotSupportedError, nvml.UnknownError): + return False + else: + return True + finally: + nvml.shutdown() + + @contextmanager def unsupported_before(device: int, expected_device_arch: nvml.DeviceArch | str | None): device_arch = nvml.device_get_architecture(device) diff --git a/cuda_bindings/tests/nvml/__init__.py b/cuda_bindings/tests/nvml/__init__.py index 830c1bf0de..854f640766 100644 --- a/cuda_bindings/tests/nvml/__init__.py +++ b/cuda_bindings/tests/nvml/__init__.py @@ -1,2 +1,10 @@ -# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE + + +import pytest + +from cuda.bindings._test_helpers.arch_check import hardware_supports_nvml + +if not hardware_supports_nvml(): + pytest.skip("NVML not supported on this platform", allow_module_level=True)