Skip to content

Commit 4e6dd60

Browse files
author
Diptorup Deb
committed
Merge branch 'upstream_master' into docs/user-guide
2 parents 9829fd7 + ccd21b6 commit 4e6dd60

File tree

11 files changed

+224
-71
lines changed

11 files changed

+224
-71
lines changed

.github/workflows/conda-package.yml

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Conda package
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
48

59
env:
610
PACKAGE_NAME: dpctl
@@ -115,6 +119,7 @@ jobs:
115119
- name: Add conda to system path
116120
run: echo $CONDA/bin >> $GITHUB_PATH
117121
- name: Install conda-build
122+
# Needed to be able to run conda index
118123
run: conda install conda-build
119124
- name: Create conda channel
120125
run: |
@@ -178,6 +183,7 @@ jobs:
178183
auto-activate-base: true
179184
activate-environment: ""
180185
- name: Install conda-build
186+
# Needed to be able to run conda index
181187
run: conda install conda-build
182188
- name: Create conda channel
183189
run: |
@@ -263,3 +269,111 @@ jobs:
263269
run: |
264270
conda install anaconda-client
265271
anaconda --token ${{ env.ANACONDA_TOKEN }} upload --user dppy --label dev ${{ env.PACKAGE_NAME }}-*.tar.bz2
272+
273+
test_examples_linux:
274+
needs: build_linux
275+
runs-on: ${{ matrix.runner }}
276+
strategy:
277+
matrix:
278+
python: [3.8]
279+
experimental: [false]
280+
runner: [ubuntu-latest]
281+
continue-on-error: ${{ matrix.experimental }}
282+
env:
283+
CHANNELS: -c intel -c defaults --override-channels
284+
285+
steps:
286+
- name: Install conda-build
287+
# Needed to be able to run conda index
288+
run: conda install conda-build python=${{ matrix.python }}
289+
- name: Checkout dpctl repo
290+
uses: actions/checkout@v2
291+
with:
292+
fetch-depth: 0
293+
- name: Download artifact
294+
uses: actions/download-artifact@v2
295+
with:
296+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
297+
- name: Add conda to system path
298+
run: echo $CONDA/bin >> $GITHUB_PATH
299+
- name: Create conda channel
300+
run: |
301+
mkdir -p $GITHUB_WORKSPACE/channel/linux-64
302+
mv ${PACKAGE_NAME}-*.tar.bz2 $GITHUB_WORKSPACE/channel/linux-64
303+
conda index $GITHUB_WORKSPACE/channel
304+
# Test channel
305+
conda search $PACKAGE_NAME -c $GITHUB_WORKSPACE/channel --override-channels
306+
- name: Collect dependencies
307+
run: |
308+
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
309+
conda install $PACKAGE_NAME python=${{ matrix.python }} $CHANNELS --only-deps --dry-run > lockfile
310+
- name: Set pkgs_dirs
311+
run: |
312+
echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc
313+
- name: Cache conda packages
314+
uses: actions/cache@v2
315+
env:
316+
CACHE_NUMBER: 0 # Increase to reset cache
317+
with:
318+
path: ~/.conda/pkgs
319+
key:
320+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }}
321+
restore-keys: |
322+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
323+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
324+
- name: Install dpctl
325+
shell: bash -l {0}
326+
run: |
327+
source $CONDA/etc/profile.d/conda.sh
328+
conda activate
329+
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
330+
conda install -y $PACKAGE_NAME pytest python=${{ matrix.python }} $CHANNELS
331+
# Test installed packages
332+
conda list
333+
- name: Install example requirements
334+
shell: bash -l {0}
335+
run: |
336+
source $CONDA/etc/profile.d/conda.sh
337+
conda install -y pybind11 cython
338+
conda install -y -c intel mkl-dpcpp mkl-devel-dpcpp numba-dppy
339+
conda create -y -n build_env -c intel dpcpp_linux-64
340+
- name: Build and run examples with native extensions
341+
shell: bash -l {0}
342+
run: |
343+
source $CONDA/etc/profile.d/conda.sh
344+
export OCL_ICD_FILENAMES=libintelocl.so
345+
export SYCL_ENABLE_HOST_DEVICE=1
346+
conda activate
347+
cd examples/pybind11
348+
export CC=dpcpp
349+
export CXX=dpcpp
350+
for d in $(ls)
351+
do
352+
pushd $d
353+
conda activate --stack build_env
354+
python setup.py build_ext --inplace || exit 1
355+
conda deactivate
356+
python example.py
357+
popd
358+
done
359+
cd ../cython
360+
for d in $(ls)
361+
do
362+
pushd $d
363+
conda activate --stack build_env
364+
python setup.py build_ext --inplace || exit 1
365+
conda deactivate
366+
python run.py
367+
popd
368+
done
369+
- name: Run Python examples
370+
shell: bash -l {0}
371+
run: |
372+
cd examples/python
373+
export OCL_ICD_FILENAMES=libintelocl.so
374+
export SYCL_ENABLE_HOST_DEVICE=1
375+
for script in $(find . \( -not -name "_*" -and -name "*.py" \))
376+
do
377+
echo "Executing ${script}"
378+
python ${script} || exit 1
379+
done

