Skip to content

Commit c478b77

Browse files
author
Diptorup Deb
committed
Improve docstring for kernel_api functions.
- Makes sure that summary fits on one line. - Add links to sycl specs - Adds some missing Args and Return tags to docstring.
1 parent b6a13b0 commit c478b77

File tree

11 files changed

+197
-121
lines changed

11 files changed

+197
-121
lines changed

docs/source/conf.py

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
# coding: utf-8
66
# Configuration file for the Sphinx documentation builder.
77

8-
import numba_dpex
9-
108
# -- Project information -----------------------------------------------------
119

10+
import sys
11+
12+
sys.path.append(".")
13+
14+
from sycl_spec_links import sycl_ext_links # noqa E402
15+
1216
project = "numba-dpex"
1317
copyright = "2020-2024, Intel Corporation"
1418
author = "Intel Corporation"
@@ -45,6 +49,8 @@
4549
# This pattern also affects html_static_path and html_extra_path.
4650
exclude_patterns = []
4751

52+
extlinks = {}
53+
extlinks.update(sycl_ext_links)
4854

4955
# -- Options for HTML output -------------------------------------------------
5056

@@ -72,14 +78,7 @@
7278
# so a file named "default.css" will overwrite the builtin "default.css".
7379
html_static_path = []
7480

75-
html_sidebars = {
76-
# "**": [
77-
# "globaltoc.html",
78-
# "sourcelink.html",
79-
# "searchbox.html",
80-
# "relations.html",
81-
# ],
82-
}
81+
html_sidebars = {}
8382

8483
html_show_sourcelink = False
8584

@@ -88,28 +87,8 @@
8887
todo_link_only = True
8988

9089
# -- InterSphinx configuration: looks for objects in external projects -----
91-
# Add here external classes you want to link from Intel SDC documentation
92-
# Each entry of the dictionary has the following format:
93-
# 'class name': ('link to object.inv file for that class', None)
94-
# intersphinx_mapping = {
95-
# 'pandas': ('https://pandas.pydata.org/pandas-docs/stable/', None),
96-
# 'python': ('http://docs.python.org/2', None),
97-
# 'numpy': ('http://docs.scipy.org/doc/numpy', None)
98-
# }
9990
intersphinx_mapping = {}
10091

101-
# -- Napoleon extension configuration (Numpy and Google docstring options) -------
102-
# napoleon_google_docstring = True
103-
# napoleon_numpy_docstring = True
104-
# napoleon_include_init_with_doc = True
105-
# napoleon_include_private_with_doc = True
106-
# napoleon_include_special_with_doc = True
107-
# napoleon_use_admonition_for_examples = False
108-
# napoleon_use_admonition_for_notes = False
109-
# napoleon_use_admonition_for_references = False
110-
# napoleon_use_ivar = False
111-
# napoleon_use_param = True
112-
# napoleon_use_rtype = True
11392

11493
# -- Prepend module name to an object name or not -----------------------------------
11594
add_module_names = False

docs/source/sycl_spec_links.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SPDX-FileCopyrightText: 2020 - 2024 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
"""Links to the SYCL 2020 specification that are used in docstring.
6+
7+
The module provides a dictionary in the format needed by the sphinx.ext.extlinks
8+
extension.
9+
"""
10+
11+
sycl_ext_links = {
12+
"sycl_item": (
13+
"https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#subsec:item.class%s",
14+
None,
15+
),
16+
"sycl_group": (
17+
"https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#group-class%s",
18+
None,
19+
),
20+
"sycl_nditem": (
21+
"https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#subsec:nditem.class%s",
22+
None,
23+
),
24+
"sycl_ndrange": (
25+
"https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#subsubsec:nd-range-class%s",
26+
None,
27+
),
28+
"sycl_range": (
29+
"https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#range-class%s",
30+
None,
31+
),
32+
"sycl_atomic_ref": (
33+
"https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:atomic-references%s",
34+
None,
35+
),
36+
"sycl_local_accessor": (
37+
"https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:accessor.local%s",
38+
None,
39+
),
40+
"sycl_private_memory": (
41+
"https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#_parallel_for_hierarchical_invoke%s",
42+
None,
43+
),
44+
"sycl_memory_scope": (
45+
"https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:memory-scope%s",
46+
None,
47+
),
48+
"sycl_memory_order": (
49+
"https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:memory-ordering%s",
50+
None,
51+
),
52+
"sycl_addr_space": (
53+
"https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#_address_space_classes%s",
54+
None,
55+
),
56+
}

numba_dpex/kernel_api/atomic_fence.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@
44

55
"""Python functions that simulate SYCL's atomic_fence primitives.
66
"""
7+
from .memory_enums import MemoryOrder, MemoryScope
78

89

