Refactor cuda-bindings setup.py to defer CUDA_HOME check to build time#1652
Conversation
|
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. |
|
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>
30954a9 to
dc8be9b
Compare
|
/ok to test |
This comment has been minimized.
This comment has been minimized.
mdboom
left a comment
There was a problem hiding this comment.
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>
|
/ok to test |
…ome-to-build-time Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # cuda_bindings/setup.py
|
/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>
|
/ok to test |
| 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"] |
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
|
Backport failed for 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 |
|
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>
#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>
Summary
cuda_bindings/build_hooks.pyas a custom PEP 517 build backend that defers all CUDA-dependent logic (header parsing, code generation, cythonization) tobuild_wheel/build_editablecuda_bindings/setup.pyas a thin shim (matchingcuda_core/setup.py) that only provides theext_modulesbridge and parallelbuild_extpyproject.tomlbuild-backend fromsetuptools.build_metatobuild_hooksMetadata queries (
uv lock,uv sync,pip install --dry-run) no longer requireCUDA_HOMEorCUDA_PATHto be set.Follows the same pattern already used by
cuda_core/build_hooks.py.Test plan
python -c "import build_hooks"succeeds withoutCUDA_HOME(confirmed locally)uv lock/uv pip compileworks withoutCUDA_HOMECUDA_HOME=/usr/local/cuda uv build --wheelproduces a working wheelpip install -e .withCUDA_HOMEset works for editable installsCloses #1635
Made with Cursor