Halide
Halide copied to clipboard
Consider upgrading pybind11 to nanobind
Per https://github.com/wjakob/nanobind:
TLDR: nanobind bindings compile ~2-3× faster, producing ~3× smaller binaries, with up to ~8× lower overheads on runtime performance (when comparing to pybind11 with -Os size optimizations).
Update: reading further, there are at least two issues with the current (Mar 2022) version of nanobind:
- Eigen and NumPy integration have been removed.
- Buffer protocol functionality was removed.
We rely (heavily) on numpy and buffer protocol; the notes currently say it's "not clear" whether they will be reintroduced.
Looks like they’ve been reintroduced! https://github.com/wjakob/nanobind/blob/master/docs/tensor.md
This does seem worth evaluating now that the buffer protocol is back.
Agreed, but availability could be an issue -- pybind11 is widely available on many systems already, and (more importantly to me personally), nanobind isn't available inside Google yet, so we'd have to get it imported and updated on a regular basis if we adopted it.)
FYI, I took a stab at doing a basic adaptation, but it looks like there are a number of API changes that aren't well-documented yet (eg buffer->tensor) and other things that we use that are (still) missing in nanobind -- see https://github.com/wjakob/nanobind/discussions/77 for a handful of things I noticed. I pushed my (very very very rough) work-in-progress to the srj/nanobind
branch if anyone is interested, but right now it looks like nanobind probably needs more work to be ready for us (and we'd probably have to contribute that work).
(One part of nanobind that is better than pybind11 is that it appears to have support for dlpack built in, which is something we really want/need, not sure if it will be backported to pybind11)