-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compiler: Minor tweaks for elastic code gen #2453
Changes from all commits
e5d2712
9d04368
b08e230
e00b5db
09f7a70
7aec615
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,7 +223,7 @@ def make_stencil_dimension(expr, _min, _max): | |
Create a StencilDimension for `expr` with unique name. | ||
""" | ||
n = len(expr.find(StencilDimension)) | ||
return StencilDimension(name='i%d' % n, _min=_min, _max=_max) | ||
return StencilDimension('i%d' % n, _min, _max) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: could these just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they are special python keywords so we tend not to as it's not recommended |
||
|
||
|
||
@cacheit | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,19 +7,21 @@ | |
from sympy.core.add import _addsort | ||
from sympy.core.mul import _mulsort | ||
|
||
from devito.finite_differences.differentiable import EvalDerivative | ||
from devito.finite_differences.differentiable import ( | ||
EvalDerivative, IndexDerivative | ||
) | ||
from devito.symbolics.extended_sympy import DefFunction, rfunc | ||
from devito.symbolics.queries import q_leaf | ||
from devito.symbolics.search import retrieve_indexed, retrieve_functions | ||
from devito.tools import as_list, as_tuple, flatten, split, transitive_closure | ||
from devito.types.basic import Basic | ||
from devito.types.basic import Basic, Indexed | ||
from devito.types.array import ComponentAccess | ||
from devito.types.equation import Eq | ||
from devito.types.relational import Le, Lt, Gt, Ge | ||
|
||
__all__ = ['xreplace_indices', 'pow_to_mul', 'indexify', 'subs_op_args', | ||
'normalize_args', 'uxreplace', 'Uxmapper', 'reuse_if_untouched', | ||
'evalrel', 'flatten_args'] | ||
'normalize_args', 'uxreplace', 'Uxmapper', 'subs_if_composite', | ||
'reuse_if_untouched', 'evalrel', 'flatten_args'] | ||
|
||
|
||
def uxreplace(expr, rule): | ||
|
@@ -246,6 +248,20 @@ def add(self, expr, make, terms=None): | |
self[base] = self.extracted[base] = make() | ||
|
||
|
||
def subs_if_composite(expr, subs): | ||
""" | ||
Call `expr.subs(subs)` if `subs` contain composite expressions, that is | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: "contains" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. noted |
||
expressions that can be part of larger expressions of the same type (e.g., | ||
`a*b` could be part of `a*b*c`, while `a[1]` cannot be part of a "larger | ||
Indexed"). Instead, if `subs` consists of just "primitive" expressions, then | ||
resort to the much faster `uxreplace`. | ||
""" | ||
if all(isinstance(i, (Indexed, IndexDerivative)) for i in subs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So why can't this just be moved inside uxreplace? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because it'd contradict the API -- uxreplace performs no re-simplifications. |
||
return uxreplace(expr, subs) | ||
else: | ||
return expr.subs(subs) | ||
|
||
|
||
def xreplace_indices(exprs, mapper, key=None): | ||
""" | ||
Replace array indices in expressions. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import abc | ||
import inspect | ||
from collections import namedtuple | ||
from ctypes import POINTER, _Pointer, c_char_p, c_char | ||
from functools import reduce, cached_property | ||
|
@@ -490,6 +491,11 @@ def _cache_key(cls, *args, **kwargs): | |
# From the kwargs | ||
key.update(kwargs) | ||
|
||
# Any missing __rkwargs__ along with their default values | ||
params = inspect.signature(cls.__init_finalize__).parameters | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ouch how can we end up in such a weird spot There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try the newly added tests without this patch 😬 I don't remember the details, but basically caching bypassed because a different cache key gets computed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure but I don't get why this needs this elaborate inspect instead of just having StencilDimension implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Im not sure what makes you think it's due to StencilDimension? the test maybe ? but it was not just that. Maybe it emerged from there, but the problem is way more general. In fact, IIRC the issue was the presence/absence of the |
||
missing = [i for i in cls.__rkwargs__ if i in set(params).difference(key)] | ||
key.update({i: params[i].default for i in missing}) | ||
|
||
return frozendict(key) | ||
|
||
def __new__(cls, *args, **kwargs): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool!