Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dpctl/_backend.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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":
Expand Down
23 changes: 23 additions & 0 deletions dpctl/_sycl_event.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
import logging

from cpython cimport pycapsule
from libc.stdint cimport uint64_t

from ._backend cimport ( # noqa: E211
DPCTLEvent_Copy,
DPCTLEvent_Create,
DPCTLEvent_Delete,
DPCTLEvent_GetBackend,
DPCTLEvent_GetCommandExecutionStatus,
DPCTLEvent_GetProfilingInfoEnd,
DPCTLEvent_GetProfilingInfoStart,
DPCTLEvent_GetProfilingInfoSubmit,
DPCTLEvent_GetWaitList,
DPCTLEvent_Wait,
DPCTLEventVector_Delete,
Expand Down Expand Up @@ -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
55 changes: 36 additions & 19 deletions dpctl/tests/test_sycl_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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")