Skip to content

Commit abc4914

Browse files
committed
tests: Add test for temp array allocation
1 parent 1c13976 commit abc4914

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

‎devito/passes/iet/langbase.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ def __new__(cls, function, *args):
538538

539539
@property
540540
def size(self):
541+
# TODO: Do operands need casting to int64 here?
541542
return prod(s for _, s in self)
542543

543544
@property

‎devito/types/basic.py‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,13 +1141,6 @@ def ndim(self):
11411141
"""The rank of the object."""
11421142
return len(self.indices)
11431143

1144-
# @property
1145-
# def safe_size(self):
1146-
# """
1147-
# The symbolic size of the object, casting to LONG to prevent overflow.
1148-
# """
1149-
# return prod(as_long(i) for i in self.symbolic_shape)
1150-
11511144
@property
11521145
def symbolic_shape(self):
11531146
"""

‎tests/test_dse.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,6 +2976,30 @@ def test_subdims_wo_block_temps(self):
29762976

29772977
op.apply()
29782978

2979+
@pytest.mark.parametrize('lang', ['C', 'CXX'])
2980+
def test_temp_array_allocation_uses_long(self, lang):
2981+
"""
2982+
Ensure that operands are cast to long when calculating the size of a
2983+
temporary array to prevent int32 wraparound.
2984+
"""
2985+
grid = Grid(shape=(31, 17, 25))
2986+
2987+
a = Function(name='a', grid=grid)
2988+
f = TimeFunction(name='f', grid=grid)
2989+
g = TimeFunction(name='g', grid=grid)
2990+
2991+
eq0 = Eq(f.forward, g + sin(a).dx)
2992+
eq1 = Eq(g.forward, f + sin(a).dx)
2993+
2994+
opt = ('advanced', {'cire-minmem': True, 'index-mode': 'int64'})
2995+
with switchconfig(language=lang):
2996+
op = Operator([eq0, eq1], opt=opt)
2997+
2998+
cast = '(long)' if lang == 'C' else 'static_cast<long>'
2999+
3000+
# 3 casts in memalign, 3 in memset
3001+
assert str(op).count(cast) == 6
3002+
29793003

29803004
class TestIsoAcoustic:
29813005

0 commit comments

Comments
 (0)