examples/cython/sycl_buffer/_buffer_example.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
# distutils: language = c++
18+
# cython: language_level=3
19+
1720
cimport numpy as cnp
1821

1922
import numpy as np

examples/cython/sycl_buffer/run.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,31 @@
2323

2424
print("Result computed by NumPy")
2525
print(X.sum(axis=0))
26-
print("Result computed by SYCL extension using default offloading target")
27-
print(sb.columnwise_total(X))
2826

27+
try:
28+
res = sb.columnwise_total(X)
29+
print("Result computed by SYCL extension using default offloading target")
30+
print(res)
31+
except dpctl.SyclQueueCreationError:
32+
print(
33+
"Could not create SyclQueue for default selected device. Nothing to do."
34+
)
35+
exit(0)
2936

3037
print("")
3138

3239
# controlling where to offload
3340

34-
q = dpctl.SyclQueue("opencl:gpu")
35-
print("Running on: ", q.sycl_device.name)
36-
print(sb.columnwise_total(X, queue=q))
37-
38-
q = dpctl.SyclQueue("opencl:cpu")
39-
print("Running on: ", q.sycl_device.name)
40-
print(sb.columnwise_total(X, queue=q))
41+
try:
42+
q = dpctl.SyclQueue("opencl:gpu")
43+
print("Running on: ", q.sycl_device.name)
44+
print(sb.columnwise_total(X, queue=q))
45+
except dpctl.SyclQueueCreationError:
46+
print("Not running onf opencl:gpu, queue could not be created")
47+
48+
try:
49+
q = dpctl.SyclQueue("opencl:cpu")
50+
print("Running on: ", q.sycl_device.name)
51+
print(sb.columnwise_total(X, queue=q))
52+
except dpctl.SyclQueueCreationError:
53+
print("Not running onf opencl:cpu, queue could not be created")

examples/cython/sycl_buffer/setup.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import os.path
18+
import sysconfig
19+
1720
import numpy as np
1821
from setuptools import Extension, setup
1922

