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

(Closes #2499) scalarization transformation implementation #2563

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
59d9875
First code towards #2499
LonelyCat124 Apr 29, 2024
ede95c7
forgotten file
LonelyCat124 Apr 29, 2024
6ae3ae3
First implementation of scalarization_trans and unit tests for the pr…
LonelyCat124 Apr 30, 2024
c7cf88c
Linting errors
LonelyCat124 Apr 30, 2024
577d702
Linting errors
LonelyCat124 Apr 30, 2024
d76bfb6
Final commits ready for a review
LonelyCat124 May 1, 2024
2523a6b
Added compile test
LonelyCat124 May 1, 2024
fece2bd
linting
LonelyCat124 May 1, 2024
ed75417
Changes to use filter to make the code easier to understand
LonelyCat124 May 20, 2024
8504137
Merged master
LonelyCat124 Jan 9, 2025
bd2144b
Changes to work with master
LonelyCat124 Jan 9, 2025
047c4a6
First section of rewriting, coverage issues to fix
LonelyCat124 Jan 10, 2025
b1d9544
linting error
LonelyCat124 Jan 10, 2025
2988358
Merge branch 'master' into 2499_scalarization_trans
LonelyCat124 Jan 10, 2025
dc69373
Updated tests for coverage. Now need to do some more complex function…
LonelyCat124 Jan 10, 2025
1a1531a
Missing coverage for other types of read
LonelyCat124 Jan 10, 2025
a506244
linting fix
LonelyCat124 Jan 10, 2025
75b77d7
Added another test
LonelyCat124 Jan 10, 2025
280cdb6
Added documentation to scalarization trans including an example
LonelyCat124 Jan 13, 2025
c97975f
Merge branch 'master' into 2499_scalarization_trans
LonelyCat124 Jan 13, 2025
74c7081
Fixed doc errors
LonelyCat124 Jan 14, 2025
058b3ef
Changes for the review
LonelyCat124 Jan 22, 2025
fae6466
Merge branch 'master' into 2499_scalarization_trans
LonelyCat124 Jan 22, 2025
4984dcd
Fixed the docuemntation
LonelyCat124 Jan 22, 2025
caf0176
Fixed linting
LonelyCat124 Jan 22, 2025
c4b9641
Changes towards review, blocked by #2870
LonelyCat124 Jan 23, 2025
e6c3072
Remove failing test that didn't meet the Fortran standard
LonelyCat124 Jan 23, 2025
ef3cd34
Added the transformation into the User guide
LonelyCat124 Jan 23, 2025
6d8bff5
Scalarize every loop to ensure nothing breaks in NEMO - Revert this l…
LonelyCat124 Jan 25, 2025
4974a6e
Fix tests to compile
LonelyCat124 Jan 27, 2025
409b859
Linting fix
LonelyCat124 Jan 27, 2025
8d51936
Failure to import scalarizationtrans fix
LonelyCat124 Jan 27, 2025
2ce0efa
Merge branch 'master' into 2499_scalarization_trans
LonelyCat124 Jan 27, 2025
dbae47c
Fix a bug from NEMO4 integration tests where the transformation faile…
LonelyCat124 Jan 27, 2025
a897bf9
git pushMerge branch '2499_scalarization_trans' of github.com:stfc/PS…
LonelyCat124 Jan 27, 2025
a840c8b
Fix another NEMO4 failure case
LonelyCat124 Jan 28, 2025
01912bd
fixed the issue in definition use chains when we find empty scopes
LonelyCat124 Jan 28, 2025
9e75ce6
flake issues
LonelyCat124 Jan 28, 2025
0b37212
Testing scalarization in passthrough instead of on GPU
LonelyCat124 Jan 28, 2025
9818e4b
Go again
LonelyCat124 Jan 29, 2025
c795eb1
another change to test things as we need to skip some files for now w…
LonelyCat124 Jan 29, 2025
4093d66
run the passthrough code for nemo4
LonelyCat124 Jan 29, 2025
956c164
Merge branch 'master' into 2499_scalarization_trans
LonelyCat124 Jan 31, 2025
250c259
Fix known bugs scalarizing NEMO
LonelyCat124 Jan 31, 2025
51814b5
linting
LonelyCat124 Jan 31, 2025
94f99eb
Linting
LonelyCat124 Jan 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/nemo_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ jobs:
module load perl/${PERL_VERSION}
make -j 4 passthrough
make -j 4 compile-passthrough
make run-passthrough |& tee output.txt
# Check the output is as expected for the first 6 digits (if not exit with error message)
tail -n 1 output.txt | grep -q " it : 10" || (echo "Error: 'it : 10' not found!" & false)
tail -n 1 output.txt | grep -q "|ssh|_max: 0.259483" || (echo "Error: '|ssh|_max: 0.259483' not found!" & false)
tail -n 1 output.txt | grep -q "|U|_max: 0.458515" || (echo "Error: '|U|_max: 0.458515' not found!" & false)
tail -n 1 output.txt | grep -q "S_min: 0.482686" || (echo "Error: 'S_min: 0.482686' not found!" & false)
tail -n 1 output.txt | grep -q "S_max: 0.407622" || (echo "Error: 'S_max: 0.407622' not found!" & false)

# PSyclone, compile and run MetOffice NEMO with OpenMP for GPUs
- name: NEMO MetOffice OpenMP for GPU
Expand Down
7 changes: 7 additions & 0 deletions doc/user_guide/transformations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,13 @@ can be found in the API-specific sections).

