Skip to content

Support installing python bindings via cmake --install (fixes #149)#403

Open
Anerudhan wants to merge 1 commit into
NVIDIA:developfrom
Anerudhan:issue-149-cmake-python-install
Open

Support installing python bindings via cmake --install (fixes #149)#403
Anerudhan wants to merge 1 commit into
NVIDIA:developfrom
Anerudhan:issue-149-cmake-python-install

Conversation

@Anerudhan

@Anerudhan Anerudhan commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

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-info in site-packages.

Solution

A new option CUDNN_FRONTEND_INSTALL_PYTHON_BINDINGS (default OFF, so nothing changes for existing wheel/setup.py builds) makes cmake --install produce 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:

  1. The cudnn package — pure-Python sources (python/cudnn/**/*.py) plus the compiled _compiled_module extension, in the same layout the wheel produces (on Windows the module goes to cudnn/Release/, matching what cudnn/__init__.py expects).
  2. A PEP 376 nvidia_cudnn_frontend-<version>.dist-info directory containing:
    • METADATA (name/version generated from the CMake project version, which matches cudnn.__version__)
    • INSTALLER (cmake) and top_level.txt
    • RECORD, generated at install time by an install(SCRIPT) step after all files are in place — so pip uninstall nvidia-cudnn-frontend works.

Destination handling:

  • Defaults to the found interpreter's Python_SITEARCH (honors virtualenvs).
  • Overridable with -DCUDNN_FRONTEND_PYTHON_INSTALL_DIR=<path> — absolute, or relative to CMAKE_INSTALL_PREFIX.
  • DESTDIR staging is supported (the RECORD generator 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=ON options for fully system-provided dependencies.

Verification

Built and installed on Linux x86_64 (CMake 3.31, CUDA 13.2, Python 3.14) with DESTDIR staging:

  • cmake --install produced cudnn/ (201 files incl. the .so) and nvidia_cudnn_frontend-1.27.0.dist-info/ with a 204-entry RECORD (including itself).
  • import cudnn from the installed location works; cudnn.__version__ == '1.27.0'.
  • importlib.metadata.version('nvidia-cudnn-frontend')1.27.0.
  • pip list --path <site-packages> shows nvidia-cudnn-frontend 1.27.0.
  • Default configuration (option OFF) is unchanged — no new install rules run, 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

    • Added support for installing the Python bindings through CMake.
    • Installed packages now include standard Python metadata, making them visible to package and metadata tools.
    • Added options for customizing the Python installation directory and using DESTDIR.
    • Added configuration controls for bundled or system-provided build dependencies.
  • Documentation

    • Documented the CMake-based Python installation, customization options, and uninstall workflow.

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>
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

CMake now optionally installs the Python bindings, compiled extension, and PEP 376 metadata. The README documents configuration, build, installation, staging, dependency, and uninstall details.

Changes

Python binding installation

Layer / File(s) Summary
Install Python package and extension
python/CMakeLists.txt, README.md
Adds an opt-in CMake installation path, configurable Python destination, platform-specific extension placement, and corresponding build/install instructions.
Generate distribution metadata
python/CMakeLists.txt
Generates and installs the package’s METADATA, INSTALLER, and top_level.txt files in a versioned .dist-info directory.
Generate installation RECORD
python/CMakeLists.txt
Creates RECORD at install time from files found beneath the configured Python site directory.

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
Loading

Suggested reviewers: hwanseoc

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding CMake-based installation for Python bindings.
Description check ✅ Passed The description covers the change, motivation, workflow, verification, and compatibility impact well enough for this template.
Linked Issues check ✅ Passed The PR delivers the linked issue's core need by enabling upstream installation of the Python bindings and dist-info metadata from CMake.
Out of Scope Changes check ✅ Passed The changes stay focused on Python binding installation support and matching documentation, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@Anerudhan Anerudhan added cat-ci CI failures, test flakiness, workflow breakage, or automation issues. mod-infra Infrastructure, CI/CD, build systems, packaging, releases, or repo maintenance. orig-external Reported or requested by an external user, customer, or community contributor. cat-infra Build, packaging, tooling, dependency, release, or repository maintenance work. labels Jul 17, 2026
@Anerudhan Anerudhan added this to the Frontend 1.27.0 milestone Jul 17, 2026
@Anerudhan Anerudhan self-assigned this Jul 17, 2026
@Anerudhan
Anerudhan requested a review from hwanseoc July 17, 2026 02:16
@Anerudhan
Anerudhan marked this pull request as ready for review July 17, 2026 02:16

@coderabbitai coderabbitai Bot 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3041f3e and 0ba44cc.

📒 Files selected for processing (2)
  • README.md
  • python/CMakeLists.txt

Comment thread python/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

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.

🗄️ 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.md

Repository: NVIDIA/cudnn-frontend

Length of output: 797


🏁 Script executed:

sed -n '1,240p' python/CMakeLists.txt

Repository: 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+.

Comment thread python/CMakeLists.txt
Comment on lines +199 to +210
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}")

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.

🗄️ 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.txt

Repository: 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.txt

Repository: 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 -n

Repository: 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.txt

Repository: 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.

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

Labels

cat-ci CI failures, test flakiness, workflow breakage, or automation issues. cat-infra Build, packaging, tooling, dependency, release, or repository maintenance work. mod-infra Infrastructure, CI/CD, build systems, packaging, releases, or repo maintenance. orig-external Reported or requested by an external user, customer, or community contributor.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Installing Python Bindings from CMake or Using System Version of cudnn-frontend in setup.py

1 participant