Skip to content

Commit 173ac59

Browse files
committed
compiler: Keep the outer Dimension parallel on a short par-tile
When a multi `par-tile` entry is shorter than the blocked nest, the innermost Dimensions consume the available block sizes and the outermost one runs into a StopIteration. It was then dropped into `compact`, which promotes it back to its root Dimension, discarding its BlockDimension. On a device that is a serialization: the Dimension ends up outside the blocked nest, `filter_iterations` rejects it as non-parallel, and the kernel is launched over a 2D grid from a host loop iterating the outer Dimension one slice at a time. Block such a Dimension reusing the innermost block size instead, so that it stays parallel. This applies to multi par-tiles only, since a single user-supplied par-tile defines the block rank on purpose.
1 parent 33c3b12 commit 173ac59

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

‎devito/passes/clusters/blocking.py‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,8 @@ def apply_par_tiles(clusters, options, **kwargs):
625625
if not options['par-tile']:
626626
return clusters
627627

628-
blk_size_gen = BlockSizeGenerator(options['par-tile'])
628+
par_tile = options['par-tile']
629+
blk_size_gen = BlockSizeGenerator(par_tile)
629630

630631
key = lambda c: c.ispace.project(lambda d: d.is_Block)
631632

@@ -642,13 +643,21 @@ def apply_par_tiles(clusters, options, **kwargs):
642643

643644
subs = {}
644645
compact = []
646+
last = None
645647
for d in reversed(bdims):
646648
try:
647-
step = sympify(umt.next())
648-
subs.update(d._rebuild_hierarchy(step=step))
649+
step = last = sympify(umt.next())
649650
except StopIteration:
650-
# No more par-tile sizes available, so we drop the BlockDimensions
651-
compact.append(d)
651+
if last is None or not par_tile.is_multi or \
652+
not is_on_device(g[0].functions, options.get('gpu-fit', ())):
653+
# No more par-tile sizes available, so we drop the
654+
# BlockDimensions
655+
compact.append(d)
656+
continue
657+
# On a device, dropping it would serialize `d`, so reuse the
658+
# innermost block size instead
659+
step = last
660+
subs.update(d._rebuild_hierarchy(step=step))
652661

653662
processed.extend(c.subs(subs, compact) for c in g)
654663

0 commit comments

Comments
 (0)