@@ -14,8 +14,8 @@ class LoopNode(IrNode):
14
14
"""
15
15
Node for the IntermediateRepresentation tree that is used for loop constructs.
16
16
"""
17
- def __init__ (self ):
18
- super ().__init__ ()
17
+ def __init__ (self , lineno : int ):
18
+ super ().__init__ (lineno )
19
19
self .collapse = None
20
20
self .gang = None
21
21
self .worker = None
@@ -28,7 +28,7 @@ def __init__(self):
28
28
self .private = None
29
29
self .reduction = None
30
30
31
- def loop (clauses , intermediate_rep , * args , ** kwargs ):
31
+ def loop (clauses , intermediate_rep , lineno , * args , ** kwargs ):
32
32
"""
33
33
From the docs:
34
34
The loop construct can describe what type of parallelism to use to
@@ -65,26 +65,31 @@ def loop(clauses, intermediate_rep, *args, **kwargs):
65
65
clause must be written such that the loop iteration count is
66
66
computable when entering the loop construct.
67
67
"""
68
- loop_node = LoopNode ()
69
- intermediate_rep .root .add_child (loop_node )
68
+ loop_node = LoopNode (lineno )
70
69
index = 0
71
70
while index != - 1 :
72
- index = _apply_clause (index , clauses , intermediate_rep )
71
+ index = _apply_clause (index , clauses , intermediate_rep , loop_node )
72
+ intermediate_rep .add_child (loop_node )
73
73
74
- def _apply_clause (index , clause_list , intermediate_rep ):
74
+ def _apply_clause (index , clause_list , intermediate_rep , loop_node ):
75
75
"""
76
76
Consumes however much of the clause list as necessary to apply the clause
77
77
found at index in the clause_list.
78
78
79
- @param index: The index into the clause_list of the clause we are
80
- interested in.
79
+ @param index: The index into the clause_list of the clause we are
80
+ interested in.
81
81
82
- @param clause_list: The list of the clauses that this clause is indexed in.
82
+ @param clause_list: The list of the clauses that this clause is indexed in.
83
83
84
- @return: The new index. If there are no more
85
- clauses after this one is done, index will be -1.
84
+ @param intermediate_rep: The intermediate representation, filled with information
85
+ about the source code in general, but not yet this node.
86
+
87
+ @param loop_node: The node who's information we are filling in with the clauses.
88
+
89
+ @return: The new index. If there are no more
90
+ clauses after this one is done, index will be -1.
86
91
"""
87
- args = (index , clause_list , intermediate_rep )
92
+ args = (index , clause_list , intermediate_rep , loop_node )
88
93
clause = clause_list [index ]
89
94
# TODO: Remove this debug print
90
95
print ("clause:" , clause )
@@ -111,11 +116,10 @@ def _apply_clause(index, clause_list, intermediate_rep):
111
116
elif clause .startswith ("reduction" ):
112
117
return _reduction (* args )
113
118
else :
114
- raise InvalidClauseError ("Clause either not allowed for this " + \
115
- "directive, or else it may be spelled " + \
116
- "incorrectly. Clause given: " + clause )
119
+ errmsg = "Clause either not allowed for this directive, or else it may be spelled incorrectly. Clause given: {} at line: {}" .format (clause , loop_node .lineno )
120
+ raise InvalidClauseError (errmsg )
117
121
118
- def _collapse (index , clause_list , intermediate_rep ):
122
+ def _collapse (index , clause_list , intermediate_rep , loop_node ):
119
123
"""
120
124
The 'collapse' clause is used to specify how many tightly nested loops
121
125
are associated with the 'loop' construct. The argument to the 'collapse'
@@ -158,7 +162,7 @@ def _collapse(index, clause_list, intermediate_rep):
158
162
159
163
return - 1
160
164
161
- def _gang (index , clause_list , intermediate_rep ):
165
+ def _gang (index , clause_list , intermediate_rep , loop_node ):
162
166
"""
163
167
When the parent compute construct is a 'parallel' construct, or on an
164
168
orphaned 'loop' construct, the 'gang' clause specifies that the
@@ -199,7 +203,7 @@ def _gang(index, clause_list, intermediate_rep):
199
203
"""
200
204
return - 1
201
205
202
- def _worker (index , clause_list , intermediate_rep ):
206
+ def _worker (index , clause_list , intermediate_rep , loop_node ):
203
207
"""
204
208
When the parent compute construct is a 'parallel' construct, or on an
205
209
orphaned 'loop' construct, the 'worker' clause specifies that the
@@ -227,7 +231,7 @@ def _worker(index, clause_list, intermediate_rep):
227
231
"""
228
232
return - 1
229
233
230
- def _vector (index , clause_list , intermediate_rep ):
234
+ def _vector (index , clause_list , intermediate_rep , loop_node ):
231
235
"""
232
236
When the parent compute construct is a 'parallel' construct, or on an
233
237
orphaned 'loop' construct, the 'vector' clause specifies that the
@@ -256,15 +260,15 @@ def _vector(index, clause_list, intermediate_rep):
256
260
"""
257
261
return - 1
258
262
259
- def _seq (index , clause_list , intermediate_rep ):
263
+ def _seq (index , clause_list , intermediate_rep , loop_node ):
260
264
"""
261
265
The 'seq' clause specifies that the associated loop or loops are to be
262
266
executed sequentially by the acclerator. This clause will override any
263
267
automatic parallelization or vectorization.
264
268
"""
265
269
return - 1
266
270
267
- def _auto (index , clause_list , intermediate_rep ):
271
+ def _auto (index , clause_list , intermediate_rep , loop_node ):
268
272
"""
269
273
The 'auto' clause specifies that the implementation must analyze the
270
274
loop and determine whether to run the loop sequentially. The
@@ -276,7 +280,7 @@ def _auto(index, clause_list, intermediate_rep):
276
280
"""
277
281
return - 1
278
282
279
- def _tile (index , clause_list , intermediate_rep ):
283
+ def _tile (index , clause_list , intermediate_rep , loop_node ):
280
284
"""
281
285
The 'tile' clause specifies that the implementation should split each
282
286
loop nest into two loops, with an outer set of tile loops and an
@@ -303,14 +307,14 @@ def _tile(index, clause_list, intermediate_rep):
303
307
"""
304
308
return - 1
305
309
306
- def _device_type (index , clause_list , intermediate_rep ):
310
+ def _device_type (index , clause_list , intermediate_rep , loop_node ):
307
311
"""
308
312
The 'device_type' clause is described in Section 2.4 Device-Specific
309
313
Clauses.
310
314
"""
311
315
return - 1
312
316
313
- def _independent (index , clause_list , intermediate_rep ):
317
+ def _independent (index , clause_list , intermediate_rep , loop_node ):
314
318
"""
315
319
The 'independent' clause tells the implementation that the iterations of
316
320
this loop are data-independent with respect to each other. This allows
@@ -327,7 +331,7 @@ def _independent(index, clause_list, intermediate_rep):
327
331
"""
328
332
return - 1
329
333
330
- def _private (index , clause_list , intermediate_rep ):
334
+ def _private (index , clause_list , intermediate_rep , loop_node ):
331
335
"""
332
336
The 'private' clause on a 'loop' construct specifies that a copy of each
333
337
item in var-list will be created. If the body of the loop is executed
@@ -341,7 +345,7 @@ def _private(index, clause_list, intermediate_rep):
341
345
"""
342
346
return - 1
343
347
344
- def _reduction (index , clause_list , intermediate_rep ):
348
+ def _reduction (index , clause_list , intermediate_rep , loop_node ):
345
349
"""
346
350
The 'reduction' clause specifies a reduction operator and one or more
347
351
scalar variables. For each reduction variable, a private copy is created
0 commit comments