Skip to content

Ship _v2 lowpp API for the driver module - #3095

Merged
mdboom merged 26 commits into
NVIDIA:mainfrom
mdboom:driver-cybind
Oct 24, 2026
Merged

mdboom merged 26 commits into
NVIDIA:mainfrom
mdboom:driver-cybind

Conversation

@mdboom

@mdboom mdboom commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@copy-pr-bot

copy-pr-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions Bot added cuda.bindings Everything related to the cuda.bindings module cuda.core Everything related to the cuda.core module labels Oct 13, 2026
@mdboom

mdboom commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@mdboom

mdboom commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@mdboom

mdboom commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@mdboom

mdboom commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test cd9a1d8

@mdboom

mdboom commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 027a11e

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor
Doc Preview CI
Preview removed because the pull request was closed or merged.

@mdboom

mdboom commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@mdboom

mdboom commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@mdboom

mdboom commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 650a8ab

@mdboom

mdboom commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0c7b2a7

@mdboom

mdboom commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@mdboom

mdboom commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test dd186df

@mdboom
mdboom marked this pull request as ready for review October 21, 2026 17:11

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🧹 Nitpick comments: 1
cuda_bindings_13/tests/test_cuda.py: 1

500-518: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

suggestion: Destroy graphExec before cleanup.

graphExec remains live until module context teardown. No later graph-memory assertion uses this context, so the measurable cross-test impact is not established.

+    driver.graph_exec_destroy(graphExec)
     driver.graph_destroy(graph)
     driver.stream_destroy_v2(stream)

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/cuda-python/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 08008359-6944-48d9-bf2e-acce3fd6e63d
📥 Commits

Reviewing files that changed from the base of the PR and between efd58e4 and dd186df.

📒 Files selected for processing: 32
  • .pre-commit-config.yaml
  • cuda_bindings_13/AGENTS.md
  • cuda_bindings_13/cuda/bindings/_v2/driver.pxd
  • cuda_bindings_13/cuda/bindings/_v2/driver.pyx
  • cuda_bindings_13/cuda/bindings/_v2/nvrtc.pxd
  • cuda_bindings_13/cuda/bindings/_v2/nvrtc.pyx
  • cuda_bindings_13/cuda/bindings/cudla.pyx
  • cuda_bindings_13/cuda/bindings/cufile.pyx
  • cuda_bindings_13/cuda/bindings/driver.pyx
  • cuda_bindings_13/cuda/bindings/nvfatbin.pyx
  • cuda_bindings_13/cuda/bindings/nvjitlink.pyx
  • cuda_bindings_13/cuda/bindings/nvml.pyx
  • cuda_bindings_13/cuda/bindings/nvvm.pyx
  • cuda_bindings_13/docs/source/api.rst
  • cuda_bindings_13/docs/source/module/driver_v2.rst
  • cuda_bindings_13/docs/source/module/nvrtc_v2.rst
  • cuda_bindings_13/docs/source/module/v2_migration.rst
  • cuda_bindings_13/docs/source/release/13.5.0-notes.rst
  • cuda_bindings_13/tests/conftest.py
  • cuda_bindings_13/tests/legacy_api/conftest.py
  • cuda_bindings_13/tests/legacy_api/nvml/test_legacy_nvml_cuda.py
  • cuda_bindings_13/tests/legacy_api/test_legacy_cuda.py
  • cuda_bindings_13/tests/legacy_api/test_legacy_cufile.py
  • cuda_bindings_13/tests/legacy_api/test_legacy_interoperability.py
  • cuda_bindings_13/tests/nvml/test_cuda.py
  • cuda_bindings_13/tests/test_cuda.py
  • cuda_bindings_13/tests/test_cufile.py
  • cuda_bindings_13/tests/test_interoperability.py
  • cuda_bindings_13/tests/test_kernelParams.py
  • cuda_bindings_13/tests/test_nvrtc.py
  • cuda_core/cuda/core/system/exceptions.py
  • cuda_core/docs/source/release/1.3.0-notes.rst

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Comment thread cuda_bindings_13/cuda/bindings/_v2/nvrtc.pyx
Comment thread cuda_bindings_13/cuda/bindings/_v2/nvrtc.pyx
Comment thread cuda_bindings_13/cuda/bindings/cufile.pyx
Comment thread cuda_bindings_13/cuda/bindings/nvml.pyx
Comment thread cuda_bindings_13/cuda/bindings/nvml.pyx
Comment thread cuda_bindings_13/cuda/bindings/nvml.pyx
Comment thread cuda_bindings_13/cuda/bindings/nvml.pyx
Comment thread cuda_bindings_13/docs/source/release/13.5.0-notes.rst
Comment thread cuda_core/cuda/core/system/exceptions.py
@mdboom
mdboom requested review from isVoid and juenglin October 22, 2026 17:57
@juenglin