@@ -39,7 +42,12 @@
3942
"_buffer_example.pyx",
4043
"use_sycl_buffer.cpp",
4144
],
42-
include_dirs=[".", np.get_include(), dpctl.get_include()],
45+
include_dirs=[
46+
".",
47+
np.get_include(),
48+
dpctl.get_include(),
49+
os.path.join(sysconfig.get_paths()["include"], ".."),
50+
],
4351
libraries=["sycl"]
4452
+ [
4553
"mkl_sycl",

examples/cython/sycl_direct_linkage/_buffer_example.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
# distutils: language = c++
18+
# cython: language_level=3
19+
1720
cimport numpy as cnp
1821

1922
import numpy as np

examples/cython/sycl_direct_linkage/setup.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import os.path
18+
import sysconfig
19+
1720
import numpy as np
1821
from setuptools import Extension, setup
1922

@@ -43,7 +46,12 @@
4346
"_buffer_example.pyx",
4447
"sycl_function.cpp",
4548
],
46-
include_dirs=[".", np.get_include(), dpctl.get_include()],
49+
include_dirs=[
50+
".",
51+
np.get_include(),
52+
dpctl.get_include(),
53+
os.path.join(sysconfig.get_paths()["include"], ".."),
54+
],
4755
libraries=["sycl"]
4856
+ [
4957
"mkl_sycl",

examples/cython/usm_memory/run.py

Lines changed: 44 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -64,59 +64,48 @@ def gen_option_params(
6464
n_opts = 3 * 10 ** 6
6565

6666
# compute on CPU sycl device
67-
cpu_q = dpctl.SyclQueue("opencl:cpu:0")
68-
opts1 = gen_option_params(
69-
n_opts,
70-
20.0,
71-
30.0,
72-
22.0,
73-
29.0,
74-
18.0,
75-
24.0,
76-
0.01,
77-
0.05,
78-
0.01,
79-
0.05,
80-
"d",
81-
queue=cpu_q,
82-
)
83-
84-
gpu_q = dpctl.SyclQueue("level_zero:gpu:0")
85-
opts2 = gen_option_params(
86-
n_opts,
87-
20.0,
88-
30.0,
89-
22.0,
90-
29.0,
91-
18.0,
92-
24.0,
93-
0.01,
94-
0.05,
95-
0.01,
96-
0.05,
97-
"d",
98-
queue=gpu_q,
99-
)
100-
101-
cpu_times = []
102-
gpu_times = []
103-
for _ in range(5):
104-
105-
t0 = timeit.default_timer()
106-
X1 = bs.black_scholes_price(opts1, queue=cpu_q)
107-
t1 = timeit.default_timer()
10867

109-
cpu_times.append(t1 - t0)
110-
111-
# compute on GPU sycl device
112-
113-
t0 = timeit.default_timer()
114-
X2 = bs.black_scholes_price(opts2, queue=gpu_q)
115-
t1 = timeit.default_timer()
116-
gpu_times.append(t1 - t0)
117-
118-
print("Using : {}".format(cpu_q.sycl_device.name))
119-
print("Wall times : {}".format(cpu_times))
120-
121-
print("Using : {}".format(gpu_q.sycl_device.name))
122-
print("Wall times : {}".format(gpu_times))
68+
queues = []
69+
for filter_str in ["cpu", "gpu"]:
70+
try:
71+
q = dpctl.SyclQueue(filter_str)
72+
queues.append(q)
73+
except dpctl.SyclQueueCreationError:
74+
continue
75+
76+
if not queues:
77+
print("No queues could not created, nothing to do.")
78+
exit(0)
79+
80+
opt_params_list = []
81+
for q in queues:
82+
opt_params = gen_option_params(
83+
n_opts,
84+
20.0,
85+
30.0,
86+
22.0,
87+
29.0,
88+
18.0,
89+
24.0,
90+
0.01,
91+
0.05,
92+
0.01,
93+
0.05,
94+
"d",
95+
queue=q,
96+
)
97+
opt_params_list.append(opt_params)
98+
99+
times_dict = dict()
100+
for q, params in zip(queues, opt_params_list):
101+
times_list = []
102+
for _ in range(5):
103+
t0 = timeit.default_timer()
104+
X1 = bs.black_scholes_price(params, queue=q)
105+
t1 = timeit.default_timer()
106+
times_list.append(t1 - t0)
107+
times_dict[q.name] = times_list
108+
109+
for dev_name, wall_times in times_dict.items():
110+
print("Using : {}".format(dev_name))
111+
print("Wall times : {}".format(wall_times))

examples/cython/usm_memory/setup.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import os.path
18+
import sysconfig
19+
1720
import numpy as np
1821
from setuptools import Extension, setup
1922

@@ -38,7 +41,12 @@
3841
"blackscholes.pyx",
3942
"sycl_blackscholes.cpp",
4043
],
41-
include_dirs=[".", np.get_include(), dpctl.get_include()],
44+
include_dirs=[
45+
".",
46+
np.get_include(),
47+
dpctl.get_include(),
48+
os.path.join(sysconfig.get_paths()["include"], ".."),
49+
],
4250
libraries=["sycl"]
4351
+ [
4452
"mkl_sycl",

examples/pybind11/external_usm_allocation/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import dpctl
2323
import dpctl.memory as dpm
2424

25-
q = dpctl.SyclQueue("gpu")
25+
q = dpctl.SyclQueue()
2626
matr = eua.DMatrix(q, 5, 5)
2727

2828
print(matr)

examples/python/device_selection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def create_device_with_aspects():
9898
Demonstrate the usage of :func:`dpctl.select_device_with_aspects()`.
9999
"""
100100
dev = dpctl.select_device_with_aspects(
101-
required_aspects=["fp64", "gpu", "usm_shared_allocations"]
101+
required_aspects=["fp64", "usm_shared_allocations"]
102102
)
103103
dev.print_device_info()
104104

0 commit comments

Comments
 (0)