Skip to content

Comments

Refactor cuda-bindings setup.py to defer CUDA_HOME check to build time#1652

Merged
kkraus14 merged 4 commits intoNVIDIA:mainfrom
kkraus14:kkraus14/defer-cuda-home-to-build-time
Feb 20, 2026
Merged

Refactor cuda-bindings setup.py to defer CUDA_HOME check to build time#1652
kkraus14 merged 4 commits intoNVIDIA:mainfrom
kkraus14:kkraus14/defer-cuda-home-to-build-time

Conversation

@kkraus14
Copy link
Collaborator

Summary

  • Introduces cuda_bindings/build_hooks.py as a custom PEP 517 build backend that defers all CUDA-dependent logic (header parsing, code generation, cythonization) to build_wheel/build_editable
  • Rewrites cuda_bindings/setup.py as a thin shim (matching cuda_core/setup.py) that only provides the ext_modules bridge and parallel build_ext
  • Changes pyproject.toml build-backend from setuptools.build_meta to build_hooks

Metadata queries (uv lock, uv sync, pip install --dry-run) no longer require CUDA_HOME or CUDA_PATH to be set.

Follows the same pattern already used by cuda_core/build_hooks.py.

Test plan

  • Verify python -c "import build_hooks" succeeds without CUDA_HOME (confirmed locally)
  • Verify uv lock / uv pip compile works without CUDA_HOME
  • Verify CUDA_HOME=/usr/local/cuda uv build --wheel produces a working wheel
  • Verify pip install -e . with CUDA_HOME set works for editable installs
  • CI wheel builds pass on Linux and Windows

Closes #1635

Made with Cursor

@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Feb 19, 2026

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

Contributors can view more details about this message here.

@kkraus14 kkraus14 marked this pull request as draft February 19, 2026 05:38
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Feb 19, 2026

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.

Move all CUDA-dependent logic (header parsing, code generation,
cythonization) from setup.py into a custom PEP 517 build backend
(build_hooks.py). Metadata queries (uv lock, uv sync, pip install
--dry-run) no longer require CUDA_HOME or CUDA_PATH to be set.

This follows the same pattern already used by cuda_core/build_hooks.py:
- Metadata hooks delegate directly to setuptools
- build_wheel/build_editable defer to _build_cuda_bindings()
- setup.py becomes a thin shim for ext_modules + parallel build_ext

Closes NVIDIA#1635

Co-authored-by: Cursor <cursoragent@cursor.com>
@kkraus14 kkraus14 force-pushed the kkraus14/defer-cuda-home-to-build-time branch from 30954a9 to dc8be9b Compare February 19, 2026 05:46
@kkraus14
Copy link
Collaborator Author

/ok to test

@kkraus14 kkraus14 added the to-be-backported Trigger the bot to raise a backport PR upon merge label Feb 19, 2026
@github-actions

This comment has been minimized.

@kkraus14 kkraus14 marked this pull request as ready for review February 19, 2026 17:26
@mdboom mdboom added the cuda.bindings Everything related to the cuda.bindings module label Feb 19, 2026
Copy link
Contributor

@mdboom mdboom left a comment

Choose a reason for hiding this comment

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

A few minor comments, none critical.

- Move extra_link_args (strip) handling alongside extra_compile_args
  in the non-debug build path instead of a separate post-loop
- Rename compiler_directives to cython_directives for clarity
- Restore deprecated PARALLEL_LEVEL env var support in setup.py
  for build_ext parallelism parity with the old code

Co-authored-by: Cursor <cursoragent@cursor.com>
@kkraus14
Copy link
Collaborator Author

/ok to test

…ome-to-build-time

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	cuda_bindings/setup.py
@kkraus14
Copy link
Collaborator Author

/ok to test

Check the compiler once in build_extensions (plural) and fix up all
extensions in one pass, instead of checking per-extension in
build_extension (singular).

Co-authored-by: Cursor <cursoragent@cursor.com>
@kkraus14
Copy link
Collaborator Author

