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

New transformation to replace a single-trip loop with an assignment to the loop variable #2738

Open
arporter opened this issue Oct 7, 2024 · 2 comments
Assignees
Labels
enhancement good first issue An issue that is probably suitable for a new PSyclone developer NG-ARCH Issues relevant to the GPU parallelisation of LFRic and other models expected to be used in NG-ARCH

Comments

@arporter
Copy link
Member

arporter commented Oct 7, 2024

Given the reshaping of arrays being passed into the UM physics routines, there are many cases where there are loops over a dimension that we know, at build time, will have an extent of just unity. To help the compiler, it would therefore be good to remove all such loops and simply replace them with an assignment to the loop variable followed by the body of the loop:

        if loop.variable.name == "jj":
            # Ensure any symbols that are in the table of the Loop are moved
            # into the outer scope.
            parent_table = loop.parent.scope.symbol_table
            parent_table.merge(loop.loop_body.symbol_table)

            # Move the body of the loop after the loop
            for statement in reversed(loop.loop_body.children):
                loop.parent.addchild(statement.detach(), loop.position + 1)

            # Create the Assignment node
            assign = Assignment.create(Reference(loop.variable),
                                       Literal("1", INTEGER_TYPE))

            # Replace the (now empty) Loop with the Assignment
            loop.replace_with(assign)

Since this isn't entirely trivial, it would be good to have this as a transformation. I'm not sure what it should be called though. Perhaps ReplaceSingleTripLoopTrans?

@arporter arporter added enhancement NG-ARCH Issues relevant to the GPU parallelisation of LFRic and other models expected to be used in NG-ARCH good first issue An issue that is probably suitable for a new PSyclone developer labels Oct 7, 2024
@arporter
Copy link
Member Author

arporter commented Oct 7, 2024

Since most of the implementation is given in the issue description, this could be a good, self-contained issue for a new person to tackle.

@arporter
Copy link
Member Author

arporter commented Oct 7, 2024

Note, if the body of the loop doesn't contain any CodeBlocks then we could go one better and replace all References to the loop variable with the value supplied to the transformation, i.e. "1" in the example given above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue An issue that is probably suitable for a new PSyclone developer NG-ARCH Issues relevant to the GPU parallelisation of LFRic and other models expected to be used in NG-ARCH
Projects
None yet
Development

No branches or pull requests

3 participants