From e5a4b3c4b9316be382611191de9a89522ac5c873 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Tue, 21 Oct 2025 17:03:48 -0700 Subject: [PATCH 1/6] Adding to the error tuple --- cuda_bindings/tests/test_graphics_apis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cuda_bindings/tests/test_graphics_apis.py b/cuda_bindings/tests/test_graphics_apis.py index ae2f074d5..7b142ea00 100644 --- a/cuda_bindings/tests/test_graphics_apis.py +++ b/cuda_bindings/tests/test_graphics_apis.py @@ -23,7 +23,7 @@ def test_graphics_api_smoketest(): if error_name == "cudaSuccess": assert int(gfx_resource) != 0 else: - assert error_name in ("cudaErrorInvalidValue", "cudaErrorUnknown") + assert error_name in ("cudaErrorInvalidValue", "cudaErrorUnknown", 'cudaErrorOperatingSystem') def test_cuda_register_image_invalid(): From d2856cc813151abbc70d35899d3943ae1880a8b5 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Tue, 21 Oct 2025 17:07:47 -0700 Subject: [PATCH 2/6] pre-commit fixes --- cuda_bindings/tests/test_graphics_apis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cuda_bindings/tests/test_graphics_apis.py b/cuda_bindings/tests/test_graphics_apis.py index 7b142ea00..259d0b632 100644 --- a/cuda_bindings/tests/test_graphics_apis.py +++ b/cuda_bindings/tests/test_graphics_apis.py @@ -23,7 +23,7 @@ def test_graphics_api_smoketest(): if error_name == "cudaSuccess": assert int(gfx_resource) != 0 else: - assert error_name in ("cudaErrorInvalidValue", "cudaErrorUnknown", 'cudaErrorOperatingSystem') + assert error_name in ("cudaErrorInvalidValue", "cudaErrorUnknown", "cudaErrorOperatingSystem") def test_cuda_register_image_invalid(): From ae3f200024fb749b79850faa9271e3a4b4a640e6 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Wed, 22 Oct 2025 08:27:59 -0700 Subject: [PATCH 3/6] Implementing greptile feedback --- cuda_bindings/tests/helpers.py | 38 +++++++++++++++++++++++ cuda_bindings/tests/test_graphics_apis.py | 3 ++ 2 files changed, 41 insertions(+) create mode 100644 cuda_bindings/tests/helpers.py diff --git a/cuda_bindings/tests/helpers.py b/cuda_bindings/tests/helpers.py new file mode 100644 index 000000000..bd15fdd5d --- /dev/null +++ b/cuda_bindings/tests/helpers.py @@ -0,0 +1,38 @@ +# 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 + sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2] / "cuda_python_test_helpers")) + import cuda_python_test_helpers + +# If we imported the package instead of the module, get the actual module +if hasattr(cuda_python_test_helpers, '__path__'): + # We imported the package, need to get the actual module + import cuda_python_test_helpers.cuda_python_test_helpers as cuda_python_test_helpers + + +IS_WSL = cuda_python_test_helpers.IS_WSL +supports_ipc_mempool = cuda_python_test_helpers.supports_ipc_mempool + + +del cuda_python_test_helpers \ No newline at end of file diff --git a/cuda_bindings/tests/test_graphics_apis.py b/cuda_bindings/tests/test_graphics_apis.py index 259d0b632..77dae1444 100644 --- a/cuda_bindings/tests/test_graphics_apis.py +++ b/cuda_bindings/tests/test_graphics_apis.py @@ -4,7 +4,9 @@ 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", "cudaErrorOperatingSystem") +@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 From e6f4c9f52db35145a5ede2df18d6e39fe35b2212 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Wed, 22 Oct 2025 08:29:56 -0700 Subject: [PATCH 4/6] removing wsl generated errors from the tuple --- cuda_bindings/tests/test_graphics_apis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cuda_bindings/tests/test_graphics_apis.py b/cuda_bindings/tests/test_graphics_apis.py index 77dae1444..56671ea85 100644 --- a/cuda_bindings/tests/test_graphics_apis.py +++ b/cuda_bindings/tests/test_graphics_apis.py @@ -25,7 +25,7 @@ def test_graphics_api_smoketest(): if error_name == "cudaSuccess": assert int(gfx_resource) != 0 else: - assert error_name in ("cudaErrorInvalidValue", "cudaErrorUnknown", "cudaErrorOperatingSystem") + assert error_name in ("cudaErrorInvalidValue", "cudaErrorUnknown") @pytest.mark.skipif(IS_WSL, reason="Graphics interop not supported on this platform") From 9da73e3c4c8970f54926279a5a6778928e38fa65 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Wed, 22 Oct 2025 08:31:54 -0700 Subject: [PATCH 5/6] pre-commit formatting --- cuda_bindings/tests/helpers.py | 4 ++-- cuda_bindings/tests/test_graphics_apis.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cuda_bindings/tests/helpers.py b/cuda_bindings/tests/helpers.py index bd15fdd5d..dad160be3 100644 --- a/cuda_bindings/tests/helpers.py +++ b/cuda_bindings/tests/helpers.py @@ -26,7 +26,7 @@ import cuda_python_test_helpers # If we imported the package instead of the module, get the actual module -if hasattr(cuda_python_test_helpers, '__path__'): +if hasattr(cuda_python_test_helpers, "__path__"): # We imported the package, need to get the actual module import cuda_python_test_helpers.cuda_python_test_helpers as cuda_python_test_helpers @@ -35,4 +35,4 @@ supports_ipc_mempool = cuda_python_test_helpers.supports_ipc_mempool -del cuda_python_test_helpers \ No newline at end of file +del cuda_python_test_helpers diff --git a/cuda_bindings/tests/test_graphics_apis.py b/cuda_bindings/tests/test_graphics_apis.py index 56671ea85..783aa923c 100644 --- a/cuda_bindings/tests/test_graphics_apis.py +++ b/cuda_bindings/tests/test_graphics_apis.py @@ -3,9 +3,9 @@ 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 From 6927cfe6fe66dbf553ccbd6ec8917c95cee9de65 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Wed, 22 Oct 2025 09:05:18 -0700 Subject: [PATCH 6/6] lazy import fix --- cuda_bindings/tests/helpers.py | 15 ++++++++------- cuda_core/tests/helpers.py | 10 ++++++++-- .../cuda_python_test_helpers/__init__.py | 5 +++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/cuda_bindings/tests/helpers.py b/cuda_bindings/tests/helpers.py index dad160be3..d44e73d46 100644 --- a/cuda_bindings/tests/helpers.py +++ b/cuda_bindings/tests/helpers.py @@ -22,13 +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 - -# If we imported the package instead of the module, get the actual module -if hasattr(cuda_python_test_helpers, "__path__"): - # We imported the package, need to get the actual module - import cuda_python_test_helpers.cuda_python_test_helpers as 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_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))