Skip to content

Commit cd36e59

Browse files
committed
Add AdaptiveCpp workflow
1 parent 86dd7ca commit cd36e59

2 files changed

Lines changed: 193 additions & 3 deletions

File tree

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
name: Build with AdaptiveCpp
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
14+
cancel-in-progress: true
15+
16+
env:
17+
CHANNELS: "-c conda-forge --override-channels"
18+
# examples that AdaptiveCpp can build
19+
SYCL_EXAMPLES: "cython/sycl_buffer cython/use_dpctl_sycl pybind11/external_usm_allocation pybind11/use_dpctl_sycl_queue"
20+
C_EXAMPLES: "c/py_sycl_ls"
21+
22+
jobs:
23+
test_linux:
24+
name: Build and test with AdaptiveCpp, Python ${{ matrix.python }}
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 120
27+
defaults:
28+
run:
29+
shell: bash -el {0}
30+
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
include:
35+
- python: '3.14'
36+
python_spec: '3.14.*=*_cp314'
37+
- python: '3.14t'
38+
python_spec: '3.14.*=*_cp314t'
39+
40+
steps:
41+
- name: Checkout dpctl repo
42+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
43+
with:
44+
persist-credentials: false
45+
# the package version comes from git describe
46+
fetch-depth: 0
47+
48+
- name: Cache conda packages
49+
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
50+
env:
51+
CACHE_NUMBER: 0 # Increase to reset cache
52+
with:
53+
path: ~/.conda/pkgs
54+
key:
55+
${{ runner.os }}-conda-acpp-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{ hashFiles('.github/workflows/adaptivecpp-build.yml') }}
56+
restore-keys: |
57+
${{ runner.os }}-conda-acpp-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
58+
${{ runner.os }}-conda-acpp-${{ env.CACHE_NUMBER }}-
59+
60+
- uses: conda-incubator/setup-miniconda@8ee1f361103df19b6f8c8655fd3967a8ecb162d5 # v4.0.1
61+
with:
62+
auto-update-conda: true
63+
miniforge-version: latest
64+
activate-environment: acpp
65+
channels: conda-forge
66+
conda-remove-defaults: true
67+
68+
- name: Set pkgs_dirs
69+
run: |
70+
echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc
71+
72+
- name: Install AdaptiveCpp and build dependencies
73+
run: |
74+
# the Python build string selects the GIL or the free-threaded variant,
75+
# clang must come from the LLVM that adaptivecpp was built against, and
76+
# intel-opencl-rt provides the OpenCL CPU device to run on
77+
conda install -y ${{ env.CHANNELS }} \
78+
"python=${{ matrix.python_spec }}" \
79+
"adaptivecpp=*=cpu_llvm19*" "clang=19.*" "clangxx=19.*" \
80+
intel-opencl-rt tbb \
81+
cmake cython ninja numpy pybind11 pytest scikit-build "setuptools<80" versioneer
82+
83+
- name: Report the environment
84+
run: |
85+
conda list
86+
python -VV
87+
acpp-info -l
88+
89+
- name: Build dpctl
90+
run: |
91+
# conda-forge builds AdaptiveCpp without the Level Zero backend
92+
python scripts/build_locally.py \
93+
--c-compiler="${CONDA_PREFIX}/bin/clang" \
94+
--cxx-compiler="${CONDA_PREFIX}/bin/acpp" \
95+
--no-level-zero \
96+
--cmake-opts="-DDPCTL_SYCL_PROVIDER=AdaptiveCpp"
97+
98+
- name: List platforms
99+
run: |
100+
python -m dpctl -f
101+
python -c "from dpctl._diagnostics import sycl_provider; assert sycl_provider() == 'AdaptiveCpp'"
102+
103+
- name: Run dpctl/tests on the OpenMP device
104+
env:
105+
ACPP_VISIBILITY_MASK: omp
106+
run: |
107+
python -m pytest -q dpctl/tests
108+
109+
- name: Run dpctl/tests on the OpenCL CPU device
110+
env:
111+
ACPP_VISIBILITY_MASK: ocl
112+
run: |
113+
python -m pytest -q dpctl/tests
114+
115+
- name: Build examples of extensions
116+
env:
117+
PYTHONPATH: ${{ github.workspace }}
118+
run: |
119+
for d in ${SYCL_EXAMPLES}; do
120+
pushd "examples/${d}" > /dev/null
121+
CC="${CONDA_PREFIX}/bin/clang" CXX="${CONDA_PREFIX}/bin/acpp" \
122+
python setup.py build_ext --inplace -G Ninja -- \
123+
-DDPCTL_SYCL_PROVIDER=AdaptiveCpp \
124+
-DDpctl_DIR="${GITHUB_WORKSPACE}/cmake"
125+
popd > /dev/null
126+
done
127+
for d in ${C_EXAMPLES}; do
128+
pushd "examples/${d}" > /dev/null
129+
python setup.py build_ext --inplace
130+
popd > /dev/null
131+
done
132+
133+
- name: Run examples of extensions on the OpenMP device
134+
env:
135+
ACPP_VISIBILITY_MASK: omp
136+
PYTHONPATH: ${{ github.workspace }}
137+
run: |
138+
for d in ${SYCL_EXAMPLES} ${C_EXAMPLES}; do
139+
# the OpenMP backend allocates plain host memory, so every USM kind
140+
# reports usm_type "host" and this example's checks cannot hold
141+
if [ "${d}" = "pybind11/external_usm_allocation" ]; then
142+
continue
143+
fi
144+
pushd "examples/${d}" > /dev/null
145+
python -m pytest -q tests
146+
popd > /dev/null
147+
done
148+
149+
- name: Run examples of extensions on the OpenCL CPU device
150+
env:
151+
ACPP_VISIBILITY_MASK: ocl
152+
PYTHONPATH: ${{ github.workspace }}
153+
run: |
154+
for d in ${SYCL_EXAMPLES} ${C_EXAMPLES}; do
155+
pushd "examples/${d}" > /dev/null
156+
python -m pytest -q tests
157+
popd > /dev/null
158+
done
159+
160+
- name: Run Python examples on the OpenMP device
161+
working-directory: examples/python
162+
env:
163+
ACPP_VISIBILITY_MASK: omp
164+
run: |
165+
while IFS= read -r script; do
166+
echo "Executing ${script}"
167+
python "${script}" --run all
168+
done < <(find . \( -not -name "_*" -and -name "*.py" \))
169+
170+
- name: Run Python examples on the OpenCL CPU device
171+
working-directory: examples/python
172+
env:
173+
ACPP_VISIBILITY_MASK: ocl
174+
run: |
175+
while IFS= read -r script; do
176+
echo "Executing ${script}"
177+
python "${script}" --run all
178+
done < <(find . \( -not -name "_*" -and -name "*.py" \))

