Skip to content

Commit 437456e

Browse files
committed
api: Start enabling specialization at operator apply
1 parent 07617e0 commit 437456e

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

devito/operator/operator.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from devito.ir.clusters import ClusterGroup, clusterize
2222
from devito.ir.iet import (Callable, CInterface, EntryFunction, DeviceFunction,
2323
FindSymbols, MetaCall, derive_parameters, iet_build)
24+
from devito.ir.iet.visitors import Specializer
2425
from devito.ir.support import AccessMode, SymbolRegistry
2526
from devito.ir.stree import stree_build
2627
from devito.operator.profiling import create_profile
@@ -990,16 +991,34 @@ def apply(self, **kwargs):
990991
>>> op = Operator(Eq(u3.forward, u3 + 1))
991992
>>> summary = op.apply(time_M=10)
992993
"""
993-
# Compile the operator before building the arguments list
994-
# to avoid out of memory with greedy compilers
995-
cfunction = self.cfunction
994+
# Get items expected to be specialized
995+
specialize = as_tuple(kwargs.pop('specialize', []))
996+
997+
if not specialize:
998+
# Compile the operator before building the arguments list
999+
# to avoid out of memory with greedy compilers
1000+
cfunction = self.cfunction
9961001

9971002
# Build the arguments list to invoke the kernel function
9981003
with self._profiler.timer_on('arguments-preprocess'):
9991004
args = self.arguments(**kwargs)
10001005
with switch_log_level(comm=args.comm):
10011006
self._emit_args_profiling('arguments-preprocess')
10021007

1008+
# In the case of specialization, arguments must be processed before
1009+
# the operator can be compiled
1010+
if specialize:
1011+
specialized_args = {p: sympify(args.pop(p.name))
1012+
for p in self.parameters if p.name in specialize}
1013+
1014+
op = Specializer(specialized_args).visit(self)
1015+
else:
1016+
op = self
1017+
1018+
from IPython import embed; embed()
1019+
1020+
# TODO: Whose profiler should get used here?
1021+
10031022
# Invoke kernel function with args
10041023
arg_values = [args[p.name] for p in self.parameters]
10051024
try:

0 commit comments

Comments
 (0)