Skip to content

Commit 51863d4

Browse files
Merge pull request #1108 from IntelPython/doc-cleanup-pass
Examples clean-up
2 parents 84a4353 + cc63bba commit 51863d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1083
-1368
lines changed

.flake8

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ per-file-ignores =
2929
dpctl/tensor/numpy_usm_shared.py: F821
3030
dpctl/tests/_cython_api.pyx: E999, E225, E227, E402
3131
dpctl/utils/_compute_follows_data.pyx: E999, E225, E227
32-
examples/cython/sycl_buffer/_buffer_example.pyx: E999, E225, E402
33-
examples/cython/sycl_direct_linkage/_buffer_example.pyx: E999, E225, E402
34-
examples/cython/usm_memory/blackscholes.pyx: E999, E225, E226, E402
32+
examples/cython/sycl_buffer/syclbuffer/_buffer_example.pyx: E999, E225, E402
33+
examples/cython/usm_memory/blackscholes/blackscholes.pyx: E999, E225, E226, E402
3534
examples/cython/use_dpctl_sycl/use_dpctl_sycl/_cython_api.pyx: E999, E225, E226, E402

.github/workflows/conda-package.yml

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -423,31 +423,25 @@ jobs:
423423
CHANNELS="-c $GITHUB_WORKSPACE/channel -c dppy/label/dev -c intel -c main --override-channels"
424424
export PACKAGE_VERSION=$(python -c "${VER_SCRIPT1} ${VER_SCRIPT2}")
425425
conda install -n examples -y ${CHANNELS} dpctl=${PACKAGE_VERSION} dpnp">=0.10.1" || exit 1
426-
- name: Build and run examples with native extensions
426+
- name: Build and run examples of pybind11 extensions
427427
shell: bash -l {0}
428428
run: |
429429
source $CONDA/etc/profile.d/conda.sh
430430
export OCL_ICD_FILENAMES=libintelocl.so
431431
conda activate examples
432432
conda list
433433
cd examples/pybind11
434-
for d in $(ls)
434+
for d in $(find . -maxdepth 1 -type d -not -path ".")
435435
do
436436
pushd $d
437437
export MKLROOT=${CONDA_PREFIX}
438438
export TBBROOT=${CONDA_PREFIX}
439439
conda activate --stack build_env
440-
if [ -e CMakeLists.txt ]
441-
then
442-
CC=icx CXX=icpx python setup.py build_ext --inplace -G Ninja -- \
443-
-DTBB_LIBRARY_DIR=${TBBROOT}/lib \
444-
-DMKL_LIBRARY_DIR=${MKLROOT}/lib \
445-
-DMKL_INCLUDE_DIR=${MKLROOT}/include \
446-
-DTBB_INCLUDE_DIR=${TBBROOT}/include || exit 1
447-
else
448-
CC=icx CXX=icpx CFLAGS="-fsycl" LDSHARED="dpcpp -shared" \
449-
python setup.py build_ext --inplace || exit 1
450-
fi
440+
CC=icx CXX=icpx python setup.py build_ext --inplace -G Ninja -- \
441+
-DTBB_LIBRARY_DIR=${TBBROOT}/lib \
442+
-DMKL_LIBRARY_DIR=${MKLROOT}/lib \
443+
-DMKL_INCLUDE_DIR=${MKLROOT}/include \
444+
-DTBB_INCLUDE_DIR=${TBBROOT}/include || exit 1
451445
conda deactivate
452446
if [ -e tests ]
453447
then
@@ -457,24 +451,32 @@ jobs:
457451
fi
458452
popd
459453
done
460-
cd ../cython
461-
for d in $(ls)
454+
- name: Build and run examples of Cython extensions
455+
shell: bash -l {0}
456+
run: |
457+
source $CONDA/etc/profile.d/conda.sh
458+
export OCL_ICD_FILENAMES=libintelocl.so
459+
conda activate examples
460+
conda list
461+
cd examples/cython
462+
for d in $(find . -maxdepth 1 -type d -not -path ".")
462463
do
463464
pushd $d
464465
conda activate --stack build_env
465-
CC=dpcpp CXX=dpcpp LDSHARED="dpcpp -shared" \
466-
python setup.py build_ext --inplace || exit 1
466+
python setup.py build_ext --inplace || exit 1
467467
conda deactivate
468-
if [ -e tests ]
469-
then
470-
LD_LIBRARY_PATH=${CONDA_PREFIX}/lib python -m pytest tests || exit 1
471-
else
472-
LD_LIBRARY_PATH=${CONDA_PREFIX}/lib python run.py || exit 1
473-
fi
468+
python -m pytest tests || exit 1
474469
popd
475470
done
476-
cd ../c
477-
for d in $(ls)
471+
- name: Build and run examples of C-extensions
472+
shell: bash -l {0}
473+
run: |
474+
source $CONDA/etc/profile.d/conda.sh
475+
export OCL_ICD_FILENAMES=libintelocl.so
476+
conda activate examples
477+
conda list
478+
cd examples/c
479+
for d in $(find . -maxdepth 1 -type d -not -path ".")
478480
do
479481
pushd $d
480482
conda activate --stack build_env

README.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The compute kernel can be a code:
1919
* that is part of a library, such as oneMKL
2020

2121
The `dpctl` library is built upon the [SYCL
22-
standard](https://www.khronos.org/sycl/). It also implements Python
22+
standard](https://www.khronos.org/sycl/). It implements Python
2323
bindings for a subset of the standard [runtime
2424
classes](https://www.khronos.org/registry/SYCL/specs/sycl-2020/html/sycl-2020.html#_sycl_runtime_classes) that allow users to:
2525
* query platforms
@@ -57,7 +57,7 @@ To get the library from the latest oneAPI release, follow the
5757
instructions from Intel(R) [oneAPI installation
5858
guide](https://www.intel.com/content/www/us/en/developer/articles/guide/installation-guide-for-oneapi-toolkits.html).
5959

60-
> **NOTE:** You need to install the Intel(R) oneAPI Basekit to get
60+
> **NOTE:** You need to install the Intel(R) oneAPI AI Analytics Tookit to get
6161
>IDP and `dpctl`.
6262
6363

@@ -85,42 +85,38 @@ To try out the current master, install it from our
8585
development channel on Anaconda cloud:
8686

8787
```bash
88-
conda install dpctl -c dppy\label\dev
88+
conda install dpctl -c dppy/label/dev
8989
```
9090

9191
# Building
9292

9393
Refer to our [Documentation](https://intelpython.github.io/dpctl) for more information on
9494
setting up a development environment and building `dpctl` from the source.
9595

96-
# Running Examples
9796

98-
Find our examples [here](examples).
97+
# Examples
9998

100-
To run these examples, use:
99+
Our examples are located in the [examples/](examples) folder and are organized in sub-folders. Examples
100+
in the [Python/](examples/python) folder demonstrate how to inspect the heterogeneous platform,
101+
select a device, create an execution queue, and how to control device memory allocation and
102+
execution placement.
101103

102-
```bash
103-
for script in `ls examples/python/`;
104-
do echo "executing ${script}";
105-
python examples/python/${script};
106-
done
107-
```
108-
109-
## Cython extensions
110-
See examples of building Cython extensions with DPC++ compiler that interoperates
111-
with `dpctl` in the [cython folder](examples\cython).
104+
Examples in [Cython/](examples/cython), [C/](examples/c), and [Pybind11](examples/pybind11) folders
105+
demonstrate creation of SYCL-powered native Python extensions. Please refer to each folder's README
106+
document for directions on how to build and use each example.
112107

113-
To build these examples, run:
114-
```bash
115-
CC=icx CXX=dpcpp python setup.py build_ext --inplace
116-
```
117-
To execute extensions, refer to the `run.py` script in each folder.
118108

119109
# Running Tests
120110

121-
Tests are located [here](dpctl/tests).
111+
Tests are located in folder [dpctl/tests](dpctl/tests).
122112

123113
To run the tests, use:
124114
```bash
125115
pytest --pyargs dpctl
126116
```
117+
118+
Running full test suite requires working C++ compiler. To run the test suite without one, use:
119+
120+
```bash
121+
pytest --pyargs dpctl -k "not test_cython_api"
122+
```
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Data Parallel Control (dpctl)
22
#
3-
# Copyright 2020-2022 Intel Corporation
3+
# Copyright 2020-2023 Intel Corporation
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -14,13 +14,11 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
import numpy as np
18-
import syclbuffer_naive as sb
17+
""" This file declares the extension types and functions for the Cython API
18+
implemented in _usmarray.pyx file.
19+
"""
1920

20-
X = np.random.randn(20, 10)
21+
# distutils: language = c++
22+
# cython: language_level=3
2123

22-
# compute column-wise total with NumPy's own host code
23-
print(X.sum(axis=0))
24-
25-
# compute column-wise total with SYCL extension
26-
print(sb.columnwise_total(X))
24+
from dpctl.tensor._usmarray cimport *

examples/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Examples of using `dpctl`
2+
3+
The `dpctl` is a foundational package facilitating use of [SYCL](sycl) to extend Python's reach to heterogeneous systems.
4+
5+
## Python
6+
7+
The `dpctl` provides Python API to SYCL runtime permitting user to
8+
inspect the heterogeneous [platform],
9+
[select](device_seelection) amongst available devices,
10+
query [properties](device_descriptors) of created devices,
11+
and construct [queues] to specify execution placement of offloaded computation.
12+
13+
Additionally, `dpctl.tensor` submodule allows to create ND-arrays on devices and manipulate them using `dpctl.tensor` library of array computation operations specified in [Python Array API standard](array_api).
14+
15+
Examples of this functionality are located in the [python](python) folder.
16+
17+
## Cython
18+
19+
The `dpctl` integrates with [Cython], a native extension generator, to facilitate building
20+
SYCL-powered Python extensions.
21+
22+
Examples of Python extensions written using Cython are located in the [cython](cython) folder.
23+
24+
## Pybind11
25+
26+
Since [SYCL](sycl) is based on C++, [pybind11] is a natural tool of choice to author SYCL-powered
27+
Python extensions. The `dpctl` provides `dpctl4pybind11.hpp` integration header to provide natural
28+
mapping between SYCL C++ classes and `dpctl` Python types.
29+
30+
Examples of Python extensions created with `pybind11` are located in the [pybind11](pybind11) folder.
31+
32+
## C
33+
34+
The `dpctl` implements `DPCTLSyclInterface` C library and C-API to work with Python objects and types
35+
implemented in `dpctl`. Use integration headers `dpctl_sycl_interface.h` and `dpctl_capi.h` to access
36+
this functionality.
37+
38+
Examples of Python extensions created using C are located in [c](c) folder.
39+
40+
41+
[platform]: https://intelpython.github.io/dpctl/latest/docfiles/user_guides/manual/dpctl/platforms.html
42+
[device_selection]: https://intelpython.github.io/dpctl/latest/docfiles/user_guides/manual/dpctl/device_selection.html
43+
[device_descriptors]: https://intelpython.github.io/dpctl/latest/docfiles/user_guides/manual/dpctl/devices.html#device-aspects-and-information-descriptors
44+
[queues]: https://intelpython.github.io/dpctl/latest/docfiles/user_guides/manual/dpctl/queues.html
45+
[array_api]: https://data-apis.org/array-api/
46+
[sycl]: https://registry.khronos.org/SYCL/
47+
[Cython]: https://cython.org/
48+
[pybind11]: https://pybind11.readthedocs.io

examples/c/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Examples C-based Python extensions using `dpctl`
2+
3+
The `dpctl` implements `DPCTLSyclInterface` C library as well as provides C-API to work with Python objects
4+
and types implemented in `dpctl`. Use integration headers `dpctl_sycl_interface.h` and `dpctl_capi.h` to access
5+
this functionality.
6+
7+
Use `python -m dpctl --includes` to get include compiler options and `python -m dpctl --library` to get linking options to link
8+
to `SyclInterface` library.

examples/c/py_sycl_ls/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Python module to enumerate SYCL devices
2+
3+
## Building
4+
5+
```bash
6+
python setup.py build_ext --inplace
7+
```
8+
9+
## Testing
10+
11+
```
12+
pytest -m tests
13+
```
14+
15+
## Running
16+
17+
```
18+
python -m py_sycl_ls
19+
```

examples/c/py_sycl_ls/setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# limitations under the License.
1616

1717
import os.path
18-
import sysconfig
1918

2019
from setuptools import Extension, setup
2120

@@ -41,7 +40,6 @@
4140
],
4241
include_dirs=[
4342
dpctl.get_include(),
44-
os.path.join(sysconfig.get_paths()["include"], ".."),
4543
],
4644
library_dirs=[
4745
os.path.join(dpctl.get_include(), ".."),

examples/c/py_sycl_ls/src/py_sycl-ls.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
// clang-format off
2828
#include "Python.h"
2929
#include "dpctl_capi.h"
30-
#include "syclinterface/dpctl_sycl_platform_interface.h"
31-
#include "syclinterface/dpctl_sycl_platform_manager.h"
32-
#include "syclinterface/dpctl_utils.h"
30+
#include "dpctl_sycl_interface.h"
3331
// clang-format on
3432

3533
PyObject *sycl_ls(PyObject *self_unused, PyObject *args)

examples/cython/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Examples of data-parallel Python extensions written in Cython
2+
3+
The `dpctl` package provides Cython definition files for types it defines.
4+
5+
Use `cimport dpctl as c_dpctl`, `cimport dpctl.memory as c_dpm`, or `cimport dpctl.tensor as c_dpt`
6+
to use these definitions.
7+
8+
Cython definition fille `dpctl.sycl` provides incomplete definitions of core SYCL runtime classes as
9+
well as conversion routine between `SyclInterface` reference types and SYCL runtime classes.

0 commit comments

Comments
 (0)