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

can_deref can unintentionally mask genuinely invalid memory accesses in ITIR #387

Open
tehrengruber opened this issue Feb 20, 2024 · 1 comment

Comments

@tehrengruber
Copy link
Contributor

tehrengruber commented Feb 20, 2024

This problem is a little convoluted to describe in a generic fashion, I'm just leaving the specific example for later investigation.
Consider the following stencil:

neighbors(C2Eₒ, (↑(λ(__arg0) → cast_(·__arg0, float64)))(⟪Koffₒ, -1ₒ⟫(__stencil_arg2))))

This stencil is only valid when when __stencil_arg2 can be derefed with a Koff of -1. However now consider we unroll the neighbor reduction we become

λ(_acc_10, _i_11) → if   can_deref(⟪Koffₒ, -1ₒ, C2CEₒ, _i_11⟫(__stencil_arg1))
                    then _acc_10 + ·⟪Koffₒ, -1ₒ, C2CEₒ, _i_11⟫(__stencil_arg1)
                                   × cast_(·⟪Koffₒ, -1ₒ, C2Eₒ, _i_11⟫(__stencil_arg2), float64)
                    else _acc_10

Now suddenly this is unconditionally valid as can_deref will just mask the previously invalid accesses in K.

@havogt
Copy link
Contributor

havogt commented Feb 21, 2024

My view on this would be:

  1. since GT4Py aims to be user-friendly, we need to catch this error at least in debug execution (which I'd say will be embedded eventually)
  2. (obviously influenced by my C++ background) since the original code is invalid, any version is invalid, even if it executes without error.

In conclusion, I don't see a problem, except that we should improve on part 1.

Or do you think there is something we should do in icon4py to fix that?

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

No branches or pull requests

2 participants