From 3d6a82439e3b5d52597998d7bcce41b0baceb8c8 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 20 Mar 2026 12:04:22 -0400 Subject: [PATCH 1/3] Add PEP723 metadata to cuda_core examples --- .github/workflows/test-wheel-linux.yml | 8 ++++ ci/tools/run-examples-pep723 | 43 +++++++++++++++++++ cuda_core/examples/cuda_graphs.py | 6 ++- cuda_core/examples/gl_interop_plasma.py | 7 +-- cuda_core/examples/jit_lto_fractal.py | 6 ++- cuda_core/examples/memory_ops.py | 6 ++- cuda_core/examples/pytorch_example.py | 6 ++- cuda_core/examples/saxpy.py | 6 ++- cuda_core/examples/show_device_properties.py | 6 ++- .../examples/simple_multi_gpu_example.py | 6 ++- cuda_core/examples/strided_memory_view_cpu.py | 6 ++- cuda_core/examples/strided_memory_view_gpu.py | 6 ++- cuda_core/examples/thread_block_cluster.py | 6 ++- cuda_core/examples/tma_tensor_map.py | 4 ++ cuda_core/examples/vector_add.py | 6 ++- 15 files changed, 114 insertions(+), 14 deletions(-) create mode 100755 ci/tools/run-examples-pep723 diff --git a/.github/workflows/test-wheel-linux.yml b/.github/workflows/test-wheel-linux.yml index c5061a16eb..1f0324790d 100644 --- a/.github/workflows/test-wheel-linux.yml +++ b/.github/workflows/test-wheel-linux.yml @@ -96,6 +96,9 @@ 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 @@ -277,6 +280,11 @@ jobs: LOCAL_CTK: ${{ matrix.LOCAL_CTK }} run: run-tests core + - name: Run cuda.core examples with PEP 723 metadata in isolation + if: ${{ env.SKIP_CUDA_BINDINGS_TEST == '0' }} + 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..6dccb6869d 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"] +# /// + 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..4702d00890 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"] +# /// + import argparse import sys diff --git a/cuda_core/examples/memory_ops.py b/cuda_core/examples/memory_ops.py index a53f33d2df..8ad7ac7b1f 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", "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..925be382b0 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"] +# /// + 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..12ab2f4819 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"] +# /// + 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..cc45478a21 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", "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..ff29e54e6a 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", "numpy"] +# /// + import os import sys diff --git a/cuda_core/examples/vector_add.py b/cuda_core/examples/vector_add.py index 3adf04882e..d0ef903bc3 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"] +# /// + import cupy as cp from cuda.core import Device, LaunchConfig, Program, ProgramOptions, launch From 6440174c4a20953b4ed84c8c29619bb13e46722d Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 20 Mar 2026 12:45:28 -0400 Subject: [PATCH 2/3] Fix cupy dependency specification --- cuda_core/examples/cuda_graphs.py | 2 +- cuda_core/examples/jit_lto_fractal.py | 2 +- cuda_core/examples/memory_ops.py | 2 +- cuda_core/examples/saxpy.py | 2 +- cuda_core/examples/simple_multi_gpu_example.py | 2 +- cuda_core/examples/strided_memory_view_gpu.py | 2 +- cuda_core/examples/tma_tensor_map.py | 2 +- cuda_core/examples/vector_add.py | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cuda_core/examples/cuda_graphs.py b/cuda_core/examples/cuda_graphs.py index 6dccb6869d..ad4271aeb5 100644 --- a/cuda_core/examples/cuda_graphs.py +++ b/cuda_core/examples/cuda_graphs.py @@ -11,7 +11,7 @@ # ################################################################################ # /// script -# dependencies = ["cuda_bindings", "cuda_core", "cupy"] +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x"] # /// import sys diff --git a/cuda_core/examples/jit_lto_fractal.py b/cuda_core/examples/jit_lto_fractal.py index 4702d00890..0e182550fe 100644 --- a/cuda_core/examples/jit_lto_fractal.py +++ b/cuda_core/examples/jit_lto_fractal.py @@ -13,7 +13,7 @@ # ################################################################################ # /// script -# dependencies = ["cuda_bindings", "cuda_core", "cupy"] +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x"] # /// import argparse diff --git a/cuda_core/examples/memory_ops.py b/cuda_core/examples/memory_ops.py index 8ad7ac7b1f..b9c7b97d39 100644 --- a/cuda_core/examples/memory_ops.py +++ b/cuda_core/examples/memory_ops.py @@ -11,7 +11,7 @@ # ################################################################################ # /// script -# dependencies = ["cuda_bindings", "cuda_core", "cupy", "numpy"] +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x", "numpy"] # /// import sys diff --git a/cuda_core/examples/saxpy.py b/cuda_core/examples/saxpy.py index 925be382b0..4848ef6850 100644 --- a/cuda_core/examples/saxpy.py +++ b/cuda_core/examples/saxpy.py @@ -11,7 +11,7 @@ # ################################################################################ # /// script -# dependencies = ["cuda_bindings", "cuda_core", "cupy"] +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x"] # /// import sys diff --git a/cuda_core/examples/simple_multi_gpu_example.py b/cuda_core/examples/simple_multi_gpu_example.py index 12ab2f4819..e4d7a1ccfb 100644 --- a/cuda_core/examples/simple_multi_gpu_example.py +++ b/cuda_core/examples/simple_multi_gpu_example.py @@ -10,7 +10,7 @@ # ################################################################################ # /// script -# dependencies = ["cuda_bindings", "cuda_core", "cupy"] +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x"] # /// import sys diff --git a/cuda_core/examples/strided_memory_view_gpu.py b/cuda_core/examples/strided_memory_view_gpu.py index cc45478a21..150c2527f5 100644 --- a/cuda_core/examples/strided_memory_view_gpu.py +++ b/cuda_core/examples/strided_memory_view_gpu.py @@ -10,7 +10,7 @@ # ################################################################################ # /// script -# dependencies = ["cuda_bindings", "cuda_core", "cupy", "numpy"] +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x", "numpy"] # /// import string diff --git a/cuda_core/examples/tma_tensor_map.py b/cuda_core/examples/tma_tensor_map.py index ff29e54e6a..5ad12f8472 100644 --- a/cuda_core/examples/tma_tensor_map.py +++ b/cuda_core/examples/tma_tensor_map.py @@ -23,7 +23,7 @@ # ################################################################################ # /// script -# dependencies = ["cuda_bindings", "cuda_core>0.6.0", "cupy", "numpy"] +# dependencies = ["cuda_bindings", "cuda_core>0.6.0", "cupy-cuda13x", "numpy"] # /// import os diff --git a/cuda_core/examples/vector_add.py b/cuda_core/examples/vector_add.py index d0ef903bc3..dd07ba1044 100644 --- a/cuda_core/examples/vector_add.py +++ b/cuda_core/examples/vector_add.py @@ -10,7 +10,7 @@ # ################################################################################ # /// script -# dependencies = ["cuda_bindings", "cuda_core", "cupy"] +# dependencies = ["cuda_bindings", "cuda_core", "cupy-cuda13x"] # /// import cupy as cp From 27d9907b4c25160b1fcd20a10fe26c2dc6ace2ef Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 20 Mar 2026 14:02:59 -0400 Subject: [PATCH 3/3] Try to get tests to run --- .github/workflows/test-wheel-linux.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-wheel-linux.yml b/.github/workflows/test-wheel-linux.yml index 1f0324790d..4ef4d31e06 100644 --- a/.github/workflows/test-wheel-linux.yml +++ b/.github/workflows/test-wheel-linux.yml @@ -104,7 +104,7 @@ jobs: 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 @@ -281,7 +281,9 @@ jobs: run: run-tests core - name: Run cuda.core examples with PEP 723 metadata in isolation - if: ${{ env.SKIP_CUDA_BINDINGS_TEST == '0' }} + env: + CUDA_VER: ${{ matrix.CUDA_VER }} + LOCAL_CTK: ${{ matrix.LOCAL_CTK }} run: | ci/tools/run-examples-pep723 cuda_core/examples/