Skip to content

Commit

Permalink
Update to overview section
Browse files Browse the repository at this point in the history
  • Loading branch information
Diptorup Deb committed Feb 20, 2024
1 parent 0c3fb55 commit 5e09f86
Showing 1 changed file with 52 additions and 10 deletions.
62 changes: 52 additions & 10 deletions docs/source/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,58 @@
Overview
========

Data Parallel Extension for Numba* (`numba-dpex`_) is an extension to
the `Numba*`_ Python JIT compiler adding an architecture-agnostic kernel
programming API, and a new front-end to compile the Data Parallel Extension
for Numpy* (`dpnp`_) library. The ``dpnp`` Python library is a data-parallel
implementation of `NumPy*`_'s API using the `SYCL*`_ language.

.. ``numba-dpex``'s support for ``dpnp`` compilation is a new way for Numba* users
.. to write code in a NumPy-like API that is already supported by Numba*, while at
.. the same time automatically running such code parallelly on various types of
.. architecture.
Data Parallel Extension for Numba* (`numba-dpex`_) is a free and open-source
LLVM-based code generator for portable accelerator programming in Python.
numba_dpex defines a new kernel programming domain-specific language (DSL)
in pure Python called `KAPI` that is modeled after the C++ embedded DSL
`SYCL*`_.

The following example illustrates a relatively simple pairwise distance matrix
computation example written in KAPI.

.. code-block:: python
from numba_dpex import kernel_api as kapi
import math
import numpy as np
def pairwise_distance_kernel(item: kapi.Item, data, distance):
i = item.get_id(0)
j = item.get_id(1)
data_dims = data.shape[1]
d = data.dtype.type(0.0)
for k in range(data_dims):
tmp = data[i, k] - data[j, k]
d += tmp * tmp
distance[j, i] = math.sqrt(d)
data = np.random.ranf((10000, 3)).astype(np.float32)
distance = np.empty(shape=(data.shape[0], data.shape[0]), dtype=np.float32)
exec_range = kapi.Range(data.shape[0], data.shape[0])
kapi.call_kernel(pairwise_distance_kernel, exec_range, data, distance)
Skipping over much of the language details, at a high-level the
``pairwise_distance_kernel`` can be viewed as a "data-parallel" function that
gets executed individually by a set of "work items". That is, each work item
runs the same function for a subset of the elements of the input ``data`` and
``distance`` arrays. For programmers familiar with the CUDA or OpenCL languages,
it is the same programming model referred to as Single Program Multiple Data
(SPMD). As Python has no concept of a work item the KAPI function runs
sequentially resulting in a very slow execution time. Experienced Python
programmers will most probably write a much faster version of the function using
NumPy*.

However, using a JIT compiler numba-dpex can compile a function written in the
KAPI language to a CPython native extension function that executes according to
the SPMD programming model, speeding up the execution time by orders of
magnitude. Currently, compilation of KAPI is possible for x86 CPU devices,
Intel Gen9 integrated GPUs, Intel UHD integrated GPUs, and Intel discrete GPUs.


``numba-dpex`` is an open-source project and can be installed as part of `Intel
AI Analytics Toolkit`_ or the `Intel Distribution for Python*`_. The package is
Expand Down

0 comments on commit 5e09f86

Please sign in to comment.