Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions devito/finite_differences/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def interp_mapper(source, target, dims):
"""
mapper = {}
for d in dims:
if d.is_Time:
continue
try:
s = source[d]
t = target[d]
Expand Down
6 changes: 1 addition & 5 deletions devito/passes/clusters/buffering.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,8 @@ def generate_buffers(clusters, key, sregistry, options, **kwargs):
# Finally create the actual buffer
cls = callback or Array
name = sregistry.make_name(prefix=f'{f.name}b')
# We specify the padding to match the input Function's one, so that
# the array can be used in place of the Function with valid strides
# Plain Array do not track mapped so we default to no padding
padding = 0 if cls is Array else f.padding
mapper[f] = cls(name=name, dimensions=dimensions, dtype=f.dtype,
padding=padding, grid=f.grid, halo=f.halo,
grid=f.grid, halo=f.halo,
space='mapped', mapped=f, f=f)

return mapper
Expand Down
14 changes: 1 addition & 13 deletions devito/passes/iet/linearization.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,7 @@ def key1(f, d):
if f.is_regular:
# For paddable objects the following holds:
# `same dim + same halo + same padding_dtype => same (auto-)padding`
if d is f.dimensions[-1]:
# Only the last dimension is padded
try:
if f.padding == f.mapped.padding:
# Padding set from the mapped Function
# e.g. from buffering or fft temp array
pad_key = f.mapped.__padding_dtype__
else:
pad_key = f.__padding_dtype__
except AttributeError:
pad_key = f.__padding_dtype__
else:
pad_key = None
pad_key = f.__padding_dtype__ if d is f.dimensions[-1] else None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random thought: do we need a dimensions_padded property rather than just [-1]? thinking about what we recently doing in PRO with all those "special" Arrays.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point yes would be good to have


return (d, f._size_halo[d], pad_key)
else:
Expand Down
37 changes: 35 additions & 2 deletions devito/types/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ def __dtype_setup__(cls, **kwargs):
def __padding_setup__(self, **kwargs):
padding = kwargs.get('padding')
if padding is None:
padding = ((0, 0),)*self.ndim
if self.is_autopaddable:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so yes

padding = self.__padding_setup_smart__(**kwargs)
else:
padding = ((0, 0),)*self.ndim
elif isinstance(padding, DimensionTuple):
padding = tuple(padding[d] for d in self.dimensions)
elif is_integer(padding):
Expand Down Expand Up @@ -244,7 +247,37 @@ class MappedArrayMixin:


class ArrayMapped(MappedArrayMixin, Array):
pass

__rkwargs__ = Array.__rkwargs__ + ('mapped',)

def __init_finalize__(self, *args, **kwargs):
self._mapped = kwargs.get('mapped')
super().__init_finalize__(*args, **kwargs)

@property
def mapped(self):
return self._mapped

@property
def is_autopaddable(self):
if self.mapped is None:
return True
return self.mapped.is_autopaddable

@property
def __padding_dtype__(self):
if self.mapped is not None:
return self.mapped.__padding_dtype__
return super().__padding_dtype__

@cached_property
def _signature(self):
# Exclude `mapped` so buf-reuse can dedup buffers across distinct
# mapped Functions
ret = [type(self), self.indices]
attrs = set(self.__rkwargs__) - {'name', 'function', 'mapped'}
ret.extend(getattr(self, i) for i in attrs)
return frozenset(ret)


class ArrayObject(ArrayBasic):
Expand Down
6 changes: 0 additions & 6 deletions devito/types/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,6 @@ def __init_finalize__(self, *args, shift=None, **kwargs):
# for homogeneity reasons
self._shift = as_tuple(shift)

def __padding_setup__(self, **kwargs):
padding = kwargs.pop('padding', None)
if padding is None:
padding = self.__padding_setup_smart__(**kwargs)
return super().__padding_setup__(padding=padding, **kwargs)

@property
def shift(self):
return self._shift
Expand Down
15 changes: 15 additions & 0 deletions tests/test_linearize.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,21 @@ def test_int64_array(order):
assert f'({2*order} + {long}y_size)*({2*order} + {long}x_size))' in str(op)


@switchconfig(autopadding=np.float32)
def test_mapped_array_symbolic_autopad():
grid = Grid(shape=(30, 30))
f = Function(name='f', grid=grid, space_order=4)

a = Array(name='ab', dimensions=grid.dimensions, dtype=f.dtype,
grid=grid, halo=f.halo, space='mapped')

assert type(a).__name__ == 'ArrayMapped'
assert a.is_autopaddable
pad = a.padding[-1][1]
assert not pad.is_Integer
assert pad.free_symbols == {grid.dimensions[-1].symbolic_size}


def test_cire_n_strides():
grid = Grid(shape=(4, 4, 4))

Expand Down
Loading