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

Hybrid indexing (absolute index in K) #64

Open
3 of 6 tasks
FlorianDeconinck opened this issue Sep 30, 2024 · 11 comments
Open
3 of 6 tasks

Hybrid indexing (absolute index in K) #64

FlorianDeconinck opened this issue Sep 30, 2024 · 11 comments
Assignees

Comments

@FlorianDeconinck
Copy link
Collaborator

FlorianDeconinck commented Sep 30, 2024

Hybrid indexing: I/J remains relative and K is absolute

The pattern to solves are as follows.

do L=1,LM
  do J=1,JM
   do I=1,IM
      ...
      Field(i,j,LM)
      Field(i,j,0)
      ...
do L=1,LM
  do J=1,JM
   do I=1,IM
      ...
      computed_k_index = FindK(...)
      Field(i,j,computed_k_index)
      ...

Current syntax: #64 (comment)


Working branch: https://github.com/FlorianDeconinck/gt4py/tree/cartesian/feature/absolute_k_indexation
ToDo:

@FlorianDeconinck
Copy link
Collaborator Author

FlorianDeconinck commented Oct 1, 2024

Solution proposal:

  • Relative index

    • Summary: default indexation, read in all scheduling, no I/J write, K write in Forward/Backward
    • Legacy subscript: field[0, 0, 1] or field[0, 0, var]
    • Axis subscript: field[K+1] or field[K+var]
  • Absolute index

    • Summary: forbidden in I/J (at first), read in K depending on interval
    • Axis subscript: field[K[-1]] (last K of interval) or field[K[var]] (var value for index)

    Question:

    • do we expose K as a readable variable? Might be a different ticket.

@FlorianDeconinck
Copy link
Collaborator Author

FlorianDeconinck commented Oct 1, 2024

Using explicit function.

def stencil(KLCL: IntField):
    with computation(PARALLEL), interval(...):
        from __externals__ import KM
        
        #v = field[0, 0, K_at(KLCL)]  # INVALID
        v = field[K_at(KLCL)]        # Axis subscript
        v = field[K_at(KM)]          # Top layer, with KM an external given by NDSL

@FlorianDeconinck
Copy link
Collaborator Author

Dropping support for field[0, 0, K_at(KLCL)] that ways it's made extra clear that I/J is can't be used with offset when doing absolute K indexation.

@romanc
Copy link

romanc commented Oct 2, 2024

I was thinking a bit about how this should look like and came up with one other option:

def stencil(KLCL: IntField):
    with computation(PARALLEL), interval(...):
        from __externals__ import KM
        
        v = field.at(K=KLCL)   # where KLCL is an integer field
        v = field.at(K=0)      # Bottom layer
        v = field.at(K=KM)     # Top layer, with KM an external given by NDSL

This is inspired by other languages' .at() function on arrays, e.g. C++, Js/Ts.

  • ➖ Probably more effort needed in parsing (on the NDSL-side)
  • ➕ Makes it abundantly clear that you can't write
  • Still no way to use I / J with offset when doing absolute K indexing

@FlorianDeconinck
Copy link
Collaborator Author

I like it. Enrique from CSCS also proposed something like field.K.at[] or field.K[] feels like a similar approach, but I'd rather do away with [] and have a function.

@FlorianDeconinck
Copy link
Collaborator Author

Working branch with the field[K_at[2]] frontend for backend numpy and dace:cpu

@FlorianDeconinck
Copy link
Collaborator Author

FlorianDeconinck commented Oct 4, 2024

Part 1 PR: FlorianDeconinck/gt4py#3, PR'ed into unstable/develop

@FlorianDeconinck
Copy link
Collaborator Author

Logged the mitigation task: #65

@FlorianDeconinck
Copy link
Collaborator Author

Syntax is now field.at(K=...)

@FlorianDeconinck
Copy link
Collaborator Author

PR up for NDSL to expose the bounds of K: NOAA-GFDL#78

@FlorianDeconinck
Copy link
Collaborator Author

Further debug on the dace:cpu side.

  • dcir.IndexAccess whenever absolute K indexing comes into play
  • parsing of the ast.Call when in a sub-ast component (e.g.OP)

Evap still not generating properly

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

3 participants