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 transpilation] (driver level) convert interface to import #422

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

MichaelSt98
Copy link
Collaborator

Convert interface to kernel calls (e.g., interface kernel ...) to the appropriate import (e.g., kernel_fc_mod, only: kernel_fc).

Copy link

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

Copy link

codecov bot commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.24%. Comparing base (cd45a6c) to head (384e2ec).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #422   +/-   ##
=======================================
  Coverage   93.24%   93.24%           
=======================================
  Files         220      220           
  Lines       41105    41137   +32     
=======================================
+ Hits        38327    38360   +33     
+ Misses       2778     2777    -1     
Flag Coverage Δ
lint_rules 96.39% <ø> (ø)
loki 93.20% <100.00%> (+<0.01%) ⬆️

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.


🚨 Try these New Features:

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, this looks good to me. I've left two remarks how to improve the implementation a little bit but that's not mandatory. I'll leave it up to you whether you want to give this a try.

Comment on lines 246 to 255
for b in i.body:
if isinstance(b, Subroutine):
if targets and b.name.lower() in targets:
# Create a new module import with explicitly qualified symbol
modname = f'{b.name}_FC_MOD'
new_symbol = Variable(name=f'{b.name}_FC', scope=routine)
new_import = Import(module=modname, c_import=False, symbols=(new_symbol,))
routine.spec.prepend(new_import)
# Mark current import for removal
removal_map[i] = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might want to use the API properties of Interface here:

Suggested change
for b in i.body:
if isinstance(b, Subroutine):
if targets and b.name.lower() in targets:
# Create a new module import with explicitly qualified symbol
modname = f'{b.name}_FC_MOD'
new_symbol = Variable(name=f'{b.name}_FC', scope=routine)
new_import = Import(module=modname, c_import=False, symbols=(new_symbol,))
routine.spec.prepend(new_import)
# Mark current import for removal
removal_map[i] = None
for s in i.symbols:
if targets and s in targets:
# Create a new module import with explicitly qualified symbol
new_symbol = s.clone(name=f'{s.name}_FC', scope=routine)
modname = f'{new_symbol.name}_MOD'
new_import = Import(module=modname, c_import=False, symbols=(new_symbol,))
routine.spec.prepend(new_import)
# Mark current import for removal
removal_map[i] = None

Comment on lines 1385 to 1416
interfaces = FindNodes(ir.Interface).visit(routine.spec)
imports = FindNodes(ir.Import).visit(routine.spec)
assert len(interfaces) == 2
assert len(imports) == 1
assert imports[0].module.upper() == 'KERNEL_FC_MOD'
Copy link
Collaborator

Choose a reason for hiding this comment

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

You might want to verify here also the name of the imported symbol.

Suggested improvement that uses more API functions:

Suggested change
interfaces = FindNodes(ir.Interface).visit(routine.spec)
imports = FindNodes(ir.Import).visit(routine.spec)
assert len(interfaces) == 2
assert len(imports) == 1
assert imports[0].module.upper() == 'KERNEL_FC_MOD'
assert len(routine.interfaces) == 2
imports = routine.imports
assert len(imports) == 1
assert imports[0].module.upper() == 'KERNEL_FC_MOD'
assert imports[0].symbols == ('KERNEL_FC',)

@reuterbal reuterbal added the rebase required Rebase required for the PR branch to resolve conflicts label Nov 24, 2024
@MichaelSt98 MichaelSt98 force-pushed the nams-f2c-interface-to-import branch from 6aaeeb3 to 8fdf8f4 Compare November 25, 2024 12:26
@MichaelSt98 MichaelSt98 mentioned this pull request Nov 25, 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.

Many thanks, looks good now. I'll wait for tests to go green, then we can put this in before 0.2.9

@reuterbal reuterbal removed the rebase required Rebase required for the PR branch to resolve conflicts label Nov 25, 2024
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.

Yes, looks great. GTG.

@reuterbal reuterbal force-pushed the nams-f2c-interface-to-import branch from fa94623 to 384e2ec Compare November 25, 2024 13:10
@reuterbal reuterbal merged commit bc0b603 into main Nov 25, 2024
13 checks passed
@reuterbal reuterbal deleted the nams-f2c-interface-to-import branch November 25, 2024 14:47
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

Successfully merging this pull request may close these issues.

3 participants