Skip to content

New transformation: ReplaceKernels#692

Open
MichaelSt98 wants to merge 1 commit into
mainfrom
nams-sk-replace-kernels
Open

New transformation: ReplaceKernels#692
MichaelSt98 wants to merge 1 commit into
mainfrom
nams-sk-replace-kernels

Conversation

@MichaelSt98
Copy link
Copy Markdown
Collaborator

Replace configured kernel calls with alternative routines.

Conceptually, the transformation walks each call site in the processed routine, looks for names listed in replace_kernels_map, resolves the replacement routine, and reconstructs the actual argument list against the replacement signature. When the original call target is unresolved in the IR, the transformation also tries to resolve the original routine from source so that remapping can still be done against the original dummy argument names instead of the raw actual expressions. Once the replacement call has been rebuilt, the transformation updates imports/includes to match the new callee and optionally marks the replacement routine as blocked for further scheduler traversal.

Description

This pull request introduces comprehensive tests for the new ReplaceKernels transformation and ensures it is imported as part of the main transformation package. The main focus is on verifying the correct remapping of kernel routine arguments, handling of optional arguments, import rewriting, plan generation, and pipeline integration.

Testing and Validation of ReplaceKernels Transformation

New test suite for kernel replacement:

  • Added test_replace_kernel.py containing multiple tests that cover argument remapping, handling of optional arguments, include/import rewriting, plan output, and integration in a pipeline. This ensures the ReplaceKernels transformation works as expected across a variety of scenarios.

Integration with transformation package:

  • Exposed replace_kernel transformation in the main loki.transformations package by importing it in __init__.py, making it available for general use.

Contributor Declaration

By opening this pull request, I affirm the following:

  • All authors agree to the Contributor License Agreement.
  • The code follows the project's coding standards.
  • I have performed self-review and added comments where needed.
  • I have added or updated tests to verify that my changes are effective and functional.
  • I have run all existing tests and confirmed they pass.

… with alternative routines.

Conceptually, the transformation walks each call site in the processed
routine, looks for names listed in ``replace_kernels_map``, resolves the
replacement routine, and reconstructs the actual argument list against the
replacement signature. When the original call target is unresolved in the
IR, the transformation also tries to resolve the original routine from
source so that remapping can still be done against the original dummy
argument names instead of the raw actual expressions. Once the replacement
call has been rebuilt, the transformation updates imports/includes to match
the new callee and optionally marks the replacement routine as blocked for
further scheduler traversal.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

❌ Patch coverage is 90.59140% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.18%. Comparing base (bfad794) to head (0a031fd).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
loki/transformations/replace_kernel.py 87.26% 34 Missing ⚠️
loki/transformations/tests/test_replace_kernel.py 99.03% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #692      +/-   ##
==========================================
- Coverage   94.19%   94.18%   -0.02%     
==========================================
  Files         288      290       +2     
  Lines       47496    47997     +501     
==========================================
+ Hits        44741    45204     +463     
- Misses       2755     2793      +38     
Flag Coverage Δ
lint_rules 96.40% <ø> (ø)
loki 94.15% <90.59%> (-0.02%) ⬇️

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.

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

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.

1 participant