Skip to content

Commit 66e1860

Browse files
Add docstrings for the SyclEvent class
1 parent 30bb03f commit 66e1860

File tree

2 files changed

+106
-4
lines changed

2 files changed

+106
-4
lines changed

dpctl/_sycl_event.pxd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ cdef public class SyclEvent [object PySyclEventObject, type PySyclEventType]:
3636

3737

3838
cdef class _SyclEventRaw:
39+
""" Data owner for SyclEvent
40+
"""
3941
cdef DPCTLSyclEventRef _event_ref
4042

4143

4244
cdef public class SyclEventRaw(_SyclEventRaw) [object PySyclEventRawObject, type PySyclEventRawType]:
45+
""" Python wrapper class for a ``cl::sycl::event``
46+
"""
4347
@staticmethod
4448
cdef SyclEventRaw _create (DPCTLSyclEventRef event)
4549
cdef int _init_event_default(self)

dpctl/_sycl_event.pyx

Lines changed: 102 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,86 @@ cdef void _event_capsule_deleter(object o):
100100
DPCTLEvent_Delete(ERef)
101101

102102
cdef void _init_helper(_SyclEventRaw event, DPCTLSyclEventRef ERef):
103+
"Populate attributes of class from opaque reference ERef"
103104
event._event_ref = ERef
104105

105106
cdef class _SyclEventRaw:
106-
""" Python wrapper class for a ``cl::sycl::event``.
107+
""" Data owner for SyclEvent
107108
"""
108109

109110
def __dealloc__(self):
110111
DPCTLEvent_Delete(self._event_ref)
111112

112113

113114
cdef class SyclEventRaw(_SyclEventRaw):
114-
""" Python wrapper class for a ``cl::sycl::event``.
115+
"""
116+
SyclEvent(arg=None)
117+
Python class representing ``cl::sycl::event``. There are multiple
118+
ways to create a :class:`dpctl.SyclEventRaw` object:
119+
120+
- Invoking the constructor with no arguments creates a ready event
121+
using the default constructor of the ``cl::sycl::event``.
122+
123+
:Example:
124+
.. code-block:: python
125+
126+
import dpctl
127+
128+
# Create a default SyclEventRaw
129+
e = dpctl.SyclEventRaw()
130+
131+
- Invoking the constuctor with a :class:`dpctl.SyclEvent` object
132+
creates an event by copying the passed object.
133+
134+
:Example:
135+
.. code-block:: python
136+
137+
import dpctl
138+
139+
# Create a SyclEventRaw by passing SyclEvent
140+
q = dpctl.SyclQueue()
141+
e = q.submit_barrier()
142+
e_r = dpctl.SyclEventRaw(e)
143+
144+
- Invoking the constuctor with a :class:`dpctl.SyclEventRaw` object
145+
creates an event by copying the passed object.
146+
147+
:Example:
148+
.. code-block:: python
149+
150+
import dpctl
151+
152+
# Create a SyclEventRaw by passing SyclEventRaw
153+
e = dpctl.SyclEventRaw()
154+
e_r = dpctl.SyclEventRaw(e)
155+
156+
- Invoking the constuctor with a named ``PyCapsule`` with name
157+
**"SyclEventRef"** that carries a pointer to a ``sycl::event``
158+
object. The capsule will be renamed upon successful consumption
159+
to ensure one-time use. A new named capsule can be constructed by
160+
using :func:`dpctl.SyclEventRaw._get_capsule` method.
161+
162+
Args:
163+
arg (optional): Defaults to ``None``.
164+
The argument can be a :class:`dpctl.SyclEvent`
165+
instance, a :class:`dpctl.SyclEventRaw` instance, or a
166+
named ``PyCapsule`` called **"SyclEventRef"**.
167+
168+
Raises:
169+
ValueError: If the :class:`dpctl.SyclEventRaw` object creation failed.
170+
TypeError: In case of incorrect arguments given to constructors,
171+
unexpected types of input arguments, or in the case the input
172+
capsule contained a null pointer or could not be renamed.
115173
"""
116174

