Skip to content

Commit 40b9058

Browse files
Add docstrings for the SyclEvent class (#551)
1 parent 2775d29 commit 40b9058

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 api 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
@@ -107,22 +107,86 @@ cdef void _event_capsule_deleter(object o):
107107
DPCTLEvent_Delete(ERef)
108108

109109
cdef void _init_helper(_SyclEventRaw event, DPCTLSyclEventRef ERef):
110+
"Populate attributes of class from opaque reference ERef"
110111
event._event_ref = ERef
111112

112113
cdef class _SyclEventRaw:
113-
""" Python wrapper class for a ``cl::sycl::event``.
114+
""" Data owner for SyclEvent
114115
"""
115116

116117
def __dealloc__(self):
117118
DPCTLEvent_Delete(self._event_ref)
118119

119120

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

124182
@staticmethod
125183
cdef SyclEventRaw _create(DPCTLSyclEventRef eref):
184+
""""
185+
This function calls DPCTLEvent_Delete(eref).
186+
187+
The user of this function must pass a copy to keep the
188+
eref argument alive.
189+
"""
126190
cdef _SyclEventRaw ret = _SyclEventRaw.__new__(_SyclEventRaw)
127191
_init_helper(ret, eref)
128192
return SyclEventRaw(ret)
@@ -232,6 +296,20 @@ cdef class SyclEventRaw(_SyclEventRaw):
232296
return <size_t>self._event_ref
233297

234298
def _get_capsule(self):
299+
"""
300+
Returns a copy of the underlying ``cl::sycl::event`` pointer as a void
301+
pointer inside a named ``PyCapsule`` that has the name
302+
**SyclEventRef**. The ownership of the pointer inside the capsule is
303+
passed to the caller, and pointer is deleted when the capsule goes out
304+
of scope.
305+
Returns:
306+
:class:`pycapsule`: A capsule object storing a copy of the
307+
``cl::sycl::event`` pointer belonging to thus
308+
:class:`dpctl.SyclEventRaw` instance.
309+
Raises:
310+
ValueError: If the ``DPCTLEvent_Copy`` fails to copy the
311+
``cl::sycl::event`` pointer.
312+
"""
235313
cdef DPCTLSyclEventRef ERef = NULL
236314
ERef = DPCTLEvent_Copy(self._event_ref)
237315
if (ERef is NULL):
@@ -244,7 +322,7 @@ cdef class SyclEventRaw(_SyclEventRaw):
244322

245323
@property
246324
def execution_status(self):
247-
""" Returns the event status.
325+
""" Returns the event_status_type enum value for this event.
248326
"""
249327
cdef _event_status_type ESTy = DPCTLEvent_GetCommandExecutionStatus(
250328
self._event_ref
@@ -260,7 +338,11 @@ cdef class SyclEventRaw(_SyclEventRaw):
260338

261339
@property
262340
def backend(self):
263-
""" Returns the Sycl backend associated with the event.
341+
"""Returns the backend_type enum value for the device
342+
associated with this event.
343+
344+
Returns:
345+
backend_type: The backend for the device.
264346
"""
265347
cdef _backend_type BE = DPCTLEvent_GetBackend(self._event_ref)
266348
if BE == _backend_type._OPENCL:
@@ -275,6 +357,10 @@ cdef class SyclEventRaw(_SyclEventRaw):
275357
raise ValueError("Unknown backend type.")
276358

277359
def get_wait_list(self):
360+
"""
361+
Returns the list of :class:`dpctl.SyclEventRaw` objects that depend
362+
on this event.
363+
"""
278364
cdef DPCTLEventVectorRef EVRef = DPCTLEvent_GetWaitList(
279365
self.get_event_ref()
280366
)
@@ -292,6 +378,10 @@ cdef class SyclEventRaw(_SyclEventRaw):
292378
return events
293379

294380
def profiling_info_submit(self):
381+
"""
382+
Returns the 64-bit time value in nanoseconds
383+
when ``cl::sycl::command_group`` was submitted to the queue.
384+
"""
295385
cdef uint64_t profiling_info_submit = 0
296386
profiling_info_submit = DPCTLEvent_GetProfilingInfoSubmit(
297387
self._event_ref
@@ -300,12 +390,20 @@ cdef class SyclEventRaw(_SyclEventRaw):
300390

301391
@property
302392
def profiling_info_start(self):
393+
"""
394+
Returns the 64-bit time value in nanoseconds
395+
when ``cl::sycl::command_group`` started execution on the device.
396+
"""
303397
cdef uint64_t profiling_info_start = 0
304398
profiling_info_start = DPCTLEvent_GetProfilingInfoStart(self._event_ref)
305399
return profiling_info_start
306400

307401
@property
308402
def profiling_info_end(self):
403+
"""
404+
Returns the 64-bit time value in nanoseconds
405+
when ``cl::sycl::command_group`` finished execution on the device.
406+
"""
309407
cdef uint64_t profiling_info_end = 0
310408
profiling_info_end = DPCTLEvent_GetProfilingInfoEnd(self._event_ref)
311409
return profiling_info_end

0 commit comments

Comments
 (0)