Skip to content

Commit cddf05f

Browse files
Merge pull request #1189 from IntelPython/better-handle-no-devices-systems
Better handle no devices systems
2 parents 5707661 + 802efbc commit cddf05f

17 files changed

+534
-237
lines changed

.github/workflows/os-llvm-sycl-build.yml

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ jobs:
1111

1212
env:
1313
DOWNLOAD_URL_PREFIX: https://github.com/intel/llvm/releases/download
14-
DRIVER_PATH: 2022-WW50
15-
OCLCPUEXP_FN: oclcpuexp-2022.15.12.0.01_rel.tar.gz
16-
FPGAEMU_FN: fpgaemu-2022.15.12.0.01_rel.tar.gz
17-
TBB_URL: https://github.com/oneapi-src/oneTBB/releases/download/v2021.7.0/
18-
TBB_INSTALL_DIR: oneapi-tbb-2021.7.0
19-
TBB_FN: oneapi-tbb-2021.7.0-lin.tgz
14+
DRIVER_PATH: 2023-WW13
15+
OCLCPUEXP_FN: oclcpuexp-2023.15.3.0.20_rel.tar.gz
16+
FPGAEMU_FN: fpgaemu-2023.15.3.0.20_rel.tar.gz
17+
TBB_URL: https://github.com/oneapi-src/oneTBB/releases/download/v2021.9.0/
18+
TBB_INSTALL_DIR: oneapi-tbb-2021.9.0
19+
TBB_FN: oneapi-tbb-2021.9.0-lin.tgz
2020

2121
steps:
2222
- name: Cancel Previous Runs
@@ -107,57 +107,49 @@ jobs:
107107
with:
108108
fetch-depth: 0
109109

110-
- name: Report compiler version
110+
- name: Create set_allvars.sh
111111
shell: bash -l {0}
112112
run: |
113+
cat << 'EOF' > set_allvars.sh
114+
#!/usr/bin/bash
113115
export SYCL_BUNDLE_FOLDER=/home/runner/work/sycl_bundle
114116
source ${SYCL_BUNDLE_FOLDER}/dpcpp_compiler/startup.sh
115117
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/oclcpuexp/x64:${LD_LIBRARY_PATH}
116118
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/fpgaemu/x64:${LD_LIBRARY_PATH}
117119
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/${TBB_INSTALL_DIR}/lib/intel64/gcc4.8:${LD_LIBRARY_PATH}
120+
export OCL_ICD_VENDORS=
118121
export OCL_ICD_FILENAMES=libintelocl.so:libintelocl_emu.so
122+
EOF
123+
chmod +x set_allvars.sh
124+
cat set_allvars.sh
125+
126+
- name: Report compiler version
127+
shell: bash -l {0}
128+
run: |
129+
source set_allvars.sh
119130
clang++ --version
120131
121132
- name: Run sycl-ls
122133
shell: bash -l {0}
123134
run: |
124-
export SYCL_BUNDLE_FOLDER=/home/runner/work/sycl_bundle
125-
source ${SYCL_BUNDLE_FOLDER}/dpcpp_compiler/startup.sh
126-
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/oclcpuexp/x64:${LD_LIBRARY_PATH}
127-
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/fpgaemu/x64:${LD_LIBRARY_PATH}
128-
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/${TBB_INSTALL_DIR}/lib/intel64/gcc4.8:${LD_LIBRARY_PATH}
129-
export OCL_ICD_FILENAMES=libintelocl.so:libintelocl_emu.so
135+
source set_allvars.sh
130136
sycl-ls
131137
132138
- name: build dpctl
133139
shell: bash -l {0}
134140
run: |
135-
export SYCL_BUNDLE_FOLDER=/home/runner/work/sycl_bundle
136-
source ${SYCL_BUNDLE_FOLDER}/dpcpp_compiler/startup.sh
137-
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/oclcpuexp/x64:${LD_LIBRARY_PATH}
138-
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/fpgaemu/x64:${LD_LIBRARY_PATH}
139-
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/${TBB_INSTALL_DIR}/lib/intel64/gcc4.8:${LD_LIBRARY_PATH}
140-
export OCL_ICD_FILENAMES=libintelocl.so:libintelocl_emu.so
141+
source set_allvars.sh
141142
CC=clang CXX=clang++ python setup.py develop -G Ninja
142143
143144
- name: Run lsplatforms
144145
shell: bash -l {0}
145146
run: |
146-
export SYCL_BUNDLE_FOLDER=/home/runner/work/sycl_bundle
147-
source ${SYCL_BUNDLE_FOLDER}/dpcpp_compiler/startup.sh
148-
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/oclcpuexp/x64:${LD_LIBRARY_PATH}
149-
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/fpgaemu/x64:${LD_LIBRARY_PATH}
150-
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/${TBB_INSTALL_DIR}/lib/intel64/gcc4.8:${LD_LIBRARY_PATH}
151-
export OCL_ICD_FILENAMES=libintelocl.so:libintelocl_emu.so
147+
source set_allvars.sh
152148
python -m dpctl -f || exit 1
153149
154150
- name: Run dpctl/tests
155151
shell: bash -l {0}
156152
run: |
157-
export SYCL_BUNDLE_FOLDER=/home/runner/work/sycl_bundle
158-
source ${SYCL_BUNDLE_FOLDER}/dpcpp_compiler/startup.sh
159-
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/oclcpuexp/x64:${LD_LIBRARY_PATH}
160-
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/fpgaemu/x64:${LD_LIBRARY_PATH}
161-
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/${TBB_INSTALL_DIR}/lib/intel64/gcc4.8:${LD_LIBRARY_PATH}
162-
export OCL_ICD_FILENAMES=libintelocl.so:libintelocl_emu.so
163-
python -m pytest -v dpctl/tests
153+
source set_allvars.sh
154+
# skip test due to https://github.com/intel/llvm/issues/9264
155+
python -m pytest -v dpctl/tests -k "not test_event_backend"

