Skip to content

Commit 4a06eb1

Browse files
Merge pull request #1691 from IntelPython/add-emulated-aspect
Add support for aspect::emulated
2 parents 65baa6d + 09b3c80 commit 4a06eb1

File tree

7 files changed

+44
-10
lines changed

7 files changed

+44
-10
lines changed

dpctl/_backend.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ cdef extern from "syclinterface/dpctl_sycl_enum_types.h":
9595
_usm_atomic_host_allocations 'usm_atomic_host_allocations',
9696
_usm_atomic_shared_allocations 'usm_atomic_shared_allocations',
9797
_host_debuggable 'host_debuggable',
98+
_emulated 'emulated',
9899

99100
ctypedef enum _partition_affinity_domain_type 'DPCTLPartitionAffinityDomainType':
100101
_not_applicable 'not_applicable',

dpctl/_sycl_device.pyx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,20 @@ cdef class SyclDevice(_SyclDevice):
778778
cdef _aspect_type AT = _aspect_type._host_debuggable
779779
return DPCTLDevice_HasAspect(self._device_ref, AT)
780780

781+
@property
782+
def has_aspect_emulated(self):
783+
""" Returns ``True`` if this device is somehow emulated, ``False``
784+
otherwise. A device with this aspect is not intended for performance,
785+
and instead will generally have another purpose such as emulation
786+
or profiling.
787+
788+
Returns:
789+
bool:
790+
Indicates if device is somehow emulated.
791+
"""
792+
cdef _aspect_type AT = _aspect_type._emulated
793+
return DPCTLDevice_HasAspect(self._device_ref, AT)
794+
781795
@property
782796
def image_2d_max_width(self):
783797
""" Returns the maximum width of a 2D image or 1D image in pixels.

dpctl/tests/_device_attributes_checks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ def check_has_aspect_host_debuggable(device):
245245
pytest.fail("has_aspect_host_debuggable call failed")
246246

247247

248+
def check_has_aspect_emulated(device):
249+
try:
250+
device.has_aspect_emulated
251+
except Exception:
252+
pytest.fail("has_aspect_emulated call failed")
253+
254+
248255
def check_is_accelerator(device):
249256
try:
250257
device.is_accelerator
@@ -698,6 +705,7 @@ def check_global_mem_cache_line_size(device):
698705
check_has_aspect_usm_atomic_host_allocations,
699706
check_has_aspect_usm_atomic_shared_allocations,
700707
check_has_aspect_host_debuggable,
708+
check_has_aspect_emulated,
701709
check_max_read_image_args,
702710
check_max_write_image_args,
703711
check_image_2d_max_width,

dpctl/tests/test_sycl_device.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,12 @@ def test_equal():
163163
"atomic64",
164164
"usm_atomic_host_allocations",
165165
"usm_atomic_shared_allocations",
166+
"emulated",
166167
]
167168

168169
# SYCL 2020 spec aspects not presently
169170
# supported in DPC++, and dpctl
170-
list_of_unsupported_aspects = [
171-
"emulated",
172-
]
171+
list_of_unsupported_aspects = []
173172

174173

175174
@pytest.fixture(params=list_of_supported_aspects)
@@ -199,14 +198,14 @@ def test_supported_aspect(supported_aspect):
199198

200199
def test_unsupported_aspect(unsupported_aspect):
201200
try:
202-
dpctl.select_device_with_aspects(unsupported_aspect)
201+
d = dpctl.SyclDevice()
202+
has_it = hasattr(d, "has_aspect_" + unsupported_aspect)
203+
except dpctl.SyclDeviceCreationError:
204+
has_it = False
205+
if has_it:
203206
raise AttributeError(
204207
f"The {unsupported_aspect} aspect is now supported in dpctl"
205208
)
206-
except AttributeError:
207-
pytest.skip(
208-
f"The {unsupported_aspect} aspect is not supported in dpctl"
209-
)
210209

211210

212211
def test_handle_no_device():

libsyclinterface/helper/source/dpctl_utils_helper.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ std::string DPCTL_AspectToStr(aspect aspectTy)
214214
case aspect::host_debuggable:
215215
ss << "host_debuggable";
216216
break;
217+
case aspect::emulated:
218+
ss << "emulated";
219+
break;
217220
default:
218221
throw std::runtime_error("Unsupported aspect type");
219222
}
@@ -280,6 +283,9 @@ aspect DPCTL_StrToAspectType(const std::string &aspectTyStr)
280283
else if (aspectTyStr == "host_debuggable") {
281284
aspectTy = aspect::host_debuggable;
282285
}
286+
else if (aspectTyStr == "emulated") {
287+
aspectTy = aspect::emulated;
288+
}
283289
else {
284290
// \todo handle the error
285291
throw std::runtime_error("Unsupported aspect type");
@@ -326,6 +332,8 @@ aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy)
326332
return aspect::usm_atomic_shared_allocations;
327333
case DPCTLSyclAspectType::host_debuggable:
328334
return aspect::host_debuggable;
335+
case DPCTLSyclAspectType::emulated:
336+
return aspect::emulated;
329337
default:
330338
throw std::runtime_error("Unsupported aspect type");
331339
}
@@ -370,6 +378,8 @@ DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect)
370378
return DPCTLSyclAspectType::usm_atomic_shared_allocations;
371379
case aspect::host_debuggable:
372380
return DPCTLSyclAspectType::host_debuggable;
381+
case aspect::emulated:
382+
return DPCTLSyclAspectType::emulated;
373383
default:
374384
throw std::runtime_error("Unsupported aspect type");
375385
}

libsyclinterface/include/syclinterface/dpctl_sycl_enum_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ typedef enum
128128
usm_atomic_host_allocations,
129129
usm_atomic_shared_allocations,
130130
host_debuggable,
131+
emulated
131132
} DPCTLSyclAspectType;
132133

133134
/*!

libsyclinterface/tests/test_sycl_device_aspects.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ auto build_params()
123123
sycl::aspect::usm_atomic_host_allocations),
124124
std::make_pair("usm_atomic_shared_allocations",
125125
sycl::aspect::usm_atomic_shared_allocations),
126-
std::make_pair("host_debuggable", sycl::aspect::host_debuggable));
126+
std::make_pair("host_debuggable", sycl::aspect::host_debuggable),
127+
std::make_pair("emulated", sycl::aspect::emulated));
127128

128129
auto pairs =
129130
build_param_pairs<const char *, std::pair<const char *, sycl::aspect>,
@@ -165,7 +166,7 @@ struct TestDPCTLSyclDeviceInterfaceAspects
165166
auto syclAspect = GetParam().second.second;
166167
try {
167168
hasAspect = D->has(syclAspect);
168-
} catch (sycl::exception const &e) {
169+
} catch (sycl::exception const &) {
169170
}
170171
}
171172

0 commit comments

Comments
 (0)