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

Conditions in Iterator IR #1177

Open
havogt opened this issue Feb 21, 2023 · 1 comment
Open

Conditions in Iterator IR #1177

havogt opened this issue Feb 21, 2023 · 1 comment
Labels
gt4py.next Issues concerning the new version with support for non-cartesian grids.

Comments

@havogt
Copy link
Contributor

havogt commented Feb 21, 2023

In if_(cond, true_branch, false_branch), both branches true_branch and false_branch will be evaluated eagerly (by construction). This can create out-of-bounds accesses. Therefore we have to pass the branches as lamdas. We need to check that lowering respects that and that type inference works for functions in true_branch and false_branch.

@havogt havogt added the gt4py.next Issues concerning the new version with support for non-cartesian grids. label Feb 21, 2023
@havogt
Copy link
Contributor Author

havogt commented May 2, 2023

Discussion with @egparedes and @tehrengruber:

  • for semantics of itir it doesn't matter what the evaluation order is, but in practice it matters for embedded execution and C++ execution
  • for embedded execution we can work around by returning whatever (in out of bounds, e.g. NaN) but that might be very slow
  • we could put unevaluated lambdas in an if_ to make them lazy, but
  • for C++ we cannot do that because the lambda's in the 2 branches have different type
  • therefore it seems the only option is to make if_ special in that only the 2nd or 3rd argument must be evaluated.

Other perspective on that problem
We can choose to leave evaluation order open, but then passes that change behavior under a certain evaluation order are not generally applicable. -> 2 choices: leave open and clearly state in each pass under which evaluation order they can be used (which means for which backend) or we fix evaluation order and all backends have to implement the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gt4py.next Issues concerning the new version with support for non-cartesian grids.
Projects
None yet
Development

No branches or pull requests

1 participant