Copy link
Copy Markdown
Contributor

Migration guide: are the suffixed legacy driver functions intentionally omitted?

The guide says the legacy module "exposes only the unsuffixed name" for versioned C symbols. But 8 suffixed legacy functions exist in driver.pyx (and on main) with no row in v2_migration.rst: cuCtxGetDevice_v2, cuCtxSynchronize_v2, cuGraphAddNode_v3, cuGraphNodeSetParams_v2, cuLaunchHostFunc_v2, cuMulticastBindAddr_v2, cuMulticastBindMem_v2, cuStreamGetCtx_v2.

This can mislead: cuCtxGetDevice → ctx_get_device_v2 is annotated "Parameters added: ctx", but a user already calling cuCtxGetDevice_v2(ctx) has no row for their actual function.

Deliberate, or should the tables add rows for the suffixed names?

@juenglin

Copy link
Copy Markdown
Contributor

Naming nit on cu_memcpy (_v2/driver.pyx L30136) — posting at top level because GitHub won't take an inline comment on this generated file (diff too large).

cu_memcpy keeps the cu prefix, which no other function in this module does — the guide says the cu/nvrtc prefix is removed (e.g. cuMemcpyAsync → memcpy_async). Stripping it here would give memcpy. Was keeping cu_memcpy intentional, or should it follow the pattern?

@juenglin juenglin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Posting this first point in the review body: GitHub won't attach an inline comment to the 43k-line generated cuda_bindings_13/cuda/bindings/_v2/driver.pyx.)

_v2/driver.pyx TensorMap.opaque (~L10281) and the other view.array getters — use-after-free.

These getters do arr = cython.view.array(..., allocate_buffer=False); arr.data = &self._ptr[0].<member>; return _numpy.asarray(arr). The returned array's base is the cython array holding the raw pointer, with no strong reference back to self. Once the wrapper is garbage-collected the backing memory is freed while the view lives on (for TensorMap the struct is inline in the Python object).

Repro (no GPU needed):

from cuda.bindings._v2 import driver
import gc
views = []
for i in range(500):
    tm = driver.TensorMap()
    tm.opaque = [i] * 16
    views.append(tm.opaque)   # keep the view, drop the wrapper
    del tm
gc.collect()
flood = [driver.TensorMap() for _ in range(500)]   # reuse the freed 128B slots
for t in flood:
    t.opaque = [9999] * 16
print(sum(int(v[0]) == 9999 for v in views))        # -> 500: every view reads reused memory

Same pattern in .address_mode, .border_color, .max_threads_dim, .max_grid_size, and the two data_ getters. The recarray-backed structs already tie lifetime via owner=obj in from_ptr; these should too. A "view outlives wrapper" regression test would help — the existing test_array_member_assignment_and_aliased_dealloc only covers the raw-address+count members.

-
* - ``nvrtcInstallBundledHeaders``
- ``install_bundled_headers``
- ``flags`` takes ``InstallHeadersFlag`` values. Returns the optional error message (``bytes`` or ``None``).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc vs. code mismatch. These rows say the bundled-header helpers return None on success, but the implementation returns b"" and the tests assert it: _v2/nvrtc.pyx:1054, :1081, :1115 and tests/test_nvrtc.py:43, :52, :54 (same for get_lowered_name at nvrtc.pyx:881). Please reconcile doc and code — a caller following the docs and writing if err is None would be wrong.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Updated the docs to match the behavior in bdeddb0

InsufficientSizeError = nvml.InsufficientSizeError
InsufficientPowerError = nvml.InsufficientPowerError
DriverNotLoadedError = nvml.DriverNotLoadedError
NvmlTimeoutError = nvml.TimeoutError

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rename doesn't actually stop the builtin shadowing. Here (and in the matching nvml.pyx) the old names are kept as aliases: cuda.bindings.nvml still defines TimeoutError = NvmlTimeoutError / MemoryError = NvmlMemoryError and has no __all__, and cuda.core.system re-exports both old names (this line plus MemoryError below, both added to __all__). So from ... import * still rebinds the builtin TimeoutError/MemoryError, which is the thing the release note says the rename fixes.

