Skip to content

Commit b1ab254

Browse files
Edits docstrings for functions in dpctl.utils namespace
1 parent e4e8c92 commit b1ab254

File tree

3 files changed

+61
-22
lines changed

3 files changed

+61
-22
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ per-file-ignores =
2929
dpctl/tensor/numpy_usm_shared.py: F821
3030
dpctl/tests/_cython_api.pyx: E999, E225, E227, E402
3131
dpctl/utils/_compute_follows_data.pyx: E999, E225, E227
32+
dpctl/utils/_onetrace_context.py: E501, W505
3233
examples/cython/sycl_buffer/syclbuffer/_buffer_example.pyx: E999, E225, E402
3334
examples/cython/usm_memory/blackscholes/blackscholes.pyx: E999, E225, E226, E402
3435
examples/cython/use_dpctl_sycl/use_dpctl_sycl/_cython_api.pyx: E999, E225, E226, E402

dpctl/utils/_compute_follows_data.pyx

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,36 @@ __all__ = ["get_execution_queue", "get_coerced_usm_type", "ExecutionPlacementErr
3232

3333

3434
class ExecutionPlacementError(Exception):
35-
"""Exception raised when execution placement target can be determined
36-
from input arrays.
35+
"""Exception raised when execution placement target can not
36+
be unambiguously determined from input arrays.
3737
38-
Make sure that input arrays are associated with the same SyclQueue,
39-
or migrate data to the same SyclQueue using usm_ndarray.to_device
40-
method.
38+
Make sure that input arrays are associated with the same
39+
:class:`dpctl.SyclQueue`,
40+
or migrate data to the same :class:`dpctl.SyclQueue` using
41+
:meth:`dpctl.tensor.usm_ndarray.to_device` method.
4142
"""
4243
pass
4344

4445

4546
cdef bint queue_equiv(SyclQueue q1, SyclQueue q2):
46-
""" Queues are equivalent if q1 == q2, that is they are copies
47+
"""Queues are equivalent if ``q1 == q2``, that is they are copies
4748
of the same underlying SYCL object and hence are the same."""
4849
return q1.__eq__(q2)
4950

5051

5152
def get_execution_queue(qs, /):
52-
""" Given a list of :class:`dpctl.SyclQueue` objects
53-
returns the execution queue under compute follows data paradigm,
54-
or returns `None` if queues are not equal.
53+
"""
54+
Get execution queue from queues associated with input arrays.
55+
56+
Args:
57+
qs (List[SyclQueue]):
58+
a list or a tuple of :class:`dpctl.SyclQueue` objects
59+
corresponding to arrays that are being combined.
60+
61+
Returns:
62+
SyclQueue:
63+
execution queue under compute follows data paradigm,
64+
or ``None`` if queues are not equal.
5565
"""
5666
if not isinstance(qs, (list, tuple)):
5767
raise TypeError(
@@ -72,10 +82,21 @@ def get_execution_queue(qs, /):
7282

7383

7484
def get_coerced_usm_type(usm_types, /):
75-
""" Given a list of strings denoting the types of USM allocations
76-
for input arrays returns the type of USM allocation for the output
77-
array(s) per compute follows data paradigm.
78-
Returns `None` if the type can not be deduced."""
85+
"""
86+
Get USM type of the output array for a function combining
87+
arrays of given USM type using compute-follows-data execution
88+
model.
89+
90+
Args:
91+
usm_types (List[str]):
92+
a list or a tuple of strings of ``.usm_types`` atributes
93+
for input arrays
94+
95+
Returns:
96+
str
97+
type of USM allocation for the output arrays (s).
98+
``None`` if any of the input string is not recognized.
99+
"""
79100
if not isinstance(usm_types, (list, tuple)):
80101
raise TypeError(
81102
"Expected a list or a tuple, got {}".format(type(usm_types))
@@ -130,16 +151,24 @@ def validate_usm_type(usm_type, /, *, allow_none=True):
130151
Args:
131152
usm_type:
132153
Specification for USM allocation type. Valid specifications
133-
are `"device"`, `"shared"`, or `"host"`. If `allow_none`
134-
keyword argument is set, a value of `None` is also permitted.
154+
are:
155+
156+
* ``"device"``
157+
* ``"shared"``
158+
* ``"host"``
159+
160+
If ``allow_none`` keyword argument is set, a value of
161+
``None`` is also permitted.
135162
allow_none (bool, optional):
136-
Whether `usm_type` value of `None` is considered valid.
163+
Whether ``usm_type`` value of ``None`` is considered valid.
137164
Default: `True`.
138165
139166
Raises:
140-
ValueError: if `usm_type` is an unrecognized string.
141-
TypeError: if `usm_type` is not a string, and `usm_type` is not `None`
142-
provided `allow_none` is `True`.
167+
ValueError:
168+
if ``usm_type`` is not a recognized string.
169+
TypeError:
170+
if ``usm_type`` is not a string, and ``usm_type`` is
171+
not ``None`` provided ``allow_none`` is ``True``.
143172
"""
144173
if allow_none:
145174
_validate_usm_type_allow_none(usm_type)

dpctl/utils/_onetrace_context.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929

3030
@contextmanager
3131
def onetrace_enabled():
32-
"""Enable `onetrace` collection for kernels executed in this context.
32+
"""Enable ``onetrace`` collection for kernels executed in this context.
3333
3434
N.B.: Proper working of this utility assumes that Python interpreter
35-
has been launched by `onetrace` or `unitrace` tool from project
35+
has been launched by ``onetrace`` or ``unitrace`` tool from project
3636
`intel/pti-gpu <https://github.com/intel/pti-gpu>`_.
3737
3838
:Example:
@@ -53,8 +53,17 @@ def onetrace_enabled():
5353
# onetrace output reporting on execution of the kernel
5454
# should be seen, starting with "Device Timeline"
5555
with onetrace_enabled():
56-
dpt.arange(100, dtype='int16')
56+
a = dpt.arange(100, dtype='int16')
5757
58+
Sample output:
59+
60+
.. code-block:: text
61+
62+
>>> with onetrace_enabled():
63+
... a = dpt.arange(100, dtype='int16')
64+
...
65+
Device Timeline (queue: 0x555aee86bed0): dpctl::tensor::kernels::constructors::linear_sequence_step_kernel<short>[SIMD32 {1; 1; 1} {100; 1; 1}]<1.1> [ns] = 44034325658 (append) 44034816544 (submit) 44036296752 (start) 44036305918 (end)
66+
>>>
5867
"""
5968
global _UNCHECKED
6069

0 commit comments

Comments
 (0)