Skip to content

(Towards #1823) Permit only module-inlined Kernels to be transformed#3294

Open
arporter wants to merge 22 commits intomasterfrom
1823_transform_inlined_kerns_only
Open

(Towards #1823) Permit only module-inlined Kernels to be transformed#3294
arporter wants to merge 22 commits intomasterfrom
1823_transform_inlined_kerns_only

Conversation

@arporter
Copy link
Member

No description provided.

@arporter arporter self-assigned this Jan 21, 2026
@arporter arporter marked this pull request as draft January 21, 2026 17:11
@arporter
Copy link
Member Author

Possibly I need to store the RoutineSymbol associated with a Kernel within the Kernel class (c.f. Call.reference). That way, I can tell whether it has been module-inlined or not and can get rid of the special flag for that.

@arporter
Copy link
Member Author

arporter commented Jan 23, 2026

Note to self: I will need to remove the kernel_outputdir test fixture.

EDIT: can't do this because we do still output OpenCL versions of kernels in some tests.

@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.95%. Comparing base (ef6e0cf) to head (7d8ada3).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3294      +/-   ##
==========================================
- Coverage   99.95%   99.95%   -0.01%     
==========================================
  Files         381      382       +1     
  Lines       53995    53878     -117     
==========================================
- Hits        53973    53856     -117     
  Misses         22       22              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@arporter
Copy link
Member Author

arporter commented Feb 4, 2026

Coverage is now all good but the LFRic extraction integration test failed :-(

@arporter
Copy link
Member Author

arporter commented Feb 4, 2026

In lfric/eg17/full_example_extract:

$ diff main_psy.f90 on_main/main_psy.f90 
4d3
<   use testkern_w0_kernel_mod, only : testkern_w0_code
74a74
>     use testkern_w0_kernel_mod, only : some_other_var, testkern_w0_code

so it appears the some_other_var import is missing on my branch.

@arporter
Copy link
Member Author

arporter commented Feb 4, 2026

This turned out to be due to the fact that I've moved the import of Kernel routines up into the Container and then the ExtractNode was falling foul of #1734

@arporter arporter marked this pull request as ready for review February 4, 2026 21:07
@arporter
Copy link
Member Author

arporter commented Feb 4, 2026

Assuming the ITs come back green this time, this is ready for review. Primarily, it adds checks such that any kernel transformations will fail unless the kernel has already been module inlined. Unfortunately, updating some of those transformations got a bit hairy (e.g. to deal with multiple calls to the same kernel). The situation will improve again once we re-name module-inlined routines (which this PR is a pre-cursor to). As part of this, I moved the location of the USE statements for kernel modules up to the container level. This affected the text checked for in quite a few tests.
Now that we require a kernel to be module-inlined before it is transformed, I have removed all of the 'rename-and-write' machinery that we used to have. Now that I write that, this probably means the user guide needs to be updated and I'm pretty sure I haven't done that. That can be for next time around ;-)
One for @hiker, @sergisiso or @LonelyCat124.

Copy link
Collaborator

@sergisiso sergisiso left a comment

Choose a reason for hiding this comment

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

@arporter I am really happy to see that we are getting rid of rename_and_write.

This is an important change with implications to the CLI and output behaviour. I would prefer that you create an issue for it instead of being just a towards a meta-issue with many other things.

Now that I write that, this probably means the user guide needs to be updated and I'm pretty sure I haven't done that.

This. But also looking at the documentation, can we delete the "--kernel-renaming" option from generator.py?

Now that we require a kernel to be module-inlined before it is transformed,

Not necessarily, LFRic can now ask psyclone to process kernel files (it is essentially what 'transmute' is). It is more "now we require kernels specifically modified for an invoke to be module-inlined first". I don't know if it belongs to our documentation, but if we do we want to be clear about it.

# Convert any accesses to imported data into kernel arguments, put an
# 'acc routine' directive inside, and module-inline each kernel
for kern in schedule.coded_kernels():
itrans.apply(kern)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you rename it to mod_inline_trans (to prevent confusions with i(nline_)trans)

f"because")

rsymbol = node.scope.symbol_table.lookup(node.name, otherwise=None)
if not rsymbol or rsymbol.is_import or rsymbol.is_unresolved:
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe: if not rsymbol or not rsymbol.is_modulevar: ?

Comment on lines +87 to +88
assert ("Cannot transform this Kernel call to 'kernel_with_global_code' "
"because it is not module inlined" in str(err.value))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am wondering if we shouldn't assume that users know what "module inline" means here, as we use it but it has been confusing before. Maybe the error could be:
"Cannot transform this kernel because its implementation resides in a different file, apply the KernelModuleInlineTrans first to bring it to this module".

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh looking at KernelTransformationMixin message it is different. Do we double check this condition?

assert expected_output in out


def test_codedkern_module_inline_getter_and_setter():
Copy link
Collaborator

Choose a reason for hiding this comment

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

The getter still exists, do we want to keep a test for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants