From 98d05290f8dba8debe23c07068a6244ba6e11e5c Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 22 May 2024 13:12:19 -0500 Subject: [PATCH 1/9] Recognize sycl::aspect::emulated --- libsyclinterface/helper/source/dpctl_utils_helper.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libsyclinterface/helper/source/dpctl_utils_helper.cpp b/libsyclinterface/helper/source/dpctl_utils_helper.cpp index 213f39a7a5..287cab3e1b 100644 --- a/libsyclinterface/helper/source/dpctl_utils_helper.cpp +++ b/libsyclinterface/helper/source/dpctl_utils_helper.cpp @@ -326,6 +326,8 @@ aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy) return aspect::usm_atomic_shared_allocations; case DPCTLSyclAspectType::host_debuggable: return aspect::host_debuggable; + case DPCTLSyclAspectType::emulated: + return aspect::emulated; default: throw std::runtime_error("Unsupported aspect type"); } @@ -370,6 +372,8 @@ DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect) return DPCTLSyclAspectType::usm_atomic_shared_allocations; case aspect::host_debuggable: return DPCTLSyclAspectType::host_debuggable; + case aspect::emulated: + return DPCTLSyclAspectType::emulated; default: throw std::runtime_error("Unsupported aspect type"); } From 244edf517669c65d3298fbeb59b558d457c0f712 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 22 May 2024 13:12:53 -0500 Subject: [PATCH 2/9] Support DPCTLSyclAspectType::emulated --- libsyclinterface/include/syclinterface/dpctl_sycl_enum_types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libsyclinterface/include/syclinterface/dpctl_sycl_enum_types.h b/libsyclinterface/include/syclinterface/dpctl_sycl_enum_types.h index c8bc0b1b20..8313db82e4 100644 --- a/libsyclinterface/include/syclinterface/dpctl_sycl_enum_types.h +++ b/libsyclinterface/include/syclinterface/dpctl_sycl_enum_types.h @@ -128,6 +128,7 @@ typedef enum usm_atomic_host_allocations, usm_atomic_shared_allocations, host_debuggable, + emulated } DPCTLSyclAspectType; /*! From 9cb17885d85d2bc289274ab49b093ac101bc159f Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 22 May 2024 13:13:35 -0500 Subject: [PATCH 3/9] Test aspect::emulated --- libsyclinterface/tests/test_sycl_device_aspects.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libsyclinterface/tests/test_sycl_device_aspects.cpp b/libsyclinterface/tests/test_sycl_device_aspects.cpp index 093c6730df..6a35c6d78b 100644 --- a/libsyclinterface/tests/test_sycl_device_aspects.cpp +++ b/libsyclinterface/tests/test_sycl_device_aspects.cpp @@ -123,7 +123,8 @@ auto build_params() sycl::aspect::usm_atomic_host_allocations), std::make_pair("usm_atomic_shared_allocations", sycl::aspect::usm_atomic_shared_allocations), - std::make_pair("host_debuggable", sycl::aspect::host_debuggable)); + std::make_pair("host_debuggable", sycl::aspect::host_debuggable), + std::make_pair("emulated", sycl::aspect::emulated)); auto pairs = build_param_pairs, From 972a4c4f25ceeb8ffa00509bb6429052ef68530d Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 22 May 2024 13:15:24 -0500 Subject: [PATCH 4/9] Support emulated aspect in _backend.pxd --- dpctl/_backend.pxd | 1 + 1 file changed, 1 insertion(+) diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index ae07e1de02..13e45f98a7 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -95,6 +95,7 @@ cdef extern from "syclinterface/dpctl_sycl_enum_types.h": _usm_atomic_host_allocations 'usm_atomic_host_allocations', _usm_atomic_shared_allocations 'usm_atomic_shared_allocations', _host_debuggable 'host_debuggable', + _emulated 'emulated', ctypedef enum _partition_affinity_domain_type 'DPCTLPartitionAffinityDomainType': _not_applicable 'not_applicable', From eebe2cc34e9264d4d656d6090a0955dc3333b4bc Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 22 May 2024 14:32:35 -0500 Subject: [PATCH 5/9] Expose has_aspect_emulated attribute for SyclDevice --- dpctl/_sycl_device.pyx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index cdbd0ac87d..e3ca5e3cec 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -770,6 +770,20 @@ cdef class SyclDevice(_SyclDevice): cdef _aspect_type AT = _aspect_type._host_debuggable return DPCTLDevice_HasAspect(self._device_ref, AT) + @property + def has_aspect_emulated(self): + """ Returns ``True`` if this device is somehow emulated, ``False`` + otherwise. A device with this aspect is not intended for performance, + and instead will generally have another purpose such as emulation + or profiling. + + Returns: + bool: + Indicates if device is somehow emulated. + """ + cdef _aspect_type AT = _aspect_type._emulated + return DPCTLDevice_HasAspect(self._device_ref, AT) + @property def image_2d_max_width(self): """ Returns the maximum width of a 2D image or 1D image in pixels. From 5a8fa2ee7b8e4964c3609352fdbd2bda2ce01de2 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 22 May 2024 14:33:10 -0500 Subject: [PATCH 6/9] Add check for has_aspect_emulated --- dpctl/tests/_device_attributes_checks.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dpctl/tests/_device_attributes_checks.py b/dpctl/tests/_device_attributes_checks.py index 466d9ca03f..d74db393b0 100644 --- a/dpctl/tests/_device_attributes_checks.py +++ b/dpctl/tests/_device_attributes_checks.py @@ -245,6 +245,13 @@ def check_has_aspect_host_debuggable(device): pytest.fail("has_aspect_host_debuggable call failed") +def check_has_aspect_emulated(device): + try: + device.has_aspect_emulated + except Exception: + pytest.fail("has_aspect_emulated call failed") + + def check_is_accelerator(device): try: device.is_accelerator @@ -698,6 +705,7 @@ def check_global_mem_cache_line_size(device): check_has_aspect_usm_atomic_host_allocations, check_has_aspect_usm_atomic_shared_allocations, check_has_aspect_host_debuggable, + check_has_aspect_emulated, check_max_read_image_args, check_max_write_image_args, check_image_2d_max_width, From 8062c0c68925b59e8c15c3cca5f52c846369028b Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 22 May 2024 14:33:49 -0500 Subject: [PATCH 7/9] Move emulated aspect from list of unsupported to list of support aspects Fixed test_unsupported_aspect to use hasattr instead of select_device_with_aspects, because system might not have any devices with specified aspect, e.g., 'emulated' aspect. --- dpctl/tests/test_sycl_device.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index f65445f73f..e85259321b 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -163,13 +163,12 @@ def test_equal(): "atomic64", "usm_atomic_host_allocations", "usm_atomic_shared_allocations", + "emulated", ] # SYCL 2020 spec aspects not presently # supported in DPC++, and dpctl -list_of_unsupported_aspects = [ - "emulated", -] +list_of_unsupported_aspects = [] @pytest.fixture(params=list_of_supported_aspects) @@ -199,14 +198,14 @@ def test_supported_aspect(supported_aspect): def test_unsupported_aspect(unsupported_aspect): try: - dpctl.select_device_with_aspects(unsupported_aspect) + d = dpctl.SyclDevice() + has_it = hasattr(d, "has_aspect_" + unsupported_aspect) + except dpctl.SyclDeviceCreationError: + has_it = False + if has_it: raise AttributeError( f"The {unsupported_aspect} aspect is now supported in dpctl" ) - except AttributeError: - pytest.skip( - f"The {unsupported_aspect} aspect is not supported in dpctl" - ) def test_handle_no_device(): From 14db26300919ec78b997e12a88a8f66daecec219 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 22 May 2024 15:12:12 -0500 Subject: [PATCH 8/9] Added missing cases for emulated aspect in switch statements --- libsyclinterface/helper/source/dpctl_utils_helper.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libsyclinterface/helper/source/dpctl_utils_helper.cpp b/libsyclinterface/helper/source/dpctl_utils_helper.cpp index 287cab3e1b..a890d26fc2 100644 --- a/libsyclinterface/helper/source/dpctl_utils_helper.cpp +++ b/libsyclinterface/helper/source/dpctl_utils_helper.cpp @@ -214,6 +214,9 @@ std::string DPCTL_AspectToStr(aspect aspectTy) case aspect::host_debuggable: ss << "host_debuggable"; break; + case aspect::emulated: + ss << "emulated"; + break; default: throw std::runtime_error("Unsupported aspect type"); } @@ -280,6 +283,9 @@ aspect DPCTL_StrToAspectType(const std::string &aspectTyStr) else if (aspectTyStr == "host_debuggable") { aspectTy = aspect::host_debuggable; } + else if (aspectTyStr == "emulated") { + aspectTy = aspect::emulated; + } else { // \todo handle the error throw std::runtime_error("Unsupported aspect type"); From 09b3c80617e612fd0217d4effedcdd2917f4f95f Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 22 May 2024 15:12:43 -0500 Subject: [PATCH 9/9] Removed unused identifier in the catch clause --- libsyclinterface/tests/test_sycl_device_aspects.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsyclinterface/tests/test_sycl_device_aspects.cpp b/libsyclinterface/tests/test_sycl_device_aspects.cpp index 6a35c6d78b..c5b8154e3e 100644 --- a/libsyclinterface/tests/test_sycl_device_aspects.cpp +++ b/libsyclinterface/tests/test_sycl_device_aspects.cpp @@ -166,7 +166,7 @@ struct TestDPCTLSyclDeviceInterfaceAspects auto syclAspect = GetParam().second.second; try { hasAspect = D->has(syclAspect); - } catch (sycl::exception const &e) { + } catch (sycl::exception const &) { } }