Skip to content

Commit 0b9f376

Browse files
Add a backend property for the SyclEventRaw class (#521)
1 parent 6c8fcca commit 0b9f376

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

dpctl/_backend.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ cdef extern from "dpctl_sycl_event_interface.h":
228228
cdef void DPCTLEvent_Wait(DPCTLSyclEventRef ERef)
229229
cdef void DPCTLEvent_Delete(DPCTLSyclEventRef ERef)
230230
cdef _event_status_type DPCTLEvent_GetCommandExecutionStatus(DPCTLSyclEventRef ERef)
231+
cdef _backend_type DPCTLEvent_GetBackend(DPCTLSyclEventRef ERef)
231232

232233

233234
cdef extern from "dpctl_sycl_kernel_interface.h":

dpctl/_sycl_event.pyx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ from ._backend cimport ( # noqa: E211
2929
DPCTLEvent_Copy,
3030
DPCTLEvent_Create,
3131
DPCTLEvent_Delete,
32+
DPCTLEvent_GetBackend,
3233
DPCTLEvent_GetCommandExecutionStatus,
3334
DPCTLEvent_Wait,
3435
DPCTLSyclEventRef,
36+
_backend_type,
3537
_event_status_type,
3638
)
3739

@@ -229,3 +231,19 @@ cdef class SyclEventRaw(_SyclEventRaw):
229231
return event_status_type.complete
230232
else:
231233
raise ValueError("Unknown event status.")
234+
235+
@property
236+
def backend(self):
237+
""" Returns the Sycl backend associated with the event.
238+
"""
239+
cdef _backend_type BE = DPCTLEvent_GetBackend(self._event_ref)
240+
if BE == _backend_type._OPENCL:
241+
return backend_type.opencl
242+
elif BE == _backend_type._LEVEL_ZERO:
243+
return backend_type.level_zero
244+
elif BE == _backend_type._HOST:
245+
return backend_type.host
246+
elif BE == _backend_type._CUDA:
247+
return backend_type.cuda
248+
else:
249+
raise ValueError("Unknown backend type.")

dpctl/tests/test_sycl_event.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,10 @@ def test_execution_status():
8080
except ValueError:
8181
pytest.fail("Failed to get an event status")
8282
assert event_status == esty.complete
83+
84+
85+
def test_backend():
86+
try:
87+
dpctl.SyclEventRaw().backend
88+
except ValueError:
89+
pytest.fail("Failed to get backend from event")

0 commit comments

Comments
 (0)