Skip to content

Commit acea0cd

Browse files
committed
compiler: Tweak break_for_parallelism
1 parent b779816 commit acea0cd

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

devito/ir/clusters/algorithms.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,27 @@ def callback(self, clusters, prefix, backlog=None, known_break=None):
189189

190190
return processed + self.callback(backlog, prefix)
191191

192-
def _break_for_parallelism(self, scope, candidates, i):
192+
def _break_for_parallelism(self, scope, candidates, timestamp):
193193
# `test` will be True if there's at least one data-dependence that would
194194
# break parallelism
195195
test = False
196-
for d in scope.d_from_access_gen(scope.a_query(i)):
197-
if d.is_local or d.is_storage_related(candidates):
196+
for dep in scope.d_all_gen():
197+
if dep.timestamp > timestamp:
198+
continue
199+
200+
if dep.is_local or dep.is_storage_related(candidates):
198201
# Would break a dependence on storage
199202
return False
200-
if any(d.is_carried(i) for i in candidates): # noqa: SIM102
201-
if (d.is_flow and d.is_lex_negative) or (d.is_anti and d.is_lex_positive):
203+
204+
if any(dep.is_carried(i) for i in candidates):
205+
test0 = dep.is_flow and dep.is_lex_negative
206+
test1 = dep.is_anti and dep.is_lex_positive
207+
if test0 or test1:
202208
# Would break a data dependence
203209
return False
204-
test = test or (bool(d.cause & candidates) and not d.is_lex_equal)
210+
211+
test = test or (bool(dep.cause & candidates) and not dep.is_lex_equal)
212+
205213
return test
206214

207215

devito/ir/support/basic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,10 @@ def function(self):
558558
def findices(self):
559559
return self.source.findices
560560

561+
@property
562+
def timestamp(self):
563+
return max(self.source.timestamp, self.sink.timestamp)
564+
561565
@cached_property
562566
def distance(self):
563567
return self.source.distance(self.sink)

tests/test_operator.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ def test_no_fission_as_illegal(self, exprs):
14851485
(('Eq(ti0[x,y,z], ti0[x,y,z] + ti1[x,y,z])',
14861486
'Eq(ti1[x,y,z], ti3[x,y,z])',
14871487
'Eq(ti3[x,y,z], ti1[x,y,z+1] + 1.)'),
1488-
'+++++', ['xyz', 'xyz', 'xyz'], 'xyzzz'),
1488+
'++++', ['xyz', 'xyz'], 'xyzz'),
14891489
# 1) WAR 1->2, 2->3
14901490
(('Eq(ti0[x,y,z], ti0[x,y,z] + ti1[x,y,z])',
14911491
'Eq(ti1[x,y,z], ti0[x,y,z+1])',
@@ -1533,7 +1533,7 @@ def test_no_fission_as_illegal(self, exprs):
15331533
(('Eq(tu[t,x,y,z], tu[t,x,y,z] + tv[t,x,y,z])',
15341534
'Eq(tv[t,x,y,z], tu[t,x,y,z-2])',
15351535
'Eq(tw[t,x,y,z], tv[t,x,y+1,z] + 1.)'),
1536-
'++++++++', ['txyz', 'txyz', 'txyz'], 'txyzyzyz'),
1536+
'+++++++', ['txyz', 'txyz', 'txyz'], 'txyzzyz'),
15371537
# 10) WAR 1->2; WAW 1->3
15381538
(('Eq(tu[t-1,x,y,z], tu[t,x,y,z] + tv[t,x,y,z])',
15391539
'Eq(tv[t,x,y,z], tu[t,x,y,z+2])',
@@ -1593,6 +1593,15 @@ def test_no_fission_as_illegal(self, exprs):
15931593
'Eq(tu[t+1,xi,yi,zi], tv[t+1,xi,yi,zi] + tv[t+1,xi+1,yi,zi])',
15941594
'Eq(tw[t+1,x,y,z], tv[t+1,x,y,z] + tv[t+1,x+1,y,z])'),
15951595
'++++++++++', ['txyz', 'txyz', 'txyz'], 'txyzxyzxyz'),
1596+
# 20) RAW 1->3, WAR 2->3; expected=2
1597+
# It's important the split occurs after the second equation, since the
1598+
# first two can safely be fused together (previously, instead,
1599+
# due to an issue in `break_for_parallelism`, the eqns were split over
1600+
# three loop nests)
1601+
(('Eq(tu[t+1,x,y,z], tu[t,x,y,z] + tu[t,x+1,y,z])',
1602+
'Eq(tv[t+1,x,y,z], tv[t,x,y,z] + 1)',
1603+
'Eq(tw[t+1,x,y,z], tu[t+1,x+1,y,z] + tw[t,x+1,y,z] + tv[t+1,x+1,y,z])'),
1604+
'+++++++', ['txyz', 'txyz'], 'txyzxyz'),
15961605
])
15971606
def test_consistency_anti_dependences(self, exprs, directions, expected, visit):
15981607
"""

0 commit comments

Comments
 (0)