Skip to content

A step added to build/run examples #722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 15, 2021
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
116 changes: 115 additions & 1 deletion .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Conda package

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:

env:
PACKAGE_NAME: dpctl
Expand Down Expand Up @@ -115,6 +119,7 @@ jobs:
- name: Add conda to system path
run: echo $CONDA/bin >> $GITHUB_PATH
- name: Install conda-build
# Needed to be able to run conda index
run: conda install conda-build
- name: Create conda channel
run: |
Expand Down Expand Up @@ -178,6 +183,7 @@ jobs:
auto-activate-base: true
activate-environment: ""
- name: Install conda-build
# Needed to be able to run conda index
run: conda install conda-build
- name: Create conda channel
run: |
Expand Down Expand Up @@ -263,3 +269,111 @@ jobs:
run: |
conda install anaconda-client
anaconda --token ${{ env.ANACONDA_TOKEN }} upload --user dppy --label dev ${{ env.PACKAGE_NAME }}-*.tar.bz2

test_examples_linux:
needs: build_linux
runs-on: ${{ matrix.runner }}
strategy:
matrix:
python: [3.8]
experimental: [false]
runner: [ubuntu-latest]
continue-on-error: ${{ matrix.experimental }}
env:
CHANNELS: -c intel -c defaults --override-channels

steps:
- name: Install conda-build
# Needed to be able to run conda index
run: conda install conda-build python=${{ matrix.python }}
- name: Checkout dpctl repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
- name: Add conda to system path
run: echo $CONDA/bin >> $GITHUB_PATH
- name: Create conda channel
run: |
mkdir -p $GITHUB_WORKSPACE/channel/linux-64
mv ${PACKAGE_NAME}-*.tar.bz2 $GITHUB_WORKSPACE/channel/linux-64
conda index $GITHUB_WORKSPACE/channel
# Test channel
conda search $PACKAGE_NAME -c $GITHUB_WORKSPACE/channel --override-channels
- name: Collect dependencies
run: |
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
conda install $PACKAGE_NAME python=${{ matrix.python }} $CHANNELS --only-deps --dry-run > lockfile
- name: Set pkgs_dirs
run: |
echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc
- name: Cache conda packages
uses: actions/cache@v2
env:
CACHE_NUMBER: 0 # Increase to reset cache
with:
path: ~/.conda/pkgs
key:
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }}
restore-keys: |
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
- name: Install dpctl
shell: bash -l {0}
run: |
source $CONDA/etc/profile.d/conda.sh
conda activate
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
conda install -y $PACKAGE_NAME pytest python=${{ matrix.python }} $CHANNELS
# Test installed packages
conda list
- name: Install example requirements
shell: bash -l {0}
run: |
source $CONDA/etc/profile.d/conda.sh
conda install -y pybind11 cython
conda install -y -c intel mkl-dpcpp mkl-devel-dpcpp numba-dppy
conda create -y -n build_env -c intel dpcpp_linux-64
- name: Build and run examples with native extensions
shell: bash -l {0}
run: |
source $CONDA/etc/profile.d/conda.sh
export OCL_ICD_FILENAMES=libintelocl.so
export SYCL_ENABLE_HOST_DEVICE=1
conda activate
cd examples/pybind11
export CC=dpcpp
export CXX=dpcpp
for d in $(ls)
do
pushd $d
conda activate --stack build_env
python setup.py build_ext --inplace || exit 1
conda deactivate
python example.py
popd
done
cd ../cython
for d in $(ls)
do
pushd $d
conda activate --stack build_env
python setup.py build_ext --inplace || exit 1
conda deactivate
python run.py
popd
done
- name: Run Python examples
shell: bash -l {0}
run: |
cd examples/python
export OCL_ICD_FILENAMES=libintelocl.so
export SYCL_ENABLE_HOST_DEVICE=1
for script in $(find . \( -not -name "_*" -and -name "*.py" \))
do
echo "Executing ${script}"
python ${script} || exit 1
done
3 changes: 3 additions & 0 deletions examples/cython/sycl_buffer/_buffer_example.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# distutils: language = c++
# cython: language_level=3

cimport numpy as cnp

import numpy as np
Expand Down
31 changes: 22 additions & 9 deletions examples/cython/sycl_buffer/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,31 @@

print("Result computed by NumPy")
print(X.sum(axis=0))
print("Result computed by SYCL extension using default offloading target")
print(sb.columnwise_total(X))

try:
res = sb.columnwise_total(X)
print("Result computed by SYCL extension using default offloading target")
print(res)
except dpctl.SyclQueueCreationError:
print(
"Could not create SyclQueue for default selected device. Nothing to do."
)
exit(0)

print("")

# controlling where to offload

q = dpctl.SyclQueue("opencl:gpu")
print("Running on: ", q.sycl_device.name)
print(sb.columnwise_total(X, queue=q))

q = dpctl.SyclQueue("opencl:cpu")
print("Running on: ", q.sycl_device.name)
print(sb.columnwise_total(X, queue=q))
try:
q = dpctl.SyclQueue("opencl:gpu")
print("Running on: ", q.sycl_device.name)
print(sb.columnwise_total(X, queue=q))
except dpctl.SyclQueueCreationError:
print("Not running onf opencl:gpu, queue could not be created")

