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
3 changes: 2 additions & 1 deletion dpctl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
)

from ._version import get_versions
from .enum_types import backend_type, device_type
from .enum_types import backend_type, device_type, event_status_type

__all__ = [
"SyclContext",
Expand Down Expand Up @@ -113,6 +113,7 @@
__all__ += [
"device_type",
"backend_type",
"event_status_type",
]
__all__ += [
"get_include",
Expand Down
7 changes: 7 additions & 0 deletions dpctl/_backend.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ cdef extern from "dpctl_sycl_enum_types.h":
_L1_cache 'L1_cache',
_next_partitionable 'next_partitionable',

ctypedef enum _event_status_type 'DPCTLSyclEventStatusType':
_UNKNOWN_STATUS 'DPCTL_UNKNOWN_STATUS'
_SUBMITTED 'DPCTL_SUBMITTED'
_RUNNING 'DPCTL_RUNNING'
_COMPLETE 'DPCTL_COMPLETE'


cdef extern from "dpctl_sycl_types.h":
cdef struct DPCTLOpaqueSyclContext
Expand Down Expand Up @@ -221,6 +227,7 @@ cdef extern from "dpctl_sycl_event_interface.h":
cdef DPCTLSyclEventRef DPCTLEvent_Copy(const DPCTLSyclEventRef ERef)
cdef void DPCTLEvent_Wait(DPCTLSyclEventRef ERef)
cdef void DPCTLEvent_Delete(DPCTLSyclEventRef ERef)
cdef _event_status_type DPCTLEvent_GetCommandExecutionStatus(DPCTLSyclEventRef ERef)


cdef extern from "dpctl_sycl_kernel_interface.h":
Expand Down
20 changes: 20 additions & 0 deletions dpctl/_sycl_event.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ from ._backend cimport ( # noqa: E211
DPCTLEvent_Copy,
DPCTLEvent_Create,
DPCTLEvent_Delete,
DPCTLEvent_GetCommandExecutionStatus,
DPCTLEvent_Wait,
DPCTLSyclEventRef,
_event_status_type,
)

from .enum_types import backend_type, event_status_type

__all__ = [
"SyclEvent",
"SyclEventRaw",
Expand Down Expand Up @@ -202,3 +206,19 @@ cdef class SyclEventRaw(_SyclEventRaw):
"SyclEventRef",
&_event_capsule_deleter
)

@property
def execution_status(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should be a read-only property.

In [2]: dpctl.SyclEventRaw().execution_status
Out[2]: <function SyclEventRaw.execution_status>

In [3]: dpctl.SyclEventRaw().execution_status()
Out[3]: <event_status_type.complete: 4>

So one would use In[2] rather than In[3].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def execution_status(self):
@property
def execution_status(self):

""" Returns the event status.
"""
cdef _event_status_type ESTy = DPCTLEvent_GetCommandExecutionStatus(
self._event_ref
)
if ESTy == _event_status_type._SUBMITTED:
return event_status_type.submitted
elif ESTy == _event_status_type._RUNNING:
return event_status_type.running
elif ESTy == _event_status_type._COMPLETE:
return event_status_type.complete
else:
raise ValueError("Unknown event status.")
9 changes: 9 additions & 0 deletions dpctl/enum_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
__all__ = [
"device_type",
"backend_type",
"event_status_type",
]


Expand Down Expand Up @@ -71,3 +72,11 @@ class backend_type(Enum):
host = auto()
level_zero = auto()
opencl = auto()


class event_status_type(Enum):

unknown_status = auto()
submitted = auto()
running = auto()
complete = auto()
10 changes: 10 additions & 0 deletions dpctl/tests/test_sycl_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import dpctl
import dpctl.memory as dpctl_mem
import dpctl.program as dpctl_prog
from dpctl import event_status_type as esty

from ._helper import has_cpu

Expand Down Expand Up @@ -70,3 +71,12 @@ def test_create_event_raw_from_capsule():
dpctl.SyclEventRaw(event_capsule)
except ValueError:
pytest.fail("Failed to create an event from capsule")


def test_execution_status():
event = dpctl.SyclEventRaw()
try:
event_status = event.execution_status
except ValueError:
pytest.fail("Failed to get an event status")
assert event_status == esty.complete