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

f2c transpile via convert #208

Merged
merged 4 commits into from
Feb 9, 2024
Merged

f2c transpile via convert #208

merged 4 commits into from
Feb 9, 2024

Conversation

MichaelSt98
Copy link
Collaborator

C transpilation via convert()

Copy link

Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/208/index.html

Copy link

codecov bot commented Jan 15, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (b85aafe) 92.30% compared to head (b7a9007) 92.31%.

Files Patch % Lines
loki/transform/fortran_c_transform.py 70.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #208      +/-   ##
==========================================
+ Coverage   92.30%   92.31%   +0.01%     
==========================================
  Files          95       95              
  Lines       17368    17368              
==========================================
+ Hits        16032    16034       +2     
+ Misses       1336     1334       -2     
Flag Coverage Δ
lint_rules 96.22% <ø> (ø)
loki 92.31% <70.00%> (+0.01%) ⬆️
transformations 91.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Collaborator

@reuterbal reuterbal left a comment

Choose a reason for hiding this comment

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

Many thanks, very much looking forward to bringing this in!

However, I think we should use this opportunity to go a little further:

  • Remove the transpile entry point from loki_transform.py. Going forward, we don't want to use this anymore so better get rid of it right away. The only place that uses this is CLOUDSC. To avoid breaking the regression tests, I would convert the loki_transform_transpile CMake wrapper to a compatibility layer that reshuffles the provided options, prints a big deprecation warning, and then calls loki_transform, similar to what loki_transform_convert does.

  • Make the Fortran2CTransformation compliant with the Transformation manifests. I'm not sure what would be the minimal invasive way (we can have an offline discussion to talk through the different options), but one possibility would be to remove all the explicit recursion from the transformation, and change the invocation for the headers such that it is invoked for every module in those.

I would, however, not include anything beyond that in this PR to not expand the scope too much. For example, a subsequent PR should split the F2C Transformation to generate derived type accessors ("the header transformation") in a separate Transformation class.

loki/transform/fortran_c_transform.py Outdated Show resolved Hide resolved
loki/transform/fortran_c_transform.py Outdated Show resolved Hide resolved
loki/transform/fortran_c_transform.py Show resolved Hide resolved
scripts/loki_transform.py Outdated Show resolved Hide resolved
f2c_transformation = FortranCTransformation(path=build)
scheduler.process(f2c_transformation)
for h in definitions:
f2c_transformation.apply(h, role='header')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, here it is applied directly to a file, but the F2C Transformation is not marked as recursing to internal scopes - instead it does this internally. I think we should take this opportunity to make the Transformation compliant with the manifest parameterisation. I'll explain in the overall review comment what I mean.

Secondly, I'm not too thrilled by the fact that we provide files as headers (which, to me, implies a "read-only for enrichment" meaning) and then apply transformations to them. Since the purpose here is to deal with derived types, which we cannot capture in the dependency graph in the current Scheduler implementation, we may have to live with this for now, but that will be different with #213. To avoid that others copy this pattern, would you mind including a comment here that explains that this is temporary?
Longer term, this transformation step to generate accessor methods for derived types should become a separate Transformation that is applied to ModuleItem only.

@MichaelSt98
Copy link
Collaborator Author

transpile() is now removed from scripts/loki_transform.py as the F2C transpilation is integrated in convert().

Unfortunately it was not possible to "re-route" the CMake loki_transform_transpile to loki_transform/loki_transform_convert because the CONFIG argument can't be generically reconstructed.

Depends on CLOUDSC PR 69.

@MichaelSt98 MichaelSt98 mentioned this pull request Feb 2, 2024
Copy link
Collaborator

@reuterbal reuterbal 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 happy with this now! This is a great base for the further developments.

Once @mlange05 has had a look, I suggest the following (as acted out before) as a merge strategy:

  1. Remove the commit that points to the custom CLOUDSC branch
  2. Merge the PR with regression tests failing
  3. Tests on CLOUDSC PR should be successful now
  4. Merge the CLOUDSC PR
  5. Run regression tests on Loki main again, should now be successful.

Copy link
Collaborator

@mlange05 mlange05 left a comment

Choose a reason for hiding this comment

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

Needs a quick rebase, but otherwise GTG I think. Merge strategy sounds good too @reuterbal . :shipit:

@@ -199,7 +201,7 @@ def convert(

# Now we instantiate our transformation pipeline and apply the main changes
transformation = None
if mode in ['idem', 'idem-stack']:
if mode in ['idem', 'idem-stack', "c"]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does the F2C transformation require an "idem" pass?

@reuterbal reuterbal force-pushed the nams_f2c_transpile_via_convert branch from adb8798 to b7a9007 Compare February 9, 2024 08:49
@reuterbal reuterbal added the ready to merge This PR has been approved and is ready to be merged label Feb 9, 2024
@reuterbal reuterbal merged commit 73c6635 into main Feb 9, 2024
8 of 12 checks passed
@reuterbal reuterbal deleted the nams_f2c_transpile_via_convert branch February 9, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge This PR has been approved and is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants