Skip to content

Commit 44b69f4

Browse files
committed
compiler: Check stability with an accumulator wider than the field
The stability check sums the whole field and asks whether the result is finite. The accumulator took the field's own dtype, so in half precision it overflowed within a few thousand points and reported an instability that wasn't there -- making `errctl=max`, the very option one reaches for to diagnose a suspected instability, unusable exactly where it is needed. Give it at least single precision.
1 parent 04e9cc5 commit 44b69f4

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎devito/passes/iet/errors.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ def _check_stability(iet, wmovs=(), rcompile=None, sregistry=None):
5656
else:
5757
continue
5858

59-
accumulator = Symbol(name='accumulator', dtype=f.dtype)
59+
# The accumulator sums the whole field, so it is given at least single
60+
# precision: in half precision it would overflow within a few thousand
61+
# points and report an instability that isn't there
62+
dtype = np.promote_types(f.dtype, np.float32).type
63+
64+
accumulator = Symbol(name='accumulator', dtype=dtype)
6065
eqns = [Eq(accumulator, 0.0),
6166
Inc(accumulator, f.subs(f.time_dim, 0))]
6267
irs, byproduct = rcompile(eqns)

0 commit comments

Comments
 (0)