oracle / graalpython

A Python 3 implementation built on GraalVM
Other
1.2k stars 104 forks source link

Fast Native Extensions #282

Closed fniephaus closed 1 year ago

fniephaus commented 1 year ago

TL;DR

We plan to allow native execution of native extensions in GraalPy (as opposed to managed execution through our LLVM bitcode interpreter), improving warmup and performance of NumPy, SciPy, PyTorch, and other Python packages that leverage a lot of C code.

Goal

Many Python packages such as NumPy, SciPy, or PyTorch deploy a lot of C/C++ code to implement performance-critical operations more efficiently than usually possible in pure Python. When such code runs on GraalPy, it currently uses GraalVM's LLVM runtime to interpret the C/C++ code by default. While this managed execution mode provides for sandboxing, it may be slow to warm up and may not be as fast compared with true native execution. We want to give users the option to choose between managed and native execution for native extensions. For that, we intend to extend GraalPy with an additional C API backend that allows native execution to improve warmup and peak performance when the benefits of managed execution are less important.

Non-Goal

Deprecate support for managed execution.

timfel commented 1 year ago

This has now been merged and per-module selection of fully native execution vs execution on GraalVM's LLVM runtime is available via the python.NativeModules option. The default is to run everything fully natively.