[Codegen |Serial Loop] Behavior of `MapToLoop` and pattern of access for arrays in serial loops

Open
#2,604 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp, python

Research direction

Start with the supplied Flux Advection archive and trace the listed pipeline: MapExpension, MapToLoop, inline SDFG, and RefineNestedAccess. Compare the generated serial-loop accesses with the examples; done means the strided accessor is lifted to loop entry, at least for center writes, without the remaining extra nesting.

Written by the indexing model from the issue text.

Description

Transforming a series of consecutive maps into a series of consecutives loop yield under performant code generation for array access by keeping the strided accessor at the deeper level of nestedness e.g.

for k
   for i
      for j
           float gtIN__vc_im1 = vc[(((__i + (31 * __j)) + (961 * __k)) - 1)];

Further more the MapToLoop mechanism inserts a NestedSDFG for each new loop.

Applying RefineNestedAccess somewhat mitigate the issue but the lifting of the access remains one level to deep e.g.

for k
    for i
         vc_K = vc[k]
         for j
              float gtIN__vc_im1 = vc_K[(((__i + (31 * __j)) - 1)];

We would like to find a way to generate (at least for center writes) the access as soon as we enter the loop.

Linked is the Flux Advection code for C-grid of the FV3 dynamical core. It shows the behavior through the "best" pipeline we found

  • original sdfg from stree
  • expand maps via MapExpension
  • convert to loop with MapToLoop
  • attempt to inline SDFG (no change)
  • refine memlets via RefineNestedAccess
Dominant language
Python
Stars
602
Forks
171
Avg merge
1d 16h
Merged PRs (30d)
43

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spcl/dace

All issues in spcl/dace

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.