Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/sources/programming_dpep.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ to execute your `Numpy*`_ script on GPU usually requires changing just a few lin
:caption: Your first NumPy code running on GPU
:name: ex_01_hello_dpnp

.. command-output:: python ./01-hello_dpnp.py
:cwd: ../../examples

In this example ``np.asarray()`` creates an array on the default `SYCL*`_ device, which is ``"gpu"`` on systems
with integrated or discrete GPU (it is ``"cpu"`` on systems that do not have GPU).
Expand All @@ -57,8 +55,6 @@ In the following example we create the array ``x`` on the GPU device, and perfor
:caption: Select device type while creating array
:name: ex_02_dpnp_device

.. command-output:: python ./02-dpnp_device.py
:cwd: ../../examples

Data Parallel Extension for Numba - numba-dpex
**********************************************
Expand All @@ -69,3 +65,9 @@ SIMD instructions, and schedules those in a way that exploits maximum instructio
The ``numba-dpex`` extension allows to compile and offload data parallel regions to any data parallel device.
It takes just a few lines to modify your CPU `Numba*`_ script to run on GPU.

.. literalinclude:: ../../examples/03-dpnp2numba-dpex.py
:language: python
:lines: 27-
:caption: Compile dpnp code with numba-dpex
:name: ex_03_dpnp2numba_dpex

3 changes: 3 additions & 0 deletions examples/01-hello_dpnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@

x = np.asarray([1, 2, 3])
y = np.sum(x)

print(y.shape) # Must be 0-dimensional array
print(y) # Expect 6
1 change: 1 addition & 0 deletions examples/02-dpnp_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
print("GPU device is not available")

y = np.sum(x)
print(y) # Expect 6
41 changes: 41 additions & 0 deletions examples/03-dpnp2numba-dpex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# *****************************************************************************
# Copyright (c) 2022, Intel Corporation All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

import dpnp as np
from numba_dpex import njit


@njit(parallel=True, fastmath=True)
def sum(x):
return np.sum(x)


x = np.empty(3)
try:
x = np.asarray([1, 2, 3], device="gpu")
except:
print("GPU device is not available")