diff --git a/cuda_bindings/cuda/bindings/_test_helpers/arch_check.py b/cuda_bindings/cuda/bindings/_test_helpers/arch_check.py index e063fd4ff8..bf66250d1e 100644 --- a/cuda_bindings/cuda/bindings/_test_helpers/arch_check.py +++ b/cuda_bindings/cuda/bindings/_test_helpers/arch_check.py @@ -3,11 +3,30 @@ 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..996effce9c 100644 --- a/cuda_bindings/tests/nvml/__init__.py +++ b/cuda_bindings/tests/nvml/__init__.py @@ -1,2 +1,9 @@ -# 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) diff --git a/cuda_core/tests/system/conftest.py b/cuda_core/tests/system/conftest.py index cb6974806d..594f2ba925 100644 --- a/cuda_core/tests/system/conftest.py +++ b/cuda_core/tests/system/conftest.py @@ -1,4 +1,4 @@ -# 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: Apache-2.0 @@ -6,8 +6,18 @@ import pytest from cuda.core import system +SHOULD_SKIP_NVML_TESTS = not system.CUDA_BINDINGS_NVML_IS_COMPATIBLE + + +if system.CUDA_BINDINGS_NVML_IS_COMPATIBLE: + from cuda.bindings._test_helpers.arch_check import hardware_supports_nvml + + SHOULD_SKIP_NVML_TESTS |= not hardware_supports_nvml() + + skip_if_nvml_unsupported = pytest.mark.skipif( - not system.CUDA_BINDINGS_NVML_IS_COMPATIBLE, reason="NVML support requires cuda.bindings version 12.9.6+ or 13.1.2+" + SHOULD_SKIP_NVML_TESTS, + reason="NVML support requires cuda.bindings version 12.9.6+ or 13.1.2+, and hardware that supports NVML", ) diff --git a/cuda_core/tests/test_device.py b/cuda_core/tests/test_device.py index 09f33b92d2..d561f92b9e 100644 --- a/cuda_core/tests/test_device.py +++ b/cuda_core/tests/test_device.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 try: @@ -35,6 +35,11 @@ def test_to_system_device(deinit_cuda): device.to_system_device() pytest.skip("NVML support requires cuda.bindings version 12.9.6+ or 13.1.2+") + from cuda.bindings._test_helpers.arch_check import hardware_supports_nvml + + if not hardware_supports_nvml(): + pytest.skip("NVML not supported on this platform") + from cuda.core.system import Device as SystemDevice system_device = device.to_system_device() diff --git a/cuda_core/tests/test_graph_mem.py b/cuda_core/tests/test_graph_mem.py index bcb8a800a1..c80dd8c982 100644 --- a/cuda_core/tests/test_graph_mem.py +++ b/cuda_core/tests/test_graph_mem.py @@ -1,4 +1,4 @@ -# 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 @@ -13,6 +13,7 @@ ProgramOptions, launch, ) +from cuda.core._utils.cuda_utils import CUDAError from helpers import IS_WINDOWS, IS_WSL from helpers.buffers import compare_buffer_to_constant, make_scratch_buffer, set_buffer @@ -166,7 +167,12 @@ def test_graph_alloc_with_output(mempool_device, mode): out.copy_from(in_, stream=gb) launch(gb, LaunchConfig(grid=1, block=1), add_one, out, NBYTES) options = GraphCompleteOptions(auto_free_on_launch=True) - graph = gb.end_building().complete(options) + try: + graph = gb.end_building().complete(options) + except CUDAError as exc: + if "CUDA_ERROR_INVALID_VALUE" in str(exc): + pytest.skip("auto_free_on_launch not supported on this platform") + raise # Launch the graph. The output buffer is allocated and set to one. graph.upload(stream)