A look at pybind/cmake_example: 671 stars on GitHub, written primarily in C++. Example pybind11 module built with a CMake-based build system
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
An example project built with pybind11, CUDA, and
scikit-build-core. Python 3.11+.
The extension renders the Mandelbrot set two ways — once on the
CPU and once on the GPU — so you can read both side by side and compare their
performance. The two implementations are written the same way on purpose:
src/mandelbrot_cpu.cpp — a plain nested loop over every pixel
src/mandelbrot.cu — the same logic as a CUDA kernel, one thread per pixel
Both return a (height, width) int32 NumPy array of escape counts. Building
requires the CUDA Toolkit (nvcc): the CMake project declares CUDA as a
required language, so configuration fails without it. The CUDA runtime is linked
statically, so the resulting wheels do not depend on libcudart and stay
importable on machines without a GPU — calling mandelbrot_gpu there raises, but
cuda_available() lets you check first.
Installation
Clone this repository
pip install ./cuda_example
The CUDA Toolkit (nvcc) must be installed and discoverable by CMake.
The Wheels workflow builds CUDA-enabled Linux wheels with cibuildwheel,
using the custom manylinux images that ship the CUDA Toolkit (see
pypa/cibuildwheel#2896). The images are configured in
pyproject.toml:
To target a different CUDA version (e.g. an older cuda12_9 to support older
drivers) without editing pyproject.toml, override the images with environment
variables when running cibuildwheel:
The available images are listed in the cibuildwheel docs; the
manylinux_2_28/manylinux_2_34 base and cuda12_9/cuda13_1 version can be
mixed and matched.
The CUDA runtime is linked statically (CUDA_RUNTIME_LIBRARY Static), so the
resulting wheels do not depend on libcudart. GitHub-hosted runners have no
GPU, so the wheels are compiled and imported, but the kernels themselves only
run on a machine with a CUDA device.
Testing the CUDA build locally with Docker
You don't need a GPU (or even a Linux machine) to compile and import the CUDA
build — the manylinux images ship the CUDA Toolkit, so nvcc runs inside the
container. The kernels are compiled and the wheel is imported; they just
can't execute on the GPU without a device (those tests are skipped).
Pick the image matching your host architecture (the aarch64 image runs
natively on Apple Silicon; on x86_64 use the x86_64 image):
The compiled wheel is written to ./wheelhouse/ on the host, so you can inspect
or install it afterwards. Because the container has no GPU, cuda_available()
returns False and the mandelbrot_gpu test is skipped (the mandelbrot_cpu
tests still run). The same flow runs in CI in the cuda job of
.github/workflows/pip.yml.
Files
This example has several files that are a good idea, but aren't strictly
necessary. The necessary files are:
pyproject.toml: The Python project file
CMakeLists.txt: The CMake configuration file, which requires the CUDA language
src/main.cpp: The pybind11 bindings (turns the results into NumPy arrays)
src/mandelbrot_cpu.cpp: The CPU implementation
src/mandelbrot.cu: The CUDA kernel and runtime device query
src/mandelbrot.h: The shared declarations
src/cuda_example/__init__.py: The Python portion of the module. The root of the module needs to be <package_name>, src/<package_name>, or python/<package_name> to be auto-discovered.
These files are also expected and highly recommended:
.gitignore: Git's ignore list, also used by scikit-build-core to select files for the SDist
README.md: The source for the PyPI description
LICENSE: The license file
There are also several completely optional directories:
.github: configuration for Dependabot and GitHub Actions
docs/: Documentation
tests/: Tests go here
And some optional files:
.pre-commit-config.yaml: Configuration for the fantastic static-check runner pre-commit.
noxfile.py: Configuration for the nox task runner, which helps make setup easier for contributors.
This is a simplified version of the recommendations in the Scientific-Python
Development Guide, which is a highly recommended read for anyone
interested in Python package development (Scientific or not). The guide also
has a cookiecutter that includes scikit-build-core and pybind11 as a backend
choice.
CI Examples
There are examples for CI in .github/workflows. The "wheels.yml" file builds
CUDA-enabled binary "wheels" for Linux (x86_64 and aarch64) using
cibuildwheel, and "pip.yml" does a quick build-and-import check in the CUDA
containers.
License
pybind11 is provided under a BSD-style license that can be found in the LICENSE
file. By using, distributing, or contributing to this project, you agree to the
terms and conditions of this license.
TopGit's last sync did not record any GitHub topics for pybind/cmake_example. GitHub topics appear in the right sidebar of a repository page; that's the authoritative place to check.
How active is development on pybind/cmake_example?
The most recent commit recorded on pybind/cmake_example was 15 days ago, based on the GitHub push timestamp. The repository has 219 forks — one of the better signals of community interest.
How many stars does pybind/cmake_example have?
pybind/cmake_example has 671 GitHub stars — refresh the page for the live number, or check github.com/pybind/cmake_example. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What language is pybind/cmake_example written in?
pybind/cmake_example is written primarily in C++. GitHub's language field is based on the largest share of bytes in the default branch.
Where do I read more about pybind/cmake_example?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/pybind/cmake_example is the definitive source.
Read full README in the tab above.
Is cmake_example worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of cmake_example.