Skip to content
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

Check legality of symbolic derivatives #1578

Open
FabioLuporini opened this issue Feb 4, 2021 · 2 comments · May be fixed by #1598
Open

Check legality of symbolic derivatives #1578

FabioLuporini opened this issue Feb 4, 2021 · 2 comments · May be fixed by #1598
Assignees
Labels

Comments

@FabioLuporini
Copy link
Contributor

For example, if we do:

u.biharmonic(1/m)

and m was not initialized with "sufficient" space order, then OOB accesses will be generated, and segfaults will happen

how to fix: make sure in the DSL layer we always check that we're not applying differential operators to arguments that would result in illegal code

@FabioLuporini FabioLuporini changed the title Check legaly of symbolic derivatives Check legality of symbolic derivatives Feb 18, 2021
@Leitevmd Leitevmd self-assigned this Feb 18, 2021
@Leitevmd
Copy link
Contributor

@FabioLuporini, as far as I understood the problem, we could just check deriv_order and space_order in evaluate of Derivative. The only thing I'm still figuring out is when spacer_order or deriv_order is tuple. I'm not sure if this solution has the depth proposed by your hint. Let me know. By the way you mean DSE layer, right?

@Leitevmd
Copy link
Contributor

Leitevmd commented Feb 19, 2021

We could check it in evaluate or __new__ of Derivative:

@property
def evaluate(self):
    # Evaluate finite-difference.
    # Note: evaluate and _eval_fd splitted for potential future different
    # types of discretizations.
    do = self.deriv_order
    if isinstance(do,int): do = (do,)
    for i, d in enumerate(self.dims):
        expr_order = self.expr.time_order if d.is_Time else self.expr.space_order
        if do[i] > expr_order:
            raise ValueError("Expression order must be equal or greater than "
                             "Derivative order")
    return self._eval_fd(self.expr)

Here is the MFE I'm testing. If any of the functions have space or time order lower than derivative, the patch will get it.

from devito import (Grid, TimeFunction, Eq, Operator)

grid = Grid(tuple([11]*2))

u = TimeFunction(name="u", grid=grid, space_order=2, time_order=2)
m = TimeFunction(name="m", grid=grid, space_order=1, time_order=1)

# op = Operator(Eq(u.forward,u.biharmonic(1/m)))
# op = Operator(Eq(u.forward,(u * m).dx2))
op = Operator(Eq(u.forward,(u * m).dt2))

op.apply(time=0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants