diff --git a/.github/workflows/build-wheel.yml b/.github/workflows/build-wheel.yml index e1ab9b2802d4..d8b8d1bb7378 100644 --- a/.github/workflows/build-wheel.yml +++ b/.github/workflows/build-wheel.yml @@ -500,9 +500,7 @@ jobs: test "${#bindings_wheels[@]}" -eq 1 test -f "${bindings_wheels[0]}" python -m pip install "${bindings_wheels[0]}" --group "${CURRENT_BINDINGS_ROOT}/pyproject.toml:test" - pushd ${{ env.CURRENT_BINDINGS_CYTHON_TESTS_DIR }} - bash build_tests.sh - popd + python "${CURRENT_BINDINGS_CYTHON_TESTS_DIR}/build_tests.py" - name: Upload cuda.bindings ${{ env.CURRENT_CUDA_MAJOR }} Cython tests if: ${{ env.TEST_BINDINGS_CURRENT == 'true' }} @@ -526,9 +524,7 @@ jobs: exit 1 fi pip install "${core_wheel}" --group ./cuda_core/pyproject.toml:test - pushd ${{ env.CUDA_CORE_CYTHON_TESTS_DIR }} - bash build_tests.sh - popd + python "${CUDA_CORE_CYTHON_TESTS_DIR}/build_tests.py" - name: Upload current cuda.core Cython tests if: ${{ env.TEST_CORE_CURRENT == 'true' }} @@ -623,9 +619,7 @@ jobs: test "${#bindings_wheels[@]}" -eq 1 test -f "${bindings_wheels[0]}" python -m pip install "${bindings_wheels[0]}" --group "${MAINTENANCE_BINDINGS_ROOT}/pyproject.toml:test" - pushd ${{ env.MAINTENANCE_BINDINGS_CYTHON_TESTS_DIR }} - bash build_tests.sh - popd + python "${MAINTENANCE_BINDINGS_CYTHON_TESTS_DIR}/build_tests.py" - name: Upload cuda.bindings ${{ env.MAINTENANCE_CUDA_MAJOR }} Cython tests if: ${{ !inputs.single-cuda-major && env.TEST_BINDINGS_MAINTENANCE == 'true' }} @@ -755,9 +749,7 @@ jobs: exit 1 fi pip install "${core_wheel}" --group ./cuda_core/pyproject.toml:test - pushd ${{ env.CUDA_CORE_CYTHON_TESTS_DIR }} - bash build_tests.sh - popd + python "${CUDA_CORE_CYTHON_TESTS_DIR}/build_tests.py" - name: Upload maintenance cuda.core Cython tests if: ${{ !inputs.single-cuda-major && env.TEST_CORE_MAINTENANCE == 'true' }} diff --git a/cuda_bindings_12/AGENTS.md b/cuda_bindings_12/AGENTS.md index 1de5d4fa199e..968d8a752483 100644 --- a/cuda_bindings_12/AGENTS.md +++ b/cuda_bindings_12/AGENTS.md @@ -35,7 +35,7 @@ for generation provenance and review expectations. From this directory, install with `python -m pip install -v -e . --group test`, then run `python -m pytest tests/`. Free-threaded development also needs the `test-ft` dependency group. -- Build Cython tests with `tests/cython/build_tests.sh` or `build_tests.bat` +- Build Cython tests with `python tests/cython/build_tests.py` before running `python -m pytest tests/cython/`. This requires the matching CUDA headers and compiler toolchain. - Legacy samples remain under `examples/`; do not assume CUDA 13's sample diff --git a/cuda_bindings_12/README.md b/cuda_bindings_12/README.md index ad736aca1c64..3320a12b7cc4 100644 --- a/cuda_bindings_12/README.md +++ b/cuda_bindings_12/README.md @@ -31,12 +31,11 @@ and pip 25.1 or newer: ```console cd cuda_bindings_12 python -m pip install -v -e . --group test -tests/cython/build_tests.sh +python tests/cython/build_tests.py python -m pytest tests/ tests/cython/ ``` -Use `build_tests.bat` on Windows. Free-threaded Python also needs the -`test-ft` dependency group. +Free-threaded Python also needs the `test-ft` dependency group. Versions follow reachable `v12.*` tags through standard `setuptools-scm`. Source builds need the matching tag and the history connecting it to the @@ -69,8 +68,9 @@ To run these tests: Cython tests are located in `tests/cython` and need to be built. These builds have the same CUDA Toolkit header requirements as [Installing from Source](https://nvidia.github.io/cuda-python/cuda-bindings/12.9.7/install.html#requirements) where the major.minor version must match `cuda.bindings`. To build them: -1. Setup environment variable `CUDA_HOME` with the path to the CUDA Toolkit installation. -2. Run the `build_tests` script located in `tests/cython` appropriate to your platform. This will both cythonize the tests and build them. +1. Set `CUDA_PATH` or `CUDA_HOME` to the CUDA Toolkit installation path. + If both are set, `CUDA_PATH` takes precedence. +2. Run `python tests/cython/build_tests.py` to cythonize and build the tests. To run these tests: * `python -m pytest tests/cython/` against editable installations diff --git a/cuda_bindings_12/pixi.toml b/cuda_bindings_12/pixi.toml index 67d351d0cc6c..81c794b6d5a1 100644 --- a/cuda_bindings_12/pixi.toml +++ b/cuda_bindings_12/pixi.toml @@ -64,12 +64,15 @@ cuda-crt-dev_win-64 = "*" # For finding headers when building the Cython tests. [feature.cython-tests.target.linux-64.activation.env] CUDA_HOME = "$CONDA_PREFIX/targets/x86_64-linux" +CUDA_PATH = "$CONDA_PREFIX/targets/x86_64-linux" [feature.cython-tests.target.linux-aarch64.activation.env] CUDA_HOME = "$CONDA_PREFIX/targets/sbsa-linux" +CUDA_PATH = "$CONDA_PREFIX/targets/sbsa-linux" [feature.cython-tests.target.win-64.activation.env] CUDA_HOME = "$CONDA_PREFIX/Library" +CUDA_PATH = "$CONDA_PREFIX/Library" [feature.cu12.dependencies] cuda-version = "12.*" @@ -139,11 +142,8 @@ libnvfatbin = "*" [package.target.linux.run-dependencies] libcufile = "*" -[target.linux.tasks.build-cython-tests] -cmd = ["$PIXI_PROJECT_ROOT/tests/cython/build_tests.sh"] - -[target.win-64.tasks.build-cython-tests] -cmd = ["$PIXI_PROJECT_ROOT/tests/cython/build_tests.bat"] +[tasks.build-cython-tests] +cmd = 'python "$PIXI_PROJECT_ROOT/tests/cython/build_tests.py"' [target.linux.tasks.test] cmd = [ diff --git a/cuda_bindings_12/pyproject.toml b/cuda_bindings_12/pyproject.toml index d281a749b597..e57393681960 100644 --- a/cuda_bindings_12/pyproject.toml +++ b/cuda_bindings_12/pyproject.toml @@ -55,6 +55,7 @@ build = [ "cython>=3.2.5,<3.3", ] test = [ + "cuda-pathfinder>=1.5", "cython>=3.2.5,<3.3", "setuptools>=80.0.0", "numpy>=1.21.1", diff --git a/cuda_bindings_12/tests/cython/build_tests.bat b/cuda_bindings_12/tests/cython/build_tests.bat deleted file mode 100644 index 0ef6abb06f3f..000000000000 --- a/cuda_bindings_12/tests/cython/build_tests.bat +++ /dev/null @@ -1,12 +0,0 @@ -@echo off - -REM SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -REM SPDX-License-Identifier: Apache-2.0 - -setlocal -set CL=%CL% /I"%CUDA_HOME%\include" -REM The Python driver provides Cython's .pxd include path and builds in this -REM directory so Windows does not duplicate the checkout path in link outputs. -python "%~dp0build_tests.py" -set "BUILD_RESULT=%ERRORLEVEL%" -endlocal & exit /b %BUILD_RESULT% diff --git a/cuda_bindings_12/tests/cython/build_tests.py b/cuda_bindings_12/tests/cython/build_tests.py index a4a26589ce94..6afcd7726f0e 100644 --- a/cuda_bindings_12/tests/cython/build_tests.py +++ b/cuda_bindings_12/tests/cython/build_tests.py @@ -98,6 +98,7 @@ def main() -> None: raise SystemExit(f"no test_*.pyx files under {script_dir}") ext_modules = _cythonize_tests(pyx_files) + build_shared._add_cython_test_include_dirs(ext_modules) # pytest imports each extension by bare module name (see test_cython.py), # so build in-place next to its .pyx regardless of the invoking cwd. diff --git a/cuda_bindings_12/tests/cython/build_tests.sh b/cuda_bindings_12/tests/cython/build_tests.sh deleted file mode 100755 index 0ca0745d2b4c..000000000000 --- a/cuda_bindings_12/tests/cython/build_tests.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -set -eo pipefail - -# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -UNAME=$(uname) -if [ "$UNAME" == "Linux" ] ; then - SCRIPTPATH=$(dirname $(realpath "$0")) - export CPLUS_INCLUDE_PATH=$CUDA_HOME/include:${CPLUS_INCLUDE_PATH:-} -elif [[ "$UNAME" == CYGWIN* || "$UNAME" == MINGW* || "$UNAME" == MSYS* ]] ; then - SCRIPTPATH="$(dirname $(cygpath -w $(realpath "$0")))" - export CL="/I\"${CUDA_HOME}\\include\" ${CL:-}" -else - exit 1 -fi - -# Use a Python driver so the cuda.bindings source root is resolved at -# runtime and passed via Cython's include_path -- avoids platform-specific -# PYTHONPATH separator handling and surfaces import errors as exceptions. -# nthreads=1 inside the driver mirrors the previous `-j 1` to side-step -# any process-pool issues and keep builds deterministic. -python "${SCRIPTPATH}/build_tests.py" diff --git a/cuda_bindings_13/AGENTS.md b/cuda_bindings_13/AGENTS.md index a892a0799f3b..4a33dd125e4c 100644 --- a/cuda_bindings_13/AGENTS.md +++ b/cuda_bindings_13/AGENTS.md @@ -46,7 +46,7 @@ subpackage in the `cuda-python` monorepo. - **Primary tests**: `pytest tests/` - **Cython tests**: - - build: `tests/cython/build_tests.sh` (or platform equivalent) + - build: `python tests/cython/build_tests.py` - run: `pytest tests/cython/` - **Samples**: run pytest-based sample coverage in `tests/example_tests/`; sample sources and instructions live in `../samples/cuda_bindings/`. diff --git a/cuda_bindings_13/README.md b/cuda_bindings_13/README.md index e603e713ec8b..1906b1b835ec 100644 --- a/cuda_bindings_13/README.md +++ b/cuda_bindings_13/README.md @@ -44,7 +44,7 @@ To run these tests: Cython tests are located in `tests/cython` and need to be built. These builds have the same CUDA Toolkit header requirements as [Installing from Source](https://nvidia.github.io/cuda-python/cuda-bindings/latest/install.html#requirements) where the major.minor version must match `cuda.bindings`. To build them: 1. Setup environment variable `CUDA_PATH` (or `CUDA_HOME`) with the path to the CUDA Toolkit installation. Note: If both are set, `CUDA_PATH` takes precedence. -2. Run the `build_tests` script located in `tests/cython` appropriate to your platform. This will both cythonize the tests and build them. +2. Run `python tests/cython/build_tests.py` to cythonize and build the tests. To run these tests: * `python -m pytest tests/cython/` against editable installations diff --git a/cuda_bindings_13/_build_shared.py b/cuda_bindings_13/_build_shared.py index 8a4faf066865..03da3c887b33 100644 --- a/cuda_bindings_13/_build_shared.py +++ b/cuda_bindings_13/_build_shared.py @@ -89,6 +89,19 @@ def _get_cuda_path() -> str: return cuda_path +def _add_cython_test_include_dirs(extensions, *package_include_dirs: Path) -> None: + """Set the compiler include paths for the Cython test extensions.""" + cuda_include_dir = Path(_get_cuda_path()) / "include" + include_dirs = [str(path) for path in (*package_include_dirs, cuda_include_dir)] + for extension in extensions: + if sys.platform == "win32": + extension.include_dirs.extend(include_dirs) + else: + # CPLUS_INCLUDE_PATH treated these directories as system headers. + for include_dir in include_dirs: + extension.extra_compile_args.extend(("-isystem", include_dir)) + + # ----------------------------------------------------------------------- # Toolchain selection diff --git a/cuda_bindings_13/pixi.toml b/cuda_bindings_13/pixi.toml index a3d33e678199..c086cf82a3f7 100644 --- a/cuda_bindings_13/pixi.toml +++ b/cuda_bindings_13/pixi.toml @@ -68,12 +68,15 @@ cuda-crt-dev_win-64 = "*" # For finding headers when building the Cython tests [feature.cython-tests.target.linux-64.activation.env] CUDA_HOME = "$CONDA_PREFIX/targets/x86_64-linux" +CUDA_PATH = "$CONDA_PREFIX/targets/x86_64-linux" [feature.cython-tests.target.linux-aarch64.activation.env] CUDA_HOME = "$CONDA_PREFIX/targets/sbsa-linux" +CUDA_PATH = "$CONDA_PREFIX/targets/sbsa-linux" [feature.cython-tests.target.win-64.activation.env] CUDA_HOME = "$CONDA_PREFIX/Library" +CUDA_PATH = "$CONDA_PREFIX/Library" [feature.cu12.dependencies] cuda-version = "12.*" @@ -152,11 +155,8 @@ libnvfatbin = "*" [package.target.linux.run-dependencies] libcufile = "*" -[target.linux.tasks.build-cython-tests] -cmd = ["$PIXI_PROJECT_ROOT/tests/cython/build_tests.sh"] - -[target.win-64.tasks.build-cython-tests] -cmd = ["$PIXI_PROJECT_ROOT/tests/cython/build_tests.bat"] +[tasks.build-cython-tests] +cmd = 'python "$PIXI_PROJECT_ROOT/tests/cython/build_tests.py"' [target.linux.tasks.test] cmd = [ diff --git a/cuda_bindings_13/pyproject.toml b/cuda_bindings_13/pyproject.toml index e6261ee483d3..466b79c9d360 100644 --- a/cuda_bindings_13/pyproject.toml +++ b/cuda_bindings_13/pyproject.toml @@ -50,6 +50,7 @@ build = [ "cython>=3.2.5,<3.3", ] test = [ + "cuda-pathfinder>=1.5", "cython>=3.2.5,<3.3", "setuptools>=80.0.0", "numpy>=1.21.1", diff --git a/cuda_bindings_13/tests/cython/build_tests.bat b/cuda_bindings_13/tests/cython/build_tests.bat deleted file mode 100644 index 0ef6abb06f3f..000000000000 --- a/cuda_bindings_13/tests/cython/build_tests.bat +++ /dev/null @@ -1,12 +0,0 @@ -@echo off - -REM SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -REM SPDX-License-Identifier: Apache-2.0 - -setlocal -set CL=%CL% /I"%CUDA_HOME%\include" -REM The Python driver provides Cython's .pxd include path and builds in this -REM directory so Windows does not duplicate the checkout path in link outputs. -python "%~dp0build_tests.py" -set "BUILD_RESULT=%ERRORLEVEL%" -endlocal & exit /b %BUILD_RESULT% diff --git a/cuda_bindings_13/tests/cython/build_tests.py b/cuda_bindings_13/tests/cython/build_tests.py index d5f0c7fe583c..664fb4fb71bb 100644 --- a/cuda_bindings_13/tests/cython/build_tests.py +++ b/cuda_bindings_13/tests/cython/build_tests.py @@ -98,6 +98,7 @@ def main() -> None: raise SystemExit(f"no test_*.pyx files under {script_dir}") ext_modules = _cythonize_tests(pyx_files) + build_shared._add_cython_test_include_dirs(ext_modules) # pytest imports each extension by bare module name (see test_cython.py), # so build in-place next to its .pyx regardless of the invoking cwd. diff --git a/cuda_bindings_13/tests/cython/build_tests.sh b/cuda_bindings_13/tests/cython/build_tests.sh deleted file mode 100755 index 0ca0745d2b4c..000000000000 --- a/cuda_bindings_13/tests/cython/build_tests.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -set -eo pipefail - -# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -UNAME=$(uname) -if [ "$UNAME" == "Linux" ] ; then - SCRIPTPATH=$(dirname $(realpath "$0")) - export CPLUS_INCLUDE_PATH=$CUDA_HOME/include:${CPLUS_INCLUDE_PATH:-} -elif [[ "$UNAME" == CYGWIN* || "$UNAME" == MINGW* || "$UNAME" == MSYS* ]] ; then - SCRIPTPATH="$(dirname $(cygpath -w $(realpath "$0")))" - export CL="/I\"${CUDA_HOME}\\include\" ${CL:-}" -else - exit 1 -fi - -# Use a Python driver so the cuda.bindings source root is resolved at -# runtime and passed via Cython's include_path -- avoids platform-specific -# PYTHONPATH separator handling and surfaces import errors as exceptions. -# nthreads=1 inside the driver mirrors the previous `-j 1` to side-step -# any process-pool issues and keep builds deterministic. -python "${SCRIPTPATH}/build_tests.py" diff --git a/cuda_core/AGENTS.md b/cuda_core/AGENTS.md index ab91616515c3..863785d22281 100644 --- a/cuda_core/AGENTS.md +++ b/cuda_core/AGENTS.md @@ -130,7 +130,7 @@ the literal floor. - **Primary tests**: `pytest tests/` - **Cython tests**: - - build: `tests/cython/build_tests.sh` (or platform equivalent) + - build: `python tests/cython/build_tests.py` - run: `pytest tests/cython/` - **Samples**: validate affected samples in `../samples/cuda_core/` when changing user workflows or public APIs. diff --git a/cuda_core/README.md b/cuda_core/README.md index 42e9aab5ed1f..ed17697b01be 100644 --- a/cuda_core/README.md +++ b/cuda_core/README.md @@ -33,7 +33,7 @@ Builds run clang-tidy on the handwritten C++ sources (`cuda/core/_cpp/`) and fai Cython tests are located in `tests/cython` and need to be built. These builds have the same CUDA Toolkit header requirements as [those of cuda.bindings](https://nvidia.github.io/cuda-python/cuda-bindings/latest/install.html#requirements) where the major.minor version must match `cuda.bindings`. To build them: 1. Set up environment variable `CUDA_PATH` (or `CUDA_HOME`) with the path to the CUDA Toolkit installation. Note: If both are set, `CUDA_PATH` takes precedence. -2. Run `build_tests` script located in `tests/cython` appropriate to your platform. This will both cythonize the tests and build them. +2. Run `python tests/cython/build_tests.py` to cythonize and build the tests. To run these tests: * `python -m pytest tests/cython/` with editable installations diff --git a/cuda_core/pixi.toml b/cuda_core/pixi.toml index b845599c039d..10dc34b46ff1 100644 --- a/cuda_core/pixi.toml +++ b/cuda_core/pixi.toml @@ -134,12 +134,15 @@ cuda-crt-dev_win-64 = "*" # For finding headers when building the Cython tests [feature.cython-tests.target.linux-64.activation.env] CUDA_HOME = "$CONDA_PREFIX/targets/x86_64-linux" +CUDA_PATH = "$CONDA_PREFIX/targets/x86_64-linux" [feature.cython-tests.target.linux-aarch64.activation.env] CUDA_HOME = "$CONDA_PREFIX/targets/sbsa-linux" +CUDA_PATH = "$CONDA_PREFIX/targets/sbsa-linux" [feature.cython-tests.target.win-64.activation.env] CUDA_HOME = "$CONDA_PREFIX/Library" +CUDA_PATH = "$CONDA_PREFIX/Library" [feature.cu13.dependencies] cuda-version = "13.5.*" @@ -294,8 +297,8 @@ numpy = "*" cuda-bindings = "*" cuda-pathfinder = "*" -[target.linux.tasks.build-cython-tests] -cmd = ["$PIXI_PROJECT_ROOT/tests/cython/build_tests.sh"] +[tasks.build-cython-tests] +cmd = 'python "$PIXI_PROJECT_ROOT/tests/cython/build_tests.py"' [target.linux.tasks.docs-build] cmd = ["$PIXI_PROJECT_ROOT/docs/build_docs.sh"] @@ -314,9 +317,6 @@ cmd = ["$PIXI_PROJECT_ROOT/docs/build_docs.sh", "latest-only"] env = { SPHINXOPTS = "-v -j 1 -d build/.doctrees" } default-environment = "docs" -[target.win-64.tasks.build-cython-tests] -cmd = ["$PIXI_PROJECT_ROOT/tests/cython/build_tests.bat"] - [target.linux.tasks.test] cmd = [ "pytest", diff --git a/cuda_core/pyproject.toml b/cuda_core/pyproject.toml index 1e5e60a52fb3..99ff2c5ededb 100644 --- a/cuda_core/pyproject.toml +++ b/cuda_core/pyproject.toml @@ -76,6 +76,7 @@ build = [ "clang-tidy==22.1.8; sys_platform != 'win32' or platform_machine != 'ARM64'", ] test = [ + "cuda-pathfinder>=1.5", "cython>=3.2.5,<3.3", "setuptools>=80", "pytest==9.1.0", diff --git a/cuda_core/tests/cython/build_tests.py b/cuda_core/tests/cython/build_tests.py index 0ae2d3531e62..d833f1917548 100644 --- a/cuda_core/tests/cython/build_tests.py +++ b/cuda_core/tests/cython/build_tests.py @@ -105,6 +105,8 @@ def main() -> None: # are stable regardless of the invoking cwd. os.chdir(script_dir) ext_modules = _cythonize_tests(pyx_files) + core_include_dir = script_dir.parents[1] / "cuda" / "core" / "_include" + build_shared._add_cython_test_include_dirs(ext_modules, core_include_dir) # Core's runtime consumer headers require C++17 with either toolchain. for extension in ext_modules: extension.extra_compile_args.append("/std:c++17" if os.name == "nt" else "-std=c++17") diff --git a/cuda_core/tests/cython/build_tests.sh b/cuda_core/tests/cython/build_tests.sh deleted file mode 100755 index 72403baf5719..000000000000 --- a/cuda_core/tests/cython/build_tests.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -set -eo pipefail - -# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -UNAME=$(uname) -if [ "$UNAME" == "Linux" ] ; then - SCRIPTPATH=$(dirname $(realpath "$0")) - export CPLUS_INCLUDE_PATH=${SCRIPTPATH}/../../cuda/core/_include:$CUDA_HOME/include:${CPLUS_INCLUDE_PATH:-} -elif [[ "$UNAME" == CYGWIN* || "$UNAME" == MINGW* || "$UNAME" == MSYS* ]] ; then - SCRIPTPATH="$(dirname $(cygpath -w $(realpath "$0")))" - CUDA_CORE_INCLUDE_PATH=$(echo "${SCRIPTPATH}\..\..\cuda\core\_include" | sed 's/\\/\\\\/g') - export CL="/I\"${CUDA_CORE_INCLUDE_PATH}\" /I\"${CUDA_HOME}\\include\" ${CL:-}" -else - exit 1 -fi - -# Use a Python driver so the cuda.bindings source root is resolved at -# runtime and passed via Cython's include_path -- avoids platform-specific -# PYTHONPATH separator handling and surfaces import errors as exceptions. -python "${SCRIPTPATH}/build_tests.py"