Skip to content

Commit c67083a

Browse files
authored
nanobind: upgraded to version 2.11.0.
2 parents a7b4459 + 6ad6416 commit c67083a

File tree

114 files changed

+3236
-1352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+3236
-1352
lines changed

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.20251204.0
1+
0.20260210.0

extern/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
- [GoogleTest](https://github.com/google/googletest) [1.17.0](https://github.com/google/googletest/releases/tag/v1.17.0)
44
- [modp_b64](https://chromium.googlesource.com/chromium/src/third_party/modp_b64/) at commit [5068510](https://chromium.googlesource.com/chromium/src/third_party/modp_b64/+/50685101d51ef9aabbd60c94f52d9e026d39c509)
5-
- [nanobind](https://github.com/wjakob/nanobind) [2.9.2](https://github.com/wjakob/nanobind/releases/tag/v2.9.2)
5+
- [nanobind](https://github.com/wjakob/nanobind) [2.11.0](https://github.com/wjakob/nanobind/releases/tag/v2.11.0)

extern/nanobind/.github/workflows/ci.yml

Lines changed: 136 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
os: ['ubuntu-latest', 'windows-2022', 'macos-13']
24-
python: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14.0-rc.2', 'pypy3.9-v7.3.16', 'pypy3.10-v7.3.17']
23+
os: ['ubuntu-latest', 'windows-2022', 'macos-15']
24+
python: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14', 'pypy3.10-v7.3.19', 'pypy3.11-v7.3.20']
2525

2626
name: "Python ${{ matrix.python }} / ${{ matrix.os }}"
2727
runs-on: ${{ matrix.os }}
@@ -107,98 +107,180 @@ jobs:
107107
cd build;
108108
python3 -m pytest
109109
110-
old-compilers:
111-
if: false # Disable for now, the CI is glitchy
112-
strategy:
113-
fail-fast: false
114-
matrix:
115-
include:
116-
- cc: gcc-8
117-
cxx: g++-8
118-
apt: gcc-8 g++-8
119-
- cc: gcc-9
120-
cxx: g++-9
121-
apt: gcc-9
122-
- cc: clang-8
123-
cxx: clang++-8
124-
apt: clang-8
125-
- cc: clang-9
126-
cxx: clang++-9
127-
apt: clang-9
128-
- cc: clang-10
129-
cxx: clang++-10
130-
apt: clang-10
131-
110+
free-threaded:
111+
name: "Python 3.14-dev / ubuntu.latest [free-threaded]"
132112
runs-on: ubuntu-latest
133-
container: ubuntu:20.04
134-
name: "${{matrix.cc}} on Ubuntu 20.04"
135-
env:
136-
CC: ${{matrix.cc}}
137-
CXX: ${{matrix.cxx}}
138-
DEBIAN_FRONTEND: noninteractive
139113

140114
steps:
141-
- name: Install dependencies
142-
run: |
143-
apt-get update
144-
apt-get install -y python3-numpy python3-pip python3-pytest libeigen3-dev cmake git ${{matrix.apt}}
145-
python3 -m pip install typing_extensions
146-
147115
- uses: actions/checkout@v4
148116
with:
149117
submodules: true
150118

119+
- uses: deadsnakes/action@v3.1.0
120+
with:
121+
python-version: 3.14-dev
122+
nogil: true
123+
124+
- name: Install the latest CMake
125+
uses: lukka/get-cmake@latest
126+
127+
- name: Install PyTest
128+
run: |
129+
python -m pip install pytest pytest-github-actions-annotate-failures
130+
151131
- name: Configure
152-
run: cmake -S . -B build
132+
run: >
133+
cmake -S . -B build -DNB_TEST_FREE_THREADED=ON
153134
154135
- name: Build C++
155-
run: cmake --build build -j 2
136+
run: >
137+
cmake --build build -j 2
156138
157139
- name: Check ABI tag
158140
run: >
159141
cd build/tests;
160-
python3 -c 'import test_functions_ext as t; print(f"ABI tag is \"{ t.abi_tag() }\"")'
142+
python -c 'import test_functions_ext as t; print(f"ABI tag is \"{ t.abi_tag() }\"")'
161143
162144
- name: Run tests
163145
run: >
164146
cd build;
165-
python3 -m pytest
147+
python -m pytest
166148
167-
free-threaded:
168-
name: "Python 3.14-dev / ubuntu.latest [free-threaded]"
169-
runs-on: ubuntu-latest
149+
mingw:
150+
runs-on: windows-2022
151+
name: "Python ${{ matrix.python }} / MinGW-w64"
152+
strategy:
153+
fail-fast: false
154+
matrix:
155+
python: ['3.12']
170156

171157
steps:
172158
- uses: actions/checkout@v4
173159
with:
174160
submodules: true
175161

176-
- uses: deadsnakes/action@v3.1.0
162+
- name: Setup Python ${{ matrix.python }}
163+
uses: actions/setup-python@v5
177164
with:
178-
python-version: 3.14-dev
179-
nogil: true
165+
python-version: ${{ matrix.python }}
166+
cache: 'pip'
167+
168+
- name: Setup MSYS2 (MINGW64)
169+
uses: msys2/setup-msys2@v2
170+
with:
171+
msystem: MINGW64
172+
install: >-
173+
mingw-w64-x86_64-gcc
174+
mingw-w64-x86_64-cmake
175+
mingw-w64-x86_64-ninja
176+
mingw-w64-x86_64-python
177+
mingw-w64-x86_64-python-pip
178+
mingw-w64-x86_64-python-pytest
179+
180+
- name: Install Python packages
181+
shell: msys2 {0}
182+
run: |
183+
python -m pip install pytest-github-actions-annotate-failures typing_extensions
184+
185+
- name: Configure
186+
shell: msys2 {0}
187+
run: |
188+
export PATH=/mingw64/bin:$PATH
189+
export CC=gcc
190+
export CXX=g++
191+
PYEXE=/mingw64/bin/python3.exe
192+
cmake -S . -B build -G Ninja \
193+
-DPython_EXECUTABLE="$(cygpath -w "$PYEXE")" \
194+
-DNB_TEST_FREE_THREADED=OFF
195+
196+
- name: Build C++
197+
shell: msys2 {0}
198+
run: cmake --build build -j 2
199+
200+
- name: Check ABI tag
201+
shell: msys2 {0}
202+
run: |
203+
cd build/tests
204+
python -c 'import test_functions_ext as t; print(f"ABI tag is \"{t.abi_tag()}\"")'
205+
206+
- name: Run tests
207+
shell: msys2 {0}
208+
run: |
209+
cd build
210+
python -m pytest
211+
212+
intel:
213+
runs-on: ubuntu-22.04
214+
name: "Python ${{ matrix.python }} / Intel ICX"
215+
strategy:
216+
fail-fast: false
217+
matrix:
218+
python: ['3.12']
219+
220+
steps:
221+
- uses: actions/checkout@v4
222+
with:
223+
submodules: true
224+
225+
- name: Setup Python ${{ matrix.python }}
226+
uses: actions/setup-python@v5
227+
with:
228+
python-version: ${{ matrix.python }}
229+
cache: 'pip'
230+
231+
- name: Cache Intel oneAPI
232+
id: cache-oneapi
233+
uses: actions/cache@v4
234+
with:
235+
path: /opt/intel/oneapi
236+
key: install-${{ runner.os }}-intel-oneapi-compiler-2025.2
237+
238+
- name: Add Intel repository
239+
if: steps.cache-oneapi.outputs.cache-hit != 'true'
240+
run: |
241+
wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null
242+
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
243+
sudo apt-get update
244+
245+
- name: Install Intel oneAPI compilers
246+
if: steps.cache-oneapi.outputs.cache-hit != 'true'
247+
run: |
248+
sudo apt-get install -y intel-oneapi-compiler-dpcpp-cpp
249+
250+
- name: Cleanup Intel oneAPI cache
251+
if: steps.cache-oneapi.outputs.cache-hit != 'true'
252+
run: |
253+
sudo rm -rf /opt/intel/oneapi/compiler/*/linux/lib/ia32
254+
sudo rm -rf /opt/intel/oneapi/compiler/*/linux/lib/emu
255+
sudo rm -rf /opt/intel/oneapi/compiler/*/linux/lib/oclfpga
180256
181257
- name: Install the latest CMake
182258
uses: lukka/get-cmake@latest
183259

184260
- name: Install PyTest
185261
run: |
186-
python -m pip install pytest pytest-github-actions-annotate-failures
262+
python -m pip install pytest pytest-github-actions-annotate-failures typing_extensions
187263
188264
- name: Configure
189-
run: >
190-
cmake -S . -B build -DNB_TEST_FREE_THREADED=ON
265+
run: |
266+
source /opt/intel/oneapi/setvars.sh
267+
export CC=icx
268+
export CXX=icpx
269+
cmake -S . -B build
191270
192271
- name: Build C++
193-
run: >
272+
run: |
273+
source /opt/intel/oneapi/setvars.sh
194274
cmake --build build -j 2
195275
196276
- name: Check ABI tag
197-
run: >
198-
cd build/tests;
277+
run: |
278+
source /opt/intel/oneapi/setvars.sh
279+
cd build/tests
199280
python -c 'import test_functions_ext as t; print(f"ABI tag is \"{ t.abi_tag() }\"")'
200281
201282
- name: Run tests
202-
run: >
203-
cd build;
283+
run: |
284+
source /opt/intel/oneapi/setvars.sh
285+
cd build
204286
python -m pytest

extern/nanobind/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ if (NOT TARGET Python::Module OR NOT TARGET Python::Interpreter)
145145
set(NB_PYTHON_DEV_MODULE Development.Module)
146146
endif()
147147

148-
find_package(Python 3.8
148+
find_package(Python 3.9
149149
REQUIRED COMPONENTS Interpreter ${NB_PYTHON_DEV_MODULE}
150150
OPTIONAL_COMPONENTS Development.SABIModule)
151151
endif()

extern/nanobind/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,64 @@ runtime overheads compared to pybind11. nanobind also outperforms Cython in
3030
important metrics (**3-12×** binary size reduction, **1.6-4×** compilation time
3131
reduction, similar runtime performance).
3232

33+
## Testimonials
34+
35+
A selection of testimonials from projects that migrated from pybind11 to nanobind.
36+
37+
<table>
38+
<tr><td>
39+
40+
**IREE** · [LLVM Discourse](https://discourse.llvm.org/t/nanobind-for-mlir-python-bindings/83511/5)
41+
42+
> *"IREE and its derivatives switched 1.5 years ago. It has been one of the single best dep decisions I've made. Not only is it much-much faster to compile, it produces smaller binaries and has a much more lean interface to the underlying Python machinery that all adds up to significant performance improvements. Worked exactly like it said on the tin."*
43+
44+
**Stella Laurenzo**, Google
45+
46+
</td></tr>
47+
<tr><td>
48+
49+
**XLA/MLIR** · [GitHub PR](https://github.com/llvm/llvm-project/pull/118583)
50+
51+
> *"For a complicated Google-internal LLM model in JAX, this change improves the MLIR lowering time by around 5s (out of around 30s), which is a significant speedup for simply switching binding frameworks."*
52+
53+
**Peter Hawkins**, Google
54+
55+
</td></tr>
56+
<tr><td>
57+
58+
**Apple MLX** · [X](https://x.com/awnihannun/status/1890495434021326974)
59+
60+
> *"MLX uses nanobind to bind C++ to Python. It's a critical piece of MLX infra and is why running Python code is nearly the same speed as running C++ directly. Also makes it super easy to move arrays between frameworks."*
61+
62+
**Awni Hannun**, Apple
63+
64+
</td></tr>
65+
<tr><td>
66+
67+
**JAX** · [GitHub](https://github.com/jax-ml/jax/commit/70b7d501816c6e9f131a0a8b3e4a527e53eeebd7)
68+
69+
> *"nanobind has a number of [advantages](https://nanobind.readthedocs.io/en/latest/why.html), notably speed of compilation and dispatch, but the main reason to do this for these bindings is because nanobind can target the Python Stable ABI starting with Python 3.12. This means that we will not need to ship per-Python version CUDA plugins starting with Python 3.12."*
70+
71+
**Peter Hawkins**, Google
72+
73+
</td></tr>
74+
<tr><td>
75+
76+
**FEniCS / DOLFINx** · [GitHub](https://github.com/FEniCS/dolfinx/pull/2820)
77+
78+
> *"nanobind is smaller than pybind11, the wrappers build faster and it has significantly improved support for wrapping multi-dimensional arrays, which we use heavily. The nanobind docs are easier to follow on the low-level details, which makes understanding the memory management in the wrapper layer easier."*
79+
80+
**Garth N. Wells**
81+
</td></tr>
82+
<tr><td>
83+
84+
**PennyLane** · [Release notes](https://docs.pennylane.ai/projects/catalyst/en/stable/dev/release_notes.html)
85+
86+
> *"Nanobind has been developed as a natural successor to the pybind11 library and offers a number of advantages like its ability to target Python's Stable ABI."*
87+
88+
</td></tr>
89+
</table>
90+
3391
## Documentation
3492

3593
Please see the following links for tutorial and reference documentation in

extern/nanobind/cmake/collect-symbols-pypy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
funcs: "set[str]" = set()
66

77
files = [
8-
('https://downloads.python.org/pypy/pypy3.9-v7.3.11-macos_arm64.tar.bz2', 'pypy3.9-v7.3.11-macos_arm64/bin/libpypy3.9-c.dylib')
8+
('https://downloads.python.org/pypy/pypy3.9-v7.3.11-macos_arm64.tar.bz2', 'pypy3.9-v7.3.11-macos_arm64/bin/libpypy3.9-c.dylib'),
9+
('https://downloads.python.org/pypy/pypy3.11-v7.3.20-macos_arm64.tar.bz2', 'pypy3.11-v7.3.20-macos_arm64/bin/libpypy3.11-c.dylib'),
910
]
1011

1112
for f in files:
@@ -25,4 +26,4 @@
2526

2627
with open("darwin-ld-pypy.sym", "w") as f:
2728
for func in sorted(list(funcs)):
28-
f.write(f'-U _{func}\n')
29+
f.write(f'-U {func}\n')

extern/nanobind/cmake/collect-symbols.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
funcs: "set[str]" = set()
1212

13-
for ver in ['3.7', '3.8', '3.9']:
13+
for ver in ['3.9']:
1414
url = f'https://raw.githubusercontent.com/python/cpython/{ver}/PC/python3.def'
1515
output = urlopen(url).read().decode('utf-8')
1616
for match in re.findall(r" (.*)=.*", output):
1717
funcs.add(match)
1818

19-
for ver in ['3.10', '3.11', 'main']:
19+
for ver in ['3.10', '3.11', '3.12', '3.13', '3.14', 'main']:
2020
url = f'https://raw.githubusercontent.com/python/cpython/{ver}/PC/python3dll.c'
2121
output = urlopen(url).read().decode('utf-8')
2222
for match in re.findall(r"EXPORT_FUNC\((.*)\)", output):

0 commit comments

Comments
 (0)