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

Support optional and named arguments in inlining #2801

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

schreiberx
Copy link
Collaborator

This PR would solve issue #2525

@schreiberx schreiberx added the NEMO Issue relates to the NEMO domain label Nov 23, 2024
Copy link

codecov bot commented Nov 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.89%. Comparing base (2307ac7) to head (447b147).
Report is 25 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #2801    +/-   ##
========================================
  Coverage   99.88%   99.89%            
========================================
  Files         359      360     +1     
  Lines       50833    51006   +173     
========================================
+ Hits        50777    50950   +173     
  Misses         56       56            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@schreiberx schreiberx requested a review from arporter November 24, 2024 19:16
@schreiberx schreiberx added ready for review PSyIR Core PSyIR functionality labels Nov 24, 2024
@schreiberx schreiberx marked this pull request as ready for review November 24, 2024 19:18
@schreiberx
Copy link
Collaborator Author

Hi @arporter , this is now ready for review.

It's on supporting the optional arguments using the previous pull request on the argument matching.
I also took out all parts from the call.py related to other routines and put them into a dedicated file, psyir/tools/call_routine_matcher.py, which keeps things tidy and better configurable with respect to the options.

Regarding the options dictionary, I'm now using a set_option(...) for some classes. This makes "override" options IMHO much clearer rather than using some dictionary that can have arbitrary strings in it. (@hiker , I think that's also what you wanted).

@schreiberx
Copy link
Collaborator Author

This PR depends on PR #2775

@schreiberx schreiberx self-assigned this Nov 28, 2024
@schreiberx schreiberx requested a review from sergisiso December 23, 2024 21:38
@schreiberx
Copy link
Collaborator Author

@arporter @sergisiso @hiker I thought it would be good to have you all informed about this PR because of some restructuring of the callee detection and I guess this is getting more and more important for other use cases of psyclone.

We have the following two different situations:

  • We like to create a call trace. However, we don't want to use the inline transformation for a call trace. What we would like to have is to find the callee.
  • If we like to inline, we need to find the callee as well.
    Since finding the matching callee for interfaced calls/subroutines is part of these two situations, and since adding the feature of supporting optional and named arguments added quite a lot of lines of codes, I put the functionality to find the matching calls/subroutine into the file in
    psyir/tools/call_routine_matcher.py
    To do the coverage tests in the Andy style (Each test has to cover 100% of the corresponding file), I moved over various test cases which have been formerly part of the call_tests.py and inline_trans_tests.py to the new test file call_routine_matcher_tests.py .
    All three test files now result in 100% coverage of the respective python file.

Copy link
Member

@arporter arporter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much Martin, this is exciting functionality. However, there are a couple of biggish issues that I want to tackle before I go any further with the review. First, you have implemented a different way of handling options for InlineTrans. We need project-wide agreement on how we do this so that we can adopt a uniform approach (#2668 ). We should use #2668 to come to some agreement and then you can implement that here. Second, you have cool new functionality to remove branching when the condition is a literal and I think that should be broken out as a separate transformation with an associated PR.
Finally, there are some files with non-functional changes that you can just revert to master to shrink this PR.

@@ -195,5 +195,5 @@
'OMPScheduleClause',
'OMPFirstprivateClause',
'OMPSharedClause',
'OMPDependClause'
]
'OMPDependClause',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert (since there's no functional change to this file).

@@ -0,0 +1,18 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this. Please could you add the usual licence/copyright header (with appropriate year).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please add a comment saying it builds the html versions of all of the docs.

make -C developer_guide html SPHINXOPTS="-W --keep-going"

reference_guide:
make -C reference_guide html SPHINXOPTS="-W --keep-going"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this gives:

build finished with problems, 2 warnings (with warnings treated as errors).
make[1]: *** [Makefile:19: html] Error 1
make[1]: Leaving directory '/home/me/Projects/PSyclone/doc/reference_guide'
make: *** [Makefile:9: reference_guide] Error 2

Possibly the simplest thing to do is not to "treat warnings as errors" for the Reference Guide.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this - I don't think we need a script to wrap around pytest -n x blah. Especially since running the whole test suite takes a few minutes.

@@ -178,7 +178,8 @@ def test_omptask_apply_kern(fortran_reader, fortran_writer):
new_container.addchild(my_test)
sym = my_test.symbol_table.lookup("test_kernel")
sym.interface.container_symbol._reference = test_kernel_mod
trans = OMPTaskTrans()
trans: OMPTaskTrans = OMPTaskTrans()
trans.set_option(check_matching_arguments_of_callee=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change to the way we set options for a transformation needs to be agreed with everyone and done as a separate PR. Please revert it here.


def __init__(self):
# List of call-to-subroutine argument indices
self._ret_arg_match_list: List[int] = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this Transformation class now holding state? I wouldn't expect this to be necessary...

:type node: :py:class:`psyclone.psyir.nodes.Routine`
:param call_node: target PSyIR node.
:type call_node: :py:class:`psyclone.psyir.nodes.Call`
:param routine: PSyIR subroutine to be inlined.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for adding this argument?


# Validate that the inlining can also be accomplish.
# This routine will also update
# self.node_routine and self._ret_arg_match_list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so that's why there's state? Please update the comments on the declarations of these member variables.

# This routine will also update
# self.node_routine and self._ret_arg_match_list
# with the routine to be inlined and the relation between the
# arguments and to which routine arguments they are matched to.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"...and which routine arguments..."

# - `True`: Replace If-Block with If-Body
# - `False`: Replace If-Block with Else-Body. If it doesn't exist
# just delete the if statement.
self._optional_arg_eliminate_ifblock_if_const_condition()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. However, I think this should be a separate transformation. That way, it can be used after @hbrunie 's new ReplaceReferenceByLiteralTrans (#2828) to eliminate branching. For preference I think this should be done as a separate PR to avoid us ending up with a massive review again.

hbrunie added a commit to hbrunie/PSyclone that referenced this pull request Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NEMO Issue relates to the NEMO domain PSyIR Core PSyIR functionality reviewed with actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants