Skip to content

Unroll array initialisers - #712

Merged
awnawab merged 4 commits into
mainfrom
naan-unroll-array-init
Jul 27, 2026
Merged

awnawab merged 4 commits into
mainfrom
naan-unroll-array-init

Conversation

@awnawab

@awnawab awnawab commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

This PR updates the ResolveVectorNotationTransformation so that array initialisers are unrolled.

Some array initialisation statements proved to be very costly in the GPU runs on jupiter. It's hard to determine a priori which ones will bite, so we unroll simple 1D constant bound array initialiasation statements automatically with this PR. A warning is printed for more complex unresolvable ones so that they are easily identifiable and can be addressed in source if necessary.

@github-actions

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.10145% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.21%. Comparing base (f42a5ac) to head (eb83512).

Files with missing lines Patch % Lines
.../transformations/array_indexing/vector_notation.py 93.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #712      +/-   ##
==========================================
+ Coverage   94.19%   94.21%   +0.01%     
==========================================
  Files         291      291              
  Lines       48719    48774      +55     
==========================================
+ Hits        45893    45950      +57     
+ Misses       2826     2824       -2     
Flag Coverage Δ
lint_rules 96.37% <ø> (ø)
loki 94.18% <97.10%> (+0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

@awnawab
awnawab force-pushed the naan-unroll-array-init branch from 2be4783 to 01abdf0 Compare July 13, 2026 07:58
@awnawab
awnawab force-pushed the naan-unroll-array-init branch from 01abdf0 to f5d9059 Compare July 13, 2026 09:52
@awnawab
awnawab marked this pull request as ready for review July 13, 2026 09:56
if resolved:
return resolved
scope_str = f' in routine "{self.scope.name}"' if self.scope is not None else ''
warning(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This warning is not really up-to-date anymore. It will get here either because the RHS is a mixed expression or because the LHS array has bar :. I'd move the warning inside _resolve_literal_list

@MichaelSt98 MichaelSt98 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There are more funky Literal lists in Fortran ...

For example:

arr(1:3) = [(i, i=1,3)]

gets transformed to:

arr(1) = ( i, i = 1,3 )

which is clearly wrong.
Especially those literal lists/ array initialisers are dangerous regarding performance...

@MichaelSt98 MichaelSt98 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great!
The only thing we could think of is making this optional.

@mlange05 mlange05 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me - only picked on a minor cosmetic nitpick (optional). Otherwise GTG and very neatly implemented. 👍 :shipit:

if l.variable.name.startswith('i_'):
generated_loop_bodies.extend(FindNodes(ir.Assignment).visit(l.body))
literal_assigns = [a for a in assigns
if hasattr(a.rhs, 'elements') or 'LiteralList' in type(a.rhs).__name__]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not isinstance(a.rhs, sym.LiteralList)? This is a very odd way of checking type, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That was an LLM-ism I didn't catch, fixed now. Thanks!

@awnawab

awnawab commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor Author

The latest release of fastjsonschema introduced a bug (see horejsek/python-fastjsonschema#213) which affects python < 3.10 builds, so I've also updated loki's pyproject.toml to skip that version.

EDIT: a patched version of the package was released, so I've removed the workaround commit.

@awnawab
awnawab force-pushed the naan-unroll-array-init branch from eb83512 to da4352c Compare July 27, 2026 14:29
@mlange05 mlange05 added the ready to merge This PR has been approved and is ready to be merged label Jul 27, 2026
@awnawab
awnawab merged commit cd715fe into main Jul 27, 2026
45 of 51 checks passed
@awnawab
awnawab deleted the naan-unroll-array-init branch July 27, 2026 15:48
@mlange05 mlange05 mentioned this pull request Aug 25, 2026
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