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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.06%. Comparing base (899f5ac) to head (6aaeeb3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #422      +/-   ##
==========================================
+ Coverage   93.04%   93.06%   +0.01%     
==========================================
  Files         198      198              
  Lines       39320    39353      +33     
==========================================
+ Hits        36587    36622      +35     
+ Misses       2733     2731       -2     
Flag Coverage Δ
lint_rules 96.39% <ø> (ø)
loki 93.01% <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.

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 +1389
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',)

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.

2 participants