Skip to content

Commit

Permalink
#1623 Updated psyclone scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiker committed Jan 16, 2025
1 parent cbe37b4 commit ec96efd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 59 deletions.
29 changes: 12 additions & 17 deletions tutorial/training/transformation/3.2/omp_parallel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -----------------------------------------------------------------------------
# BSD 3-Clause License
#
# Copyright (c) 2018-2024, Science and Technology Facilities Council
# Copyright (c) 2024-2025, Science and Technology Facilities Council
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -31,18 +31,9 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# Authors: R. W. Ford, A. R. Porter and S. Siso, STFC Daresbury Lab
# Author: J. Henrichs, Bureau of Meteorology

'''A simple transformation script for the introduction of OpenMP with PSyclone.
In order to use it you must first install PSyclone. See README.md in the
top-level psyclone directory.
Once you have PSyclone installed, this script may be used by doing:
>>> psyclone -s ./omp_levels_trans.py traldf_iso.F90
This should produce a lot of output, ending with generated
Fortran.
'''A simple generic transformation script to apply omp parallel and omp do.
'''

from psyclone.transformations import OMPLoopTrans, OMPParallelTrans
Expand All @@ -58,7 +49,8 @@

def trans(psyir):
''' Transform a specific Schedule by making all loops
over levels OpenMP parallel.
over latitudes OpenMP parallel, and adding an omp parallel
in the calling subroutine.
:param psyir: the PSyIR of the provided file.
:type psyir: :py:class:`psyclone.psyir.nodes.FileContainer`
Expand All @@ -67,13 +59,16 @@ def trans(psyir):
omp_parallel = OMPParallelTrans()
omp_do = OMPLoopTrans()

# In case of a transformation, the argument psyir is a FileContainer
# The argument psyir is a FileContainer
print("Filename is", psyir.name)

# Apply it to each loop over levels containing a kernel
# Apply it to each loop over latitudes containing a kernel
for loop in psyir.walk(Loop):
if loop.loop_type == "lat":
# Apply transformation for outer loops:
# Apply transformation. Note that you need to specify
# "--backend disable-validation" on the PSyclone command line,
# since PSyclone will otherwise prevent you from adding a `omp do`
# with no surrounding omp parallel.
omp_do.apply(loop)
elif loop.loop_type == None and # Check file name before applying
elif loop.loop_type is None and # Check file name before applying
# TODO: Add omp parallel in the time stepping loop
18 changes: 5 additions & 13 deletions tutorial/training/transformation/3.2/omp_trans.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -----------------------------------------------------------------------------
# BSD 3-Clause License
#
# Copyright (c) 2018-2024, Science and Technology Facilities Council
# Copyright (c) 2024-2025, Science and Technology Facilities Council
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -31,18 +31,9 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# Authors: R. W. Ford, A. R. Porter and S. Siso, STFC Daresbury Lab
# Author: J. Henrichs, Bureau of Meteorology

'''A simple transformation script for the introduction of OpenMP with PSyclone.
In order to use it you must first install PSyclone. See README.md in the
top-level psyclone directory.
Once you have PSyclone installed, this script may be used by doing:
>>> psyclone -s ./omp_levels_trans.py traldf_iso.F90
This should produce a lot of output, ending with generated
Fortran.
'''A simple generic transformation script to apply omp parallel do.
'''

from psyclone.transformations import OMPParallelLoopTrans, TransformationError
Expand All @@ -58,7 +49,7 @@

def trans(psyir):
''' Transform a specific Schedule by making all loops
over levels OpenMP parallel.
over latitudes OpenMP parallel do.
:param psyir: the PSyIR of the provided file.
:type psyir: :py:class:`psyclone.psyir.nodes.FileContainer`
Expand All @@ -68,5 +59,6 @@ def trans(psyir):
ompt = OMPParallelLoopTrans()
# Apply it to each loop over levels containing a kernel
for loop in psyir.walk(Loop):
print("loop", loop.loop_type)
if loop.loop_type == "TODO #loop type as defined in inference rules"
# Apply transformation
30 changes: 14 additions & 16 deletions tutorial/training/transformation/3.2/solution/omp_parallel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -----------------------------------------------------------------------------
# BSD 3-Clause License
#
# Copyright (c) 2018-2024, Science and Technology Facilities Council
# Copyright (c) 2024-2025, Science and Technology Facilities Council
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -31,18 +31,9 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# Authors: R. W. Ford, A. R. Porter and S. Siso, STFC Daresbury Lab
# Author: J. Henrichs, Bureau of Meteorology

'''A simple transformation script for the introduction of OpenMP with PSyclone.
In order to use it you must first install PSyclone. See README.md in the
top-level psyclone directory.
Once you have PSyclone installed, this script may be used by doing:
>>> psyclone -s ./omp_levels_trans.py traldf_iso.F90
This should produce a lot of output, ending with generated
Fortran.
'''A simple generic transformation script to apply omp parallel and omp do.
'''

from psyclone.transformations import OMPLoopTrans, OMPParallelTrans
Expand All @@ -58,7 +49,8 @@

def trans(psyir):
''' Transform a specific Schedule by making all loops
over levels OpenMP parallel.
over latitudes OpenMP parallel, and adding an omp parallel
in the calling subroutine.
:param psyir: the PSyIR of the provided file.
:type psyir: :py:class:`psyclone.psyir.nodes.FileContainer`
Expand All @@ -67,11 +59,17 @@ def trans(psyir):
omp_parallel = OMPParallelTrans()
omp_do = OMPLoopTrans()

# Apply it to each loop over levels containing a kernel
# The argument psyir is a FileContainer
print("Filename is", psyir.name)

# Apply it to each loop over latitudes containing a kernel
for loop in psyir.walk(Loop):
if loop.loop_type == "lat":
# Apply transformation
# Apply transformation. Note that you need to specify
# "--backend disable-validation" on the PSyclone command line,
# since PSyclone will otherwise prevent you from adding a `omp do`
# with no surrounding omp parallel.
omp_do.apply(loop)
elif loop.loop_type == None and psyir.name == "time_step_mod.x90":
elif loop.loop_type is None and psyir.name == "time_step_mod.x90":
# Add omp parallel in the time stepping loop
omp_parallel.apply(loop.loop_body)
17 changes: 4 additions & 13 deletions tutorial/training/transformation/3.2/solution/omp_trans.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -----------------------------------------------------------------------------
# BSD 3-Clause License
#
# Copyright (c) 2018-2024, Science and Technology Facilities Council
# Copyright (c) 2024-2025, Science and Technology Facilities Council
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -31,18 +31,9 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# Authors: R. W. Ford, A. R. Porter and S. Siso, STFC Daresbury Lab
# Author: J. Henrichs, Bureau of Meteorology

'''A simple transformation script for the introduction of OpenMP with PSyclone.
In order to use it you must first install PSyclone. See README.md in the
top-level psyclone directory.
Once you have PSyclone installed, this script may be used by doing:
>>> psyclone -s ./omp_levels_trans.py traldf_iso.F90
This should produce a lot of output, ending with generated
Fortran.
'''A simple generic transformation script to apply omp parallel do.
'''

from psyclone.transformations import OMPParallelLoopTrans, TransformationError
Expand All @@ -58,7 +49,7 @@

def trans(psyir):
''' Transform a specific Schedule by making all loops
over levels OpenMP parallel.
over latitudes OpenMP parallel do.
:param psyir: the PSyIR of the provided file.
:type psyir: :py:class:`psyclone.psyir.nodes.FileContainer`
Expand Down

0 comments on commit ec96efd

Please sign in to comment.