117175
@staticmethod
118176
cdef SyclEventRaw _create(DPCTLSyclEventRef eref):
177+
""""
178+
This function calls DPCTLEvent_Delete(eref).
179+
180+
The user of this function must pass a copy to keep the
181+
eref argument alive.
182+
"""
119183
cdef _SyclEventRaw ret = _SyclEventRaw.__new__(_SyclEventRaw)
120184
_init_helper(ret, eref)
121185
return SyclEventRaw(ret)
@@ -225,6 +289,20 @@ cdef class SyclEventRaw(_SyclEventRaw):
225289
return <size_t>self._event_ref
226290

227291
def _get_capsule(self):
292+
"""
293+
Returns a copy of the underlying ``cl::sycl::event`` pointer as a void
294+
pointer inside a named ``PyCapsule`` that has the name
295+
**SyclEventRef**. The ownership of the pointer inside the capsule is
296+
passed to the caller, and pointer is deleted when the capsule goes out
297+
of scope.
298+
Returns:
299+
:class:`pycapsule`: A capsule object storing a copy of the
300+
``cl::sycl::event`` pointer belonging to thus
301+
:class:`dpctl.SyclEventRaw` instance.
302+
Raises:
303+
ValueError: If the ``DPCTLEvent_Copy`` fails to copy the
304+
``cl::sycl::event`` pointer.
305+
"""
228306
cdef DPCTLSyclEventRef ERef = NULL
229307
ERef = DPCTLEvent_Copy(self._event_ref)
230308
if (ERef is NULL):
@@ -237,7 +315,7 @@ cdef class SyclEventRaw(_SyclEventRaw):
237315

238316
@property
239317
def execution_status(self):
240-
""" Returns the event status.
318+
""" Returns the event_status_type enum value for this event.
241319
"""
242320
cdef _event_status_type ESTy = DPCTLEvent_GetCommandExecutionStatus(
243321
self._event_ref
@@ -253,7 +331,11 @@ cdef class SyclEventRaw(_SyclEventRaw):
253331

254332
@property
255333
def backend(self):
256-
""" Returns the Sycl backend associated with the event.
334+
"""Returns the backend_type enum value for the device
335+
associated with this event.
336+
337+
Returns:
338+
backend_type: The backend for the device.
257339
"""
258340
cdef _backend_type BE = DPCTLEvent_GetBackend(self._event_ref)
259341
if BE == _backend_type._OPENCL:
@@ -268,6 +350,10 @@ cdef class SyclEventRaw(_SyclEventRaw):
268350
raise ValueError("Unknown backend type.")
269351

270352
def get_wait_list(self):
353+
"""
354+
Returns the list of :class:`dpctl.SyclEventRaw` objects that depend
355+
on this event.
356+
"""
271357
cdef DPCTLEventVectorRef EVRef = DPCTLEvent_GetWaitList(
272358
self.get_event_ref()
273359
)
@@ -285,6 +371,10 @@ cdef class SyclEventRaw(_SyclEventRaw):
285371
return events
286372

287373
def profiling_info_submit(self):
374+
"""
375+
Returns the 64-bit time value in nanoseconds
376+
when ``cl::sycl::command_group`` was submitted to the queue.
377+
"""
288378
cdef uint64_t profiling_info_submit = 0
289379
profiling_info_submit = DPCTLEvent_GetProfilingInfoSubmit(
290380
self._event_ref
@@ -293,12 +383,20 @@ cdef class SyclEventRaw(_SyclEventRaw):
293383

294384
@property
295385
def profiling_info_start(self):
386+
"""
387+
Returns the 64-bit time value in nanoseconds
388+
when ``cl::sycl::command_group`` started execution on the device.
389+
"""
296390
cdef uint64_t profiling_info_start = 0
297391
profiling_info_start = DPCTLEvent_GetProfilingInfoStart(self._event_ref)
298392
return profiling_info_start
299393

300394
@property
301395
def profiling_info_end(self):
396+
"""
397+
Returns the 64-bit time value in nanoseconds
398+
when ``cl::sycl::command_group`` finished execution on the device.
399+
"""
302400
cdef uint64_t profiling_info_end = 0
303401
profiling_info_end = DPCTLEvent_GetProfilingInfoEnd(self._event_ref)
304402
return profiling_info_end

0 commit comments

Comments
 (0)