From 1742622b736681360cd319bf5c91afbbd373d5c5 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 28 Apr 2022 12:45:06 -0500 Subject: [PATCH 1/2] Added DPCTLDevice_GetProfilingTimerResolution --- .../include/dpctl_sycl_device_interface.h | 11 +++++++++++ .../source/dpctl_sycl_device_interface.cpp | 13 +++++++++++++ .../tests/test_sycl_device_interface.cpp | 16 ++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/libsyclinterface/include/dpctl_sycl_device_interface.h b/libsyclinterface/include/dpctl_sycl_device_interface.h index 1c8d57802d..676ab4c367 100644 --- a/libsyclinterface/include/dpctl_sycl_device_interface.h +++ b/libsyclinterface/include/dpctl_sycl_device_interface.h @@ -587,3 +587,14 @@ DPCTLDevice_GetParentDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef); */ DPCTL_API size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef); + +/*! + * @brief Wrapper over + * device.get_info + * + * @param DRef Opaque pointer to a sycl::device + * @return Returns the resolution of device timer in nanoseconds. + */ +DPCTL_API +size_t DPCTLDevice_GetProfilingTimerResolution( + __dpctl_keep const DPCTLSyclDeviceRef DRef); diff --git a/libsyclinterface/source/dpctl_sycl_device_interface.cpp b/libsyclinterface/source/dpctl_sycl_device_interface.cpp index 47109fd21c..214e3ad0d1 100644 --- a/libsyclinterface/source/dpctl_sycl_device_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_device_interface.cpp @@ -648,3 +648,16 @@ size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef) return 0; } } + +size_t DPCTLDevice_GetProfilingTimerResolution( + __dpctl_keep const DPCTLSyclDeviceRef DRef) +{ + if (DRef) { + auto D = unwrap(DRef); + return D->get_info(); + } + else { + error_handler("Argument DRef is null", __FILE__, __func__, __LINE__); + return 0; + } +} diff --git a/libsyclinterface/tests/test_sycl_device_interface.cpp b/libsyclinterface/tests/test_sycl_device_interface.cpp index a55bacecd7..17cc1f0343 100644 --- a/libsyclinterface/tests/test_sycl_device_interface.cpp +++ b/libsyclinterface/tests/test_sycl_device_interface.cpp @@ -375,6 +375,14 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkGetParentDevice) EXPECT_TRUE(pDRef == nullptr); } +TEST_P(TestDPCTLSyclDeviceInterface, ChkGetProfilingTimerResolution) +{ + size_t res = 0; + EXPECT_NO_FATAL_FAILURE(res = + DPCTLDevice_GetProfilingTimerResolution(DRef)); + EXPECT_TRUE(res != 0); +} + INSTANTIATE_TEST_SUITE_P(DPCTLDeviceFns, TestDPCTLSyclDeviceInterface, ::testing::Values("opencl", @@ -673,3 +681,11 @@ TEST_F(TestDPCTLSyclDeviceNullArgs, ChkHash) EXPECT_NO_FATAL_FAILURE(hash = DPCTLDevice_Hash(Null_DRef)); ASSERT_TRUE(hash == 0); } + +TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetProfilingTimerResolution) +{ + size_t res = 1; + EXPECT_NO_FATAL_FAILURE( + res = DPCTLDevice_GetProfilingTimerResolution(Null_DRef)); + ASSERT_TRUE(res == 0); +} From d9d1570771a353681e6801e345dc7f3f7c75c181 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 28 Apr 2022 13:21:11 -0500 Subject: [PATCH 2/2] Added SyclDevice.profiling_timer_resolution property --- dpctl/_backend.pxd | 1 + dpctl/_sycl_device.pyx | 14 ++++++++++++++ dpctl/tests/test_sycl_device.py | 11 +++++++++++ 3 files changed, 26 insertions(+) diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 4eb59e0fa3..4ff2ed1fd6 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -190,6 +190,7 @@ cdef extern from "syclinterface/dpctl_sycl_device_interface.h": const DPCTLSyclDeviceRef DRef, _partition_affinity_domain_type PartitionAffinityDomainTy) cdef DPCTLSyclDeviceRef DPCTLDevice_GetParentDevice(const DPCTLSyclDeviceRef DRef) + cdef size_t DPCTLDevice_GetProfilingTimerResolution(const DPCTLSyclDeviceRef DRef) cdef extern from "syclinterface/dpctl_sycl_device_manager.h": diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index ee30002cce..ff8ceaa591 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -57,6 +57,7 @@ from ._backend cimport ( # noqa: E211 DPCTLDevice_GetPreferredVectorWidthInt, DPCTLDevice_GetPreferredVectorWidthLong, DPCTLDevice_GetPreferredVectorWidthShort, + DPCTLDevice_GetProfilingTimerResolution, DPCTLDevice_GetSubGroupIndependentForwardProgress, DPCTLDevice_GetVendor, DPCTLDevice_HasAspect, @@ -924,6 +925,19 @@ cdef class SyclDevice(_SyclDevice): return None return SyclDevice._create(pDRef) + @property + def profiling_timer_resolution(self): + """ Profiling timer resolution. + + Returns: + int: The resolution of device timer in nanoseconds. + """ + cdef size_t timer_res = 0 + timer_res = DPCTLDevice_GetProfilingTimerResolution(self._device_ref) + if (timer_res == 0): + raise RuntimeError("Failed to get device timer resolution.") + return timer_res + cdef cpp_bool equals(self, SyclDevice other): """ Returns ``True`` if the :class:`dpctl.SyclDevice` argument has the same _device_ref as this SyclDevice. diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index 6277504ef2..77e3ae85cc 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -485,6 +485,17 @@ def check_repr(device): assert type(repr(device)) is str +def check_profiling_timer_resolution(device): + try: + resol = device.profiling_timer_resolution + except Exception: + pytest.fail( + "Encountered an exception inside " + "profiling_timer_resolution property." + ) + assert isinstance(resol, int) and resol > 0 + + list_of_checks = [ check_get_max_compute_units, check_get_max_work_item_dims,