arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2304.02712cs.PL
收藏

使用 cppyy 与 Cling 实现高效且准确的自动 Python 绑定

Efficient and Accurate Automatic Python Bindings with cppyy & Cling

Baidyanath Kundu, Vassil Vassilev, Wim Lavrijsen

AI总结:

本文提出基于C++解释器Cling和反射库InterOp的cppyy自动Python绑定方案,解决静态C++与动态Python间的阻抗失配问题,无需库作者支持即可在运行时延迟构建绑定,性能优于PyBind11,并探索了跨语言优化与上游LLVM组件重构路径。

摘要:

Python 的简洁性与 C++ 的强大功能迫使科学软件栈面临艰难的抉择。尽管已有多种通过实现语言绑定来缓解语言边界的开发成果,但 C++ 的静态特性与 Python 的动态特性之间的阻抗失配阻碍了它们的实现;例如在模板化 C++ 中使用用户定义的 Python 类型以及高级内存管理。C++ 解释器 Cling 的开发改变了我们对语言绑定的思考方式,因为它提供了运行时可用的增量编译基础设施。也就是说,Python 可以按需查询 C++,并且绑定可以在运行时被延迟构建。这种自动绑定提供机制不需要库作者的直接支持,并且提供了比 PyBind11 等替代方案更好的性能。ROOT 通过 PyROOT 开创了这种方法,后来其继任者 cppyy 对此进行了增强。然而,直到现在,cppyy 仍然依赖于 ROOT 的反射层,而该层在提供的功能和性能方面存在局限。本文提出了 cppyy 在语言互操作性方面的下一步发展,促进了对统一跨语言执行环境的研究,并增加了跨语言边界的优化机会。我们通过 cppyy 展示了在 Numba 加速的 Python 中使用高级 C++ 的方法。我们概述了重构 cppyy 部分组件以使用上游 LLVM 组件来提升性能和可持续性的前进路径。我们展示了完全基于 C++ 反射库 InterOp 的 cppyy,该库提供了基于 Cling 和 Clang-Repl 的互操作性原语。

英文摘要:

The simplicity of Python and the power of C++ force stark choices on a scientific software stack. There have been multiple developments to mitigate language boundaries by implementing language bindings, but the impedance mismatch between the static nature of C++ and the dynamic one of Python hinders their implementation; examples include the use of user-defined Python types with templated C++ and advanced memory management. The development of the C++ interpreter Cling has changed the way we can think of language bindings as it provides an incremental compilation infrastructure available at runtime. That is, Python can interrogate C++ on demand, and bindings can be lazily constructed at runtime. This automatic binding provision requires no direct support from library authors and offers better performance than alternative solutions, such as PyBind11. ROOT pioneered this approach with PyROOT, which was later enhanced with its successor, cppyy. However, until now, cppyy relied on the reflection layer of ROOT, which is limited in terms of provided features and performance. This paper presents the next step for language interoperability with cppyy, enabling research into uniform cross-language execution environments and boosting optimization opportunities across language boundaries. We illustrate the use of advanced C++ in Numba-accelerated Python through cppyy. We outline a path forward for re-engineering parts of cppyy to use upstream LLVM components to improve performance and sustainability. We demonstrate cppyy purely based on a C++ reflection library, InterOp, which offers interoperability primitives based on Cling and Clang-Repl.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