diff --git a/.github/workflows/os-llvm-sycl-build.yml b/.github/workflows/os-llvm-sycl-build.yml index 6e12b309f7..efe327c9d9 100644 --- a/.github/workflows/os-llvm-sycl-build.yml +++ b/.github/workflows/os-llvm-sycl-build.yml @@ -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 @@ -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" diff --git a/dpctl/tests/test_service.py b/dpctl/tests/test_service.py index 3ba3f7fd8f..1161a42ec2 100644 --- a/dpctl/tests/test_service.py +++ b/dpctl/tests/test_service.py @@ -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(): @@ -189,8 +194,9 @@ 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(): @@ -198,8 +204,9 @@ def test_main_long_list(): [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(): @@ -207,8 +214,9 @@ def test_main_summary(): [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(): @@ -216,7 +224,7 @@ def test_main_warnings(): [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") @@ -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") diff --git a/dpctl/tests/test_sycl_context.py b/dpctl/tests/test_sycl_context.py index 7a92c4f693..41b7f4fc74 100644 --- a/dpctl/tests/test_sycl_context.py +++ b/dpctl/tests/test_sycl_context.py @@ -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) @@ -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" @@ -103,7 +109,10 @@ 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" @@ -111,7 +120,10 @@ 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 @@ -181,12 +193,19 @@ 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 @@ -194,7 +213,10 @@ 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"] @@ -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"] @@ -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") diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index af22876dd3..d7122b9397 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -18,6 +18,7 @@ """ import pytest +from helper import get_queue_or_skip import dpctl from dpctl import SyclDeviceCreationError @@ -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) @@ -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 @@ -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) @@ -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"] @@ -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"] diff --git a/dpctl/tests/test_sycl_event.py b/dpctl/tests/test_sycl_event.py index 3fdd07fa93..afb6e6745f 100644 --- a/dpctl/tests/test_sycl_event.py +++ b/dpctl/tests/test_sycl_event.py @@ -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: diff --git a/dpctl/tests/test_sycl_queue.py b/dpctl/tests/test_sycl_queue.py index a5038e4612..3d159f98ba 100644 --- a/dpctl/tests/test_sycl_queue.py +++ b/dpctl/tests/test_sycl_queue.py @@ -47,7 +47,7 @@ def test_current_device(check): try: q = dpctl.get_current_queue() except Exception: - pytest.fail("Encountered an exception inside get_current_queue().") + pytest.skip("Encountered an exception inside get_current_queue().") device = q.get_sycl_device() check(device) @@ -125,7 +125,7 @@ def test_has_enable_profiling(): try: q = dpctl.SyclQueue(property="enable_profiling") except dpctl.SyclQueueCreationError: - pytest.skip() + pytest.skip("Could not create queue with profiling property enabled") assert q.has_enable_profiling @@ -135,7 +135,11 @@ def test_hashing_of_queue(): a dictionary key. """ - queue_dict = {dpctl.SyclQueue(): "default_queue"} + try: + q = dpctl.SyclQueue() + except dpctl.SyclQueueCreationError: + pytest.skip("Default-constructed queue could not be created") + queue_dict = {q: "default_queue"} assert queue_dict @@ -144,7 +148,7 @@ def test_channeling_device_properties(capsys): q = dpctl.SyclQueue() dev = q.sycl_device except dpctl.SyclQueueCreationError: - pytest.fail("Failed to create device from default selector") + pytest.skip("Failed to create device from default selector") q.print_device_info() # should execute without raising q_captured = capsys.readouterr() @@ -177,20 +181,39 @@ def test_queue_submit_barrier(valid_filter): def test_queue__repr__(): - q1 = dpctl.SyclQueue(property=0) + try: + q1 = dpctl.SyclQueue(property=0) + except dpctl.SyclQueueCreationError: + pytest.skip() r1 = q1.__repr__() - q2 = dpctl.SyclQueue(property="in_order") - r2 = q2.__repr__() - q3 = dpctl.SyclQueue(property="enable_profiling") - r3 = q3.__repr__() - q4 = dpctl.SyclQueue(property="default") - r4 = q4.__repr__() - q5 = dpctl.SyclQueue(property=["in_order", "enable_profiling", 0]) - r5 = q5.__repr__() assert type(r1) is str + + try: + q2 = dpctl.SyclQueue(property="in_order") + except dpctl.SyclQueueCreationError: + pytest.skip() + r2 = q2.__repr__() assert type(r2) is str + + try: + q3 = dpctl.SyclQueue(property="enable_profiling") + except dpctl.SyclQueueCreationError: + pytest.skip() + r3 = q3.__repr__() assert type(r3) is str + + try: + q4 = dpctl.SyclQueue(property="default") + except dpctl.SyclQueueCreationError: + pytest.skip() + r4 = q4.__repr__() assert type(r4) is str + + try: + q5 = dpctl.SyclQueue(property=["in_order", "enable_profiling", 0]) + except dpctl.SyclQueueCreationError: + pytest.skip() + r5 = q5.__repr__() assert type(r5) is str @@ -202,7 +225,10 @@ def test_queue_invalid_property(): def test_queue_capsule(): - q = dpctl.SyclQueue() + try: + q = dpctl.SyclQueue() + except dpctl.SyclQueueCreationError: + pytest.skip("Can not defaul-construct SyclQueue") cap = q._get_capsule() cap2 = q._get_capsule() q2 = dpctl.SyclQueue(cap) @@ -227,7 +253,10 @@ def test_queue_ctor(): def test_cpython_api_SyclQueue_GetQueueRef(): - q = dpctl.SyclQueue() + try: + q = dpctl.SyclQueue() + except dpctl.SyclQueueCreationError: + pytest.skip("Can not defaul-construct SyclQueue") mod = sys.modules[q.__class__.__module__] # get capsule storign SyclQueue_GetQueueRef function ptr q_ref_fn_cap = mod.__pyx_capi__["SyclQueue_GetQueueRef"] @@ -247,7 +276,10 @@ def test_cpython_api_SyclQueue_GetQueueRef(): def test_cpython_api_SyclQueue_Make(): - q = dpctl.SyclQueue() + try: + q = dpctl.SyclQueue() + except dpctl.SyclQueueCreationError: + pytest.skip("Can not defaul-construct SyclQueue") mod = sys.modules[q.__class__.__module__] # get capsule storing SyclQueue_Make function ptr make_SyclQueue_fn_cap = mod.__pyx_capi__["SyclQueue_Make"] @@ -271,7 +303,10 @@ def test_constructor_many_arg(): dpctl.SyclQueue(None, None, None, None) with pytest.raises(TypeError): dpctl.SyclQueue(None, None) - ctx = dpctl.SyclContext() + try: + ctx = dpctl.SyclContext() + except dpctl.SyclContextCreationError: + pytest.skip() with pytest.raises(TypeError): dpctl.SyclQueue(ctx, None) with pytest.raises(TypeError): @@ -370,6 +405,12 @@ def dpctl_cython_extension(tmp_path_factory): def test_cython_api(dpctl_cython_extension): - q = dpctl_cython_extension.call_create_from_context_and_devices() - d = dpctl.SyclDevice() + try: + q = dpctl_cython_extension.call_create_from_context_and_devices() + except (dpctl.SyclDeviceCreationError, dpctl.SyclQueueCreationError): + pytest.skip() + try: + d = dpctl.SyclDevice() + except dpctl.SyclDeviceCreationError: + pytest.skip("Default-construction of SyclDevice failed") assert q.sycl_device == d diff --git a/dpctl/tests/test_sycl_queue_memcpy.py b/dpctl/tests/test_sycl_queue_memcpy.py index ffd738dc00..45c8e41f61 100644 --- a/dpctl/tests/test_sycl_queue_memcpy.py +++ b/dpctl/tests/test_sycl_queue_memcpy.py @@ -18,7 +18,6 @@ """ import pytest -from helper import has_sycl_platforms import dpctl import dpctl.memory @@ -30,12 +29,11 @@ def _create_memory(q): return mobj -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_memcpy_copy_usm_to_usm(): - q = dpctl.SyclQueue() + try: + q = dpctl.SyclQueue() + except dpctl.SyclQueueCreationError: + pytest.skip("Default constructor for SyclQueue failed") mobj1 = _create_memory(q) mobj2 = _create_memory(q) @@ -49,12 +47,11 @@ def test_memcpy_copy_usm_to_usm(): assert mv2[:3], b"123" -# @pytest.mark.skipif( -# not has_sycl_platforms(), -# reason="No SYCL devices except the default host device." -# ) def test_memcpy_type_error(): - q = dpctl.SyclQueue() + try: + q = dpctl.SyclQueue() + except dpctl.SyclQueueCreationError: + pytest.skip("Default constructor for SyclQueue failed") mobj = _create_memory(q) with pytest.raises(TypeError) as cm: diff --git a/dpctl/tests/test_sycl_usm.py b/dpctl/tests/test_sycl_usm.py index 0efb6ccf6d..7e86e8a0da 100644 --- a/dpctl/tests/test_sycl_usm.py +++ b/dpctl/tests/test_sycl_usm.py @@ -19,7 +19,6 @@ import numpy as np import pytest -from helper import has_cpu, has_gpu, has_sycl_platforms import dpctl from dpctl.memory import ( @@ -43,15 +42,14 @@ def __sycl_usm_array_interface(self): return iface -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_memory_create(memory_ctor): import sys nbytes = 1024 - queue = dpctl.SyclQueue() + try: + queue = dpctl.SyclQueue() + except dpctl.SyclQueueCreationError: + pytest.skip("SyclQueue() failed, skip further testing...") mobj = memory_ctor(nbytes, alignment=64, queue=queue) assert mobj.nbytes == nbytes assert hasattr(mobj, "__sycl_usm_array_interface__") @@ -65,12 +63,12 @@ def test_memory_create(memory_ctor): assert sys.getsizeof(mobj) > nbytes -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_memory_create_with_np(): nbytes = 16384 + try: + dpctl.SyclQueue() + except dpctl.SyclQueueCreationError: + pytest.skip("SyclQueue() failed, skip further testing...") mobj = dpctl.memory.MemoryUSMShared(np.int64(nbytes)) assert mobj.nbytes == nbytes assert hasattr(mobj, "__sycl_usm_array_interface__") @@ -78,7 +76,10 @@ def test_memory_create_with_np(): def _create_memory(): nbytes = 1024 - queue = dpctl.SyclQueue() + try: + queue = dpctl.SyclQueue() + except dpctl.SyclQueueCreationError: + pytest.skip("SyclQueue() failed, skip further testing...") mobj = MemoryUSMShared(nbytes, alignment=64, queue=queue) return mobj @@ -90,10 +91,6 @@ def _create_host_buf(nbytes): return ba -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_memory_without_context(): mobj = _create_memory() @@ -102,7 +99,6 @@ def test_memory_without_context(): assert mobj.get_usm_type(syclobj=dpctl.SyclContext()) == "shared" -@pytest.mark.skipif(not has_cpu(), reason="No SYCL CPU device available.") def test_memory_cpu_context(): mobj = _create_memory() @@ -111,7 +107,10 @@ def test_memory_cpu_context(): usm_type = mobj.get_usm_type() assert usm_type == "shared" - cpu_queue = dpctl.SyclQueue("cpu") + try: + cpu_queue = dpctl.SyclQueue("cpu") + except dpctl.SyclQueueCreationError: + pytest.skip("SyclQueue('cpu') failed, skip further testing") # type as view from CPU queue usm_type = mobj.get_usm_type(cpu_queue) # type can be unknown if current queue is @@ -119,22 +118,20 @@ def test_memory_cpu_context(): assert usm_type in ["unknown", "shared"] -@pytest.mark.skipif(not has_gpu(), reason="No OpenCL GPU queues available") def test_memory_gpu_context(): mobj = _create_memory() # GPU context usm_type = mobj.get_usm_type() assert usm_type == "shared" - gpu_queue = dpctl.SyclQueue("opencl:gpu") + try: + gpu_queue = dpctl.SyclQueue("opencl:gpu") + except dpctl.SyclQueueCreationError: + pytest.skip("SyclQueue('opencl:gpu') failed, skipping") usm_type = mobj.get_usm_type(gpu_queue) assert usm_type in ["unknown", "shared"] -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_buffer_protocol(): mobj = _create_memory() mv1 = memoryview(mobj) @@ -142,10 +139,6 @@ def test_buffer_protocol(): assert mv1 == mv2 -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_copy_host_roundtrip(): mobj = _create_memory() host_src_obj = _create_host_buf(mobj.nbytes) @@ -155,10 +148,6 @@ def test_copy_host_roundtrip(): assert host_src_obj == host_dest_obj -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_zero_copy(): mobj = _create_memory() mobj2 = type(mobj)(mobj) @@ -169,14 +158,13 @@ def test_zero_copy(): assert mobj_data == mobj2_data -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_pickling(memory_ctor): import pickle - mobj = memory_ctor(1024, alignment=64) + try: + mobj = memory_ctor(1024, alignment=64) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") host_src_obj = _create_host_buf(mobj.nbytes) mobj.copy_from_host(host_src_obj) @@ -192,14 +180,13 @@ def test_pickling(memory_ctor): ), "Pickling/unpickling should be changing pointer" -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_pickling_reconstructor_invalid_type(memory_ctor): import pickle - mobj = memory_ctor(1024, alignment=64) + try: + mobj = memory_ctor(1024, alignment=64) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") good_pickle_bytes = pickle.dumps(mobj) usm_types = expected_usm_type_str(memory_ctor).encode("utf-8") i = good_pickle_bytes.rfind(usm_types) @@ -231,48 +218,44 @@ def expected_usm_type_enum(ctor): return mapping.get(ctor, 0) -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_create_with_size_and_alignment_and_queue(memory_ctor): - q = dpctl.SyclQueue() + try: + q = dpctl.SyclQueue() + except dpctl.SyclQueueCreationError: + pytest.skip("SyclQueue() failed, skip further testing") m = memory_ctor(1024, alignment=64, queue=q) assert m.nbytes == 1024 assert m.get_usm_type() == expected_usm_type_str(memory_ctor) assert m.get_usm_type_enum() == expected_usm_type_enum(memory_ctor) -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_create_with_size_and_queue(memory_ctor): - q = dpctl.SyclQueue() + try: + q = dpctl.SyclQueue() + except dpctl.SyclQueueCreationError: + pytest.skip("SyclQueue() failed, skip further testing") m = memory_ctor(1024, queue=q) assert m.nbytes == 1024 assert m.get_usm_type() == expected_usm_type_str(memory_ctor) assert m.get_usm_type_enum() == expected_usm_type_enum(memory_ctor) -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_create_with_size_and_alignment(memory_ctor): - m = memory_ctor(1024, alignment=64) + try: + m = memory_ctor(1024, alignment=64) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") assert m.nbytes == 1024 assert m.get_usm_type() == expected_usm_type_str(memory_ctor) assert m.get_usm_type_enum() == expected_usm_type_enum(memory_ctor) -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) -def test_usm_type_execeptions(): +def test_usm_type_exceptions(): ctor = MemoryUSMDevice - m = ctor(1024) + try: + m = ctor(1024) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") assert m.nbytes == 1024 q = m.sycl_queue assert m.get_usm_type(syclobj=q) == expected_usm_type_str(ctor) @@ -286,12 +269,11 @@ def test_usm_type_execeptions(): m.get_usm_type_enum(syclobj=list()) -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_sycl_usm_array_interface(memory_ctor): - m = memory_ctor(256) + try: + m = memory_ctor(256) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") m2 = Dummy(m.nbytes) hb = np.random.randint(0, 256, size=256, dtype="|u1") m2.copy_from_host(hb) @@ -552,15 +534,14 @@ def test_with_constructor(memory_ctor): check_view(v) -@pytest.mark.skipif( - not has_sycl_platforms(), - reason="No SYCL devices except the default host device.", -) def test_cpython_api(memory_ctor): import ctypes import sys - mobj = memory_ctor(1024) + try: + mobj = memory_ctor(1024) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") mod = sys.modules[mobj.__class__.__module__] # get capsules storing function pointers mem_ptr_fn_cap = mod.__pyx_capi__["Memory_GetUsmPointer"] diff --git a/dpctl/tests/test_tensor_asarray.py b/dpctl/tests/test_tensor_asarray.py index 7a92a7ce32..2c1b6501a9 100644 --- a/dpctl/tests/test_tensor_asarray.py +++ b/dpctl/tests/test_tensor_asarray.py @@ -34,7 +34,10 @@ ], ) def test_asarray_change_usm_type(src_usm_type, dst_usm_type): - d = dpctl.SyclDevice() + try: + d = dpctl.SyclDevice() + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") X = dpt.empty(10, dtype="u1", usm_type=src_usm_type) Y = dpt.asarray(X, usm_type=dst_usm_type) assert X.shape == Y.shape @@ -61,7 +64,10 @@ def test_asarray_change_usm_type(src_usm_type, dst_usm_type): def test_asarray_from_numpy(): Xnp = np.arange(10) - Y = dpt.asarray(Xnp, usm_type="device") + try: + Y = dpt.asarray(Xnp, usm_type="device") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") assert type(Y) is dpt.usm_ndarray assert Y.shape == Xnp.shape assert Y.dtype == Xnp.dtype @@ -81,7 +87,10 @@ def test_asarray_from_numpy(): def test_asarray_from_sequence(): X = [1, 2, 3] - Y = dpt.asarray(X, usm_type="device") + try: + Y = dpt.asarray(X, usm_type="device") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") assert type(Y) is dpt.usm_ndarray X = [(1, 1), (2.0, 2.0 + 1.0j), range(4, 6), np.array([3, 4], dtype="c16")] @@ -114,7 +123,10 @@ def __init__(self, obj, iface): self.obj = obj self.__sycl_usm_array_interface__ = iface - X = dpt.empty((2, 3, 4), dtype="f4") + try: + X = dpt.empty((2, 3, 4), dtype="f4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") Y = dpt.asarray(Dummy(X, X.__sycl_usm_array_interface__)) assert Y.shape == X.shape assert X.usm_type == Y.usm_type @@ -141,9 +153,14 @@ def test_asarray_input_validation(): with pytest.raises(ValueError): # usm_type has wrong value dpt.asarray([1], usm_type="mistake") + try: + wrong_queue_type = dpctl.SyclContext() + except dpctl.SyclContextCreationError: + # use any other type + wrong_queue_type = Ellipsis with pytest.raises(TypeError): # sycl_queue type is not right - dpt.asarray([1], sycl_queue=dpctl.SyclContext()) + dpt.asarray([1], sycl_queue=wrong_queue_type) with pytest.raises(ValueError): # sequence is not rectangular dpt.asarray([[1], 2]) @@ -170,7 +187,10 @@ def test_asarray_input_validation2(): def test_asarray_scalars(): import ctypes - Y = dpt.asarray(5) + try: + Y = dpt.asarray(5) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") assert Y.dtype == dpt.dtype(int) Y = dpt.asarray(5.2) if Y.sycl_device.has_aspect_fp64: diff --git a/dpctl/tests/test_usm_ndarray_ctor.py b/dpctl/tests/test_usm_ndarray_ctor.py index 844993f4fa..affdbcc4da 100644 --- a/dpctl/tests/test_usm_ndarray_ctor.py +++ b/dpctl/tests/test_usm_ndarray_ctor.py @@ -161,7 +161,10 @@ def test_properties(dt): """ Test that properties execute """ - X = dpt.usm_ndarray((3, 4, 5), dtype=dt) + try: + X = dpt.usm_ndarray((3, 4, 5), dtype=dt) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") assert isinstance(X.sycl_queue, dpctl.SyclQueue) assert isinstance(X.sycl_device, dpctl.SyclDevice) assert isinstance(X.sycl_context, dpctl.SyclContext) @@ -193,7 +196,10 @@ def test_properties(dt): @pytest.mark.parametrize("shape", [tuple(), (1,), (1, 1), (1, 1, 1)]) @pytest.mark.parametrize("dtype", ["|b1", "|u2", "|f4", "|i8"]) def test_copy_scalar_with_func(func, shape, dtype): - X = dpt.usm_ndarray(shape, dtype=dtype) + try: + X = dpt.usm_ndarray(shape, dtype=dtype) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") Y = np.arange(1, X.size + 1, dtype=dtype).reshape(shape) X.usm_data.copy_from_host(Y.reshape(-1).view("|u1")) assert func(X) == func(Y) @@ -205,7 +211,10 @@ def test_copy_scalar_with_func(func, shape, dtype): @pytest.mark.parametrize("shape", [tuple(), (1,), (1, 1), (1, 1, 1)]) @pytest.mark.parametrize("dtype", ["|b1", "|u2", "|f4", "|i8"]) def test_copy_scalar_with_method(method, shape, dtype): - X = dpt.usm_ndarray(shape, dtype=dtype) + try: + X = dpt.usm_ndarray(shape, dtype=dtype) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") Y = np.arange(1, X.size + 1, dtype=dtype).reshape(shape) X.usm_data.copy_from_host(Y.reshape(-1).view("|u1")) assert getattr(X, method)() == getattr(Y, method)() @@ -214,7 +223,10 @@ def test_copy_scalar_with_method(method, shape, dtype): @pytest.mark.parametrize("func", [bool, float, int, complex]) @pytest.mark.parametrize("shape", [(2,), (1, 2), (3, 4, 5), (0,)]) def test_copy_scalar_invalid_shape(func, shape): - X = dpt.usm_ndarray(shape, dtype="i8") + try: + X = dpt.usm_ndarray(shape, dtype="i8") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") with pytest.raises(ValueError): func(X) @@ -222,7 +234,10 @@ def test_copy_scalar_invalid_shape(func, shape): def test_index_noninteger(): import operator - X = dpt.usm_ndarray(1, "f4") + try: + X = dpt.usm_ndarray(1, "f4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") with pytest.raises(IndexError): operator.index(X) @@ -251,7 +266,10 @@ def test_index_noninteger(): ], ) def test_basic_slice(ind): - X = dpt.usm_ndarray((2 * 3, 2 * 4, 3 * 5, 2 * 7), dtype="u1") + try: + X = dpt.usm_ndarray((2 * 3, 2 * 4, 3 * 5, 2 * 7), dtype="u1") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") Xnp = np.empty(X.shape, dtype=X.dtype) S = X[ind] Snp = Xnp[ind] @@ -262,7 +280,10 @@ def test_basic_slice(ind): def test_empty_slice(): # see gh801 - X = dpt.empty((1, 0, 1), dtype="u1") + try: + X = dpt.empty((1, 0, 1), dtype="u1") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") Y = X[:, ::-1, :] assert Y.shape == X.shape Z = X[:, ::2, :] @@ -279,7 +300,10 @@ def test_empty_slice(): def test_slice_constructor_1d(): Xh = np.arange(37, dtype="i4") - Xusm = dpt.arange(Xh.size, dtype="i4") + try: + Xusm = dpt.arange(Xh.size, dtype="i4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") for ind in [ slice(1, None, 2), slice(0, None, 3), @@ -297,7 +321,10 @@ def test_slice_constructor_1d(): def test_slice_constructor_3d(): Xh = np.ones((37, 24, 35), dtype="i4") - Xusm = dpt.ones(Xh.shape, dtype=Xh.dtype) + try: + Xusm = dpt.ones(Xh.shape, dtype=Xh.dtype) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") for ind in [ slice(1, None, 2), slice(0, None, 3), @@ -317,7 +344,10 @@ def test_slice_constructor_3d(): @pytest.mark.parametrize("usm_type", ["device", "shared", "host"]) def test_slice_suai(usm_type): Xh = np.arange(0, 10, dtype="u1") - Xusm = dpt.arange(0, 10, dtype="u1", usm_type=usm_type) + try: + Xusm = dpt.arange(0, 10, dtype="u1", usm_type=usm_type) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") for ind in [slice(2, 3, None), slice(5, 7, None), slice(3, 9, None)]: assert np.array_equal( dpm.as_usm_memory(Xusm[ind]).copy_to_host(), Xh[ind] @@ -325,7 +355,10 @@ def test_slice_suai(usm_type): def test_slicing_basic(): - Xusm = dpt.usm_ndarray((10, 5), dtype="c8") + try: + Xusm = dpt.usm_ndarray((10, 5), dtype="c8") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") Xusm[None] Xusm[...] Xusm[8] @@ -360,7 +393,10 @@ def test_ctor_invalid_order(): def test_ctor_buffer_kwarg(): - dpt.usm_ndarray(10, dtype="i8", buffer=b"device") + try: + dpt.usm_ndarray(10, dtype="i8", buffer=b"device") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") with pytest.raises(ValueError): dpt.usm_ndarray(10, buffer="invalid_param") Xusm = dpt.usm_ndarray((10, 5), dtype="c8") @@ -373,7 +409,10 @@ def test_ctor_buffer_kwarg(): def test_usm_ndarray_props(): - Xusm = dpt.usm_ndarray((10, 5), dtype="c8", order="F") + try: + Xusm = dpt.usm_ndarray((10, 5), dtype="c8", order="F") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") Xusm.ndim repr(Xusm) Xusm.flags @@ -390,7 +429,10 @@ def test_usm_ndarray_props(): def test_datapi_device(): - X = dpt.usm_ndarray(1, dtype="i4") + try: + X = dpt.usm_ndarray(1, dtype="i4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") dev_t = type(X.device) with pytest.raises(TypeError): dev_t() @@ -433,7 +475,10 @@ def _pyx_capi_fnptr_to_callable( def test_pyx_capi_get_data(): - X = dpt.usm_ndarray(17, dtype="i8")[1::2] + try: + X = dpt.usm_ndarray(17, dtype="i8")[1::2] + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") get_data_fn = _pyx_capi_fnptr_to_callable( X, "UsmNDArray_GetData", @@ -447,7 +492,10 @@ def test_pyx_capi_get_data(): def test_pyx_capi_get_shape(): - X = dpt.usm_ndarray(17, dtype="u4")[1::2] + try: + X = dpt.usm_ndarray(17, dtype="u4")[1::2] + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") get_shape_fn = _pyx_capi_fnptr_to_callable( X, "UsmNDArray_GetShape", @@ -461,7 +509,10 @@ def test_pyx_capi_get_shape(): def test_pyx_capi_get_strides(): - X = dpt.usm_ndarray(17, dtype="f4")[1::2] + try: + X = dpt.usm_ndarray(17, dtype="f4")[1::2] + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") get_strides_fn = _pyx_capi_fnptr_to_callable( X, "UsmNDArray_GetStrides", @@ -478,7 +529,10 @@ def test_pyx_capi_get_strides(): def test_pyx_capi_get_ndim(): - X = dpt.usm_ndarray(17, dtype="?")[1::2] + try: + X = dpt.usm_ndarray(17, dtype="?")[1::2] + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") get_ndim_fn = _pyx_capi_fnptr_to_callable( X, "UsmNDArray_GetNDim", @@ -490,7 +544,10 @@ def test_pyx_capi_get_ndim(): def test_pyx_capi_get_typenum(): - X = dpt.usm_ndarray(17, dtype="c8")[1::2] + try: + X = dpt.usm_ndarray(17, dtype="c8")[1::2] + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") get_typenum_fn = _pyx_capi_fnptr_to_callable( X, "UsmNDArray_GetTypenum", @@ -504,7 +561,10 @@ def test_pyx_capi_get_typenum(): def test_pyx_capi_get_elemsize(): - X = dpt.usm_ndarray(17, dtype="u8")[1::2] + try: + X = dpt.usm_ndarray(17, dtype="u8")[1::2] + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") get_elemsize_fn = _pyx_capi_fnptr_to_callable( X, "UsmNDArray_GetElementSize", @@ -518,7 +578,10 @@ def test_pyx_capi_get_elemsize(): def test_pyx_capi_get_flags(): - X = dpt.usm_ndarray(17, dtype="i8")[1::2] + try: + X = dpt.usm_ndarray(17, dtype="i8")[1::2] + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") get_flags_fn = _pyx_capi_fnptr_to_callable( X, "UsmNDArray_GetFlags", @@ -531,7 +594,10 @@ def test_pyx_capi_get_flags(): def test_pyx_capi_get_offset(): - X = dpt.usm_ndarray(17, dtype="u2")[1::2] + try: + X = dpt.usm_ndarray(17, dtype="u2")[1::2] + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") get_offset_fn = _pyx_capi_fnptr_to_callable( X, "UsmNDArray_GetOffset", @@ -545,7 +611,10 @@ def test_pyx_capi_get_offset(): def test_pyx_capi_get_queue_ref(): - X = dpt.usm_ndarray(17, dtype="i2")[1::2] + try: + X = dpt.usm_ndarray(17, dtype="i2")[1::2] + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") get_queue_ref_fn = _pyx_capi_fnptr_to_callable( X, "UsmNDArray_GetQueueRef", @@ -789,7 +858,10 @@ def _pyx_capi_int(X, pyx_capi_name, caps_name=b"int", val_restype=ctypes.c_int): def test_pyx_capi_check_constants(): - X = dpt.usm_ndarray(17, dtype="i1")[1::2] + try: + X = dpt.usm_ndarray(17, dtype="i1")[1::2] + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") cc_flag = _pyx_capi_int(X, "USM_ARRAY_C_CONTIGUOUS") assert cc_flag > 0 and 0 == (cc_flag & (cc_flag - 1)) fc_flag = _pyx_capi_int(X, "USM_ARRAY_F_CONTIGUOUS") @@ -996,7 +1068,10 @@ def relaxed_strides_equal(st1, st2, sh): 4, 5, ) - X = dpt.usm_ndarray(sh_s, dtype="i8") + try: + X = dpt.usm_ndarray(sh_s, dtype="i8") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") X.shape = sh_f assert X.shape == sh_f assert relaxed_strides_equal(X.strides, cc_strides(sh_f), sh_f) @@ -1054,7 +1129,10 @@ def relaxed_strides_equal(st1, st2, sh): def test_len(): - X = dpt.usm_ndarray(1, "i4") + try: + X = dpt.usm_ndarray(1, "i4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") assert len(X) == 1 X = dpt.usm_ndarray((2, 1), "i4") assert len(X) == 2 @@ -1064,20 +1142,29 @@ def test_len(): def test_array_namespace(): - X = dpt.usm_ndarray(1, "i4") + try: + X = dpt.usm_ndarray(1, "i4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") X.__array_namespace__() X._set_namespace(dpt) assert X.__array_namespace__() is dpt def test_dlpack(): - X = dpt.usm_ndarray(1, "i4") + try: + X = dpt.usm_ndarray(1, "i4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") X.__dlpack_device__() X.__dlpack__(stream=None) def test_to_device(): - X = dpt.usm_ndarray(1, "f4") + try: + X = dpt.usm_ndarray(1, "f4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") for dev in dpctl.get_devices(): if dev.default_selector_score > 0: Y = X.to_device(dev) @@ -1095,7 +1182,10 @@ def test_to_device_migration(): def test_astype(): - X = dpt.empty((5, 5), dtype="i4") + try: + X = dpt.empty((5, 5), dtype="i4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") X[:] = np.full((5, 5), 7, dtype="i4") Y = dpt.astype(X, "c8", order="C") assert np.allclose(dpt.to_numpy(Y), np.full((5, 5), 7, dtype="c8")) @@ -1109,13 +1199,19 @@ def test_astype(): def test_astype_invalid_order(): - X = dpt.usm_ndarray(5, "i4") + try: + X = dpt.usm_ndarray(5, "i4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") with pytest.raises(ValueError): dpt.astype(X, "i4", order="WRONG") def test_copy(): - X = dpt.usm_ndarray((5, 5), "i4")[2:4, 1:4] + try: + X = dpt.usm_ndarray((5, 5), "i4")[2:4, 1:4] + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") X[:] = 42 Yc = dpt.copy(X, order="C") Yf = dpt.copy(X, order="F") @@ -1137,7 +1233,10 @@ def test_copy(): def test_ctor_invalid(): - m = dpm.MemoryUSMShared(12) + try: + m = dpm.MemoryUSMShared(12) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") with pytest.raises(ValueError): dpt.usm_ndarray((4,), dtype="i4", buffer=m) m = dpm.MemoryUSMShared(64) @@ -1146,7 +1245,10 @@ def test_ctor_invalid(): def test_reshape(): - X = dpt.usm_ndarray((5, 5), "i4") + try: + X = dpt.usm_ndarray((5, 5), "i4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") # can be done as views Y = dpt.reshape(X, (25,)) assert Y.shape == (25,) @@ -1192,7 +1294,10 @@ def test_reshape(): def test_reshape_copy_kwrd(): - X = dpt.usm_ndarray((2, 3), "i4") + try: + X = dpt.usm_ndarray((2, 3), "i4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") new_shape = (6,) Z = dpt.reshape(X, new_shape, copy=True) assert Z.shape == new_shape @@ -1208,7 +1313,10 @@ def test_reshape_copy_kwrd(): def test_transpose(): n, m = 2, 3 - X = dpt.usm_ndarray((n, m), "f4") + try: + X = dpt.usm_ndarray((n, m), "f4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") Xnp = np.arange(n * m, dtype="f4").reshape((n, m)) X[:] = Xnp assert np.array_equal(dpt.to_numpy(X.T), Xnp.T) @@ -1217,7 +1325,10 @@ def test_transpose(): def test_real_imag_views(): n, m = 2, 3 - X = dpt.usm_ndarray((n, m), "c8") + try: + X = dpt.usm_ndarray((n, m), "c8") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") Xnp_r = np.arange(n * m, dtype="f4").reshape((n, m)) Xnp_i = np.arange(n * m, 2 * n * m, dtype="f4").reshape((n, m)) Xnp = Xnp_r + 1j * Xnp_i @@ -1262,10 +1373,22 @@ def test_full(dtype): def test_full_dtype_inference(): - assert np.issubdtype(dpt.full(10, 4).dtype, np.integer) - assert dpt.full(10, True).dtype is dpt.dtype(np.bool_) + try: + X = dpt.full(10, 4) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") + assert np.issubdtype(X.dtype, np.integer) + try: + X = dpt.full(10, True) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") + assert X.dtype is dpt.dtype(np.bool_) assert np.issubdtype(dpt.full(10, 12.3).dtype, np.floating) - cdt = dpt.full(10, 0.3 - 2j).dtype + try: + X = dpt.full(10, 0.3 - 2j) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") + cdt = X.dtype assert np.issubdtype(cdt, np.complexfloating) assert np.issubdtype(dpt.full(10, 12.3, dtype=int).dtype, np.integer) @@ -1488,7 +1611,10 @@ def test_empty_like(dt, usm_kind): def test_empty_unexpected_data_type(): with pytest.raises(TypeError): - dpt.empty(1, dtype=np.object_) + try: + dpt.empty(1, dtype=np.object_) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") @pytest.mark.parametrize( @@ -1815,7 +1941,10 @@ def test_common_arg_validation(): dpt.full(10, 1, order=order) with pytest.raises(ValueError): dpt.eye(10, order=order) - X = dpt.empty(10) + try: + X = dpt.empty(10) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") with pytest.raises(ValueError): dpt.empty_like(X, order=order) with pytest.raises(ValueError): @@ -1843,7 +1972,10 @@ def test_common_arg_validation(): def test_flags(): - x = dpt.empty(tuple(), "i4") + try: + x = dpt.empty(tuple(), "i4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") f = x.flags f.__repr__() assert f.c_contiguous == f["C"] @@ -1859,7 +1991,10 @@ def test_flags(): def test_asarray_uint64(): Xnp = np.ndarray(1, dtype=np.uint64) - X = dpt.asarray(Xnp) + try: + X = dpt.asarray(Xnp) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") assert X.dtype == Xnp.dtype diff --git a/dpctl/tests/test_usm_ndarray_dlpack.py b/dpctl/tests/test_usm_ndarray_dlpack.py index e442cff43f..5801ddf2d1 100644 --- a/dpctl/tests/test_usm_ndarray_dlpack.py +++ b/dpctl/tests/test_usm_ndarray_dlpack.py @@ -85,7 +85,10 @@ def test_dlpack_exporter_empty(typestr, usm_type): caps_fn = ctypes.pythonapi.PyCapsule_IsValid caps_fn.restype = bool caps_fn.argtypes = [ctypes.py_object, ctypes.c_char_p] - sycl_dev = dpctl.select_default_device() + try: + sycl_dev = dpctl.select_default_device() + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") skip_if_dtype_not_supported(typestr, sycl_dev) X = dpt.empty((0,), dtype=typestr, usm_type=usm_type, device=sycl_dev) caps = X.__dlpack__() diff --git a/dpctl/tests/test_usm_ndarray_manipulation.py b/dpctl/tests/test_usm_ndarray_manipulation.py index 282cbe0b9a..1cee5e6c8f 100644 --- a/dpctl/tests/test_usm_ndarray_manipulation.py +++ b/dpctl/tests/test_usm_ndarray_manipulation.py @@ -20,6 +20,7 @@ from helper import get_queue_or_skip from numpy.testing import assert_, assert_array_equal, assert_raises_regex +import dpctl import dpctl.tensor as dpt @@ -139,7 +140,10 @@ def test_expand_dims_tuple(axes): def test_expand_dims_incorrect_tuple(): - X = dpt.empty((3, 3, 3), dtype="i4") + try: + X = dpt.empty((3, 3, 3), dtype="i4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") with pytest.raises(np.AxisError): dpt.expand_dims(X, (0, -6)) with pytest.raises(np.AxisError): @@ -1014,7 +1018,11 @@ def test_moveaxis_move_multiples(shape, source, destination, expected): def test_moveaxis_errors(): - x = dpt.reshape(dpt.arange(6), (1, 2, 3)) + try: + x_flat = dpt.arange(6) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") + x = dpt.reshape(x_flat, (1, 2, 3)) assert_raises_regex( np.AxisError, "source.*out of bounds", dpt.moveaxis, x, 3, 0 ) @@ -1044,7 +1052,11 @@ def test_moveaxis_errors(): def test_unstack_axis0(): - y = dpt.reshape(dpt.arange(6), (2, 3)) + try: + x_flat = dpt.arange(6) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") + y = dpt.reshape(x_flat, (2, 3)) res = dpt.unstack(y) assert_array_equal(dpt.asnumpy(y[0, ...]), dpt.asnumpy(res[0])) @@ -1052,7 +1064,11 @@ def test_unstack_axis0(): def test_unstack_axis1(): - y = dpt.reshape(dpt.arange(6), (2, 3)) + try: + x_flat = dpt.arange(6) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") + y = dpt.reshape(x_flat, (2, 3)) res = dpt.unstack(y, 1) assert_array_equal(dpt.asnumpy(y[:, 0, ...]), dpt.asnumpy(res[0])) @@ -1061,7 +1077,11 @@ def test_unstack_axis1(): def test_unstack_axis2(): - y = dpt.reshape(dpt.arange(60), (4, 5, 3)) + try: + x_flat = dpt.arange(60) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") + y = dpt.reshape(x_flat, (4, 5, 3)) res = dpt.unstack(y, 2) assert_array_equal(dpt.asnumpy(y[:, :, 0, ...]), dpt.asnumpy(res[0])) diff --git a/dpctl/tests/test_usm_ndarray_operators.py b/dpctl/tests/test_usm_ndarray_operators.py index 98211c0780..92dc38bd47 100644 --- a/dpctl/tests/test_usm_ndarray_operators.py +++ b/dpctl/tests/test_usm_ndarray_operators.py @@ -16,6 +16,7 @@ import pytest +import dpctl import dpctl.tensor as dpt @@ -48,7 +49,10 @@ def multiply(a, b): @pytest.mark.parametrize("namespace", [None, Dummy()]) def test_fp_ops(namespace): - X = dpt.ones(1) + try: + X = dpt.ones(1) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") X._set_namespace(namespace) assert X.__array_namespace__() is namespace X[0] = -2.5 @@ -79,7 +83,10 @@ def test_fp_ops(namespace): @pytest.mark.parametrize("namespace", [None, Dummy()]) def test_int_ops(namespace): - X = dpt.usm_ndarray(1, "i4") + try: + X = dpt.usm_ndarray(1, "i4") + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") X._set_namespace(namespace) assert X.__array_namespace__() is namespace X.__lshift__(2) @@ -108,7 +115,10 @@ def test_int_ops(namespace): @pytest.mark.parametrize("namespace", [None, Dummy()]) def test_mat_ops(namespace): - M = dpt.eye(3, 3) + try: + M = dpt.eye(3, 3) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") M._set_namespace(namespace) assert M.__array_namespace__() is namespace M.__matmul__(M) diff --git a/dpctl/tests/test_usm_ndarray_print.py b/dpctl/tests/test_usm_ndarray_print.py index e876a8a6d0..09b292fa73 100644 --- a/dpctl/tests/test_usm_ndarray_print.py +++ b/dpctl/tests/test_usm_ndarray_print.py @@ -18,6 +18,7 @@ import pytest from helper import get_queue_or_skip, skip_if_dtype_not_supported +import dpctl import dpctl.tensor as dpt @@ -53,7 +54,10 @@ def test_usm_ndarray_repr_arg_validation(self): with pytest.raises(TypeError): dpt.usm_ndarray_repr(X) - X = dpt.arange(4) + try: + X = dpt.arange(4) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") with pytest.raises(TypeError): dpt.usm_ndarray_repr(X, line_width="I") @@ -68,7 +72,11 @@ def test_usm_ndarray_str_arg_validation(self): with pytest.raises(TypeError): dpt.usm_ndarray_str(X) - X = dpt.arange(4) + try: + X = dpt.arange(4) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") + with pytest.raises(TypeError): dpt.usm_ndarray_str(X, line_width="I") @@ -363,8 +371,12 @@ def test_usm_ndarray_repr_prefix(self): class TestContextManager: def test_context_manager_basic(self): options = dpt.get_print_options() + try: + X = dpt.asarray(1.234567) + except dpctl.SyclDeviceCreationError: + pytest.skip("No SYCL devices available") with dpt.print_options(precision=4): - s = str(dpt.asarray(1.234567)) + s = str(X) assert s == "1.2346" assert options == dpt.get_print_options() diff --git a/libsyclinterface/source/dpctl_sycl_device_manager.cpp b/libsyclinterface/source/dpctl_sycl_device_manager.cpp index 71160089cb..014299721b 100644 --- a/libsyclinterface/source/dpctl_sycl_device_manager.cpp +++ b/libsyclinterface/source/dpctl_sycl_device_manager.cpp @@ -116,9 +116,15 @@ struct DeviceCacheBuilder static const DeviceCache &getDeviceCache() { static DeviceCache *cache = new DeviceCache([] { - DeviceCache cache_l; + DeviceCache cache_l{}; dpctl_default_selector mRanker; - auto Platforms = platform::get_platforms(); + std::vector Platforms{}; + try { + Platforms = platform::get_platforms(); + } catch (std::exception const &e) { + error_handler(e, __FILE__, __func__, __LINE__); + return cache_l; + } for (const auto &P : Platforms) { auto Devices = P.get_devices(); for (const auto &D : Devices) { @@ -169,7 +175,15 @@ DPCTLDeviceMgr_GetCachedContext(__dpctl_keep const DPCTLSyclDeviceRef DRef) __FILE__, __func__, __LINE__); return CRef; } - auto &cache = DeviceCacheBuilder::getDeviceCache(); + + using CacheT = typename DeviceCacheBuilder::DeviceCache; + CacheT const &cache = DeviceCacheBuilder::getDeviceCache(); + + if (cache.empty()) { + // an exception was caught and logged by getDeviceCache + return nullptr; + } + auto entry = cache.find(*Device); if (entry != cache.end()) { context *ContextPtr = nullptr; @@ -208,7 +222,14 @@ DPCTLDeviceMgr_GetDevices(int device_identifier) if (!device_identifier) return wrap(Devices); - const auto &root_devices = device::get_devices(); + std::vector root_devices; + try { + root_devices = device::get_devices(); + } catch (std::exception const &e) { + delete Devices; + error_handler(e, __FILE__, __func__, __LINE__); + return nullptr; + } dpctl_default_selector mRanker; for (const auto &root_device : root_devices) { @@ -282,7 +303,13 @@ int DPCTLDeviceMgr_GetPositionInDevices(__dpctl_keep DPCTLSyclDeviceRef DRef, size_t DPCTLDeviceMgr_GetNumDevices(int device_identifier) { size_t nDevices = 0; - auto &cache = DeviceCacheBuilder::getDeviceCache(); + using CacheT = typename DeviceCacheBuilder::DeviceCache; + CacheT const &cache = DeviceCacheBuilder::getDeviceCache(); + + if (cache.empty()) { + // an exception was caught and logged by getDeviceCache + return 0; + } device_identifier = to_canonical_device_id(device_identifier); if (!device_identifier) diff --git a/libsyclinterface/source/dpctl_sycl_platform_interface.cpp b/libsyclinterface/source/dpctl_sycl_platform_interface.cpp index b72d828b09..2083259611 100644 --- a/libsyclinterface/source/dpctl_sycl_platform_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_platform_interface.cpp @@ -194,7 +194,13 @@ __dpctl_give DPCTLPlatformVectorRef DPCTLPlatform_GetPlatforms() using vecTy = std::vector; vecTy *Platforms = nullptr; - auto platforms = platform::get_platforms(); + std::vector platforms; + try { + platforms = platform::get_platforms(); + } catch (std::exception const &e) { + error_handler(e, __FILE__, __func__, __LINE__); + return nullptr; + } try { Platforms = new vecTy(); diff --git a/pyproject.toml b/pyproject.toml index e6e21f2cb2..6b9aa52210 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,12 +22,14 @@ source = [ omit = [ "dpctl/tests/*", "dpctl/_version.py", + "*/_cython_api*/stringsource", ] [tool.coverage.report] omit = [ "dpctl/tests/*", "dpctl/_version.py", + "*/_cython_api*/stringsource", ] [tool.pytest.ini.options]