Skip to content

build: add opt-in Cython generated-source cache - #2933

Open
juenglin wants to merge 1 commit into
NVIDIA:toolchain-override-backendfrom
juenglin:opt-in-cython-cache
Open

juenglin wants to merge 1 commit into
NVIDIA:toolchain-override-backendfrom
juenglin:opt-in-cython-cache

Conversation

@juenglin

@juenglin juenglin commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on top of #2903 (toolchain-override-backend). Merge after #2903.

Summary

Adds an opt-in Cython generated-source cache behind CUDA_PYTHON_CYTHON_CACHE_DIR for cuda.bindings and cuda.core builds. When unset, cythonize() is called without cache= and builds are unchanged. POSIX only; on Windows the helper returns None with a warning.

Two problems it works around:

  • Cache namespace (_cython_cache_path): Cython's native fingerprint omits compiler_directives ([BUG] Cache fingerprinting ignores compiler_directives cython/cython#7532). The helper namespaces the cache by package, Python version, and a SHA-256 of output-affecting config (compiler_directives, compile_time_env, language_level, cplus, debug, cuda_major). The helper and its workaround-specific tests can be removed once #7532 is fixed in a released Cython version covered by cuda-python's minimum.
  • Stable dependency paths (_stable_cython_alias): Cython hashes the absolute path of each resolved .pxd, and PEP 517 installs land under randomized temp prefixes. Atomic package-local directory symlinks (.cython-stdlib, and .cython-bindings for cuda.core) give Cython stable relative include paths; created before cythonize() and removed in finally.

Sync mechanism

The two helpers are vendored in both build_hooks.py files (PEP 517 isolation forbids a shared import). Drift is enforced by the existing pre-commit hook toolshed/check_build_hooks_sync.py, which now checks one merged "shared build helpers" block (toolchain + cache helpers) instead of the toolchain-only block. There is no runtime drift test.

Tests

Shared tests live in cuda_python_test_helpers/cuda_python_test_helpers/cython_cache.py (mixins, miss/hit smoke test, cross-isolated-env cache-hit regression) and are exercised by both packages' tests/test_build_hooks.py. POSIX-only tests skip on Windows; a Windows-only test asserts the set-env warn + None path.

Notes

  • cuda.core keeps its existing per-configuration build_dir (cu{major}-{toolchain}-{debug|opt}[-cov]); only cache= / include_path were added.
  • CUDA_PYTHON_CYTHON_CACHE_DIR is intentionally not documented in environment_variables.rst; it joins CUDA_PYTHON_TOOLCHAIN under the "no support guarantee" comment in both build_hooks.py files.
  • Expected to be opted into only by persistent (e.g. RISC-V) runners; ephemeral runners gain little since Cython's cache is disk-only.

@copy-pr-bot

copy-pr-bot Bot commented Sep 22, 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 labels Sep 22, 2026
@juenglin juenglin added CI/CD CI/CD infrastructure enhancement Any code-related improvements labels Sep 22, 2026
@juenglin juenglin added this to the cuda.bindings next milestone Sep 22, 2026
@juenglin juenglin self-assigned this Sep 22, 2026
@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test 41c8db9

Add an opt-in Cython cache behind CUDA_PYTHON_CYTHON_CACHE_DIR for
cuda.bindings and cuda.core builds. When unset, cythonize() is called
without cache= and builds are unchanged. POSIX only; Windows returns
None with a warning.

_cython_cache_path namespaces the cache by package, Python version, and
a SHA-256 of output-affecting config (compiler_directives,
compile_time_env, language_level, cplus, debug, cuda_major). This works
around cython/cython#7532 (Cython omits compiler_directives from its native
fingerprint); the helper and its tests can be removed once that issue is
fixed in a released Cython version covered by cuda-python's minimum.

_stable_cython_alias creates package-local directory symlinks
(.cython-stdlib, and .cython-bindings for cuda.core) before cythonize()
and removes them in finally, giving Cython stable relative include paths
across PEP 517 builds that install deps under randomized temp prefixes.

The two helpers are vendored in both build_hooks.py files (PEP 517
isolation forbids a shared import) and kept in sync by the existing
pre-commit hook toolshed/check_build_hooks_sync.py, now covering one
merged "shared build helpers" block instead of the toolchain-only block.
No runtime drift test.

Tests live in cuda_python_test_helpers/cython_cache.py (shared mixins +
miss/hit smoke test + cross-isolated-env cache-hit regression) and are
exercised by both packages' tests/test_build_hooks.py. POSIX-only tests
skip on Windows; a Windows-only test asserts the set-env warn+None path.
@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test c929252

@juenglin
juenglin requested a review from rwgk September 22, 2026 21:55
@juenglin
juenglin marked this pull request as ready for review September 22, 2026 21:56
@github-actions

Copy link
Copy Markdown
Contributor

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

Approving, based on several stages of reviewing with codex gpt-5.6-sol medium. There are no findings anymore.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/CD CI/CD infrastructure 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.

2 participants