dpctl/tests/test_service.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,24 @@ def test_dev_utils():
119119

120120
ctx_mngr = dd.syclinterface_diagnostics
121121

122+
try:
123+
device = dpctl.SyclDevice()
124+
except dpctl.SyclDeviceCreationError:
125+
pytest.skip("Default-constructed device could not be created")
126+
122127
with ctx_mngr():
123-
dpctl.SyclDevice().parent_device
128+
device.parent_device
124129
with ctx_mngr(verbosity="error"):
125-
dpctl.SyclDevice().parent_device
130+
device.parent_device
126131
with pytest.raises(ValueError):
127132
with ctx_mngr(verbosity="blah"):
128-
dpctl.SyclDevice().parent_device
133+
device.parent_device
129134
with tempfile.TemporaryDirectory() as temp_dir:
130135
with ctx_mngr(log_dir=temp_dir):
131-
dpctl.SyclDevice().parent_device
136+
device.parent_device
132137
with pytest.raises(ValueError):
133138
with ctx_mngr(log_dir="/not_a_dir"):
134-
dpctl.SyclDevice().parent_device
139+
device.parent_device
135140

136141

137142
def test_syclinterface():
@@ -189,34 +194,37 @@ def test_main_full_list():
189194
[sys.executable, "-m", "dpctl", "-f"], capture_output=True
190195
)
191196
assert res.returncode == 0
192-
assert res.stdout
193-
assert res.stdout.decode("utf-8")
197+
if dpctl.get_num_devices() > 0:
198+
assert res.stdout
199+
assert res.stdout.decode("utf-8")
194200

195201

196202
def test_main_long_list():
197203
res = subprocess.run(
198204
[sys.executable, "-m", "dpctl", "-l"], capture_output=True
199205
)
200206
assert res.returncode == 0
201-
assert res.stdout
202-
assert res.stdout.decode("utf-8")
207+
if dpctl.get_num_devices() > 0:
208+
assert res.stdout
209+
assert res.stdout.decode("utf-8")
203210

204211

205212
def test_main_summary():
206213
res = subprocess.run(
207214
[sys.executable, "-m", "dpctl", "-s"], capture_output=True
208215
)
209216
assert res.returncode == 0
210-
assert res.stdout
211-
assert res.stdout.decode("utf-8")
217+
if dpctl.get_num_devices() > 0:
218+
assert res.stdout
219+
assert res.stdout.decode("utf-8")
212220

213221

214222
def test_main_warnings():
215223
res = subprocess.run(
216224
[sys.executable, "-m", "dpctl", "-s", "--includes"], capture_output=True
217225
)
218226
assert res.returncode == 0
219-
assert res.stdout
227+
assert res.stdout or dpctl.get_num_devices() == 0
220228
assert "UserWarning" in res.stderr.decode("utf-8")
221229
assert "is being ignored." in res.stderr.decode("utf-8")
222230

