Skip to content

Commit d1bd071

Browse files
authored
cuda.bindings: integrate CUDA 12 source with shared build tooling (#3173)
* Integrate the CUDA 12 source with shared build and test helpers Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com> * test(bindings): isolate CUDA 12 graph capture by thread Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com> * test: classify CUDA 12 bindings alongside CUDA 13 Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com> * Restore the security scan for the integrated CUDA 12 sources Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com> * Remove superseded CUDA 12 package benchmarks Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com> * Document CUDA 12 support for Python 3.15 Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com> * Enable pre-commit checks for the integrated CUDA 12 source Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com> * Defer CUDA 12 runtime backports to a focused maintenance layer Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com> * Defer CUDA 12 NVML test maintenance to CI integration Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com> * Pin CUDA 12 documentation links to a published snapshot Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com> --------- Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
1 parent afa6249 commit d1bd071

84 files changed

Lines changed: 1418 additions & 1465 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/labeler.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
cuda.bindings:
99
- changed-files:
1010
- any-glob-to-any-file:
11+
- 'cuda_bindings_12/**'
1112
- 'cuda_bindings_13/**'
1213
- 'samples/cuda_bindings/**'
1314

‎.github/workflows/bandit.yml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ jobs:
4242
echo "codes=$(uvx toml2json ./ruff.toml | jq -r '.lint.ignore | map(select(test("^S\\d+"))) | join(",")')" >> "$GITHUB_OUTPUT"
4343
- name: Perform Bandit Analysis using Ruff
4444
uses: astral-sh/ruff-action@278981a28ce3188b1e39527901f38254bf3aac89 # v4.1.0
45-
# Preserve the inactive CUDA 12 snapshot; the source-integration layer
46-
# adapts its security annotations and removes this temporary exclusion.
4745
with:
48-
args: "check --select S --ignore ${{ steps.ignore-codes.outputs.codes }} --extend-exclude cuda_bindings_12 --output-format sarif --output-file results.sarif"
46+
args: "check --select S --ignore ${{ steps.ignore-codes.outputs.codes }} --output-format sarif --output-file results.sarif"
4947
- name: Upload SARIF file
5048
uses: github/codeql-action/upload-sarif@24c54180a607b1449ed407dd24f251e4e9147c8d # v4.38.3
5149
with:

‎.gitignore‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ cuda_bindings_13/cuda/bindings/_internal/runtime.pyx
4040
cuda_bindings_13/cuda/bindings/_internal/runtime_ptds.pyx
4141
cuda_bindings_13/cuda/bindings/utils/_get_handle.pyx
4242

43+
# CUDA 12 bindings source generation
44+
cuda_bindings_12/cuda/bindings/_bindings/cyruntime.pxd
45+
cuda_bindings_12/cuda/bindings/_bindings/cyruntime.pyx
46+
cuda_bindings_12/cuda/bindings/_bindings/cyruntime_ptds.pxd
47+
cuda_bindings_12/cuda/bindings/_bindings/cyruntime_ptds.pyx
48+
cuda_bindings_12/cuda/bindings/_internal/cufile.pyx
49+
cuda_bindings_12/cuda/bindings/_internal/driver.pyx
50+
cuda_bindings_12/cuda/bindings/_internal/nvfatbin.pyx
51+
cuda_bindings_12/cuda/bindings/_internal/nvjitlink.pyx
52+
cuda_bindings_12/cuda/bindings/_internal/nvml.pyx
53+
cuda_bindings_12/cuda/bindings/_internal/nvrtc.pyx
54+
cuda_bindings_12/cuda/bindings/_internal/nvvm.pyx
55+
cuda_bindings_12/cuda/bindings/cyruntime.pxd
56+
cuda_bindings_12/cuda/bindings/cyruntime.pyx
57+
cuda_bindings_12/cuda/bindings/cyruntime_functions.pxi
58+
cuda_bindings_12/cuda/bindings/cyruntime_types.pxi
59+
cuda_bindings_12/cuda/bindings/runtime.pxd
60+
cuda_bindings_12/cuda/bindings/runtime.pyx
61+
4362
# Version files from setuptools_scm
4463
_version.py
4564

‎.pre-commit-config.yaml‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ ci:
1414

1515
# Please update the rev: SHAs below with this command:
1616
# pre-commit autoupdate --freeze
17-
# This unchanged maintenance-source import is inactive until its integration layer.
18-
exclude: ^cuda_bindings_12/
19-
2017
repos:
2118
# Runs first so a leaked credential blocks the commit before any formatter runs.
2219
# Self-installing: the hook downloads a pinned, checksum-verified trufflehog on
@@ -31,7 +28,7 @@ repos:
3128
hooks:
3229
- id: ruff-check
3330
args: [--fix, --show-fixes]
34-
exclude: (^cuda_bindings_13/cuda/bindings/_internal/_fast_enum\.py$)|(.*\.pyi$)
31+
exclude: (^cuda_bindings_(?:12|13)/cuda/bindings/_internal/_fast_enum\.py$)|(.*\.pyi$)
3532
- id: ruff-format
3633
exclude: .*\.pyi$
3734

@@ -71,7 +68,7 @@ repos:
7168
name: Check generated-file seals
7269
entry: python ./toolshed/check_generated_file_seals.py
7370
language: python
74-
files: ^cuda_bindings_13/
71+
files: ^cuda_bindings_(?:12|13)/
7572
types: [text]
7673

7774
- id: check-pixi-cuda-version
@@ -96,6 +93,9 @@ repos:
9693
- "_" # fake script name, because bash considers $0 (the first argument) to be the script name
9794
language: system
9895
files: '^.*/docs/source/.*\.md$'
96+
# The imported CUDA 12.9 documentation retains its historical MyST
97+
# sources; new documentation elsewhere must continue to use reST.
98+
exclude: '^cuda_bindings_12/docs/source/'
9999

100100
- id: stubgen-pyx-cuda-core
101101
name: Generate .pyi stubs for cuda_core
@@ -155,7 +155,7 @@ repos:
155155
rev: "3e8a8703264a2f4a69428a0aa4dcb512790b2c8c" # frozen: v6.0.0
156156
hooks:
157157
- id: check-added-large-files
158-
exclude: cuda_bindings_13/cuda/bindings/nvml.pyx
158+
exclude: '^(?:cuda_bindings_13/cuda/bindings/nvml\.pyx|cuda_bindings_12/cuda/bindings/(?:driver\.pyx|runtime\.pyx\.in|nvml\.pyx))$'
159159
- id: check-case-conflict
160160
- id: check-docstring-first
161161
- id: check-merge-conflict
@@ -164,14 +164,14 @@ repos:
164164
- id: check-yaml
165165
- id: debug-statements
166166
- id: end-of-file-fixer
167-
exclude: &gen_exclude '^(?:cuda_python/README\.md|(?:.*/)?CLAUDE\.md|(?:.*/)?\.git_archival\.txt|cuda_bindings_13/cuda/bindings/.*\.in?|cuda_bindings_13/docs/source/module/.*\.rst?|.*\.pyi)$'
167+
exclude: &gen_exclude '^(?:cuda_python/README\.md|(?:.*/)?CLAUDE\.md|(?:.*/)?\.git_archival\.txt|cuda_bindings_(?:12|13)/cuda/bindings/.*\.in?|cuda_bindings_(?:12|13)/docs/source/module/.*\.rst?|.*\.pyi)$'
168168
- id: mixed-line-ending
169169
- id: trailing-whitespace
170170
exclude: |
171171
(?x)^(?:
172172
cuda_python/README\.md|
173-
cuda_bindings_13/cuda/bindings/.*\.in?|
174-
cuda_bindings_13/docs/source/module/.*\.rst?|
173+
cuda_bindings_(?:12|13)/cuda/bindings/.*\.in?|
174+
cuda_bindings_(?:12|13)/docs/source/module/.*\.rst?|
175175
.*\.patch$
176176
)$
177177
@@ -213,7 +213,7 @@ repos:
213213
hooks:
214214
- id: cython-lint
215215
args: [--no-pycodestyle]
216-
exclude: ^cuda_bindings_13/
216+
exclude: ^cuda_bindings_(?:12|13)/
217217
additional_dependencies:
218218
- Cython==3.2.9
219219

‎benchmarks/cuda_bindings/runner/runtime.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ def ensure_context() -> int:
3030
assert_drv(err)
3131
_device = device
3232

33-
err, ctx = cuda.cuCtxCreate(None, 0, device)
33+
if cuda.CUDA_VERSION < 13000:
34+
err, ctx = cuda.cuCtxCreate(0, device)
35+
else:
36+
err, ctx = cuda.cuCtxCreate(None, 0, device)
3437
assert_drv(err)
3538
_ctx = ctx
3639
return ctx

‎cuda_bindings_12/DESCRIPTION.rst‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
cuda-bindings: Low-level CUDA interfaces
66
****************************************
77

8-
`cuda.bindings <https://nvidia.github.io/cuda-python/cuda-bindings/>`_ is a standard set of low-level interfaces, providing full coverage of and 1:1 access to the CUDA host APIs from Python. Checkout the `Overview <https://nvidia.github.io/cuda-python/cuda-bindings/latest/overview.html>`_ for the workflow and performance results.
8+
.. Keep documentation URLs aligned with README.md and build_hooks.py.
9+
Use a published CUDA 12 snapshot; latest follows the current CUDA major.
910
10-
* `Repository <https://github.com/NVIDIA/cuda-python/tree/main/cuda_bindings>`_
11-
* `Documentation <https://nvidia.github.io/cuda-python/cuda-bindings/>`_
12-
* `Examples <https://github.com/NVIDIA/cuda-python/tree/main/cuda_bindings/examples>`_
11+
`cuda.bindings <https://nvidia.github.io/cuda-python/cuda-bindings/12.9.7/>`_ is a standard set of low-level interfaces, providing full coverage of and 1:1 access to the CUDA host APIs from Python. Checkout the `Overview <https://nvidia.github.io/cuda-python/cuda-bindings/12.9.7/overview.html>`_ for the workflow and performance results.
12+
13+
* `Repository <https://github.com/NVIDIA/cuda-python/tree/main/cuda_bindings_12>`_
14+
* `Documentation <https://nvidia.github.io/cuda-python/cuda-bindings/12.9.7/>`_
15+
* `Examples <https://github.com/NVIDIA/cuda-python/tree/main/cuda_bindings_12/examples>`_
1316
* `Issue tracker <https://github.com/NVIDIA/cuda-python/issues/>`_
1417

15-
For the installation instruction, please refer to the `Installation <https://nvidia.github.io/cuda-python/cuda-bindings/latest/install.html>`_ page.
18+
For the installation instruction, please refer to the `Installation <https://nvidia.github.io/cuda-python/cuda-bindings/12.9.7/install.html>`_ page.

‎cuda_bindings_12/LICENSE‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,28 @@ Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
176176
of your accepting any such warranty or additional liability.
177177

178178
END OF TERMS AND CONDITIONS
179+
180+
APPENDIX: How to apply the Apache License to your work.
181+
182+
To apply the Apache License to your work, attach the following
183+
boilerplate notice, with the fields enclosed by brackets "[]"
184+
replaced with your own identifying information. (Don't include
185+
the brackets!) The text should be enclosed in the appropriate
186+
comment syntax for the file format. We also recommend that a
187+
file or class name and description of purpose be included on the
188+
same "printed page" as the copyright notice for easier
189+
identification within third-party archives.
190+
191+
Copyright [yyyy] [name of copyright owner]
192+
193+
Licensed under the Apache License, Version 2.0 (the "License");
194+
you may not use this file except in compliance with the License.
195+
You may obtain a copy of the License at
196+
197+
http://www.apache.org/licenses/LICENSE-2.0
198+
199+
Unless required by applicable law or agreed to in writing, software
200+
distributed under the License is distributed on an "AS IS" BASIS,
201+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202+
See the License for the specific language governing permissions and
203+
limitations under the License.

‎cuda_bindings_12/MANIFEST.in‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
recursive-include cuda/ *.pyx *.pxd *.pxi
4+
recursive-include cuda/ *.pyx *.pxd *.pxi *.pyx.in *.pxd.in *.pxi.in *.h
5+
include build_hooks.py
56
# at least with setuptools 75.0.0 this folder was added erroneously
67
# to the payload, causing file copying to the build environment failed
78
exclude cuda/bindings cuda?bindings
89
exclude cuda/bindings/_bindings cuda?bindings?_bindings
10+
# package-local shared PEP 517 helper
11+
include _build_shared.py

‎cuda_bindings_12/README.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# `cuda.bindings`: Low-level CUDA interfaces
22

3-
`cuda.bindings` is a standard set of low-level interfaces, providing full coverage of and access to the CUDA host APIs from Python. Checkout the [Overview page](https://nvidia.github.io/cuda-python/cuda-bindings/latest/overview.html) for the workflow and performance results.
3+
`cuda.bindings` is a standard set of low-level interfaces, providing full coverage of and access to the CUDA host APIs from Python. Checkout the [Overview page](https://nvidia.github.io/cuda-python/cuda-bindings/12.9.7/overview.html) for the workflow and performance results.
4+
5+
<!-- Keep documentation URLs aligned with DESCRIPTION.rst and build_hooks.py.
6+
Use a published CUDA 12 snapshot; latest follows the current CUDA major. -->
47

58
## Installing
69

7-
Please refer to the [Installation page](https://nvidia.github.io/cuda-python/cuda-bindings/latest/install.html) for instructions and required/optional dependencies.
10+
Please refer to the [Installation page](https://nvidia.github.io/cuda-python/cuda-bindings/12.9.7/install.html) for instructions and required/optional dependencies.
811

912
## Developing
1013

@@ -31,7 +34,7 @@ To run these tests:
3134

3235
### Cython Unit Tests
3336

34-
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:
37+
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:
3538

3639
1. Setup environment variable `CUDA_HOME` with the path to the CUDA Toolkit installation.
3740
2. Run `build_tests` script located in `test/cython` appropriate to your platform. This will both cythonize the tests and build them.
@@ -60,8 +63,5 @@ To run these samples:
6063

6164
### Benchmark
6265

63-
Allows for analyzing binding performance using plugin [pytest-benchmark](https://github.com/ionelmc/pytest-benchmark).
64-
65-
To run these benchmarks:
66-
* `python -m pytest --benchmark-only benchmarks/` against editable installations
67-
* `pytest --benchmark-only benchmarks/` against installed packages
66+
See the shared [cuda.bindings benchmark harness](../benchmarks/cuda_bindings/README.md)
67+
for performance benchmarks and usage instructions.

‎cuda_bindings_12/_build_shared.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../cuda_bindings_13/_build_shared.py

0 commit comments

Comments
 (0)