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

Problem in dependency analysis #920

Open
havogt opened this issue May 15, 2018 · 14 comments
Open

Problem in dependency analysis #920

havogt opened this issue May 15, 2018 · 14 comments

Comments

@havogt
Copy link
Contributor

havogt commented May 15, 2018

Adding an ij-cache for the rxm or rxp placeholder in the following example will give an out-of-bounds in the cache storage
https://github.com/MeteoSwiss-APN/cosmo-prerelease-gridtools/blob/2dd9994914714326e2f4cf0fb6f5d4d8aab9ef0a/dycore_gridtools/src/dycore/Stencils/HorizontalDiffusion/HorizontalDiffusionType2Limiter.cpp#L140.

@cosunae and I debugged the issue and we found the following problem:

  • The size of the cache is deduced to be <-2,1,-2,1> which is correct.
  • Dependency analysis computes the wrong extent<-2,1,-2,1> (the region of computation) for the LimitFluxStage.
  • However this stage has access extent<0, 1, 0, 1> on the rxp, rxm accessors. I.e. it will access at i+2 and j+2 which is out-of-bounds.

From our analysis we conclude the LimitFluxStage should have extent<-1,0,-1,0> (which is quite obvious as it is the second last stage and therefore we can directly read the extents from the accessors).

All other extents of the stages are correct. A possible problem could be the pattern in->flx->rxp->flx->out, i.e. we are writing and reading twice into/from the same temporary flx.

Workaround: The problem can be fixed by using make_stage_with_extent.

I attach the file which contains at the bottom the result of the dependency analysis. The first type contains the extents for the stages. The second type computed extended extents for the placeholders.

HorizontalDiffusionType2Limiter.txt

@mbianco
Copy link
Contributor

mbianco commented May 15, 2018

Could you put the link to the Laplacian operator?

@mbianco
Copy link
Contributor

mbianco commented May 15, 2018

The limitflux stage should have a <-1,1,-1,1> right?

@havogt
Copy link
Contributor Author

havogt commented May 15, 2018

I think the limitflux stage should be <-1,0,-1,0> as these are the accesses on the data stage which is the consumer.

@mbianco
Copy link
Contributor

mbianco commented May 15, 2018

Sorry,I meant the extent computed by the analysis...

@havogt
Copy link
Contributor Author

havogt commented May 15, 2018

Yes, I think so.

@havogt
Copy link
Contributor Author

havogt commented May 15, 2018

And I think the dependency analysis has this correct if I read the type correctly.

My understanding of the following is, that the the data stage is computed on <0, 0, 0, 0, 0, 0>, the flux stage on <-2, 1, -1, 0, 0, 0>, etc. Correct?

  boost::mpl::v_item<gridtools::extent<0, 0, 0, 0, 0, 0>,
                    boost::mpl::v_item<gridtools::extent<-2, 1, -1, 0, 0, 0>,
                                       boost::mpl::v_item<gridtools::extent<-1, 1, -1, 1, 0, 0>,
                                           boost::mpl::v_item<gridtools::extent<-2, 1, -2, 1, 0, 0>,
                                                              boost::mpl::v_item<gridtools::extent<-2, 2, -2, 2, 0, 0>,

@havogt
Copy link
Contributor Author

havogt commented May 15, 2018

Mauro proposed to split the fluxstage into 2, one for each flux.

It doesn't change the result: both flux stages have the same wrong extent <-2,1,-2,1,0,0>.

@havogt
Copy link
Contributor Author

havogt commented May 16, 2018

Standalone example #922

@havogt
Copy link
Contributor Author

havogt commented May 16, 2018

Just for reference: actually this is not a problem with the cache. If you don't specify a halo for the datastore then you will get an out of bounds as well. The reason why you don't get it with halo is the over-allocation of the temporaries. In that case we just read from the padding area.

@havogt
Copy link
Contributor Author

havogt commented Feb 11, 2019

The dependency analysis requires that each field must be written at most once. For the release we should check that this is very visible in the documentation and think about protections.

@mbianco
Copy link
Contributor

mbianco commented Feb 22, 2019

I think this check should be done outside of the extent analysis. Doing it in there would require to add an additional flag to the placeholders to check if they have been found to be written in a previous iteration of the algorithm, but this additional flag would be used only for checking the rule. I would check the rule in an independent metafunction that just checks that, and it should not be difficult to implement (we just need to check that in a composition a certain placeholder is indicated as output only once). Now, do it with the meta would be a natural solution, I'm not sure how long it would take for me to do it. Opinions?

@havogt havogt added this to the Release milestone Mar 4, 2019
@havogt
Copy link
Contributor Author

havogt commented Mar 18, 2019

Documentation is updated to clearly state this behavior. A check will be done later (not part of the release).

@havogt havogt removed this from the Release milestone Mar 18, 2019
@anstaf
Copy link
Contributor

anstaf commented Feb 24, 2020

Solution:

  • The user is not allowed to re-use temporaries.
  • We detect that a temporary can be re-used and optimize.

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

No branches or pull requests

3 participants