diff --git a/.github/workflows/test-wheel-linux.yml b/.github/workflows/test-wheel-linux.yml index c5061a16eb..4ef4d31e06 100644 --- a/.github/workflows/test-wheel-linux.yml +++ b/.github/workflows/test-wheel-linux.yml @@ -96,12 +96,15 @@ jobs: uses: nv-gha-runners/setup-proxy-cache@main continue-on-error: true + - name: Install uv + uses: astral-sh/setup-uv@v7 + - name: Install dependencies uses: ./.github/actions/install_unix_deps continue-on-error: false with: # for artifact fetching, graphics libs - dependencies: "jq wget libgl1 libegl1" + dependencies: "jq wget libgl1 libegl1 g++" dependent_exes: "jq wget" - name: Set environment variables @@ -277,6 +280,13 @@ jobs: LOCAL_CTK: ${{ matrix.LOCAL_CTK }} run: run-tests core + - name: Run cuda.core examples with PEP 723 metadata in isolation + env: + CUDA_VER: ${{ matrix.CUDA_VER }} + LOCAL_CTK: ${{ matrix.LOCAL_CTK }} + run: | + ci/tools/run-examples-pep723 cuda_core/examples/ + - name: Ensure cuda-python installable run: | if [[ "${{ matrix.LOCAL_CTK }}" == 1 ]]; then diff --git a/ci/tools/run-examples-pep723 b/ci/tools/run-examples-pep723 new file mode 100755 index 0000000000..96ddce86d6 --- /dev/null +++ b/ci/tools/run-examples-pep723 @@ -0,0 +1,43 @@ +#!/bin/bash + +# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Runs a directory of examples using `uv run` to test that the PEP 723 +# dependency metadata in them is valid. + +# We allow a resolution to fail for cuda_core or cuda_bindings only, since there +# we assume it is pinned to some future release. This allows examples to be +# written for unreleased features. Testing examples against prereleases is +# already covered by CI elsewhere. + +TARGET_DIR=$1 + +if [ -z "$TARGET_DIR" ]; then + echo "Usage: $0 " + exit 1 +fi + +FAILED=0 + +while IFS= read -r -d '' file; do + echo "Running $file..." + OUTPUT=$(uv run "$file" 2>&1) + EXIT_CODE=$? + + if [ $EXIT_CODE -ne 0 ]; then + if echo "$OUTPUT" | grep -Eq "Because only cuda-(core|bindings)"; then + echo "SKIPPED: $file (No solution found)" + else + echo "FAILED: $file" + echo "$OUTPUT" + FAILED=1 + fi + else + echo "PASSED: $file" + fi +done < <(find "$TARGET_DIR" -name "*.py" -print0) + +if [ $FAILED -ne 0 ]; then + exit 1 +fi diff --git a/cuda_core/examples/cuda_graphs.py b/cuda_core/examples/cuda_graphs.py index be23067200..ad4271aeb5 100644 --- a/cuda_core/examples/cuda_graphs.py +++ b/cuda_core/examples/cuda_graphs.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 @@ -10,6 +10,10 @@ # # ################################################################################ +# /// script +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x"] +# /// + import sys import time diff --git a/cuda_core/examples/gl_interop_plasma.py b/cuda_core/examples/gl_interop_plasma.py index 3d881a90f2..d303abdc25 100644 --- a/cuda_core/examples/gl_interop_plasma.py +++ b/cuda_core/examples/gl_interop_plasma.py @@ -53,9 +53,10 @@ # effect popular in the demoscene). The window title shows the current FPS. # Close the window or press Escape to exit. # -# Requirements -# ============ -# pip install pyglet + +# /// script +# dependencies = ["cuda_bindings", "cuda_core>0.6.0", "pyglet"] +# /// import ctypes import sys diff --git a/cuda_core/examples/jit_lto_fractal.py b/cuda_core/examples/jit_lto_fractal.py index acf96be0f0..0e182550fe 100644 --- a/cuda_core/examples/jit_lto_fractal.py +++ b/cuda_core/examples/jit_lto_fractal.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 @@ -12,6 +12,10 @@ # # ################################################################################ +# /// script +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x"] +# /// + import argparse import sys diff --git a/cuda_core/examples/memory_ops.py b/cuda_core/examples/memory_ops.py index a53f33d2df..b9c7b97d39 100644 --- a/cuda_core/examples/memory_ops.py +++ b/cuda_core/examples/memory_ops.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 @@ -10,6 +10,10 @@ # # ################################################################################ +# /// script +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x", "numpy"] +# /// + import sys import cupy as cp diff --git a/cuda_core/examples/pytorch_example.py b/cuda_core/examples/pytorch_example.py index 6909272b4d..5826c0a442 100644 --- a/cuda_core/examples/pytorch_example.py +++ b/cuda_core/examples/pytorch_example.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 @@ -9,6 +9,10 @@ # # ################################################################################ +# /// script +# dependencies = ["cuda_bindings", "cuda_core", "torch"] +# /// + import sys import torch diff --git a/cuda_core/examples/saxpy.py b/cuda_core/examples/saxpy.py index 6e5b320f90..4848ef6850 100644 --- a/cuda_core/examples/saxpy.py +++ b/cuda_core/examples/saxpy.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 @@ -10,6 +10,10 @@ # # ################################################################################ +# /// script +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x"] +# /// + import sys import cupy as cp diff --git a/cuda_core/examples/show_device_properties.py b/cuda_core/examples/show_device_properties.py index 093b89b331..566f689094 100644 --- a/cuda_core/examples/show_device_properties.py +++ b/cuda_core/examples/show_device_properties.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 @@ -9,6 +9,10 @@ # # ################################################################################ +# /// script +# dependencies = ["cuda_bindings", "cuda_core"] +# /// + import sys from cuda.core import Device, system diff --git a/cuda_core/examples/simple_multi_gpu_example.py b/cuda_core/examples/simple_multi_gpu_example.py index 236a1cca20..e4d7a1ccfb 100644 --- a/cuda_core/examples/simple_multi_gpu_example.py +++ b/cuda_core/examples/simple_multi_gpu_example.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 @@ -9,6 +9,10 @@ # # ################################################################################ +# /// script +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x"] +# /// + import sys import cupy as cp diff --git a/cuda_core/examples/strided_memory_view_cpu.py b/cuda_core/examples/strided_memory_view_cpu.py index 8482021c45..e01e51dd7b 100644 --- a/cuda_core/examples/strided_memory_view_cpu.py +++ b/cuda_core/examples/strided_memory_view_cpu.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 @@ -9,6 +9,10 @@ # # ################################################################################ +# /// script +# dependencies = ["cuda_bindings", "cuda_core", "cffi", "setuptools", "numpy"] +# /// + import importlib import string import sys diff --git a/cuda_core/examples/strided_memory_view_gpu.py b/cuda_core/examples/strided_memory_view_gpu.py index 0abf5d086e..150c2527f5 100644 --- a/cuda_core/examples/strided_memory_view_gpu.py +++ b/cuda_core/examples/strided_memory_view_gpu.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 @@ -9,6 +9,10 @@ # # ################################################################################ +# /// script +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x", "numpy"] +# /// + import string import sys diff --git a/cuda_core/examples/thread_block_cluster.py b/cuda_core/examples/thread_block_cluster.py index 495fe882a9..24a001a09d 100644 --- a/cuda_core/examples/thread_block_cluster.py +++ b/cuda_core/examples/thread_block_cluster.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 @@ -10,6 +10,10 @@ # # ################################################################################ +# /// script +# dependencies = ["cuda_bindings", "cuda_core", "numpy"] +# /// + import os import sys diff --git a/cuda_core/examples/tma_tensor_map.py b/cuda_core/examples/tma_tensor_map.py index b914651089..5ad12f8472 100644 --- a/cuda_core/examples/tma_tensor_map.py +++ b/cuda_core/examples/tma_tensor_map.py @@ -22,6 +22,10 @@ # # ################################################################################ +# /// script +# dependencies = ["cuda_bindings", "cuda_core>0.6.0", "cupy-cuda13x", "numpy"] +# /// + import os import sys diff --git a/cuda_core/examples/vector_add.py b/cuda_core/examples/vector_add.py index 3adf04882e..dd07ba1044 100644 --- a/cuda_core/examples/vector_add.py +++ b/cuda_core/examples/vector_add.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 @@ -9,6 +9,10 @@ # # ################################################################################ +# /// script +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x"] +# /// + import cupy as cp from cuda.core import Device, LaunchConfig, Program, ProgramOptions, launch