9-
def atomic_fence(memory_order, memory_scope): # pylint: disable=unused-argument
10-
"""The function for performing memory fence across all work-items.
11-
Modeled after ``sycl::atomic_fence`` function.
12-
It provides control over re-ordering of memory load
13-
and store operations. The ``atomic_fence`` function acts as a
14-
fence across all work-items and devices specified by a
15-
memory_scope argument.
10+
def atomic_fence(
11+
memory_order: MemoryOrder, memory_scope: MemoryScope
12+
): # pylint: disable=unused-argument
13+
"""Performs a memory fence operations across all work-items.
1614
17-
Args:
18-
memory_order: The memory synchronization order.
15+
The function is equivalent to the ``sycl::atomic_fence`` function and
16+
controls the order of memory accesses (loads and stores) by individual
17+
work-items.
18+
19+
.. important::
20+
The function is a no-op during CPython execution and only available in
21+
JIT compiled mode of execution.
1922
20-
memory_scope: The set of work-items and devices to which
21-
the memory ordering constraints apply.
23+
Args:
24+
memory_order (MemoryOrder): The memory synchronization order.
25+
memory_scope (MemoryScope): The set of work-items and devices to which
26+
the memory ordering constraints apply.
2227
2328
"""

numba_dpex/kernel_api/atomic_ref.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class AtomicRef:
13-
"""Analogue to the ``sycl::atomic_ref`` class.
13+
"""Analogue to the :sycl_atomic_ref:`sycl::atomic_ref <>` class.
1414
1515
An atomic reference is a view into a data container that can be then updated
1616
atomically using any of the ``fetch_*`` member functions of the class.

numba_dpex/kernel_api/barrier.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,34 @@
99
from .memory_enums import MemoryScope
1010

1111

12-
def group_barrier(group: Group, fence_scope=MemoryScope.WORK_GROUP):
13-
"""Performs a barrier operation across all work-items in a work group.
12+
def group_barrier(
13+
group: Group, fence_scope: MemoryScope = MemoryScope.WORK_GROUP
14+
):
15+
"""Performs a barrier operation across all work-items in a work-group.
1416
15-
The function is modeled after the ``sycl::group_barrier`` function. It
16-
synchronizes work within a group of work items. All the work-items
17+
The function is equivalent to the ``sycl::group_barrier`` function. It
18+
synchronizes work within a group of work-items. All the work-items
1719
of the group must execute the barrier call before any work-item
1820
continues execution beyond the barrier.
1921
20-
The ``group_barrier`` performs mem-fence operations ensuring that memory
22+
The ``group_barrier`` performs a memory fence operation ensuring that memory
2123
accesses issued before the barrier are not re-ordered with those issued
22-
after the barrier: all work-items in group G execute a release fence prior
24+
after the barrier. All work-items in group G execute a release fence prior
2325
to synchronizing at the barrier, all work-items in group G execute an
2426
acquire fence afterwards, and there is an implicit synchronization of these
2527
fences as if provided by an explicit atomic operation on an atomic object.
2628
29+
.. important::
30+
The function is not implemented yet for pure CPython execution and is
31+
only supported in JIT compiled mode of execution.
32+
2733
Args:
28-
fence_scope (optional): scope of any memory consistency
29-
operations that are performed by the barrier.
34+
group (Group): Indicates the work-group inside which the barrier is to
35+
be executed.
36+
fence_scope (MemoryScope) (optional): scope of any memory
37+
consistency operations that are performed by the barrier.
38+
Raises:
39+
NotImplementedError: When the function is called directly from Python.
3040
"""
3141

3242
# TODO: A pure Python simulation of a group_barrier will be added later.

numba_dpex/kernel_api/index_space_ids.py

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111

1212

1313
class Group:
14-
"""Analogue to the ``sycl::group`` type."""
14+
# pylint: disable=line-too-long
15+
"""Analogue to the :sycl_group:`sycl::group <>` class.
16+
17+
Represents a particular work-group within a parallel execution and
18+
provides API to extract various properties of the work-group. An instance
19+
of the class is not user-constructible. Users should use
20+
:func:`numba_dpex.kernel_api.NdItem.get_group` to access the Group to which
21+
a work-item belongs.
22+
"""
1523

