Support installing python bindings via cmake --install (fixes #149)#403
Support installing python bindings via cmake --install (fixes #149)#403Anerudhan wants to merge 1 commit into
Conversation
Add a CUDNN_FRONTEND_INSTALL_PYTHON_BINDINGS option (default OFF) that installs the cudnn python package, the compiled extension module, and a PEP 376 .dist-info directory (METADATA, INSTALLER, top_level.txt, and an install-time generated RECORD) into the python site-packages, so the install is discoverable by pip / importlib.metadata and removable with pip uninstall. The destination defaults to the found interpreter's platlib and can be overridden with CUDNN_FRONTEND_PYTHON_INSTALL_DIR; DESTDIR staging is supported. This enables system packagers who cannot go through pip/setup.py to ship the python bindings directly from the CMake build. Fixes NVIDIA#149 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughCMake now optionally installs the Python bindings, compiled extension, and PEP 376 metadata. The README documents configuration, build, installation, staging, dependency, and uninstall details. ChangesPython binding installation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CMakeInstall
participant PythonSitePackages
participant PipMetadata
CMakeInstall->>PythonSitePackages: Install cudnn package and compiled extension
CMakeInstall->>PythonSitePackages: Install dist-info metadata
CMakeInstall->>PythonSitePackages: Generate RECORD
PipMetadata->>PythonSitePackages: Read installed package metadata
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@python/CMakeLists.txt`:
- Line 178: Update the Python binding installation configuration to gate
CUDNN_FRONTEND_INSTALL_PYTHON_BINDINGS on Python 3.9 or newer, aligning its
find_package(Python ...) requirement with the existing Requires-Python: >=3.9
metadata. Ensure Python 3.8 is rejected for this installation path while
preserving support for 3.9+.
- Around line 199-210: Update the RECORD generation block in
python/CMakeLists.txt to enumerate only the files created by this install step,
rather than recursively scanning the entire cudnn and dist-info directories. Use
the install step’s explicit file list as the source for _installed_files, while
retaining exclusion of the RECORD entry and the existing _record formatting and
write behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 68cbe8d1-6787-4242-baec-d67885e6b937
📒 Files selected for processing (2)
README.mdpython/CMakeLists.txt
| Summary: NVIDIA cuDNN Frontend — Python and C++ Graph API | ||
| Home-page: https://github.com/NVIDIA/cudnn-frontend | ||
| License: MIT | ||
| Requires-Python: >=3.9 |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/sh
set -eu
rg -n -C 2 'find_package\(Python|Requires-Python|Python 3\.9\+' \
python/CMakeLists.txt README.mdRepository: NVIDIA/cudnn-frontend
Length of output: 797
🏁 Script executed:
sed -n '1,240p' python/CMakeLists.txtRepository: NVIDIA/cudnn-frontend
Length of output: 7397
Gate CUDNN_FRONTEND_INSTALL_PYTHON_BINDINGS on Python 3.9+.
find_package(Python 3.8 ...) still accepts 3.8, but the installed metadata says Requires-Python: >=3.9. That lets cmake --install lay down a distribution that advertises a higher minimum than the interpreter used to install it.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@python/CMakeLists.txt` at line 178, Update the Python binding installation
configuration to gate CUDNN_FRONTEND_INSTALL_PYTHON_BINDINGS on Python 3.9 or
newer, aligning its find_package(Python ...) requirement with the existing
Requires-Python: >=3.9 metadata. Ensure Python 3.8 is rejected for this
installation path while preserving support for 3.9+.
| file(GLOB_RECURSE _installed_files LIST_DIRECTORIES false | ||
| RELATIVE "${_site_dir}" | ||
| "${_site_dir}/cudnn/*" | ||
| "${_site_dir}/${_dist_info}/*" | ||
| ) | ||
| list(REMOVE_ITEM _installed_files "${_dist_info}/RECORD") | ||
| set(_record "") | ||
| foreach(_file IN LISTS _installed_files) | ||
| string(APPEND _record "${_file},,\n") | ||
| endforeach() | ||
| string(APPEND _record "${_dist_info}/RECORD,,\n") | ||
| file(WRITE "${_site_dir}/${_dist_info}/RECORD" "${_record}") |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/sh
set -eu
rg -n -A 14 -B 2 \
'file\(GLOB_RECURSE _installed_files|string\(APPEND _record|file\(WRITE.*RECORD' \
python/CMakeLists.txtRepository: NVIDIA/cudnn-frontend
Length of output: 946
🏁 Script executed:
#!/bin/sh
set -eu
# Show the surrounding install logic in python/CMakeLists.txt
sed -n '1,260p' python/CMakeLists.txt | cat -n
# Find where the package payload is installed
rg -n -A 4 -B 4 'install\(.*(cudnn|dist-info|site_dir|RECORD)|_cudnn_fe_python_install_dir|_cudnn_fe_dist_info' python/CMakeLists.txtRepository: NVIDIA/cudnn-frontend
Length of output: 11345
🏁 Script executed:
#!/bin/sh
set -eu
# Map the CMake file structure first, then inspect only the relevant ranges.
ast-grep outline python/CMakeLists.txt --view expanded || true
sed -n '120,240p' python/CMakeLists.txt | cat -nRepository: NVIDIA/cudnn-frontend
Length of output: 4924
🏁 Script executed:
#!/bin/sh
set -eu
# Inspect the install/publishing context around the generated RECORD file.
sed -n '1,260p' python/CMakeLists.txt | cat -n | sed -n '1,260p'Repository: NVIDIA/cudnn-frontend
Length of output: 8909
🏁 Script executed:
#!/bin/sh
set -eu
rg -n -A 3 -B 3 '_cudnn_fe_python_install_dir|_cudnn_fe_dist_info|install\(SCRIPT|DESTDIR|wheel|bdist|pip' .Repository: NVIDIA/cudnn-frontend
Length of output: 50380
🏁 Script executed:
#!/bin/sh
set -eu
# Find the install rules that populate the Python package tree.
rg -n -A 4 -B 4 'install\((FILES|DIRECTORY|TARGETS|SCRIPT)|_cudnn_fe_python_install_dir|_cudnn_fe_dist_info' python/CMakeLists.txtRepository: NVIDIA/cudnn-frontend
Length of output: 2595
Build RECORD from the files this install step creates.
python/CMakeLists.txt:199-210 recursively scans ${_site_dir}/cudnn and ${_site_dir}/${_dist_info}, so stale __pycache__ or user-added files can get recorded and later removed by pip uninstall.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@python/CMakeLists.txt` around lines 199 - 210, Update the RECORD generation
block in python/CMakeLists.txt to enumerate only the files created by this
install step, rather than recursively scanning the entire cudnn and dist-info
directories. Use the install step’s explicit file list as the source for
_installed_files, while retaining exclusion of the RECORD entry and the existing
_record formatting and write behavior.
Summary
Fixes #149 — adds first-class support for installing the Python bindings directly from the CMake build system, so system packagers (and anyone who cannot go through
pip/setup.py) no longer need a fork to ship the bindings. This follows the same approach Z3 uses for its CMake-installed Python bindings, including a.dist-infoinsite-packages.Solution
A new option
CUDNN_FRONTEND_INSTALL_PYTHON_BINDINGS(defaultOFF, so nothing changes for existing wheel/setup.pybuilds) makescmake --installproduce a complete, pip-visible installation:cmake -DCUDNN_FRONTEND_BUILD_PYTHON_BINDINGS=ON \ -DCUDNN_FRONTEND_INSTALL_PYTHON_BINDINGS=ON \ -DCUDNN_FRONTEND_BUILD_SAMPLES=OFF -DCUDNN_FRONTEND_BUILD_TESTS=OFF .. cmake --build . -j cmake --install .What gets installed into
site-packages:cudnnpackage — pure-Python sources (python/cudnn/**/*.py) plus the compiled_compiled_moduleextension, in the same layout the wheel produces (on Windows the module goes tocudnn/Release/, matching whatcudnn/__init__.pyexpects).nvidia_cudnn_frontend-<version>.dist-infodirectory containing:METADATA(name/version generated from the CMake project version, which matchescudnn.__version__)INSTALLER(cmake) andtop_level.txtRECORD, generated at install time by aninstall(SCRIPT)step after all files are in place — sopip uninstall nvidia-cudnn-frontendworks.Destination handling:
Python_SITEARCH(honors virtualenvs).-DCUDNN_FRONTEND_PYTHON_INSTALL_DIR=<path>— absolute, or relative toCMAKE_INSTALL_PREFIX.DESTDIRstaging is supported (theRECORDgenerator prefixes$ENV{DESTDIR}).Also removes the stale "using python bindings directly with cmake build system is not supported" comment, and documents the new workflow in the README ("Building from Source" section), including how to combine it with the existing
CUDNN_FRONTEND_FETCH_PYBINDS_IN_CMAKE=OFF/CUDNN_FRONTEND_USE_SYSTEM_DLPACK=ONoptions for fully system-provided dependencies.Verification
Built and installed on Linux x86_64 (CMake 3.31, CUDA 13.2, Python 3.14) with
DESTDIRstaging:cmake --installproducedcudnn/(201 files incl. the.so) andnvidia_cudnn_frontend-1.27.0.dist-info/with a 204-entryRECORD(including itself).import cudnnfrom the installed location works;cudnn.__version__ == '1.27.0'.importlib.metadata.version('nvidia-cudnn-frontend')→1.27.0.pip list --path <site-packages>showsnvidia-cudnn-frontend 1.27.0.setup.py/wheel path untouched.cc @BwL1289 — this should allow deprecating the meson fork (
eugo-inc/cudnn-frontend-meson-python); feedback welcome on whether this covers your use case.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
DESTDIR.Documentation