11
11
12
12
13
13
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
+ """
15
23
16
24
def __init__ (
17
25
self ,
@@ -27,12 +35,20 @@ def __init__(
27
35
self ._leader = False
28
36
29
37
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.
32
39
33
40
Since the work-items in a work-group have a defined position within the
34
41
global nd-range, the returned group id can be used along with the local
35
42
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.
36
52
"""
37
53
if dim > len (self ._index ) - 1 :
38
54
raise ValueError (
@@ -41,7 +57,12 @@ def get_group_id(self, dim):
41
57
return self ._index [dim ]
42
58
43
59
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
+ """
45
66
if self .dimensions == 1 :
46
67
return self .get_group_id (0 )
47
68
if self .dimensions == 2 :
@@ -59,28 +80,48 @@ def get_group_linear_id(self):
59
80
)
60
81
61
82
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.
64
90
"""
65
91
return self ._group_range [dim ]
66
92
67
93
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
+ """
69
100
num_wg = 1
70
101
for i in range (self .dimensions ):
71
102
num_wg *= self .get_group_range (i )
72
103
73
104
return num_wg
74
105
75
106
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.
79
115
"""
80
116
return self ._local_range [dim ]
81
117
82
118
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
+ """
84
125
num_wi = 1
85
126
for i in range (self .dimensions ):
86
127
num_wi *= self .get_local_range (i )
@@ -89,24 +130,22 @@ def get_local_linear_range(self):
89
130
90
131
@property
91
132
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.
95
134
96
135
The leader of the work-group is determined during construction of the
97
136
work-group, and is invariant for the lifetime of the work-group. The
98
137
leader of the work-group is guaranteed to be the work-item with a
99
138
local id of 0.
100
139
101
-
102
140
Returns:
103
141
bool: If the work item is the designated leader of the
104
142
"""
105
143
return self ._leader
106
144
107
145
@property
108
146
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
+
110
149
Returns:
111
150
int: Number of dimensions in the Group object
112
151
"""
@@ -119,22 +158,21 @@ def leader(self, work_item_id):
119
158
120
159
121
160
class Item :
122
- """Analogue to the `` sycl::item` ` class.
161
+ """Analogue to the :sycl_item:` sycl::item <> ` class.
123
162
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 .
126
165
"""
127
166
128
167
def __init__ (self , extent : Range , index : list ):
129
168
self ._extent = extent
130
169
self ._index = index
131
170
132
171
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.
135
173
136
174
Returns:
137
- int: The linear id.
175
+ int: The linear id of the work item in the global range .
138
176
"""
139
177
if self .dimensions == 1 :
140
178
return self .get_id (0 )
@@ -181,7 +219,7 @@ def dimensions(self) -> int:
181
219
182
220
183
221
class NdItem :
184
- """Analogue to the `` sycl::nd_item` ` class.
222
+ """Analogue to the :sycl_nditem:` sycl::nd_item <> ` class.
185
223
186
224
Identifies an instance of the function object executing at each point in an
187
225
:class:`.NdRange`.
0 commit comments