Skip to content

Better handle no devices systems #1189

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 18 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f3edec3
Error handling specific for system with no devices
oleksandr-pavlyk Apr 25, 2023
6dd0231
Modify test_sycl_device.py to run if DPC++ sees no devices
oleksandr-pavlyk Apr 25, 2023
7d70a99
Mark getDeviceCache noexcept, handle exception in get_platforms
oleksandr-pavlyk Apr 26, 2023
fa40693
Adjust test suite to not crash when no devices are present
oleksandr-pavlyk Apr 26, 2023
a59084c
Added exception handling for when queue, etc could not be created
oleksandr-pavlyk Apr 26, 2023
08c4c04
Removing noexcept specifier. new can fail with bad_alloc
oleksandr-pavlyk Apr 26, 2023
1788952
Handle SyclQueueCreationError
oleksandr-pavlyk Apr 26, 2023
841e5de
Handle device/queue construction exceptions
oleksandr-pavlyk Apr 26, 2023
8b46964
Handle exceptions where no devices present
oleksandr-pavlyk Apr 26, 2023
6a30ae8
Handle exceptions when RT sees no devices
oleksandr-pavlyk Apr 26, 2023
6eb7421
Handle device creation exceptions
oleksandr-pavlyk Apr 26, 2023
8ebfde7
Handle device creation exceptions
oleksandr-pavlyk Apr 26, 2023
47f3b8c
Handle SyclDeviceCreationError
oleksandr-pavlyk Apr 26, 2023
7dc7734
Handle SyclDeviceException
oleksandr-pavlyk Apr 26, 2023
b2df0f3
Update OCL driver versions
oleksandr-pavlyk Apr 26, 2023
fdc7b19
bump up TBB version
oleksandr-pavlyk Apr 26, 2023
874f4fe
Modularize setting up steps into a script, and deploy it
oleksandr-pavlyk Apr 30, 2023
802efbc
Adding */_cython_api*/stringsource pattern to omit for coverage.run/c…
oleksandr-pavlyk May 1, 2023
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
56 changes: 24 additions & 32 deletions .github/workflows/os-llvm-sycl-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:

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

steps:
- name: Cancel Previous Runs
Expand Down Expand Up @@ -107,57 +107,49 @@ jobs:
with:
fetch-depth: 0

- name: Report compiler version
- name: Create set_allvars.sh
shell: bash -l {0}
run: |
cat << 'EOF' > set_allvars.sh
#!/usr/bin/bash
export SYCL_BUNDLE_FOLDER=/home/runner/work/sycl_bundle
source ${SYCL_BUNDLE_FOLDER}/dpcpp_compiler/startup.sh
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/oclcpuexp/x64:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/fpgaemu/x64:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/${TBB_INSTALL_DIR}/lib/intel64/gcc4.8:${LD_LIBRARY_PATH}
export OCL_ICD_VENDORS=
export OCL_ICD_FILENAMES=libintelocl.so:libintelocl_emu.so
EOF
chmod +x set_allvars.sh
cat set_allvars.sh

- name: Report compiler version
shell: bash -l {0}
run: |
source set_allvars.sh
clang++ --version

- name: Run sycl-ls
shell: bash -l {0}
run: |
export SYCL_BUNDLE_FOLDER=/home/runner/work/sycl_bundle
source ${SYCL_BUNDLE_FOLDER}/dpcpp_compiler/startup.sh
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/oclcpuexp/x64:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/fpgaemu/x64:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/${TBB_INSTALL_DIR}/lib/intel64/gcc4.8:${LD_LIBRARY_PATH}
export OCL_ICD_FILENAMES=libintelocl.so:libintelocl_emu.so
source set_allvars.sh
sycl-ls

- name: build dpctl
shell: bash -l {0}
run: |
export SYCL_BUNDLE_FOLDER=/home/runner/work/sycl_bundle
source ${SYCL_BUNDLE_FOLDER}/dpcpp_compiler/startup.sh
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/oclcpuexp/x64:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/fpgaemu/x64:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/${TBB_INSTALL_DIR}/lib/intel64/gcc4.8:${LD_LIBRARY_PATH}
export OCL_ICD_FILENAMES=libintelocl.so:libintelocl_emu.so
source set_allvars.sh
CC=clang CXX=clang++ python setup.py develop -G Ninja

- name: Run lsplatforms
shell: bash -l {0}
run: |
export SYCL_BUNDLE_FOLDER=/home/runner/work/sycl_bundle
source ${SYCL_BUNDLE_FOLDER}/dpcpp_compiler/startup.sh
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/oclcpuexp/x64:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/fpgaemu/x64:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/${TBB_INSTALL_DIR}/lib/intel64/gcc4.8:${LD_LIBRARY_PATH}
export OCL_ICD_FILENAMES=libintelocl.so:libintelocl_emu.so
source set_allvars.sh
python -m dpctl -f || exit 1

