Skip to content

Bump Cython to >=3.3,<3.4 - #2771

Merged
juenglin merged 10 commits into
NVIDIA:mainfrom
juenglin:cython-3.3-upgrade
Nov 30, 2026
Merged

juenglin merged 10 commits into
NVIDIA:mainfrom
juenglin:cython-3.3-upgrade

Conversation

@juenglin

@juenglin juenglin commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

Bumps the Cython build/test pin from >=3.2.5,<3.3 to >=3.3.1,<3.4 across cuda_bindings_12, cuda_bindings_13, cuda_core, cuda_pathfinder, the docs environment files, and the cython-lint pre-commit hook. The minimum stays at 3.3.1; the cuda_bindings_12 / cuda_bindings_13 pixi lock files and the cython-lint hook resolve Cython 3.3.2.

No motivating issue -- routine dependency upgrade to stay on a supported Cython release line.

Why 3.3.1 rather than 3.3.0

Cython 3.3.1 is mostly a fix release for 3.3.0 regressions, several of which generated incorrect C code (e.g. cython/cython#7991, #7937, #7907). It also fixes Cython file-cache problems that affect our cached builds: concurrent processes deleting each other's cache files (#7983, #7985, #8090) and a cache key that ignored compiler directives (#7532).

Required code changes

Cython 3.3 added a new critical_section misuse warning (cython/cython#6766), promoted to a build error by our warning_errors=True builds. It flags three patterns in cuda_core; all still fire with 3.3.1:

  • cuda/core/_memory/_buffer.pyx, cuda/core/_memoryview.pyx: narrowed cython.critical_section coverage to only the cdef-attribute check-and-set; Python-level construction/reads now happen outside the lock, since the lock never actually protected them (see cython/cython#7324).
  • cuda/core/_device_resources.pyx: WorkqueueResourceOptions now uses @dataclass(init=False) with a hand-written __init__, because Cython 3.3 wraps the dataclass-generated __init__ in a critical section and then warns about its own generated call to __post_init__.

Cython 3.3 also enforces declared container item types at runtime. The generated pArray setters of CUeglFrame / cudaEglFrame were annotated list[CUarray] / list[cudaArray_t], so assigning a list of plain ints raised TypeError. main now carries the generator fix that widens the annotation to list[CUarray | int] / list[cudaArray_t | int], so the generated bindings are identical to main and the test_eglFrame / test_cudart_eglFrame tests are unchanged and pass with plain ints.

The stubgen-pyx pre-commit hook stays on Cython 3.2.9 because stubgen-pyx 0.2.23 requires Cython<3.3.

pixi lock files

The cuda_bindings_12 and cuda_bindings_13 lock files resolve Cython 3.3.2 (3.3.1 is the minimum allowed by the pins). Conflicts with main in the lock files were resolved by regenerating them with Pixi 0.83.0. cuda_core and cuda_pathfinder lock files still resolve Cython 3.3.1, which satisfies the pins.

Performance

The launch-path slowdown observed with Cython 3.3.0 earlier in this PR's history no longer reproduces: the hot loop in _HelperKernelParams was rewritten by #2904, so the 3.3.0 codegen changes that caused it are no longer on that path. Same sources, only the Cython version changed (pinned P-core, performance governor, 12 interleaved rounds, gcc 13.3), ratio vs. 3.2.9 (min):

Benchmark 3.3.0 3.3.1
_HelperKernelParams, 512 c_int args 0.996 0.997
launch_256_args 0.988 0.990
launch_512_args 1.002 0.990
other bench_launch cases 0.990-1.003 0.992-1.006

Re-measured for Cython 3.3.2 on the current branch (merged with main): the same cuda_bindings_13 sources built three times with Cython 3.2.9, 3.3.1 and 3.3.2 (CUDA 13.5 headers, Python 3.12, gcc 13.3), repo bench_launch.py functions plus a direct timing of _HelperKernelParams with 512 c_int args, fresh process per measurement pinned to one P-core, 12 interleaved rounds. The CPU governor was powersave for this run, not performance. Ratio of the min:

Benchmark 3.3.1 / 3.2.9 3.3.2 / 3.2.9 3.3.2 / 3.3.1
_HelperKernelParams, 512 c_int args 0.980 0.980 1.000
launch_256_args 0.992 0.992 1.000
launch_512_args 0.987 0.990 1.003
other bench_launch cases 0.995-1.007 0.992-1.005 0.997-1.001

Cython 3.3.2 is indistinguishable from 3.3.1 on these benchmarks (all 3.3.2 / 3.3.1 ratios within 0.5%), and neither shows a slowdown relative to 3.2.9.

Testing

Local GPU (RTX 6000 Ada), clean builds in fresh virtual environments with Cython 3.3.2, after merging main:

  • cuda_bindings_13 (CUDA 13.5): 770 passed / 38 skipped
  • cuda_bindings_12 (CUDA 12.9): 399 passed / 37 skipped / 9 failed. The same 9 tests fail on main with Cython 3.2.9 (8 sm_60 cases in test_nvjitlink.py with ERROR_UNSUPPORTED_ARCH and test_cufile.py::test_set_get_parameter_bool), so they are not caused by this change.

Earlier results with Cython 3.3.1, before merging main (cuda_core was not re-run on 3.3.2):

  • cuda_bindings_13 (cu13): 779 passed / 38 skipped
  • cuda_bindings_12 (cu12): 416 passed / 38 skipped
  • cuda_core (cu13): 4191 passed / 337 skipped / 4 xfailed

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@copy-pr-bot

copy-pr-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

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 cuda.pathfinder Everything related to the cuda.pathfinder module labels Sep 4, 2026
@juenglin juenglin added this to the cuda.bindings next milestone Sep 4, 2026
@juenglin juenglin added dependencies Pull requests that update a dependency file and removed cuda.pathfinder Everything related to the cuda.pathfinder module labels Sep 4, 2026
@juenglin juenglin self-assigned this Sep 4, 2026
@juenglin
juenglin requested a review from mdboom September 4, 2026 21:08
@juenglin juenglin added the P1 Medium priority - Should do label Sep 4, 2026
@juenglin

juenglin commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 6f24210

@juenglin
juenglin marked this pull request as ready for review September 4, 2026 21:26
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@mdboom mdboom 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.

From the description:

Python 3.15 support path: Cython 3.3 adapts to 3.15 and its Limited API; our test dependency groups already carry python_version < '3.15' guards to be removed once 3.15 is officially supported.

This is related to some dependencies having not released 3.15 support or wheels yet (at the time we started Python 3.15 support). Seems totally unrelated to this PR, but we should file separate PRs to check the status of those dependencies and see if they support Python 3.15 now.

Free-threading improvements: critical sections on auto-generated functions, prange/parallel() without releasing the GIL, pymutex.locked().

These are Cython improvements? They don't seem to be related to this PR or be relevant to us since we don't use those features.

@mdboom

mdboom commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

We should do a benchmark run on this and make sure there are no major regressions as well.

@juenglin
juenglin marked this pull request as draft September 10, 2026 15:02
@juenglin

Copy link
Copy Markdown
Contributor Author

We should do a benchmark run on this and make sure there are no major regressions as well.

Good call. I ran the benchmark and it showed a regression, so we will need to work that out first. I will dig into it on the side.

istitov added a commit to istitov/stuff that referenced this pull request Nov 5, 2026
The comment said only that build_hooks.py uses Cython 3.2.x. Upstream's
own move to 3.3 (NVIDIA/cuda-python#2771) is still open over a
benchmark regression, and 3.3 changes runtime type checks, so the cap
stays and the comment now says why. Comment only; 13.5.0 is not yet
pushed.
Bump the remaining Cython pins (build dependency groups added on main,
cuda_bindings_12, and the cython-lint pre-commit hook) and raise the floor
to 3.3.1. The stubgen-pyx hook stays on Cython 3.2.9 because
stubgen-pyx 0.2.23 requires Cython<3.3.

Update the cuda_bindings_12 eglFrame tests the same way as
cuda_bindings_13: Cython 3.3 enforces the generated list[CUarray] /
list[cudaArray_t] setter annotations at runtime.
@github-actions github-actions Bot added the cuda.pathfinder Everything related to the cuda.pathfinder module label Nov 10, 2026
@juenglin

Copy link
Copy Markdown
Contributor Author

We should do a benchmark run on this and make sure there are no major regressions as well.

Good call. I ran the benchmark and it showed a regression, so we will need to work that out first. I will dig into it on the side.

There no longer is a performance regression thanks to #2904.

Generated with `pixi update --no-install cython` using the CI-pinned
Pixi v0.82.1, so the only package change is cython 3.2.9 -> 3.3.1.
cuda_bindings_12 also drops a few orphaned package records that no
environment referenced.
@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test 79ecfe4

Cython 3.3 enforces declared list item types at runtime.  The pArray
setters on CUeglFrame.frame and cudaEglFrame.frame were annotated as
list[CUarray] / list[cudaArray_t], so passing plain ints raised
TypeError.  The fix is a generator change (cybind !621, cython_gen):
widen the annotation to list[CUarray | int] / list[cudaArray_t | int].

The setter body already converts each element with int() before casting,
so accepting plain ints was always safe; the annotation was just narrower
than the implementation.

Generated files updated from cybind branch accept-int-handle-arrays
(da353763) against CTK 12.9 (cuda_bindings_12) and 13.5 (cuda_bindings_13).
Seals recomputed.  Test workarounds that wrapped plain ints in handle
objects are reverted to their original plain-int form.
@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test 64feee6

@juenglin
juenglin marked this pull request as ready for review November 10, 2026 18:11
@juenglin
juenglin enabled auto-merge (squash) November 10, 2026 18:13

@mdboom mdboom 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.

Did you fully regenerate the files? I would have expected all of the changes from #3410 as well.

I worry that if the agent just hand-wrote these updates instead they may get clobbered by the next generation update.

I think we should merge #3410, and then fully regenerate this (and maybe hold of on the 12.9.x updates for now).

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved concurrent access to cached buffer and tensor information.
    • Work queue options now validate sharing scope and reject concurrency limits below one.
  • Chores
    • Updated the supported Cython version range to 3.3.x across package, build, test, and documentation environments.

The PR updates Cython requirements across build, test, documentation, and lint configurations. It also changes WorkqueueResourceOptions initialization and narrows critical sections around buffer and memory-view caches.

Changes: Cython version and core runtime updates

Layer / File(s) Summary
Update Cython requirements
.pre-commit-config.yaml, cuda_bindings_12/{pixi.toml,pyproject.toml}, cuda_bindings_13/{pixi.toml,pyproject.toml}, cuda_core/{pixi.toml,pyproject.toml}, cuda_pathfinder/pixi.toml, cuda_python/docs/environment-docs.yml, toolshed/setup-docs-env.sh
The lint hook now pins Cython 3.3.2. Build, test, documentation, and host dependency constraints now require >=3.3.1,<3.4.
Define WorkqueueResourceOptions initialization
cuda_core/cuda/core/_device_resources.pyx, cuda_core/cuda/core/_device_resources.pyi
The generated dataclass initializer is disabled. An explicit initializer validates and assigns both options, and the stub declares its optional parameters.
Narrow memory cache critical sections
cuda_core/cuda/core/_memory/_buffer.pyx, cuda_core/cuda/core/_memoryview.pyx
Buffer.ipc_descriptor, _get_torch_tensor_type, get_buffer, and get_dtype use explicit critical sections for cache access and publication. get_layout no longer has a critical-section decorator.

Suggested reviewers: rwgk

Change: Other

Merge Risk: Minimal · up to b3f61 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Architecture risk: Low · up to b3f61

The change affects 6 systems.

Changed systems: cuda_core, cuda_bindings_12, cuda_bindings_13, cuda_pathfinder, cuda_python, toolshed

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — cuda_core (service) was modified; 6 changed files map to changed impact.
  • observed — cuda_bindings_12 (service) was modified; 2 changed files map to changed impact.
  • observed — cuda_bindings_13 (service) was modified; 2 changed files map to changed impact.
  • observed — cuda_pathfinder (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in cuda_core/cuda/core/_device_resources.pyi: WorkqueueResourceOptions now declares an explicit dataclass initializer instead of using the generated initializer.
  • observed — Modified behavior in cuda_core/cuda/core/_device_resources.pyi: The stub replaces the __post_init__ declaration with __init__, exposing optional sharing_scope and concurrency_limit parameters, both defaulting to None.
  • observed — Modified behavior in cuda_core/cuda/core/_device_resources.pyx: WorkqueueResourceOptions now disables the dataclass-generated initializer.
  • observed — Modified behavior in cuda_core/cuda/core/_device_resources.pyx: An explicit initializer validates sharing_scope and rejects concurrency_limit below 1 when set, then assigns both options. The removed __post_init__ performed the same validation after dataclass initialization.
Finishing Touches

Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 64feee6 and b3f6187.

Files ignored due to path filters: 4

  • cuda_bindings_12/pixi.lock is excluded by !**/*.lock
  • cuda_bindings_13/pixi.lock is excluded by !**/*.lock
  • cuda_core/pixi.lock is excluded by !**/*.lock
  • cuda_pathfinder/pixi.lock is excluded by !**/*.lock
Files selected for processing: 8

  • .pre-commit-config.yaml
  • cuda_bindings_12/pixi.toml
  • cuda_bindings_12/pyproject.toml
  • cuda_bindings_13/pixi.toml
  • cuda_bindings_13/pyproject.toml
  • cuda_core/cuda/core/_memoryview.pyx
  • cuda_core/pixi.toml
  • cuda_core/pyproject.toml

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

@juenglin
juenglin disabled auto-merge November 10, 2026 18:33
@juenglin

Copy link
Copy Markdown
Contributor Author

Did you fully regenerate the files? I would have expected all of the changes from #3410 as well.

No, I regenerated the driver and runtime files only.

@juenglin
juenglin marked this pull request as draft November 10, 2026 19:32
# Conflicts:
#	cuda_bindings_12/cuda/bindings/driver.pyx
#	cuda_bindings_12/cuda/bindings/runtime.pyx
#	cuda_bindings_12/pixi.toml
#	cuda_bindings_12/pyproject.toml
#	cuda_bindings_13/cuda/bindings/driver.pyx
#	cuda_bindings_13/cuda/bindings/runtime.pyx
#	cuda_bindings_13/pixi.lock
#	cuda_bindings_13/pyproject.toml
#	cuda_core/pyproject.toml
@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test 44b5d59

@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test b3f6187

@juenglin
juenglin marked this pull request as ready for review November 25, 2026 18:52
@juenglin
juenglin requested a review from mdboom November 25, 2026 18:52
@juenglin
juenglin enabled auto-merge (squash) November 30, 2026 17:27

@mdboom mdboom 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.

LGTM. Thanks.

@juenglin
juenglin merged commit 76fb327 into NVIDIA:main Nov 30, 2026
230 of 232 checks passed
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 cuda.pathfinder Everything related to the cuda.pathfinder module dependencies Pull requests that update a dependency file P1 Medium priority - Should do

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants