pybind/pybind11

[ENH]: Add DLPack casters to pybind11

Open

#3 858 ouverte le 11 avr. 2022

Voir sur GitHub
 (12 commentaires) (0 réactions) (1 assigné)C++ (2 005 forks)batch import
enhancementhelp wanted

Métriques du dépôt

Stars
 (14 677 stars)
Métriques de merge PR
 (Merge moyen 5j 2h) (10 PRs mergées en 30 j)

Description

Required prerequisites

Problem description

  • Recently, nanobind added a new type of array caster that uses DLPack to convert to and from array. We would like to backport this caster type to pybind. DLPack is a protocol for quickly and efficiently sharing arrays between programs that are backed by either CPU or GPU memory. For example, with a properly written caster one could transfer between a CUDA GPU Array to a PyTorch Tensor. While this is currently possible with custom caster in PyBind11, it would be nice to have official caster support to make this type of generic array sharing easier. Recent version of Numpy also have native APIs to create Numpy arrays from DLPack.
  1. This is not a replacement for the Eigen / Numpy bindings, but a supplement to them. Our current bindings support versions of Numpy that are fairly old. Additionally, we have a lot of convenience functions for dealing with numpy arrays that DLPack likely will not support (reshaping, resizing etc.
  2. This would be implemented as custom type casters. To use them, the user would need to specify an optional include (similar to how they already need to for Eigen/Numpy Bindings.
  3. The testing suite and much of the code can be ripped from nanobind. Note that there are signficant differences between the type casters though: https://github.com/wjakob/nanobind#api-differences . We should ensure that the ported casters handle errors the pybind11 way.

Guide contributeur