From 5ba2cdcac3b4f6b78f3060b8db7d3c72aff31931 Mon Sep 17 00:00:00 2001 From: vlad-perevezentsev Date: Thu, 12 Aug 2021 06:51:25 -0500 Subject: [PATCH] Add 3 methods of SyclEventRaw class for profiling --- dpctl/_backend.pxd | 5 +++- dpctl/_sycl_event.pyx | 23 ++++++++++++++ dpctl/tests/test_sycl_event.py | 55 ++++++++++++++++++++++------------ 3 files changed, 63 insertions(+), 20 deletions(-) diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 03ec7f21d1..30701b44ca 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -21,7 +21,7 @@ types defined by dpctl's C API. """ -from libc.stdint cimport int64_t, uint32_t +from libc.stdint cimport int64_t, uint32_t, uint64_t from libcpp cimport bool @@ -238,6 +238,9 @@ cdef extern from "dpctl_sycl_event_interface.h": size_t index) cdef DPCTLEventVectorRef DPCTLEvent_GetWaitList( DPCTLSyclEventRef ERef) + cdef uint64_t DPCTLEvent_GetProfilingInfoSubmit(DPCTLSyclEventRef ERef) + cdef uint64_t DPCTLEvent_GetProfilingInfoStart(DPCTLSyclEventRef ERef) + cdef uint64_t DPCTLEvent_GetProfilingInfoEnd(DPCTLSyclEventRef ERef) cdef extern from "dpctl_sycl_kernel_interface.h": diff --git a/dpctl/_sycl_event.pyx b/dpctl/_sycl_event.pyx index 919e44152c..499949eff6 100644 --- a/dpctl/_sycl_event.pyx +++ b/dpctl/_sycl_event.pyx @@ -24,6 +24,7 @@ import logging from cpython cimport pycapsule +from libc.stdint cimport uint64_t from ._backend cimport ( # noqa: E211 DPCTLEvent_Copy, @@ -31,6 +32,9 @@ from ._backend cimport ( # noqa: E211 DPCTLEvent_Delete, DPCTLEvent_GetBackend, DPCTLEvent_GetCommandExecutionStatus, + DPCTLEvent_GetProfilingInfoEnd, + DPCTLEvent_GetProfilingInfoStart, + DPCTLEvent_GetProfilingInfoSubmit, DPCTLEvent_GetWaitList, DPCTLEvent_Wait, DPCTLEventVector_Delete, @@ -260,3 +264,22 @@ cdef class SyclEventRaw(_SyclEventRaw): events.append(SyclEventRaw._create(ERef)) DPCTLEventVector_Delete(EVRef) return events + + def profiling_info_submit(self): + cdef uint64_t profiling_info_submit = 0 + profiling_info_submit = DPCTLEvent_GetProfilingInfoSubmit( + self._event_ref + ) + return profiling_info_submit + + @property + def profiling_info_start(self): + cdef uint64_t profiling_info_start = 0 + profiling_info_start = DPCTLEvent_GetProfilingInfoStart(self._event_ref) + return profiling_info_start + + @property + def profiling_info_end(self): + cdef uint64_t profiling_info_end = 0 + profiling_info_end = DPCTLEvent_GetProfilingInfoEnd(self._event_ref) + return profiling_info_end diff --git a/dpctl/tests/test_sycl_event.py b/dpctl/tests/test_sycl_event.py index f298405743..4e0fe30f49 100644 --- a/dpctl/tests/test_sycl_event.py +++ b/dpctl/tests/test_sycl_event.py @@ -28,6 +28,32 @@ from ._helper import has_cpu +def produce_event(profiling=False): + oclSrc = " \ + kernel void add(global int* a) { \ + size_t index = get_global_id(0); \ + a[index] = a[index] + 1; \ + }" + if profiling: + q = dpctl.SyclQueue("opencl:cpu", property="enable_profiling") + else: + q = dpctl.SyclQueue("opencl:cpu") + prog = dpctl_prog.create_program_from_source(q, oclSrc) + addKernel = prog.get_sycl_kernel("add") + + bufBytes = 1024 * np.dtype("i").itemsize + abuf = dpctl_mem.MemoryUSMShared(bufBytes, queue=q) + a = np.ndarray((1024), buffer=abuf, dtype="i") + a[:] = np.arange(1024) + args = [] + + args.append(a.base) + r = [1024] + ev = q.submit(addKernel, args, r) + + return ev + + def test_create_default_event_raw(): try: dpctl.SyclEventRaw() @@ -37,25 +63,7 @@ def test_create_default_event_raw(): def test_create_event_raw_from_SyclEvent(): if has_cpu(): - oclSrc = " \ - kernel void add(global int* a) { \ - size_t index = get_global_id(0); \ - a[index] = a[index] + 1; \ - }" - q = dpctl.SyclQueue("opencl:cpu") - prog = dpctl_prog.create_program_from_source(q, oclSrc) - addKernel = prog.get_sycl_kernel("add") - - bufBytes = 1024 * np.dtype("i").itemsize - abuf = dpctl_mem.MemoryUSMShared(bufBytes, queue=q) - a = np.ndarray((1024), buffer=abuf, dtype="i") - a[:] = np.arange(1024) - args = [] - - args.append(a.base) - r = [1024] - ev = q.submit(addKernel, args, r) - + ev = produce_event() try: dpctl.SyclEventRaw(ev) except ValueError: @@ -132,5 +140,14 @@ def test_get_wait_list(): "Failed to get a list of waiting events from SyclEventRaw" ) assert len(wait_list) + + +def test_profiling_info(): + if has_cpu(): + event = produce_event(profiling=True) + event_raw = dpctl.SyclEventRaw(event) + assert event_raw.profiling_info_submit + assert event_raw.profiling_info_start + assert event_raw.profiling_info_end else: pytest.skip("No OpenCL CPU queues available")