####

.. autoclass:: psyclone.psyir.transformations.ScalarizationTrans
:members: apply
:noindex:

####


Algorithm-layer
---------------

Expand Down
13 changes: 12 additions & 1 deletion examples/nemo/scripts/passthrough.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,21 @@
''' Process Nemo code with PSyclone but don't do any changes. This file is only
needed to provide a FILES_TO_SKIP list. '''
from utils import PASSTHROUGH_ISSUES
# TODO Remove
from psyclone.psyir.transformations import ScalarizationTrans
from psyclone.psyir.nodes import Routine, Loop

# List of all files that psyclone will skip processing
FILES_TO_SKIP = PASSTHROUGH_ISSUES


def trans(_):
def trans(psyir):
''' Don't do any changes. '''
if psyir.name.startswith("obs_"):
print("Skipping file", psyir.name)
return
# TODO REMOVE
for subroutine in psyir.walk(Routine):
scalartrans = ScalarizationTrans()
for loop in subroutine.walk(Loop):
scalartrans.apply(loop)
17 changes: 17 additions & 0 deletions src/psyclone/psyir/nodes/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,23 @@ def update_parent_symbol_table(self, new_parent):

'''

def is_descendent_of(self, potential_ancestor) -> bool:
'''
Checks if this node is a descendant of the `potential_ancestor` node.

:param potential_ancestor: The Node to check whether its an ancestor
of self.
:type node: :py:class:`psyclone.psyir.nodes.Node`

:returns: whether potential_ancestor is an ancestor of this node.
'''
current_node = self
while (current_node is not potential_ancestor and
current_node.parent is not None):
current_node = current_node.parent

return current_node is potential_ancestor


# For automatic documentation generation
# TODO #913 the 'colored' routine shouldn't be in this module.
Expand Down
54 changes: 36 additions & 18 deletions src/psyclone/psyir/tools/definition_use_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,20 @@ def find_forward_accesses(self):
.abs_position
+ 1
)
# We make a copy of the reference to have a detached
# node to avoid handling the special cases based on
# the parents of the reference.
chain = DefinitionUseChain(
self._reference.copy(),
body,
start_point=ancestor.abs_position,
stop_point=sub_stop_point,
)
chains.insert(0, chain)
# If we have a basic block with no children then skip it,
# e.g. for an if block with no code before the else
# statement, as is found in NEMO4.
if len(body) > 0:
# We make a copy of the reference to have a detached
# node to avoid handling the special cases based on
# the parents of the reference.
chain = DefinitionUseChain(
self._reference.copy(),
body,
start_point=ancestor.abs_position,
stop_point=sub_stop_point,
)
chains.insert(0, chain)
# If its a while loop, create a basic block for the while
# condition.
if isinstance(ancestor, WhileLoop):
Expand Down Expand Up @@ -300,6 +304,11 @@ def find_forward_accesses(self):
# Now add all the other standardly handled basic_blocks to the
# list of chains.
for block in basic_blocks:
# If we have a basic block with no children then skip it,
# e.g. for an if block with no code before the else
# statement, as is found in NEMO4.
if len(block) == 0:
continue
chain = DefinitionUseChain(
self._reference,
block,
Expand Down Expand Up @@ -835,6 +844,11 @@ def find_backward_accesses(self):
# Now add all the other standardly handled basic_blocks to the
# list of chains.
for block in basic_blocks:
# If we have a basic block with no children then skip it,
# e.g. for an if block with no code before the else
# statement, as is found in NEMO4.
if len(block) == 0:
continue
chain = DefinitionUseChain(
self._reference,
block,
Expand Down Expand Up @@ -874,14 +888,18 @@ def find_backward_accesses(self):
).abs_position
else:
sub_start_point = self._reference.abs_position
chain = DefinitionUseChain(
self._reference.copy(),
body,
start_point=sub_start_point,
stop_point=sub_stop_point,
)
chains.append(chain)
control_flow_nodes.append(ancestor)
# If we have a basic block with no children then skip it,
# e.g. for an if block with no code before the else
# statement, as is found in NEMO4.
if len(body) > 0:
chain = DefinitionUseChain(
self._reference.copy(),
body,
start_point=sub_start_point,
stop_point=sub_stop_point,
)
chains.append(chain)
control_flow_nodes.append(ancestor)
# If its a while loop, create a basic block for the while
# condition.
if isinstance(ancestor, WhileLoop):
Expand Down
3 changes: 3 additions & 0 deletions src/psyclone/psyir/transformations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
ReplaceInductionVariablesTrans
from psyclone.psyir.transformations.reference2arrayrange_trans import \
Reference2ArrayRangeTrans
from psyclone.psyir.transformations.scalarization_trans import \
ScalarizationTrans


# For AutoAPI documentation generation
Expand Down Expand Up @@ -145,5 +147,6 @@
'Reference2ArrayRangeTrans',
'RegionTrans',
'ReplaceInductionVariablesTrans',
'ScalarizationTrans',
'TransformationError',
'ValueRangeCheckTrans']
Loading
Loading