Skip to content

Commit 6c8fcca

Browse files
Add a execution_status method for SyclEventRaw (#522)
1 parent 729cbed commit 6c8fcca

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

dpctl/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
)
6666

6767
from ._version import get_versions
68-
from .enum_types import backend_type, device_type
68+
from .enum_types import backend_type, device_type, event_status_type
6969

7070
__all__ = [
7171
"SyclContext",
@@ -113,6 +113,7 @@
113113
__all__ += [
114114
"device_type",
115115
"backend_type",
116+
"event_status_type",
116117
]
117118
__all__ += [
118119
"get_include",

dpctl/_backend.pxd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ cdef extern from "dpctl_sycl_enum_types.h":
104104
_L1_cache 'L1_cache',
105105
_next_partitionable 'next_partitionable',
106106

107+
ctypedef enum _event_status_type 'DPCTLSyclEventStatusType':
108+
_UNKNOWN_STATUS 'DPCTL_UNKNOWN_STATUS'
109+
_SUBMITTED 'DPCTL_SUBMITTED'
110+
_RUNNING 'DPCTL_RUNNING'
111+
_COMPLETE 'DPCTL_COMPLETE'
112+
107113

108114
cdef extern from "dpctl_sycl_types.h":
109115
cdef struct DPCTLOpaqueSyclContext
@@ -221,6 +227,7 @@ cdef extern from "dpctl_sycl_event_interface.h":
221227
cdef DPCTLSyclEventRef DPCTLEvent_Copy(const DPCTLSyclEventRef ERef)
222228
cdef void DPCTLEvent_Wait(DPCTLSyclEventRef ERef)
223229
cdef void DPCTLEvent_Delete(DPCTLSyclEventRef ERef)
230+
cdef _event_status_type DPCTLEvent_GetCommandExecutionStatus(DPCTLSyclEventRef ERef)
224231

225232

226233
cdef extern from "dpctl_sycl_kernel_interface.h":

dpctl/_sycl_event.pyx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ from ._backend cimport ( # noqa: E211
2929
DPCTLEvent_Copy,
3030
DPCTLEvent_Create,
3131
DPCTLEvent_Delete,
32+
DPCTLEvent_GetCommandExecutionStatus,
3233
DPCTLEvent_Wait,
3334
DPCTLSyclEventRef,
35+
_event_status_type,
3436
)
3537

38+
from .enum_types import backend_type, event_status_type
39+
3640
__all__ = [
3741
"SyclEvent",
3842
"SyclEventRaw",
@@ -209,3 +213,19 @@ cdef class SyclEventRaw(_SyclEventRaw):
209213
"SyclEventRef",
210214
&_event_capsule_deleter
211215
)
216+
217+
@property
218+
def execution_status(self):
219+
""" Returns the event status.
220+
"""
221+
cdef _event_status_type ESTy = DPCTLEvent_GetCommandExecutionStatus(
222+
self._event_ref
223+
)
224+
if ESTy == _event_status_type._SUBMITTED:
225+
return event_status_type.submitted
226+
elif ESTy == _event_status_type._RUNNING:
227+
return event_status_type.running
228+
elif ESTy == _event_status_type._COMPLETE:
229+
return event_status_type.complete
230+
else:
231+
raise ValueError("Unknown event status.")

dpctl/enum_types.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
__all__ = [
2626
"device_type",
2727
"backend_type",
28+
"event_status_type",
2829
]
2930

3031

@@ -71,3 +72,11 @@ class backend_type(Enum):
7172
host = auto()
7273
level_zero = auto()
7374
opencl = auto()
75+
76+
77+
class event_status_type(Enum):
78+
79+
unknown_status = auto()
80+
submitted = auto()
81+
running = auto()
82+
complete = auto()

dpctl/tests/test_sycl_event.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import dpctl
2424
import dpctl.memory as dpctl_mem
2525
import dpctl.program as dpctl_prog
26+
from dpctl import event_status_type as esty
2627

2728
from ._helper import has_cpu
2829

@@ -70,3 +71,12 @@ def test_create_event_raw_from_capsule():
7071
dpctl.SyclEventRaw(event_capsule)
7172
except ValueError:
7273
pytest.fail("Failed to create an event from capsule")
74+
75+
76+
def test_execution_status():
77+
event = dpctl.SyclEventRaw()
78+
try:
79+
event_status = event.execution_status
80+
except ValueError:
81+
pytest.fail("Failed to get an event status")
82+
assert event_status == esty.complete

0 commit comments

Comments
 (0)