@@ -4,60 +4,49 @@ Compiling and Offloading ``dpnp`` Functions
4
4
===========================================
5
5
6
6
Data Parallel Extension for NumPy* (``dpnp ``) is a drop-in ``NumPy* ``
7
- replacement library built on top of oneMKL.
7
+ replacement library built on top of oneMKL. ``numba-dpex `` allows various
8
+ ``dpnp `` library functions to be jit-compiled thorugh its ``dpjit `` decorator.
8
9
10
+ ``numba-dpex `` implements its own runtime library to support offloading ``dpnp ``
11
+ library functions to SYCL devices. For ``dpnp `` function signatures that are
12
+ offloaded, ``numba-dpex `` implements their corresponding function calls through
13
+ Numba*'s |numba.extending.overload |_ and |numba.extending.intrinsic |_
14
+ constructs.
9
15
10
- ``numba-dpex `` relies on ``dpnp `` to
11
- support offloading ``NumPy `` library functions to SYCL devices. For ``NumPy ``
12
- functions that are offloaded using ``dpnp ``, ``numba-dpex `` generates library
13
- calls directly to ``dpnp ``'s `low-level API `_ inside the generated LLVM IR.
14
-
15
- .. _low-level API : https://github.com/IntelPython/dpnp/tree/master/dpnp/backend
16
-
17
- .. _integration-dpnp-backend :
18
-
19
- During compiling a Python function decorated with the ``numba.njit ``
20
- decorator, ``numba-dpex `` substitutes ``NumPy `` function calls with corresponding ``dpnp ``
21
- low-level API function calls. The substitution happens transparent to an
22
- end-user and is implemented as a renaming pass in ``numba-dpex ``'s pass pipeline.
16
+ During compiling a Python function decorated with the ``numba_dpex.dpjit ``
17
+ decorator, ``numba-dpex `` generates ``dpnp `` function calls through its runtime
18
+ library and injects them into the LLVM IR through |numba.extending.intrinsic |_.
23
19
24
20
.. code-block :: python
25
21
26
- import numpy as np
27
- from numba import njit
28
- import dpctl
29
-
30
-
31
- @njit
32
- def foo (a ):
33
- return np.sum(a) # this call will be replaced with the dpnp.sum function
22
+ import dpnp
23
+ from numba_dpex import dpjit
34
24
35
25
36
- a = np.arange(42 )
26
+ @dpjit
27
+ def foo ():
28
+ return dpnp.ones(10 ) # the function call for this signature
29
+ # will be generated through the runtime
30
+ # library and inlined into the LLVM IR
37
31
38
- with dpctl.device_context():
39
- result = foo(a)
40
32
41
- print (result)
33
+ a = foo()
34
+ print (a)
35
+ print (type (a))
42
36
43
- :samp: `np.sum(a) ` will be replaced with `dpnp_sum_c<int, int>(...) `_.
44
-
45
- .. _`dpnp_sum_c<int, int>(...)` : https://github.com/IntelPython/dpnp/blob/ef404c0f284b0c508ed1e556e140f02f76ae5551/dpnp/backend/kernels/dpnp_krnl_reduction.cpp#L58
37
+ :samp: `dpnp.ones(10) ` will be called through |ol_dpnp_ones(...) |_.
46
38
47
39
The following sections go over as aspects of the dpnp integration inside
48
40
numba-dpex.
49
41
50
- .. _dpnp-integration-repository-map :
51
-
52
42
Repository map
53
43
--------------
54
44
55
- - The code for numba-dpex's dpnp integration resides in the
56
- :file: `numba_dpex/dpnp_iface ` sub-module.
57
- - Tests resides in :file: `numba_dpex/tests/njit_tests/dpnp `.
58
- - Helper pass resides in :file: `numba_dpex/rename_numpy_functions_pass.py `.
59
-
60
- .. _dpnp-integration-architecture :
45
+ - The code for numba-dpex's dpnp integration runtime resides in the
46
+ :file: `numba_dpex/core/runtime ` sub-module.
47
+ - All the |numba.extending.overload |_ for ``dpnp `` function signatures are
48
+ implemented in :file: `numba_dpex/dpnp_iface/arrayobj.py `
49
+ - Tests resides in :file: `numba_dpex/tests/dpjit_tests/dpnp `.
61
50
62
51
Design
63
52
------
@@ -101,3 +90,12 @@ context. ``prange`` automatically takes care of data privatization:
101
90
102
91
- prange, reduction prange
103
92
- blackscholes, math example
93
+
94
+ .. |numba.extending.overload | replace :: ``numba.extending.overload ``
95
+ .. |numba.extending.intrinsic | replace :: ``numba.extending.intrinsic ``
96
+ .. |ol_dpnp_ones(...) | replace :: ``ol_dpnp_ones(...) ``
97
+
98
+ .. _low-level API : https://github.com/IntelPython/dpnp/tree/master/dpnp/backend
99
+ .. _`ol_dpnp_ones(...)` : https://github.com/IntelPython/numba-dpex/blob/main/numba_dpex/dpnp_iface/arrayobj.py#L358
100
+ .. _`numba.extending.overload` : https://numba.pydata.org/numba-doc/latest/extending/high-level.html#implementing-functions
101
+ .. _`numba.extending.intrinsic` : https://numba.pydata.org/numba-doc/latest/extending/high-level.html#implementing-intrinsics
0 commit comments