Skip to content

Commit 4b1c8a9

Browse files
author
Diptorup Deb
authored
Merge pull request #1341 from IntelPython/docs/overview
[Documentation] Update to overview section of documentation
2 parents 3d8c8fe + 219d4ed commit 4b1c8a9

24 files changed

+410
-777
lines changed

docs/_templates/autoapi/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ API Reference
44
This page contains auto-generated API reference documentation [#f1]_.
55

66
.. toctree::
7-
:maxdepth: 2
7+
:maxdepth: 1
88

99
numba_dpex/kernel_api/index
10+
numba_dpex/experimental/decorators/index
11+
numba_dpex/experimental/launcher/index
1012

1113
{% for page in pages %}
1214
{% if page.top_level_object and page.display %}

docs/source/conf.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"sphinx.ext.extlinks",
2828
"sphinx.ext.githubpages",
2929
"sphinx.ext.napoleon",
30-
"sphinx.ext.autosectionlabel",
3130
"sphinxcontrib.programoutput",
3231
"sphinxcontrib.googleanalytics",
3332
"myst_parser",
@@ -114,19 +113,10 @@
114113

115114
# -- Auto API configurations ---------------------------------------------------
116115

117-
118-
# def skip_util_classes(app, what, name, obj, skip, options):
119-
# if what == "module" and "experimental" in name:
120-
# if what == "module" and "decorators" not in name:
121-
# skip = True
122-
# return skip
123-
124-
125-
# def setup(sphinx):
126-
# sphinx.connect("autoapi-skip-member", skip_util_classes)
127-
128-
129-
autoapi_dirs = ["../../numba_dpex/kernel_api"]
116+
autoapi_dirs = [
117+
"../../numba_dpex/kernel_api",
118+
"../../numba_dpex/experimental",
119+
]
130120
autoapi_type = "python"
131121

132122
autoapi_template_dir = "_templates/autoapi"
@@ -160,3 +150,14 @@ def prepare_jinja_env(jinja_env) -> None:
160150

161151

162152
autoapi_prepare_jinja_env = prepare_jinja_env
153+
154+
155+
def skip_member(app, what, name, obj, skip, options):
156+
# skip submodules
157+
if what == "module":
158+
skip = True
159+
return skip
160+
161+
162+
def setup(sphinx):
163+
sphinx.connect("autoapi-skip-member", skip_member)

docs/source/experimental/index.rst

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
.. _index:
2+
.. include:: ./../ext_links.txt
3+
4+
Experimental Features
5+
=====================
6+
7+
Numba-dpex includes various experimental features that are not yet suitable for
8+
everyday production usage, but are included as an engineering preview.
9+
The most prominent experimental features currently included in numba-dpex are
10+
listed in this section.
11+
12+
13+
Compiling and Offloading ``dpnp`` statements
14+
--------------------------------------------
15+
16+
Data Parallel Extension for NumPy* (`dpnp`_) is a drop-in NumPy* replacement
17+
library built using the oneAPI software stack including `oneMKL`_, `oneDPL`_ and
18+
`SYCL*`_. numba-dpex has experimental support for compiling a subset of dpnp
19+
functions. The feature is enabled by the :py:func:`numba_dpex.dpjit` decorator.
20+
21+
An example of a supported usage of dpnp in numba-dpex is provided in the
22+
following code snippet:
23+
24+
.. code-block:: python
25+
26+
import dpnp
27+
from numba_dpex import dpjit
28+
29+
30+
@dpjit
31+
def foo():
32+
a = dpnp.ones(1024, device="gpu")
33+
return dpnp.sqrt(a)
34+
35+
36+
a = foo()
37+
print(a)
38+
print(type(a))
39+
40+
41+
Offloading ``prange`` loops
42+
---------------------------
43+
44+
numba-dpex supports using the ``numba.prange`` statements with
45+
``dpnp.ndarray`` objects. All such ``prange`` loops are offloaded as kernels and
46+
executed on a device inferred using the compute follows data programming model.
47+
The next examples shows using a ``prange`` loop.
48+
49+
50+
.. code-block:: python
51+
52+
import dpnp
53+
from numba_dpex import dpjit, prange
54+
55+
56+
@dpjit
57+
def foo():
58+
x = dpnp.ones(1024, device="gpu")
59+
o = dpnp.empty_like(a)
60+
for i in prange(x.shape[0]):
61+
o[i] = x[i] * x[i]
62+
return o
63+
64+
65+
c = foo()
66+
print(c)
67+
print(type(c))
68+
69+
70+
``prange`` loop statements can also be used to write reduction loops as
71+
demonstrated by the following naive pairwise distance computation.
72+
73+
.. code-block:: python
74+
75+
from numba_dpex import dpjit, prange
76+
import dpnp
77+
import dpctl
78+
79+
80+
@dpjit
81+
def pairwise_distance(X1, X2, D):
82+
"""Naïve pairwise distance impl - take an array representing M points in N
83+
dimensions, and return the M x M matrix of Euclidean distances
84+
85+
Args:
86+
X1 : Set of points
87+
X2 : Set of points
88+
D : Outputted distance matrix
89+
"""
90+
# Size of inputs
91+
X1_rows = X1.shape[0]
92+
X2_rows = X2.shape[0]
93+
X1_cols = X1.shape[1]
94+
95+
float0 = X1.dtype.type(0.0)
96+
97+
# Outermost parallel loop over the matrix X1
98+
for i in prange(X1_rows):
99+
# Loop over the matrix X2
100+
for j in range(X2_rows):
101+
d = float0
102+
# Compute exclidean distance
103+
for k in range(X1_cols):
104+
tmp = X1[i, k] - X2[j, k]
105+
d += tmp * tmp
106+
# Write computed distance to distance matrix
107+
D[i, j] = dpnp.sqrt(d)
108+
109+
110+
q = dpctl.SyclQueue()
111+
X1 = dpnp.ones((10, 2), sycl_queue=q)
112+
X2 = dpnp.zeros((10, 2), sycl_queue=q)
113+
D = dpnp.empty((10, 2), sycl_queue=q)
114+
115+
pairwise_distance(X1, X2, D)
116+
print(D)
117+
118+
119+
Kernel fusion
120+
-------------
121+
122+
.. ``numba-dpex`` can identify each NumPy* (or ``dpnp``) array expression as a
123+
.. data-parallel kernel and fuse them together to generate a single SYCL kernel.
124+
.. The kernel is automatically offloaded to the specified device where the fusion
125+
.. operation is invoked. Here is a simple example of a Black-Scholes formula
126+
.. computation where kernel fusion occurs at different ``dpnp`` math functions:

docs/source/ext_links.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@
2525
.. _Intel VTune Profiler: https://www.intel.com/content/www/us/en/developer/tools/oneapi/vtune-profiler.html
2626
.. _Intel Advisor: https://www.intel.com/content/www/us/en/developer/tools/oneapi/advisor.html
2727
.. _oneMKL: https://www.intel.com/content/www/us/en/docs/oneapi/programming-guide/2023-2/intel-oneapi-math-kernel-library-onemkl.html
28+
.. _oneDPL: https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-library.html#gs.5izf63
29+
.. _UXL: https://uxlfoundation.org/
30+
.. _oneAPI GPU optimization guide: https://www.intel.com/content/www/us/en/docs/oneapi/optimization-guide-gpu/2024-0/general-purpose-computing-on-gpu.html

docs/source/glossary.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

docs/source/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,26 @@ Data Parallel Extension for Numba*
4141
.. module:: numba_dpex
4242

4343
.. toctree::
44-
:maxdepth: 2
44+
:maxdepth: 1
4545

4646
overview
4747
getting_started
4848
programming_model
4949
user_guide/index
5050
autoapi/index
51+
experimental/index
5152
useful_links
5253

5354
.. toctree::
54-
:maxdepth: 2
55+
:maxdepth: 1
5556
:caption: Development
5657

5758
contribution_guide
5859

5960
.. toctree::
60-
:maxdepth: 2
61+
:maxdepth: 1
6162
:caption: Misc Notes
6263

6364
examples
64-
glossary
6565
license
6666
release-notes

0 commit comments

Comments
 (0)