Skip to content

Commit d9d1570

Browse files
Added SyclDevice.profiling_timer_resolution property
1 parent 1742622 commit d9d1570

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

dpctl/_backend.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ cdef extern from "syclinterface/dpctl_sycl_device_interface.h":
190190
const DPCTLSyclDeviceRef DRef,
191191
_partition_affinity_domain_type PartitionAffinityDomainTy)
192192
cdef DPCTLSyclDeviceRef DPCTLDevice_GetParentDevice(const DPCTLSyclDeviceRef DRef)
193+
cdef size_t DPCTLDevice_GetProfilingTimerResolution(const DPCTLSyclDeviceRef DRef)
193194

194195

195196
cdef extern from "syclinterface/dpctl_sycl_device_manager.h":

dpctl/_sycl_device.pyx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ from ._backend cimport ( # noqa: E211
5757
DPCTLDevice_GetPreferredVectorWidthInt,
5858
DPCTLDevice_GetPreferredVectorWidthLong,
5959
DPCTLDevice_GetPreferredVectorWidthShort,
60+
DPCTLDevice_GetProfilingTimerResolution,
6061
DPCTLDevice_GetSubGroupIndependentForwardProgress,
6162
DPCTLDevice_GetVendor,
6263
DPCTLDevice_HasAspect,
@@ -924,6 +925,19 @@ cdef class SyclDevice(_SyclDevice):
924925
return None
925926
return SyclDevice._create(pDRef)
926927

928+
@property
929+
def profiling_timer_resolution(self):
930+
""" Profiling timer resolution.
931+
932+
Returns:
933+
int: The resolution of device timer in nanoseconds.
934+
"""
935+
cdef size_t timer_res = 0
936+
timer_res = DPCTLDevice_GetProfilingTimerResolution(self._device_ref)
937+
if (timer_res == 0):
938+
raise RuntimeError("Failed to get device timer resolution.")
939+
return timer_res
940+
927941
cdef cpp_bool equals(self, SyclDevice other):
928942
""" Returns ``True`` if the :class:`dpctl.SyclDevice` argument has the
929943
same _device_ref as this SyclDevice.

dpctl/tests/test_sycl_device.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,17 @@ def check_repr(device):
485485
assert type(repr(device)) is str
486486

487487

488+
def check_profiling_timer_resolution(device):
489+
try:
490+
resol = device.profiling_timer_resolution
491+
except Exception:
492+
pytest.fail(
493+
"Encountered an exception inside "
494+
"profiling_timer_resolution property."
495+
)
496+
assert isinstance(resol, int) and resol > 0
497+
498+
488499
list_of_checks = [
489500
check_get_max_compute_units,
490501
check_get_max_work_item_dims,

0 commit comments

Comments
 (0)