Skip to content
19 changes: 19 additions & 0 deletions cuda_bindings/cuda/bindings/_test_helpers/arch_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion cuda_bindings/tests/nvml/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 12 additions & 2 deletions cuda_core/tests/system/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# 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


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",
)


Expand Down
7 changes: 6 additions & 1 deletion cuda_core/tests/test_device.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 8 additions & 2 deletions cuda_core/tests/test_graph_mem.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
Loading