Skip to content

Commit 75d6b31

Browse files
committed
compiler: Make half arithmetic a symbolic option
Whether an Operator working in half also computes in half decides what is calculated, not how quickly: the literals and the FD coefficients are rounded to three decimal digits. That is a mathematical choice, so it belongs with `interp-mode` in `sym_opt` rather than among the codegen options, and is validated and defaulted alongside it.
1 parent b9490c3 commit 75d6b31

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎devito/core/operator.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ class BasicOperator(Operator):
186186
# ------------------------------------------------------------------
187187

188188
INTERP_MODE = 'direct'
189+
190+
HALF_ARITH = False
191+
"""
192+
Whether an Operator working in half precision carries the arithmetic there
193+
too, rounding its literals and its FD weights to half. Off by default: half
194+
is a storage format, and giving up the accuracy of the coefficients as well
195+
is a mathematical choice rather than a consequence of it.
196+
"""
189197
"""
190198
Default for the `sym_opt={'interp-mode': ...}` option. Controls how
191199
a product of fields living at different staggered locations is mapped
@@ -230,7 +238,8 @@ def _normalize_sym_kwargs(cls, **kwargs):
230238
the Operator. Returns the normalized `sym_options` dict.
231239
"""
232240
so = dict(kwargs.get('sym_options', {}))
233-
out = {'interp-mode': so.pop('interp-mode', cls.INTERP_MODE)}
241+
out = {'interp-mode': so.pop('interp-mode', cls.INTERP_MODE),
242+
'half-arith': so.pop('half-arith', cls.HALF_ARITH)}
234243

235244
if so:
236245
raise InvalidOperator(

‎devito/operator/operator.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ def _soname(self):
813813
def _printer(self):
814814
# A Target may offer a second printer for Operators that have opted
815815
# into carrying their precision into the arithmetic
816-
if self._options.get('half-arith'):
816+
if self._sym_options.get('half-arith'):
817817
with suppress(AttributeError):
818818
return self._Target.HalfArithPrinter
819819
return self._Target.Printer

0 commit comments

Comments
 (0)