High-Performance Python-C++ Bindings with PyPy and Cling

High-Performance Python-C++ Bindings with PyPy and Cling
复制标题

使用 PyPy 和 Cling 进行高性能 Python-C 绑定

DOI:
--
复制
发表时间:
2016
期刊:
Workshop on Python for High-Performance and Scientific Computing
影响因子:
--
通讯作者:
Aditi Dutta
Aditi Dutta
中科院分区:
--
文献类型:
--
作者:
W. Lavrijsen;Aditi Dutta

文献摘要

被引文献

相似文献

使用Python作为基于c++编写的高性能库的高级生产力语言,需要高效、高功能和易于使用的跨语言绑定。c++在1998年被标准化,直到2011年,它只经历了一次小的修改。从那时起,修订的步伐大大加快,在接口定义中表达语义意图方面做了许多改进。对于自动python - c++绑定生成器来说,这既是最坏的时代,因为解析器需要跟上,也是最好的时代,因为对象所有权和线程安全等重要信息现在可以表达了。我们介绍了cppyy,它使用基于Clang/ llvm的c++解释器Clang/ llvm来自动为cppyy生成python - c++绑定。Cling提供了对现代c++解析器的动态访问,而PyPy提供了一个完整的动态优化工具箱,以实现高性能。使用Cling进行解析,可以在现在和可预见的将来提供最新的c++支持。我们表明,使用PyPy,从Python调用c++函数的开销可以比在CPython中等效的开销减少一个数量级,使得它足够低,除了最短的c++函数之外,其他所有函数都无法测量。同样,在c++中对数据的访问比在CPython中访问减少了两个数量级。我们的方法不需要中间语言,c++库的更Python化的表示可以用Python本身编写,由于PyPy的内联,性能成本很小。这允许未来的动态优化完全透明。
The use of Python as a high level productivity language on top of high performance libraries written in C++ requires efficient, highly functional, and easy-to-use cross-language bindings. C++ was standardized in 1998 and up until 2011 it saw only one minor revision. Since then, the pace of revisions has increased considerably, with a lot of improvements made to expressing semantic intent in interface definitions. For automatic Python-C++ bindings generators it is both the worst of times, as parsers need to keep up, and the best of times, as important information such as object ownership and thread safety can now be expressed. We present cppyy, which uses Cling, the Clang/LLVM-based C++ interpreter, to automatically generate Python-C++ bindings for PyPy. Cling provides dynamic access to a modern C++ parser and PyPy brings a full toolbox of dynamic optimizations for high performance. The use of Cling for parsing, provides up-to-date C++ support now and in the foreseeable future. We show that with PyPy the overhead of calls to C++ functions from Python can be reduced by an order of magnitude compared to the equivalent in CPython, making it sufficiently low to be unmeasurable for all but the shortest C++ functions. Similarly, access to data in C++ is reduced by two orders of magnitude over access from CPython. Our approach requires no intermediate language and more pythonistic presentations of the C++ libraries can be written in Python itself, with little performance cost due to inlining by PyPy. This allows for future dynamic optimizations to be fully transparent.