- name: Run dpctl/tests
shell: bash -l {0}
run: |
export SYCL_BUNDLE_FOLDER=/home/runner/work/sycl_bundle
source ${SYCL_BUNDLE_FOLDER}/dpcpp_compiler/startup.sh
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/oclcpuexp/x64:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/fpgaemu/x64:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=${SYCL_BUNDLE_FOLDER}/${TBB_INSTALL_DIR}/lib/intel64/gcc4.8:${LD_LIBRARY_PATH}
export OCL_ICD_FILENAMES=libintelocl.so:libintelocl_emu.so
python -m pytest -v dpctl/tests
source set_allvars.sh
# skip test due to https://github.com/intel/llvm/issues/9264
python -m pytest -v dpctl/tests -k "not test_event_backend"
34 changes: 21 additions & 13 deletions dpctl/tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,24 @@ def test_dev_utils():

ctx_mngr = dd.syclinterface_diagnostics

try:
device = dpctl.SyclDevice()
except dpctl.SyclDeviceCreationError:
pytest.skip("Default-constructed device could not be created")

with ctx_mngr():
dpctl.SyclDevice().parent_device
device.parent_device
with ctx_mngr(verbosity="error"):
dpctl.SyclDevice().parent_device
device.parent_device
with pytest.raises(ValueError):
with ctx_mngr(verbosity="blah"):
dpctl.SyclDevice().parent_device
device.parent_device
with tempfile.TemporaryDirectory() as temp_dir:
with ctx_mngr(log_dir=temp_dir):
dpctl.SyclDevice().parent_device
device.parent_device
with pytest.raises(ValueError):
with ctx_mngr(log_dir="/not_a_dir"):
dpctl.SyclDevice().parent_device
device.parent_device


def test_syclinterface():
Expand Down Expand Up @@ -189,34 +194,37 @@ def test_main_full_list():
[sys.executable, "-m", "dpctl", "-f"], capture_output=True
)
assert res.returncode == 0
assert res.stdout
assert res.stdout.decode("utf-8")
if dpctl.get_num_devices() > 0:
assert res.stdout
assert res.stdout.decode("utf-8")


def test_main_long_list():
res = subprocess.run(
[sys.executable, "-m", "dpctl", "-l"], capture_output=True
)
assert res.returncode == 0
assert res.stdout
assert res.stdout.decode("utf-8")
if dpctl.get_num_devices() > 0:
assert res.stdout
assert res.stdout.decode("utf-8")


def test_main_summary():
res = subprocess.run(
[sys.executable, "-m", "dpctl", "-s"], capture_output=True
)
assert res.returncode == 0
assert res.stdout
assert res.stdout.decode("utf-8")
if dpctl.get_num_devices() > 0:
assert res.stdout
assert res.stdout.decode("utf-8")


def test_main_warnings():
res = subprocess.run(
[sys.executable, "-m", "dpctl", "-s", "--includes"], capture_output=True
)
assert res.returncode == 0
assert res.stdout
assert res.stdout or dpctl.get_num_devices() == 0
assert "UserWarning" in res.stderr.decode("utf-8")
assert "is being ignored." in res.stderr.decode("utf-8")

Expand All @@ -225,6 +233,6 @@ def test_main_warnings():
capture_output=True,
)
assert res.returncode == 0
assert res.stdout
assert res.stdout or dpctl.get_num_devices() == 0
assert "UserWarning" in res.stderr.decode("utf-8")
assert "are being ignored." in res.stderr.decode("utf-8")
45 changes: 36 additions & 9 deletions dpctl/tests/test_sycl_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def test_address_of():
"""
Test if the address_of method returns an int value.
"""
ctx = dpctl.SyclContext()
try:
ctx = dpctl.SyclContext()
except dpctl.SyclContextCreationError:
pytest.skip("Failed to create context using default constructor")
assert ctx.addressof_ref() is not None
assert isinstance(ctx.addressof_ref(), int)

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


Expand All @@ -103,15 +109,21 @@ def test_name():
"""
Test if a __name__ method is defined for SyclContext.
"""
ctx = dpctl.SyclContext()
try:
ctx = dpctl.SyclContext()
except dpctl.SyclContextCreationError:
pytest.skip("Failed to create context using default constructor")
assert ctx.__name__ == "SyclContext"


def test_repr():
"""
Test if a __repr__ method is defined for SyclContext.
"""
ctx = dpctl.SyclContext()
try:
ctx = dpctl.SyclContext()
except dpctl.SyclContextCreationError:
pytest.skip("Failed to create context using default constructor")
assert ctx.__repr__ is not None


