Skip to content

Commit

Permalink
compiler: Refine DataSpace derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioLuporini committed Feb 11, 2022
1 parent 979202e commit 22341f1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
22 changes: 17 additions & 5 deletions devito/ir/clusters/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from cached_property import cached_property

from devito.ir.equations import ClusterizedEq
from devito.ir.support import (PARALLEL, PARALLEL_IF_PVT, BaseGuardBoundNext, Forward,
Interval, IntervalGroup, IterationSpace, DataSpace, Scope,
detect_accesses, detect_io, normalize_properties)
from devito.ir.support import (INBOUNDS, PARALLEL, PARALLEL_IF_PVT, BaseGuardBoundNext,
Forward, Interval, IntervalGroup, IterationSpace,
DataSpace, Scope, detect_accesses, detect_io,
normalize_properties)
from devito.symbolics import estimate_cost
from devito.tools import as_tuple, flatten, frozendict
from devito.types import normalize_syncs
Expand Down Expand Up @@ -247,7 +248,18 @@ def dspace(self):
if f is None:
continue

intervals = [Interval(d, min(offs), max(offs)) for d, offs in v.items()]
intervals = []
for d, offs in v.items():
if d.symbolic_size.is_integer and \
INBOUNDS not in self.properties.get(d, {INBOUNDS}):
# Special case: when we statically know the endpoint of `f`'s
# iteration space, we can extend the DataSpace accordingly
m = min(offs)
M = max(offs) + (d.symbolic_size - 1)
else:
m = min(offs)
M = max(offs)
intervals.append(Interval(d, m, M))
intervals = IntervalGroup(intervals)

# Factor in the IterationSpace -- if the min/max points aren't zero,
Expand Down Expand Up @@ -291,7 +303,7 @@ def dspace(self):
if i.lower < 0 or \
i.upper > f._size_nodomain[d].left + f._size_halo[d].right:
# It'd mean trying to access a point before the
# left halo (test0) or after the right halo (test1)
# left halo or after the right halo
oobs.update(d._defines)
except (KeyError, TypeError):
# Unable to detect presence of OOB accesses (e.g., `d` not in
Expand Down
6 changes: 6 additions & 0 deletions devito/ir/support/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ def __init__(self, name, val=None):
and "regular".
"""

INBOUNDS = Property('inbounds')
"""
A Dimension defining an iteration space that is, or will be, explicitly guarded
to avoid iteration outside of [d_m, d_M].
"""


def normalize_properties(*args):
if not args:
Expand Down
6 changes: 1 addition & 5 deletions devito/ir/support/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ def detect_accesses(exprs):
# accesses such as `time / factor - 1`
assert d in a.free_symbols

if d.symbolic_size.is_integer:
# Explicitly unfold Default and CustomDimensions
mapper[f][d].update(range(off, d.symbolic_size + off))
else:
mapper[f][d].add(off)
mapper[f][d].add(off)

# Compute M[None]
other_dims = set()
Expand Down
11 changes: 5 additions & 6 deletions devito/passes/clusters/blocking.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from sympy import sympify

from devito.ir.clusters import Queue
from devito.ir.support import (AFFINE, PARALLEL, PARALLEL_IF_ATOMIC, PARALLEL_IF_PVT,
SEQUENTIAL, SKEWABLE, TILABLE, Interval, IntervalGroup,
IterationSpace, Scope)
from devito.ir.support import (AFFINE, INBOUNDS, PARALLEL, PARALLEL_IF_ATOMIC,
PARALLEL_IF_PVT, SEQUENTIAL, SKEWABLE, TILABLE,
Interval, IntervalGroup, IterationSpace, Scope)
from devito.symbolics import uxreplace, xreplace_indices
from devito.tools import UnboundedMultiTuple, as_tuple, flatten
from devito.types import BlockDimension
Expand Down Expand Up @@ -256,11 +256,10 @@ def callback(self, clusters, prefix):
# Use the innermost BlockDimension in place of `d`
exprs = [uxreplace(e, {d: bd}) for e in c.exprs]

# The new Cluster properties
# TILABLE property is dropped after the blocking.
properties = dict(c.properties)
properties.pop(d)
properties.update({bd: c.properties[d] - {TILABLE} for bd in block_dims})
properties.update({bd: c.properties[d] - {TILABLE} | {INBOUNDS}
for bd in block_dims})

processed.append(c.rebuild(exprs=exprs, ispace=ispace,
properties=properties))
Expand Down

0 comments on commit 22341f1

Please sign in to comment.