examples/python/sycl_queue.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ def create_queue_from_device():
4141
"""
4242
Create a queue from SyclDevice instance.
4343
"""
44-
cpu_d = dpctl.SyclDevice("opencl:cpu:0")
44+
try:
45+
cpu_d = dpctl.SyclDevice("opencl:cpu:0")
46+
except dpctl.SyclDeviceCreationError:
47+
print("An OpenCL CPU driver needs to be installed on the system")
48+
return
4549
q = dpctl.SyclQueue(cpu_d, property="enable_profiling")
4650
assert q.sycl_device == cpu_d
4751
print(
@@ -54,7 +58,11 @@ def create_queue_from_subdevice():
5458
"""
5559
Create a queue from a sub-device.
5660
"""
57-
cpu_d = dpctl.SyclDevice("opencl:cpu:0")
61+
try:
62+
cpu_d = dpctl.SyclDevice("opencl:cpu:0")
63+
except dpctl.SyclDeviceCreationError:
64+
print("An OpenCL CPU driver needs to be installed on the system")
65+
return
5866
try:
5967
sub_devs = cpu_d.create_sub_devices(partition=2)
6068
except dpctl.SyclSubDeviceCreationError:
@@ -73,7 +81,11 @@ def create_queue_from_subdevice_multidevice_context():
7381
"""
7482
Create a queue from a sub-device.
7583
"""
76-
cpu_d = dpctl.SyclDevice("opencl:cpu:0")
84+
try:
85+
cpu_d = dpctl.SyclDevice("opencl:cpu:0")
86+
except dpctl.SyclDeviceCreationError:
87+
print("An OpenCL CPU driver needs to be installed on the system")
88+
return
7789
try:
7890
sub_devs = cpu_d.create_sub_devices(partition=2)
7991
except dpctl.SyclSubDeviceCreationError:

0 commit comments

Comments
 (0)