Expand Down Expand Up @@ -181,20 +193,30 @@ def test_hashing_of_context():
as a dictionary key.

"""
ctx_dict = {dpctl.SyclContext(): "default_context"}
try:
ctx = dpctl.SyclContext()
except dpctl.SyclContextCreationError:
pytest.skip("Failed to create context using default constructor")
ctx_dict = {ctx: "default_context"}
assert ctx_dict


def test_context_repr():
ctx = dpctl.SyclContext()
try:
ctx = dpctl.SyclContext()
except dpctl.SyclContextCreationError:
pytest.skip("Failed to create context using default constructor")
assert type(ctx.__repr__()) is str


def test_cpython_api_SyclContext_GetContextRef():
import ctypes
import sys

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

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

def test_multi_device_different_platforms():
devs = dpctl.get_devices() # all devices
if len(devs) > 1:
if len(devs) > 1 and len(set(d.sycl_platform for d in devs)) > 1:
with pytest.raises(dpctl.SyclContextCreationError):
dpctl.SyclContext(devs)
else:
pytest.skip("Insufficient amount of available devices for this test")
38 changes: 26 additions & 12 deletions dpctl/tests/test_sycl_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""

import pytest
from helper import get_queue_or_skip

import dpctl
from dpctl import SyclDeviceCreationError
Expand All @@ -29,18 +30,18 @@ def test_standard_selectors(device_selector, check):
"""
try:
device = device_selector()
check(device)
except dpctl.SyclDeviceCreationError:
pytest.skip()
pytest.skip("Could not create default-selected device")
check(device)


def test_current_device(check):
"""Test is the device for the current queue is valid."""
q = get_queue_or_skip()
try:
q = dpctl.get_current_queue()
except Exception:
pytest.fail("Encountered an exception inside get_current_queue().")
device = q.get_sycl_device()
device = q.get_sycl_device()
except dpctl.SyclDeviceCreationError:
pytest.skip("Could not create default-selected device")
check(device)


Expand Down Expand Up @@ -125,13 +126,20 @@ def test_hashing_of_device():
a dictionary key.

"""
device_dict = {dpctl.SyclDevice(): "default_device"}
try:
device = dpctl.SyclDevice()
except dpctl.SyclDeviceCreationError:
pytest.skip("Could not create default-constructed device")
device_dict = {device: "default_device"}
assert device_dict


def test_equal():
d1 = dpctl.SyclDevice()
d2 = dpctl.SyclDevice()
try:
d1 = dpctl.SyclDevice()
d2 = dpctl.SyclDevice()
except dpctl.SyclDeviceCreationError:
pytest.skip("Could not create default-selected device")
assert d1 != Ellipsis
assert d1 == d2

Expand Down Expand Up @@ -178,7 +186,7 @@ def test_supported_aspect(supported_aspect):
try:
d = dpctl.SyclDevice()
has_it = getattr(d, "has_aspect_" + supported_aspect)
except dpctl.SyclDevieCreationError:
except dpctl.SyclDeviceCreationError:
has_it = False
try:
d_wa = dpctl.select_device_with_aspects(supported_aspect)
Expand Down Expand Up @@ -212,7 +220,10 @@ def test_cpython_api_SyclDevice_GetDeviceRef():
import ctypes
import sys

d = dpctl.SyclDevice()
try:
d = dpctl.SyclDevice()
except dpctl.SyclDeviceCreationError:
pytest.skip("Could not create default-constructed device")
mod = sys.modules[d.__class__.__module__]
# get capsule storing SyclDevice_GetDeviceRef function ptr
d_ref_fn_cap = mod.__pyx_capi__["SyclDevice_GetDeviceRef"]
Expand All @@ -235,7 +246,10 @@ def test_cpython_api_SyclDevice_Make():
import ctypes
import sys

d = dpctl.SyclDevice()
try:
d = dpctl.SyclDevice()
except dpctl.SyclDeviceCreationError:
pytest.skip("Could not create default-constructed device")
mod = sys.modules[d.__class__.__module__]
# get capsule storign SyclContext_Make function ptr
make_d_fn_cap = mod.__pyx_capi__["SyclDevice_Make"]
Expand Down
4 changes: 3 additions & 1 deletion dpctl/tests/test_sycl_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def test_execution_status_nondefault_event():
assert type(wl) is list


def test_backend():
def test_event_backend():
if dpctl.get_num_devices() == 0:
pytest.skip("No backends are available")
try:
dpctl.SyclEvent().backend
except ValueError:
Expand Down
Loading