1624
def __init__(
1725
self,
@@ -27,12 +35,20 @@ def __init__(
2735
self._leader = False
2836

2937
def get_group_id(self, dim):
30-
"""Returns the index of the work-group within the global nd-range for
31-
specified dimension.
38+
"""Returns a specific coordinate of the multi-dimensional index of a group.
3239
3340
Since the work-items in a work-group have a defined position within the
3441
global nd-range, the returned group id can be used along with the local
3542
id to uniquely identify the work-item in the global nd-range.
43+
44+
Args:
45+
dim (int): An integral value between (1..3) for which the group
46+
index is returned.
47+
Returns:
48+
int: The coordinate for the ``dim`` dimension for the group's
49+
multi-dimensional index within an nd-range.
50+
Raises:
51+
ValueError: If the ``dim`` argument is not in the (1..3) interval.
3652
"""
3753
if dim > len(self._index) - 1:
3854
raise ValueError(
@@ -41,7 +57,12 @@ def get_group_id(self, dim):
4157
return self._index[dim]
4258

4359
def get_group_linear_id(self):
44-
"""Returns a linearized version of the work-group index."""
60+
"""Returns a linearized version of the work-group index.
61+
62+
Returns:
63+
int: The linearized index for the group's position within an
64+
nd-range.
65+
"""
4566
if self.dimensions == 1:
4667
return self.get_group_id(0)
4768
if self.dimensions == 2:
@@ -59,28 +80,48 @@ def get_group_linear_id(self):
5980
)
6081

6182
def get_group_range(self, dim):
62-
"""Returns a the extent of the range representing the number of groups
63-
in the nd-range for a specified dimension.
83+
"""Returns the extent of the range of groups in an nd-range for given dimension.
84+
85+
Args:
86+
dim (int): An integral value between (1..3) for which the group
87+
index is returned.
88+
Returns:
89+
int: The extent of group range for the specified dimension.
6490
"""
6591
return self._group_range[dim]
6692

6793
def get_group_linear_range(self):
68-
"""Return the total number of work-groups in the nd_range."""
94+
"""Returns the total number of work-groups in the nd_range.
95+
96+
Returns:
97+
int: Returns the number of groups in a parallel execution of an
98+
nd-range kernel.
99+
"""
69100
num_wg = 1
70101
for i in range(self.dimensions):
71102
num_wg *= self.get_group_range(i)
72103

73104
return num_wg
74105

75106
def get_local_range(self, dim):
76-
"""Returns the extent of the SYCL range representing all dimensions
77-
of the local range for a specified dimension. This local range may
78-
have been provided by the programmer, or chosen by the SYCL runtime.
107+
"""Returns the extent of the range of work-items in a work-group for given dimension.
108+
109+
Args:
110+
dim (int): An integral value between (1..3) for which the group
111+
index is returned.
112+
Returns:
113+
int: The extent of the local work-item range for the specified
114+
dimension.
79115
"""
80116
return self._local_range[dim]
81117

82118
def get_local_linear_range(self):
83-
"""Return the total number of work-items in the work-group."""
119+
"""Return the total number of work-items in the work-group.
120+
121+
Returns:
122+
int: Returns the linearized size of the local range inside an
123+
nd-range.
124+
"""
84125
num_wi = 1
85126
for i in range(self.dimensions):
86127
num_wi *= self.get_local_range(i)
@@ -89,24 +130,22 @@ def get_local_linear_range(self):
89130

90131
@property
91132
def leader(self):
92-
"""Return true for exactly one work-item in the work-group, if the
93-
calling work-item is the leader of the work-group, and false for all
94-
other work-items in the work-group.
133+
"""Return true if the caller work-item is the leader of the work-group.
95134
96135
The leader of the work-group is determined during construction of the
97136
work-group, and is invariant for the lifetime of the work-group. The
98137
leader of the work-group is guaranteed to be the work-item with a
99138
local id of 0.
100139
101-
102140
Returns:
103141
bool: If the work item is the designated leader of the
104142
"""
105143
return self._leader
106144

107145
@property
108146
def dimensions(self) -> int:
109-
"""Returns the rank of a Group object.
147+
"""Returns the dimensionality of the range to which the work-group belongs.
148+
110149
Returns:
111150
int: Number of dimensions in the Group object
112151
"""
@@ -119,22 +158,21 @@ def leader(self, work_item_id):
119158

120159

121160
class Item:
122-
"""Analogue to the ``sycl::item`` class.
161+
"""Analogue to the :sycl_item:`sycl::item <>` class.
123162
124-
Identifies an instance of the function object executing at each point in an
125-
:class:`.Range`.
163+
Identifies the work-item in a parallel execution of a kernel launched with
164+
the :class:`.Range` index-space class.
126165
"""
127166

128167
def __init__(self, extent: Range, index: list):
129168
self._extent = extent
130169
self._index = index
131170

132171
def get_linear_id(self):
133-
"""Get the linear id associated with this item for all dimensions.
134-
Original implementation could be found at ``sycl::item_base`` class.
172+
"""Returns the linear id associated with this item for all dimensions.
135173
136174
Returns:
137-
int: The linear id.
175+
int: The linear id of the work item in the global range.
138176
"""
139177
if self.dimensions == 1:
140178
return self.get_id(0)
@@ -181,7 +219,7 @@ def dimensions(self) -> int:
181219

182220

183221
class NdItem:
184-
"""Analogue to the ``sycl::nd_item`` class.
222+
"""Analogue to the :sycl_nditem:`sycl::nd_item <>` class.
185223
186224
Identifies an instance of the function object executing at each point in an
187225
:class:`.NdRange`.

0 commit comments

Comments
 (0)