Skip to content

Commit ecae1c6

Browse files
Profiling timer resolution device property (#825)
* Added DPCTLDevice_GetProfilingTimerResolution * Added SyclDevice.profiling_timer_resolution property
2 parents 8ad3e1c + d9d1570 commit ecae1c6

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-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,

libsyclinterface/include/dpctl_sycl_device_interface.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,3 +587,14 @@ DPCTLDevice_GetParentDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef);
587587
*/
588588
DPCTL_API
589589
size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef);
590+
591+
/*!
592+
* @brief Wrapper over
593+
* device.get_info<info::device::profiling_timer_resolution>
594+
*
595+
* @param DRef Opaque pointer to a sycl::device
596+
* @return Returns the resolution of device timer in nanoseconds.
597+
*/
598+
DPCTL_API
599+
size_t DPCTLDevice_GetProfilingTimerResolution(
600+
__dpctl_keep const DPCTLSyclDeviceRef DRef);

libsyclinterface/source/dpctl_sycl_device_interface.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,3 +648,16 @@ size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef)
648648
return 0;
649649
}
650650
}
651+
652+
size_t DPCTLDevice_GetProfilingTimerResolution(
653+
__dpctl_keep const DPCTLSyclDeviceRef DRef)
654+
{
655+
if (DRef) {
656+
auto D = unwrap(DRef);
657+
return D->get_info<info::device::profiling_timer_resolution>();
658+
}
659+
else {
660+
error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
661+
return 0;
662+
}
663+
}

libsyclinterface/tests/test_sycl_device_interface.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,14 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkGetParentDevice)
375375
EXPECT_TRUE(pDRef == nullptr);
376376
}
377377

378+
TEST_P(TestDPCTLSyclDeviceInterface, ChkGetProfilingTimerResolution)
379+
{
380+
size_t res = 0;
381+
EXPECT_NO_FATAL_FAILURE(res =
382+
DPCTLDevice_GetProfilingTimerResolution(DRef));
383+
EXPECT_TRUE(res != 0);
384+
}
385+
378386
INSTANTIATE_TEST_SUITE_P(DPCTLDeviceFns,
379387
TestDPCTLSyclDeviceInterface,
380388
::testing::Values("opencl",
@@ -673,3 +681,11 @@ TEST_F(TestDPCTLSyclDeviceNullArgs, ChkHash)
673681
EXPECT_NO_FATAL_FAILURE(hash = DPCTLDevice_Hash(Null_DRef));
674682
ASSERT_TRUE(hash == 0);
675683
}
684+
685+
TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetProfilingTimerResolution)
686+
{
687+
size_t res = 1;
688+
EXPECT_NO_FATAL_FAILURE(
689+
res = DPCTLDevice_GetProfilingTimerResolution(Null_DRef));
690+
ASSERT_TRUE(res == 0);
691+
}

0 commit comments

Comments
 (0)