Skip to content

Commit 2f48e45

Browse files
committed
Some improvements to dpnp_offload.rst
1 parent ae62abd commit 2f48e45

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

docs/source/user_guide/dpnp_offload.rst

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,49 @@ Compiling and Offloading ``dpnp`` Functions
44
===========================================
55

66
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.
89

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.
915

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|_.
2319

2420
.. code-block:: python
2521
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
3424
3525
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
3731
38-
with dpctl.device_context():
39-
result = foo(a)
4032
41-
print(result)
33+
a = foo()
34+
print(a)
35+
print(type(a))
4236
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(...)|_.
4638

4739
The following sections go over as aspects of the dpnp integration inside
4840
numba-dpex.
4941

50-
.. _dpnp-integration-repository-map:
51-
5242
Repository map
5343
--------------
5444

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`.
6150

6251
Design
6352
------
@@ -101,3 +90,12 @@ context. ``prange`` automatically takes care of data privatization:
10190

10291
- prange, reduction prange
10392
- 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

Comments
 (0)