Visitar URL original
Updates for expansion of array dimensions by schreiberx · Pull Request #3620 · stfc/PSyclone · GitHub
Skip to content

Updates for expansion of array dimensions - #3620

Open
schreiberx wants to merge 39 commits into
masterfrom
martin_array_dim_expansion
Open

schreiberx wants to merge 39 commits into
masterfrom
martin_array_dim_expansion

Conversation

@schreiberx

Copy link
Copy Markdown
Collaborator

It rejects expanding array dimensions for return values of functions.

@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a3f7aa9) to head (e80004e).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #3620   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          403       403           
  Lines        57394     57437   +43     
=========================================
+ Hits         57394     57437   +43     

☔ 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.

@arporter

arporter commented Oct 5, 2026

Copy link
Copy Markdown
Member

Thanks @schreiberx - please could you fix the coverage problems and then I'll review.

@schreiberx

Copy link
Copy Markdown
Collaborator Author

100% coverage. Your turn.

SCHREIBER Martin added 2 commits October 21, 2026 14:39
@schreiberx

Copy link
Copy Markdown
Collaborator Author

back to you

@arporter
arporter deployed to integration October 22, 2026 15:06 — with GitHub Actions Active
@arporter

Copy link
Copy Markdown
Member

Rather than to-and-fro on this Martin, I've taken it on.

@arporter

arporter commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

I'm worried that this PR may be hurting GPU performance (second blue bar from left):
image

@arporter

arporter commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

I've checked the three files where we do this transformation and the results of running PSyclone with this branch are identical to those on master:

$ psyclone --keep-comments --enable-cache -l output -s ${HOME}/PSyclone/examples/nemo/scripts/insert_loop_parallelism.py tests/BENCH_OMP_OFFLOAD_NVHPC/BLD/ppsrc/nemo/dynzdf.f90 -o psy_dynzdf_martin.f90
...
$ diff psy_dynzdf_ma*.f90
$ diff psy_trazdf_ma*.f90
$ diff psy_zdftke_ma*.f90

@arporter

Copy link
Copy Markdown
Member

I'm having a lot of trouble getting NEMO built so that I can test locally. I therefore propose that this is ready for review and I can try again later (or perhaps a re-run of the ITs will resolve it).
One for @sergisiso or @LonelyCat124.

@sergisiso sergisiso 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.

Thanks @arporter, I was not sure if I had to resolve the comments in the previous reviews or you still want to close those?

f"inside a Routine.")

# Convert to list of symbols, if provided as strings
arrays_symbols: list[DataSymbol] = []

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.

Maybe rename it to "arrays_symbols_to_increase" ?

Comment on lines +187 to +210
# This checks for assignments of the form `a = ...` where 'a'
# is requested to have its rank increased.
if assignment.lhs.symbol not in arrays_symbols:
continue

if assignment.is_descendant_of(target_loop):
continue

if not assignment.rhs.walk(Call):
continue

if isinstance(assignment.lhs.datatype,
(ArrayType, UnresolvedType)):
# Reject because such an assignment needs to change
# the function as well (or introduce one or more
# additional loops), e.g.:
# a(1,:) = 1 + dummy_func()
info_str = assignment.debug_string().strip()
raise TransformationError(
f"{self.name} No call on r.h.s. of an assignment"
" to an array range is allowed as this would"
" imply a change to the return type of the call"
f" ({info_str})."
)

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.

At the first glance I don't see why this is needed, the function does not need to change because in Fortran the rhs rank does not need to match the lhs rank, the value is expanded to all the missing range, it's the same as:
a(1,:) = 1
converted to:
a(1,:,:) = 1

@sergisiso sergisiso Oct 29, 2026 •

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.

Ok, I see it is not valid if dummy_func() returns an array, but this is not what is being tested, maybe we could do:
if not isinstance(assignment.rhs.datatype, ScalarType): ? and remove the walk(Call) as this is also true without the calls?

f"{self.name} can't be applied to character arrays.")

if (not array.is_automatic or not array.is_array or
isinstance(sym.datatype.intrinsic, DataTypeSymbol)):

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.

I suppose its array.datatype....., sym should not be used anymore

f"{self.name} provided array '{sym_or_name}' does not "
f"exist in this scope."
) from err
arrays_symbols.append(sym)

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.

Careful here we can insert non-DataSymbols in what we said it is a arrays_symbols: list[DataSymbol] = [], this means that the type checker is happy with some operations below, like array.datatype in line 252, but it will fail at runtime with an AttributeError.

I think we want to do is first the lookups then the DataSym validation:

if isinstance(sym_or_name, str):
      try:
          sym = target_loop.scope.symbol_table.lookup(array)
     except:
          # Error
else
   sym = sym_or_name
if isinstance(sym, DataSymbol):
   arrays_symbols.append(sym)
else:
   # Error

Comment on lines +284 to +285
# We iterate here over the arrays since it's more efficient
# than in the outer.

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.

No need for this 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.

In fact we don't do anything with array, why don't we simply do:

for ref in target_loop.walk(Reference):
    if ref in array_symbols:
        if type(ref) ...

f"for arrays accessed without indices. Found "
f"'{ref.ancestor(Statement).debug_string().strip()}'.")

array_ref: ArrayReference = ref

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.

I am a bit scared of this type statements, are we sure ref is always an ArrayReference here? If it should be, why not make it explicit by using:
if not isinstance(ref, ArrayReference):
if the condition above, then the typechecker already infers that "ref" is ArrayReference without a manual annotation that could lie.

integer :: i, j, k

! Reject because of such an assignment
a(1,:) = 1 + dummy_func()

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.

I have added the same comment in my review :) but in my case I cannot see why we reject this yet

integer :: i, j, k

! Reject because of such an assignment
a = 1 + dummy_func()

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.

Same here, why reject this?

This branch was successfully deployed

1 active (outdated) deployment
integration — b5f6c52d Deployed Oct 22, 2026 by arporter via build #1898
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.

4 participants