Skip to content

Commit 49ee2f4

Browse files
Add 3 methods of SyclEventRaw class for profiling
1 parent 414de9c commit 49ee2f4

File tree

3 files changed

+63
-20
lines changed

3 files changed

+63
-20
lines changed

dpctl/_backend.pxd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
types defined by dpctl's C API.
2222
"""
2323

24-
from libc.stdint cimport int64_t, uint32_t
24+
from libc.stdint cimport int64_t, uint32_t, uint64_t
2525
from libcpp cimport bool
2626

2727

@@ -221,6 +221,9 @@ cdef extern from "dpctl_sycl_event_interface.h":
221221
cdef DPCTLSyclEventRef DPCTLEvent_Copy(const DPCTLSyclEventRef ERef)
222222
cdef void DPCTLEvent_Wait(DPCTLSyclEventRef ERef)
223223
cdef void DPCTLEvent_Delete(DPCTLSyclEventRef ERef)
224+
cdef uint64_t DPCTLEvent_GetProfilingInfoSubmit(DPCTLSyclEventRef ERef)
225+
cdef uint64_t DPCTLEvent_GetProfilingInfoStart(DPCTLSyclEventRef ERef)
226+
cdef uint64_t DPCTLEvent_GetProfilingInfoEnd(DPCTLSyclEventRef ERef)
224227

225228

226229
cdef extern from "dpctl_sycl_kernel_interface.h":

dpctl/_sycl_event.pyx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@
2424
import logging
2525

2626
from cpython cimport pycapsule
27+
from libc.stdint cimport uint64_t
2728

2829
from ._backend cimport ( # noqa: E211
2930
DPCTLEvent_Copy,
3031
DPCTLEvent_Create,
3132
DPCTLEvent_Delete,
33+
DPCTLEvent_GetProfilingInfoEnd,
34+
DPCTLEvent_GetProfilingInfoStart,
35+
DPCTLEvent_GetProfilingInfoSubmit,
3236
DPCTLEvent_Wait,
3337
DPCTLSyclEventRef,
3438
)
@@ -202,3 +206,20 @@ cdef class SyclEventRaw(_SyclEventRaw):
202206
"SyclEventRef",
203207
&_event_capsule_deleter
204208
)
209+
210+
def profiling_info_submit(self):
211+
cdef uint64_t profiling_info_submit = 0
212+
profiling_info_submit = DPCTLEvent_GetProfilingInfoSubmit(
213+
self._event_ref
214+
)
215+
return profiling_info_submit
216+
217+
def profiling_info_start(self):
218+
cdef uint64_t profiling_info_start = 0
219+
profiling_info_start = DPCTLEvent_GetProfilingInfoStart(self._event_ref)
220+
return profiling_info_start
221+
222+
def profiling_info_end(self):
223+
cdef uint64_t profiling_info_end = 0
224+
profiling_info_end = DPCTLEvent_GetProfilingInfoEnd(self._event_ref)
225+
return profiling_info_end

dpctl/tests/test_sycl_event.py

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@
2727
from ._helper import has_cpu
2828

2929

30+
def produce_event(profiling=False):
31+
oclSrc = " \
32+
kernel void add(global int* a) { \
33+
size_t index = get_global_id(0); \
34+
a[index] = a[index] + 1; \
35+
}"
36+
if profiling:
37+
q = dpctl.SyclQueue("opencl:cpu", property="enable_profiling")
38+
else:
39+
q = dpctl.SyclQueue("opencl:cpu")
40+
prog = dpctl_prog.create_program_from_source(q, oclSrc)
41+
addKernel = prog.get_sycl_kernel("add")
42+
43+
bufBytes = 1024 * np.dtype("i").itemsize
44+
abuf = dpctl_mem.MemoryUSMShared(bufBytes, queue=q)
45+
a = np.ndarray((1024), buffer=abuf, dtype="i")
46+
a[:] = np.arange(1024)
47+
args = []
48+
49+
args.append(a.base)
50+
r = [1024]
51+
ev = q.submit(addKernel, args, r)
52+
53+
return ev
54+
55+
3056
def test_create_default_event_raw():
3157
try:
3258
dpctl.SyclEventRaw()
@@ -36,25 +62,7 @@ def test_create_default_event_raw():
3662

3763
def test_create_event_raw_from_SyclEvent():
3864
if has_cpu():
39-
oclSrc = " \
40-
kernel void add(global int* a) { \
41-
size_t index = get_global_id(0); \
42-
a[index] = a[index] + 1; \
43-
}"
44-
q = dpctl.SyclQueue("opencl:cpu")
45-
prog = dpctl_prog.create_program_from_source(q, oclSrc)
46-
addKernel = prog.get_sycl_kernel("add")
47-
48-
bufBytes = 1024 * np.dtype("i").itemsize
49-
abuf = dpctl_mem.MemoryUSMShared(bufBytes, queue=q)
50-
a = np.ndarray((1024), buffer=abuf, dtype="i")
51-
a[:] = np.arange(1024)
52-
args = []
53-
54-
args.append(a.base)
55-
r = [1024]
56-
ev = q.submit(addKernel, args, r)
57-
65+
ev = produce_event()
5866
try:
5967
dpctl.SyclEventRaw(ev)
6068
except ValueError:
@@ -70,3 +78,14 @@ def test_create_event_raw_from_capsule():
7078
dpctl.SyclEventRaw(event_capsule)
7179
except ValueError:
7280
pytest.fail("Failed to create an event from capsule")
81+
82+
83+
def test_profiling_info():
84+
if has_cpu():
85+
event = produce_event(profiling=True)
86+
event_raw = dpctl.SyclEventRaw(event)
87+
assert event_raw.profiling_info_submit()
88+
assert event_raw.profiling_info_start()
89+
assert event_raw.profiling_info_end()
90+
else:
91+
pytest.skip("No OpenCL CPU queues available")

0 commit comments

Comments
 (0)