@@ -225,6 +233,6 @@ def test_main_warnings():
225233
capture_output=True,
226234
)
227235
assert res.returncode == 0
228-
assert res.stdout
236+
assert res.stdout or dpctl.get_num_devices() == 0
229237
assert "UserWarning" in res.stderr.decode("utf-8")
230238
assert "are being ignored." in res.stderr.decode("utf-8")

dpctl/tests/test_sycl_context.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ def test_address_of():
5858
"""
5959
Test if the address_of method returns an int value.
6060
"""
61-
ctx = dpctl.SyclContext()
61+
try:
62+
ctx = dpctl.SyclContext()
63+
except dpctl.SyclContextCreationError:
64+
pytest.skip("Failed to create context using default constructor")
6265
assert ctx.addressof_ref() is not None
6366
assert isinstance(ctx.addressof_ref(), int)
6467

@@ -85,7 +88,10 @@ def test_context_not_equals2():
8588
Test if comparing a SyclContext object to some random Python object is
8689
correctly handled and returns False.
8790
"""
88-
ctx = dpctl.SyclContext()
91+
try:
92+
ctx = dpctl.SyclContext()
93+
except dpctl.SyclContextCreationError:
94+
pytest.skip("Failed to create context using default constructor")
8995
assert ctx != "some context"
9096

9197

@@ -103,15 +109,21 @@ def test_name():
103109
"""
104110
Test if a __name__ method is defined for SyclContext.
105111
"""
106-
ctx = dpctl.SyclContext()
112+
try:
113+
ctx = dpctl.SyclContext()
114+
except dpctl.SyclContextCreationError:
115+
pytest.skip("Failed to create context using default constructor")
107116
assert ctx.__name__ == "SyclContext"
108117

109118

110119
def test_repr():
111120
"""
112121
Test if a __repr__ method is defined for SyclContext.
113122
"""
114-
ctx = dpctl.SyclContext()
123+
try:
124+
ctx = dpctl.SyclContext()
125+
except dpctl.SyclContextCreationError:
126+
pytest.skip("Failed to create context using default constructor")
115127
assert ctx.__repr__ is not None
116128

117129

@@ -181,20 +193,30 @@ def test_hashing_of_context():
181193
as a dictionary key.
182194
183195
"""
184-
ctx_dict = {dpctl.SyclContext(): "default_context"}
196+
try:
197+
ctx = dpctl.SyclContext()
198+
except dpctl.SyclContextCreationError:
199+
pytest.skip("Failed to create context using default constructor")
200+
ctx_dict = {ctx: "default_context"}
185201
assert ctx_dict
186202

187203

188204
def test_context_repr():
189-
ctx = dpctl.SyclContext()
205+
try:
206+
ctx = dpctl.SyclContext()
207+
except dpctl.SyclContextCreationError:
208+
pytest.skip("Failed to create context using default constructor")
190209
assert type(ctx.__repr__()) is str
191210

192211

193212
def test_cpython_api_SyclContext_GetContextRef():
194213
import ctypes
195214
import sys
196215

197-
ctx = dpctl.SyclContext()
216+
try:
217+
ctx = dpctl.SyclContext()
218+
except dpctl.SyclContextCreationError:
219+
pytest.skip("Failed to create context using default constructor")
198220
mod = sys.modules[ctx.__class__.__module__]
199221
# get capsule storign SyclContext_GetContextRef function ptr
200222
ctx_ref_fn_cap = mod.__pyx_capi__["SyclContext_GetContextRef"]
@@ -217,7 +239,10 @@ def test_cpython_api_SyclContext_Make():
217239
import ctypes
218240
import sys
219241

220-
ctx = dpctl.SyclContext()
242+
try:
243+
ctx = dpctl.SyclContext()
244+
except dpctl.SyclContextCreationError:
245+
pytest.skip("Failed to create context using default constructor")
221246
mod = sys.modules[ctx.__class__.__module__]
222247
# get capsule storign SyclContext_Make function ptr
223248
make_ctx_fn_cap = mod.__pyx_capi__["SyclContext_Make"]
@@ -243,6 +268,8 @@ def test_invalid_capsule():
243268