/ok to test

Comment on lines +43 to +45
if _is_clang(self.compiler):
for ext in self.extensions:
ext.extra_compile_args = [a for a in ext.extra_compile_args if a != "-fno-var-tracking-assignments"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mdboom I moved this so we only check this once instead of per extension. Would be great if you could take a look in case I have the wrong idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this should be fine. It would be nicer to do it where we set the flags in the first place, but we don't know what the compiler is yet at that point.

@kkraus14 kkraus14 merged commit 9e60c6f into NVIDIA:main Feb 20, 2026
86 checks passed
@github-actions
Copy link

Backport failed for 12.9.x, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 12.9.x
git worktree add -d .worktree/backport-1652-to-12.9.x origin/12.9.x
cd .worktree/backport-1652-to-12.9.x
git switch --create backport-1652-to-12.9.x
git cherry-pick -x 9e60c6fcff8ba2e44b7f54994db4a803d45e35f7

@github-actions
Copy link

Doc Preview CI
Preview removed because the pull request was closed or merged.

kkraus14 added a commit to kkraus14/cuda-python that referenced this pull request Feb 20, 2026
NVIDIA#1652)

* Refactor cuda-bindings setup.py to defer CUDA_HOME check to build time

Move all CUDA-dependent logic (header parsing, code generation,
cythonization) from setup.py into a custom PEP 517 build backend
(build_hooks.py). Metadata queries (uv lock, uv sync, pip install
--dry-run) no longer require CUDA_HOME or CUDA_PATH to be set.

This follows the same pattern already used by cuda_core/build_hooks.py:
- Metadata hooks delegate directly to setuptools
- build_wheel/build_editable defer to _build_cuda_bindings()
- setup.py becomes a thin shim for ext_modules + parallel build_ext

Closes NVIDIA#1635

Co-authored-by: Cursor <cursoragent@cursor.com>

* Address review feedback and restore PARALLEL_LEVEL compat

- Move extra_link_args (strip) handling alongside extra_compile_args
  in the non-debug build path instead of a separate post-loop
- Rename compiler_directives to cython_directives for clarity
- Restore deprecated PARALLEL_LEVEL env var support in setup.py
  for build_ext parallelism parity with the old code

Co-authored-by: Cursor <cursoragent@cursor.com>

* Move clang detection to build_extensions for single check

Check the compiler once in build_extensions (plural) and fix up all
extensions in one pass, instead of checking per-extension in
build_extension (singular).

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
kkraus14 added a commit that referenced this pull request Feb 20, 2026
#1652) (#1666)

* Refactor cuda-bindings setup.py to defer CUDA_HOME check to build time

Move all CUDA-dependent logic (header parsing, code generation,
cythonization) from setup.py into a custom PEP 517 build backend
(build_hooks.py). Metadata queries (uv lock, uv sync, pip install
--dry-run) no longer require CUDA_HOME or CUDA_PATH to be set.

This follows the same pattern already used by cuda_core/build_hooks.py:
- Metadata hooks delegate directly to setuptools
- build_wheel/build_editable defer to _build_cuda_bindings()
- setup.py becomes a thin shim for ext_modules + parallel build_ext

Closes #1635



* Address review feedback and restore PARALLEL_LEVEL compat

- Move extra_link_args (strip) handling alongside extra_compile_args
  in the non-debug build path instead of a separate post-loop
- Rename compiler_directives to cython_directives for clarity
- Restore deprecated PARALLEL_LEVEL env var support in setup.py
  for build_ext parallelism parity with the old code



* Move clang detection to build_extensions for single check

Check the compiler once in build_extensions (plural) and fix up all
extensions in one pass, instead of checking per-extension in
build_extension (singular).



---------

Co-authored-by: Cursor <cursoragent@cursor.com>
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 to-be-backported Trigger the bot to raise a backport PR upon merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor cuda-bindings setup.py to defer CUDA_HOME check to build time

2 participants