stfc / PSyclone

Domain-specific compiler and code transformation system for Finite Difference/Volume/Element Earth-system models in Fortran
BSD 3-Clause "New" or "Revised" License
103 stars 25 forks source link

Re-evaluate stencil declaration #2530

Open hiker opened 3 months ago

hiker commented 3 months ago

Now that we have the ability to parse code (including kernels), we should re-evaluate the need to declare stencial accesses in the meta-data, since we might be able to determine the actual stencil based on the code.

Complications:

  1. Calling other subroutines would either require the follow the whole call tree (which we can do in most cases, except for usage of function pointers - but it will be quite expensive due to the fparser overhead)
  2. Even if no subroutine is called, the access pattern could be hidden:
    ip = i+1
    im = i-1
    ...
    a(ip, j) = a(im,j)

    etc.

The same could also be done for LFRic, though due to the indirect addressing that might be impossible to do statically.

Potential outcomes:

  1. We make the stencil declaration optional
  2. We use the stencil meta data for verification (potentially at run time, i.e. a debug option that could be enabled?)
arporter commented 3 months ago

I believe that it is best to keep the stencil metadata - it makes it explicit to everyone what is going on. However, I do really like the idea of being able to verify it. (As an aside, we should make it possible to disable such verification as there are times when I've found it useful that PSyclone doesn't check things - it lets us try things out.)