diff --git a/cuda_bindings/tests/helpers.py b/cuda_bindings/tests/helpers.py new file mode 100644 index 000000000..d44e73d46 --- /dev/null +++ b/cuda_bindings/tests/helpers.py @@ -0,0 +1,39 @@ +# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +import os +import pathlib +import sys + +CUDA_PATH = os.environ.get("CUDA_PATH") +CUDA_INCLUDE_PATH = None +CCCL_INCLUDE_PATHS = None +if CUDA_PATH is not None: + path = os.path.join(CUDA_PATH, "include") + if os.path.isdir(path): + CUDA_INCLUDE_PATH = path + CCCL_INCLUDE_PATHS = (path,) + path = os.path.join(path, "cccl") + if os.path.isdir(path): + CCCL_INCLUDE_PATHS = (path,) + CCCL_INCLUDE_PATHS + + +try: + import cuda_python_test_helpers +except ImportError: + # Import shared platform helpers for tests across repos + test_helpers_path = str(pathlib.Path(__file__).resolve().parents[2] / "cuda_python_test_helpers") + try: + sys.path.insert(0, test_helpers_path) + import cuda_python_test_helpers + finally: + # Clean up sys.path modification + if test_helpers_path in sys.path: + sys.path.remove(test_helpers_path) + + +IS_WSL = cuda_python_test_helpers.IS_WSL +supports_ipc_mempool = cuda_python_test_helpers.supports_ipc_mempool + + +del cuda_python_test_helpers diff --git a/cuda_bindings/tests/test_graphics_apis.py b/cuda_bindings/tests/test_graphics_apis.py index ae2f074d5..783aa923c 100644 --- a/cuda_bindings/tests/test_graphics_apis.py +++ b/cuda_bindings/tests/test_graphics_apis.py @@ -3,8 +3,10 @@ import pytest from cuda.bindings import runtime as cudart +from helpers import IS_WSL +@pytest.mark.skipif(IS_WSL, reason="Graphics interop not supported on this platform") def test_graphics_api_smoketest(): # Due to lazy importing in pyglet, pytest.importorskip doesn't work try: @@ -26,6 +28,7 @@ def test_graphics_api_smoketest(): assert error_name in ("cudaErrorInvalidValue", "cudaErrorUnknown") +@pytest.mark.skipif(IS_WSL, reason="Graphics interop not supported on this platform") def test_cuda_register_image_invalid(): """Exercise cudaGraphicsGLRegisterImage with dummy handle only using CUDA runtime API.""" fake_gl_texture_id = 1 diff --git a/cuda_core/tests/helpers.py b/cuda_core/tests/helpers.py index 10af3dcc2..d44e73d46 100644 --- a/cuda_core/tests/helpers.py +++ b/cuda_core/tests/helpers.py @@ -22,8 +22,14 @@ import cuda_python_test_helpers except ImportError: # Import shared platform helpers for tests across repos - sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2] / "cuda_python_test_helpers")) - import cuda_python_test_helpers + test_helpers_path = str(pathlib.Path(__file__).resolve().parents[2] / "cuda_python_test_helpers") + try: + sys.path.insert(0, test_helpers_path) + import cuda_python_test_helpers + finally: + # Clean up sys.path modification + if test_helpers_path in sys.path: + sys.path.remove(test_helpers_path) IS_WSL = cuda_python_test_helpers.IS_WSL diff --git a/cuda_python_test_helpers/cuda_python_test_helpers/__init__.py b/cuda_python_test_helpers/cuda_python_test_helpers/__init__.py index 5996498d9..b8c5f2fe6 100644 --- a/cuda_python_test_helpers/cuda_python_test_helpers/__init__.py +++ b/cuda_python_test_helpers/cuda_python_test_helpers/__init__.py @@ -6,8 +6,6 @@ from contextlib import suppress from typing import Union -from cuda.core.experimental._utils.cuda_utils import handle_return - def _detect_wsl() -> bool: data = "" @@ -39,6 +37,9 @@ def supports_ipc_mempool(device_id: Union[int, object]) -> bool: except Exception: from cuda import cuda as driver # type: ignore + # Lazy import handle_return to avoid hard dependency on cuda.core + from cuda.core.experimental._utils.cuda_utils import handle_return + # Initialize CUDA handle_return(driver.cuInit(0))