Broader question: the NVML rename and the regeneration of nvml/cufile/cudla/nvvm/nvjitlink/nvfatbin plus the legacy driver seem unrelated to the _v2 driver API work. Is bundling them here intentional, or would it be cleaner as a separate PR? They carry user-visible changes not called out in the description.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, we can't remove the old names without breaking API. Nor can we actually create deprecation warnings about their use (since they are used in a try/except and not actually called as functions). So the best we can do is add the new names as aliases now and declare them deprecated in the CHANGELOG, so we can remove the old names in the 14.x release.

An additional wrinkle is that cuda-core has to work with the latest /released/ version of cuda-bindings 13.4.x (not only the version here on main), so it has to continue to use the old names until 13.5.x is released and we can bump cuda-core's version floor on cuda-bindings.

Broader question: the NVML rename and the regeneration of nvml/cufile/cudla/nvvm/nvjitlink/nvfatbin plus the legacy driver seem unrelated to the _v2 driver API work. Is bundling them here intentional, or would it be cleaner as a separate PR? They carry user-visible changes not called out in the description.

These are due to bugs that were found during the course of the development of _v2.driver that also apply to these existing modules. (Bugs that only are found because the test coverage on driver is so much larger than any of the other modules). It would add complexity to the generator to generate in different ways for different modules, so we should be consistent.

However, it is a good callout that these changes (which are all backward-compatible) are not called out in the release notes. I have added them in e82804d.

(``cuStreamCreate`` becomes ``stream_create``). Driver functions keep the version suffix of
the C symbol (``mem_alloc_v2``), whereas the legacy module drops it.
- Parameters and struct members use ``snake_case``. Names that would clash with a Python keyword or
builtin, or with a name reserved by the generated classes, get a trailing underscore (``input_``, ``flags_``).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule doesn't match the generated names. This says names clashing with a Python builtin get a trailing underscore (input_, flags_), but several _v2.driver parameters keep builtin names: type (x11), object (x4), len (x2), bytes (x2), input (x2), format, map (input_ doesn't actually appear in driver.pyx). Since renaming later would be breaking, worth settling before the API firms up — adjust either the rule or the generator.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the note is wrong -- it's not about shadowing Python builtins, it's about avoiding shadowing Numpy methods that would shadow a field name. It turns out we don't /actually/ need to do this -- it's a bug -- but fixing it would breaking existing API, so it needs to be fixed by adding aliases to the old name, deprecating and then removing. For that reason, I think we should address it separately, and I will make an issue for the generator for that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The note is fixed in 6d0109c

@isVoid isVoid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My agent didn't find anything outside of the generated files region. I do have a small trivia below.

Comment on lines +64 to +69
Enumerations
------------

Enumeration classes are ``int`` subclasses. Functions accept either the enumeration members or plain integers.
Their members expose a description of the value automatically, so the individual members
are no longer documented one by one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into similar agent design decision when doing rust bindings. Semantically C enums are closer to plain integers instead of python/rust enum. I find that interesting how different language bindings landed at the same design.

@mdboom

mdboom commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Migration guide: are the suffixed legacy driver functions intentionally omitted?

No, that's just an omission in the migration guide. Fixed in 1e81c7e.

cu_memcpy keeps the cu prefix, which no other function in this module does

This was a good catch. My agent did this because it cimported the stdlib memcpy into the file and then thought this would shadow it. The solution is to rename the private/internal C stdlib memcpy, not the other way around. Fixed in c50ee15.

_v2/driver.pyx TensorMap.opaque (~L10281) and the other view.array getters — use-after-free.

This is describing an existing bug in all of the other cybind modules that has existed for a long time. It's a real issue, but may require some care and complexity to fix in an API-backward-compatible way. Since no one has actually reported the bug as an issue, I think this is lower priority and shouldn't hold up merging this PR. @juenglin already filed #3193 for this, so I think we just work on that separately.

@mdboom
mdboom requested a review from juenglin October 23, 2026 14:19

@juenglin juenglin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks.

@mdboom
mdboom enabled auto-merge (squash) October 23, 2026 17:54
@mdboom
mdboom merged commit 2da9c65 into NVIDIA:main Oct 24, 2026
118 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 24, 2026
Removed preview folders for the following PRs:
- PR #3095
- PR #3126
- PR #3173
- PR #3191
- PR #3197
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.bindings Everything related to the cuda.bindings module cuda.core Everything related to the cuda.core module enhancement Any code-related improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants