Skip to content

Commit b8ca579

Browse files
committed
fix: estimate irregular arrays from their maximum byte size
1 parent a9a5de5 commit b8ca579

3 files changed

Lines changed: 14 additions & 22 deletions

File tree

‎devito/operator/operator.py‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
split, timed_pass, timed_region
4444
)
4545
from devito.types import Buffer, Evaluable, device_layer, disk_layer, host_layer
46-
from devito.types.args import ArgProvider
4746
from devito.types.dimension import SubDimension, SubsamplingOffset, Thickness
4847
from devito.warnings import warn
4948

@@ -691,7 +690,9 @@ def _prepare_arguments(self, autotune=None, estimate_memory=False, **kwargs):
691690

692691
# An ArgumentsMap carries additional metadata that may be used by
693692
# the subsequent phases of the arguments processing
694-
args = kwargs['args'] = ArgumentsMap(args, grid, self, discretizations)
693+
args = kwargs['args'] = self._make_arguments_map(
694+
args, grid, discretizations, estimate_memory=estimate_memory
695+
)
695696

696697
if estimate_memory:
697698
# No need to do anything more if only checking the memory
@@ -740,19 +741,12 @@ def _prepare_arguments(self, autotune=None, estimate_memory=False, **kwargs):
740741

741742
SubDimension._arg_check_thickness(self.dimensions, args)
742743

743-
# Resolve metadata for every bound argument before any one of them
744-
# caches the available memory and allocates its storage.
745-
parameters = [(p, kwargs.get(p.name, p)) for p in self.parameters]
746-
for _, value in parameters:
747-
if isinstance(value, ArgProvider):
748-
value._arg_pre_finalize(args)
749-
750744
# Turn arguments into a format suitable for the generated code
751745
# E.g., instead of NumPy arrays for Functions, the generated code expects
752746
# pointers to ctypes.Struct
753-
for p, value in parameters:
747+
for p in self.parameters:
754748
try:
755-
args.update(value._arg_finalize(args, alias=p))
749+
args.update(kwargs.get(p.name, p)._arg_finalize(args, alias=p))
756750
except AttributeError:
757751
# User-provided floats/ndarray obviously do not have `_arg_finalize`
758752
args.update(p._arg_finalize(args, alias=p))
@@ -762,6 +756,9 @@ def _prepare_arguments(self, autotune=None, estimate_memory=False, **kwargs):
762756

763757
return args
764758

759+
def _make_arguments_map(self, args, grid, discretizations, estimate_memory=False):
760+
return ArgumentsMap(args, grid, self, discretizations)
761+
765762
def _postprocess_errors(self, retval, comm=None):
766763
if retval == 0:
767764
return
@@ -1452,7 +1449,10 @@ def _get_nbytes(self, i):
14521449
# to nbytes, as it is typically zero
14531450
nbytes = obj.nbytes
14541451

1455-
# Could nominally have symbolic nbytes at this point
1452+
return self._evaluate_nbytes(nbytes)
1453+
1454+
def _evaluate_nbytes(self, nbytes):
1455+
"""Resolve a symbolic allocation size against the bound arguments."""
14561456
if isinstance(nbytes, sympy.Basic):
14571457
return subs_op_args(nbytes, self)
14581458

@@ -1590,10 +1590,10 @@ def nbytes_consumed_arrays(self):
15901590
continue
15911591

15921592
try:
1593-
nbytes = i.nbytes if i.is_regular else i._arg_nbytes(self)
1593+
nbytes = i.nbytes if i.is_regular else i.nbytes_max
15941594
except NotImplementedError:
15951595
continue
1596-
v = subs_op_args(nbytes, self) if isinstance(nbytes, sympy.Basic) else nbytes
1596+
v = self._evaluate_nbytes(nbytes)
15971597
if not is_integer(v):
15981598
# E.g. the Arrays used to store the MPI halo exchanges
15991599
continue

‎devito/types/args.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ def _arg_apply(self, *args, **kwargs):
5858
# By default, this is a no-op
5959
return
6060

61-
def _arg_pre_finalize(self, args):
62-
"""Prepare runtime metadata needed to estimate allocation sizes."""
63-
return
64-
6561
def _arg_finalize(self, args, **kwargs):
6662
"""
6763
Finalize the arguments produced by self, eventually turning them into ctypes.

‎devito/types/basic.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,10 +2032,6 @@ class IrregularFunctionInterface:
20322032
def nbytes_max(self):
20332033
raise NotImplementedError
20342034

2035-
def _arg_nbytes(self, args):
2036-
"""Provide the byte bound, optionally using bound argument metadata."""
2037-
return self.nbytes_max
2038-
20392035

20402036
class LocalType(Basic):
20412037
"""

0 commit comments

Comments
 (0)