Skip to content

Commit dd3d7c0

Browse files
Add 3 methods of SyclEventRaw class for profiling
1 parent 3a691a7 commit dd3d7c0

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

@@ -238,6 +238,9 @@ cdef extern from "dpctl_sycl_event_interface.h":
238238
size_t index)
239239
cdef DPCTLEventVectorRef DPCTLEvent_GetWaitList(
240240
DPCTLSyclEventRef ERef)
241+
cdef uint64_t DPCTLEvent_GetProfilingInfoSubmit(DPCTLSyclEventRef ERef)
242+
cdef uint64_t DPCTLEvent_GetProfilingInfoStart(DPCTLSyclEventRef ERef)
243+
cdef uint64_t DPCTLEvent_GetProfilingInfoEnd(DPCTLSyclEventRef ERef)
241244

242245

243246
cdef extern from "dpctl_sycl_kernel_interface.h":

dpctl/_sycl_event.pyx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@
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,
3233
DPCTLEvent_GetBackend,
3334
DPCTLEvent_GetCommandExecutionStatus,
35+
DPCTLEvent_GetProfilingInfoEnd,
36+
DPCTLEvent_GetProfilingInfoStart,
37+
DPCTLEvent_GetProfilingInfoSubmit,
3438
DPCTLEvent_GetWaitList,
3539
DPCTLEvent_Wait,
3640
DPCTLEventVector_Delete,
@@ -267,3 +271,22 @@ cdef class SyclEventRaw(_SyclEventRaw):
267271
events.append(SyclEventRaw._create(ERef))
268272
DPCTLEventVector_Delete(EVRef)
269273
return events
274+
275+
def profiling_info_submit(self):
276+
cdef uint64_t profiling_info_submit = 0
277+
profiling_info_submit = DPCTLEvent_GetProfilingInfoSubmit(
278+
self._event_ref
279+
)
280+
return profiling_info_submit
281+
282+
@property
283+
def profiling_info_start(self):
284+
cdef uint64_t profiling_info_start = 0
285+
profiling_info_start = DPCTLEvent_GetProfilingInfoStart(self._event_ref)
286+
return profiling_info_start
287+
288+
@property
289+
def profiling_info_end(self):
290+
cdef uint64_t profiling_info_end = 0
291+
profiling_info_end = DPCTLEvent_GetProfilingInfoEnd(self._event_ref)
292+
return profiling_info_end

dpctl/tests/test_sycl_event.py

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

3030

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

3864
def test_create_event_raw_from_SyclEvent():
3965
if has_cpu():
40-
oclSrc = " \
41-
kernel void add(global int* a) { \
42-
size_t index = get_global_id(0); \
43-
a[index] = a[index] + 1; \
44-
}"
45-
q = dpctl.SyclQueue("opencl:cpu")
46-
prog = dpctl_prog.create_program_from_source(q, oclSrc)
47-
addKernel = prog.get_sycl_kernel("add")
48-
49-
bufBytes = 1024 * np.dtype("i").itemsize
50-
abuf = dpctl_mem.MemoryUSMShared(bufBytes, queue=q)
51-
a = np.ndarray((1024), buffer=abuf, dtype="i")
52-
a[:] = np.arange(1024)
53-
args = []
54-
55-
args.append(a.base)
56-
r = [1024]
57-
ev = q.submit(addKernel, args, r)
58-
66+
ev = produce_event()
5967
try:
6068
dpctl.SyclEventRaw(ev)
6169
except ValueError:
@@ -132,5 +140,14 @@ def test_get_wait_list():
132140
"Failed to get a list of waiting events from SyclEventRaw"
133141
)
134142
assert len(wait_list)
143+
144+
145+
def test_profiling_info():
146+
if has_cpu():
147+
event = produce_event(profiling=True)
148+
event_raw = dpctl.SyclEventRaw(event)
149+
assert event_raw.profiling_info_submit
150+
assert event_raw.profiling_info_start
151+
assert event_raw.profiling_info_end
135152
else:
136153
pytest.skip("No OpenCL CPU queues available")

0 commit comments

Comments
 (0)