4343 split , timed_pass , timed_region
4444)
4545from devito .types import Buffer , Evaluable , device_layer , disk_layer , host_layer
46- from devito .types .args import ArgProvider
4746from devito .types .dimension import SubDimension , SubsamplingOffset , Thickness
4847from 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
0 commit comments