244269
def test_multi_device_different_platforms():
245270
devs = dpctl.get_devices() # all devices
246-
if len(devs) > 1:
271+
if len(devs) > 1 and len(set(d.sycl_platform for d in devs)) > 1:
247272
with pytest.raises(dpctl.SyclContextCreationError):
248273
dpctl.SyclContext(devs)
274+
else:
275+
pytest.skip("Insufficient amount of available devices for this test")

dpctl/tests/test_sycl_device.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"""
1919

2020
import pytest
21+
from helper import get_queue_or_skip
2122

2223
import dpctl
2324
from dpctl import SyclDeviceCreationError
@@ -29,18 +30,18 @@ def test_standard_selectors(device_selector, check):
2930
"""
3031
try:
3132
device = device_selector()
32-
check(device)
3333
except dpctl.SyclDeviceCreationError:
34-
pytest.skip()
34+
pytest.skip("Could not create default-selected device")
35+
check(device)
3536

3637

3738
def test_current_device(check):
3839
"""Test is the device for the current queue is valid."""
40+
q = get_queue_or_skip()
3941
try:
40-
q = dpctl.get_current_queue()
41-
except Exception:
42-
pytest.fail("Encountered an exception inside get_current_queue().")
43-
device = q.get_sycl_device()
42+
device = q.get_sycl_device()
43+
except dpctl.SyclDeviceCreationError:
44+
pytest.skip("Could not create default-selected device")
4445
check(device)
4546

4647

@@ -125,13 +126,20 @@ def test_hashing_of_device():
125126
a dictionary key.
126127
127128
"""
128-
device_dict = {dpctl.SyclDevice(): "default_device"}
129+
try:
130+
device = dpctl.SyclDevice()
131+
except dpctl.SyclDeviceCreationError:
132+
pytest.skip("Could not create default-constructed device")
133+
device_dict = {device: "default_device"}
129134
assert device_dict
130135

131136

132137
def test_equal():
133-
d1 = dpctl.SyclDevice()
134-
d2 = dpctl.SyclDevice()
138+
try:
139+
d1 = dpctl.SyclDevice()
140+
d2 = dpctl.SyclDevice()
141+
except dpctl.SyclDeviceCreationError:
142+
pytest.skip("Could not create default-selected device")
135143
assert d1 != Ellipsis
136144
assert d1 == d2
137145

@@ -178,7 +186,7 @@ def test_supported_aspect(supported_aspect):
178186
try:
179187
d = dpctl.SyclDevice()
180188
has_it = getattr(d, "has_aspect_" + supported_aspect)
181-
except dpctl.SyclDevieCreationError:
189+
except dpctl.SyclDeviceCreationError:
182190
has_it = False
183191
try:
184192
d_wa = dpctl.select_device_with_aspects(supported_aspect)
@@ -212,7 +220,10 @@ def test_cpython_api_SyclDevice_GetDeviceRef():
212220
import ctypes
213221
import sys
214222

215-
d = dpctl.SyclDevice()
223+
try:
224+
d = dpctl.SyclDevice()
225+
except dpctl.SyclDeviceCreationError:
226+
pytest.skip("Could not create default-constructed device")
216227
mod = sys.modules[d.__class__.__module__]
217228
# get capsule storing SyclDevice_GetDeviceRef function ptr
218229
d_ref_fn_cap = mod.__pyx_capi__["SyclDevice_GetDeviceRef"]
@@ -235,7 +246,10 @@ def test_cpython_api_SyclDevice_Make():
235246
import ctypes
236247
import sys
237248

238-
d = dpctl.SyclDevice()
249+
try:
250+
d = dpctl.SyclDevice()
251+
except dpctl.SyclDeviceCreationError:
252+
pytest.skip("Could not create default-constructed device")
239253
mod = sys.modules[d.__class__.__module__]
240254
# get capsule storign SyclContext_Make function ptr
241255
make_d_fn_cap = mod.__pyx_capi__["SyclDevice_Make"]

dpctl/tests/test_sycl_event.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ def test_execution_status_nondefault_event():
121121
assert type(wl) is list
122122

123123

124-
def test_backend():
124+
def test_event_backend():
125+
if dpctl.get_num_devices() == 0:
126+
pytest.skip("No backends are available")
125127
try:
126128
dpctl.SyclEvent().backend
127129
except ValueError:

0 commit comments

Comments
 (0)