You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The target of this research was to demonstrate a generic prototype that
61
63
automatically brings advanced C++ features (e.g., highly optimized numeric
62
64
libraries) to Numba-accelerated Python, with help from cppyy. This required
63
-
re-engineering of the cppyy back-end to directly use LLVM components. A new
65
+
re-engineering of the cppyy-backend to directly use LLVM components. A new
64
66
CppInterOp library was also introduced to implement interoperability
65
67
primitives based on Cling and Clang-Repl (also an interactive interpreter, a
66
68
progression on Cling).
@@ -91,20 +93,24 @@ either C++ or Python, as appropriate.
91
93
92
94
### Prototype Overview
93
95
94
-
To bring C++ to Numba, a reflection interface was developed on top of cppyy.
95
-
This enables Python programmers to develop and debug their code in Python and
96
-
selectively switching on the Numba JIT for performance-critical tasks.
96
+
The primary motivation behind the addition of Numba support in cppyy is the elimination of the overhead that arises from crossing the languiage barrier, which can multiply into large slowdowns when using loops with cppyy objects. Since Numba compiles Python code into machine code it only crosses the language barrier once and the loops thus run faster
Python is a dynamically typed language. It wraps and later unwraps objects (referred to as boxing/unboxing). These costly operations are eliminated with Numba, which unboxes the inputs of a function and converts it to machine code. This improves the performance of heavily looped code that perform certain operations. At the end, the output is boxed so that Python can use it. For this to work, Numba needs to infer the types of not only the input and output but the intermediate variables as well.
101
+
102
+
To bring C++ to Numba, a custom module was developed on top of cppyy using the Numba low level extension API.
103
+
This enables Python programmers to selectively enable Numba acceleration for performance-critical tasks by importing `cppyy.numba_ext`
The extension aids Numba's three phases which are- Typing, Lowering(to LLVM IR) and Boxing/Unboxing which process all (or most) C++ proxies held by the Python interpreter in the form of cppyy objects.
97
108
98
-
Python is a dynamically typed language. It wraps and later unwraps objects
99
-
(referred to as boxing/unboxing). This is a costly operation that can be
100
-
eliminated with Numba, while using the new Reflection API. The Reflection API
101
-
uses a function called `__cpp_reflex__` that takes the reflection type and
102
-
format as parameters and returns the requested information (e.g., an object’s
103
-
C++ type).
109
+
The biggest challenge while integrating cppyy support in Numba is to teach Numba what cppyy types and data mean. We approach this by utilising an improved reflection API within cppyy (`__cpp_reflex__`). Reflex returns information about cppyy objects within the scope of the Numba accelerated function. This allows us to inherit Numba's typing classes and populate them with more information without which we cannot box/unbox and lower to LLVM IR.
104
110
105
-
Let's look at the interaction between Numba, numba extention and cppyy.
111
+
Let's look at the interaction between Cppyy, Numba and the Numba extension:
0 commit comments