try:
q = dpctl.SyclQueue("opencl:cpu")
print("Running on: ", q.sycl_device.name)
print(sb.columnwise_total(X, queue=q))
except dpctl.SyclQueueCreationError:
print("Not running onf opencl:cpu, queue could not be created")
10 changes: 9 additions & 1 deletion examples/cython/sycl_buffer/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os.path
import sysconfig

import numpy as np
from setuptools import Extension, setup

Expand All @@ -39,7 +42,12 @@
"_buffer_example.pyx",
"use_sycl_buffer.cpp",
],
include_dirs=[".", np.get_include(), dpctl.get_include()],
include_dirs=[
".",
np.get_include(),
dpctl.get_include(),
os.path.join(sysconfig.get_paths()["include"], ".."),
],
libraries=["sycl"]
+ [
"mkl_sycl",
Expand Down
3 changes: 3 additions & 0 deletions examples/cython/sycl_direct_linkage/_buffer_example.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# distutils: language = c++
# cython: language_level=3

cimport numpy as cnp

import numpy as np
Expand Down
10 changes: 9 additions & 1 deletion examples/cython/sycl_direct_linkage/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os.path
import sysconfig

import numpy as np
from setuptools import Extension, setup

Expand Down Expand Up @@ -43,7 +46,12 @@
"_buffer_example.pyx",
"sycl_function.cpp",
],
include_dirs=[".", np.get_include(), dpctl.get_include()],
include_dirs=[
".",
np.get_include(),
dpctl.get_include(),
os.path.join(sysconfig.get_paths()["include"], ".."),
],
libraries=["sycl"]
+ [
"mkl_sycl",
Expand Down
99 changes: 44 additions & 55 deletions examples/cython/usm_memory/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,59 +64,48 @@ def gen_option_params(
n_opts = 3 * 10 ** 6

# compute on CPU sycl device
cpu_q = dpctl.SyclQueue("opencl:cpu:0")
opts1 = gen_option_params(
n_opts,
20.0,
30.0,
22.0,
29.0,
18.0,
24.0,
0.01,
0.05,
0.01,
0.05,
"d",
queue=cpu_q,
)

gpu_q = dpctl.SyclQueue("level_zero:gpu:0")
opts2 = gen_option_params(
n_opts,
20.0,
30.0,
22.0,
29.0,
18.0,
24.0,
0.01,
0.05,
0.01,
0.05,
"d",
queue=gpu_q,
)

cpu_times = []
gpu_times = []
for _ in range(5):

t0 = timeit.default_timer()
X1 = bs.black_scholes_price(opts1, queue=cpu_q)
t1 = timeit.default_timer()

cpu_times.append(t1 - t0)

# compute on GPU sycl device

t0 = timeit.default_timer()
X2 = bs.black_scholes_price(opts2, queue=gpu_q)
t1 = timeit.default_timer()
gpu_times.append(t1 - t0)

print("Using : {}".format(cpu_q.sycl_device.name))
print("Wall times : {}".format(cpu_times))

print("Using : {}".format(gpu_q.sycl_device.name))
print("Wall times : {}".format(gpu_times))
queues = []
for filter_str in ["cpu", "gpu"]:
try:
q = dpctl.SyclQueue(filter_str)
queues.append(q)
except dpctl.SyclQueueCreationError:
continue

if not queues:
print("No queues could not created, nothing to do.")
exit(0)

opt_params_list = []
for q in queues:
opt_params = gen_option_params(
n_opts,
20.0,
30.0,
22.0,
29.0,
18.0,
24.0,
0.01,
0.05,
0.01,
0.05,
"d",
queue=q,
)
opt_params_list.append(opt_params)

times_dict = dict()
for q, params in zip(queues, opt_params_list):
times_list = []
for _ in range(5):
t0 = timeit.default_timer()
X1 = bs.black_scholes_price(params, queue=q)
t1 = timeit.default_timer()
times_list.append(t1 - t0)
times_dict[q.name] = times_list

for dev_name, wall_times in times_dict.items():
print("Using : {}".format(dev_name))
print("Wall times : {}".format(wall_times))
10 changes: 9 additions & 1 deletion examples/cython/usm_memory/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os.path
import sysconfig

import numpy as np
from setuptools import Extension, setup

Expand All @@ -38,7 +41,12 @@
"blackscholes.pyx",
"sycl_blackscholes.cpp",
],
include_dirs=[".", np.get_include(), dpctl.get_include()],
include_dirs=[
".",
np.get_include(),
dpctl.get_include(),
os.path.join(sysconfig.get_paths()["include"], ".."),
],
libraries=["sycl"]
+ [
"mkl_sycl",
Expand Down
2 changes: 1 addition & 1 deletion examples/pybind11/external_usm_allocation/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import dpctl
import dpctl.memory as dpm

q = dpctl.SyclQueue("gpu")
q = dpctl.SyclQueue()
matr = eua.DMatrix(q, 5, 5)

print(matr)
Expand Down
2 changes: 1 addition & 1 deletion examples/python/device_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def create_device_with_aspects():
Demonstrate the usage of :func:`dpctl.select_device_with_aspects()`.
"""
dev = dpctl.select_device_with_aspects(
required_aspects=["fp64", "gpu", "usm_shared_allocations"]
required_aspects=["fp64", "usm_shared_allocations"]
)
dev.print_device_info()

Expand Down
Loading