Halide icon indicating copy to clipboard operation
Halide copied to clipboard

Consider upgrading pybind11 to nanobind

Open steven-johnson opened this issue 2 years ago • 8 comments

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).

steven-johnson avatar Mar 29 '22 01:03 steven-johnson

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.

steven-johnson avatar Mar 29 '22 18:03 steven-johnson

Looks like they’ve been reintroduced! https://github.com/wjakob/nanobind/blob/master/docs/tensor.md

rootjalex avatar Apr 05 '22 14:04 rootjalex

This does seem worth evaluating now that the buffer protocol is back.

alexreinking avatar Aug 25 '22 22:08 alexreinking

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.)

steven-johnson avatar Aug 25 '22 23:08 steven-johnson

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).

steven-johnson avatar Oct 05 '22 20:10 steven-johnson

(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)

steven-johnson avatar Oct 05 '22 20:10 steven-johnson