Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4e47def
#2757 Added --script-kwargs command line option to specify transforma…
hiker Jun 4, 2026
227c6e3
#2757 Fixed up typing.
hiker Jun 5, 2026
5e9b7e4
Merge remote-tracking branch 'origin/master' into 2757_script_arguments
hiker Jun 10, 2026
6b5f2ac
#2757 Updated docs.
hiker Jun 12, 2026
7bec6b0
Merge remote-tracking branch 'origin/master' into 2757_script_arguments
hiker Jun 15, 2026
c3f8df8
#2757 Started to add tests.
hiker Jun 15, 2026
ed81d59
#2757 Automatically convert script kwargs keys to be strings.
hiker Jun 16, 2026
b83eaa8
#2757 Added tests, improved coding style.
hiker Jun 18, 2026
c10d8e6
#2757 Added command line option to example.
hiker Jun 19, 2026
66893cb
#2757 Added documentation.
hiker Jun 19, 2026
8b580ef
#2757 Add keyword argument example to training.
hiker Jun 19, 2026
e3bbe18
#2757 Added more tests, fixed missing arguments.
hiker Jun 23, 2026
8bbe4e3
#2757 Ensure sys.path is not modified (which could affect the caller).
hiker Jun 23, 2026
b4ba079
#2757 Use consistent naming for transmutation functions.
hiker Jun 23, 2026
742b067
#2757 Reverted fixing sys.path and renaming the function, since it br…
hiker Jun 23, 2026
1caf710
#2757 Updated user guide for trans_alg.
hiker Jun 23, 2026
e3f8fdc
Merge remote-tracking branch 'origin/master' into 2757_script_arguments
hiker Jun 23, 2026
ea73141
#2757 Fixed flake8 failure.
hiker Jun 23, 2026
c47cd15
#2757 Make sure PARSE_STRING is always defined.
hiker Jun 24, 2026
adba928
Merge remote-tracking branch 'origin/master' into 2757_script_arguments
hiker Jun 24, 2026
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
25 changes: 25 additions & 0 deletions doc/user_guide/user_scripts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ and/or kernels) contained within the provided tree.
The :ref:`examples section<examples>` provides a list of psyclone user scripts
and associated usage instructions for multiple applications.

.. _script_kwargs:

Arguments for Scripts
---------------------
Scripts can take optional keyword arguments specified on the command line
using the option `--script-kwargs`. The keyword arguments are specified
as separate `keyword:value` pairs, separate by `,`. For example:

.. code-block:: shell

psyclone -s ./optimise.py input_source.f90 \
--scripts-kwargs "omp: True, tiling: [4,4]"

This will result in the additional keyword arguments for any transformation call:

.. code-block:: python

def trans(psyir, omp: bool, tiling: list[int]):
# Modify psyir tree


.. _sec_script_globals:

Expand Down Expand Up @@ -142,3 +162,8 @@ associated with the merged invoke.

An example of the use of a script making use of the ``trans_alg``
function can be found in ``examples/gocean/eg7``.

Note that the ``trans_alg`` function will receive the same keyword arguments
as the ``trans`` function if the PSyclone command line option
``--script-kwargs`` is used (see :ref:`script_kwargs`). It is therefore
important that both functions accept the same keyword arguments.
3 changes: 2 additions & 1 deletion examples/nemo/eg8/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ PSYCLONE_PROFILING_LIB ?= ${PSYCLONE_PROFILING_DIR}/libsimple_timing.a
PSYCLONE_PROFILING_LIBS ?= -L${PSYCLONE_PROFILING_DIR} -lsimple_timing

transform:
ENABLE_PROFILING=1 ${PSYCLONE} -s ./omp_gpu_profile_trans.py ../code/tra_adv.F90 -o traadv_instrumented.F90
${PSYCLONE} -s ./omp_gpu_profile_trans.py --script-kwargs "profiling: True" \
../code/tra_adv.F90 -o traadv_instrumented.F90

compile: transform traadv.exe

Expand Down
3 changes: 2 additions & 1 deletion examples/nemo/eg8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ make transform
or explicitly:

```sh
ENABLE_PROFILING=1 ${PSYCLONE} -s ./omp_gpu_profile_trans.py ../code/tra_adv.F90 -o traadv_instrumented.F90
${PSYCLONE} -s ./omp_gpu_profile_trans.py --script-kwargs "profiling: True" \
../code/tra_adv.F90 -o traadv_instrumented.F90
```

This emits transformed Fortran code with PSyData profiling around OpenMP target
Expand Down
22 changes: 13 additions & 9 deletions examples/nemo/eg8/omp_gpu_profile_trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------

import os
import pathlib
import sys
from typing import List, Union
from psyclone.psyir.nodes import (
Assignment, IfBlock, Node, OMPDirective, OMPTargetDirective, ProfileNode,
Routine, Schedule)
Assignment, FileContainer, IfBlock, Node, OMPDirective,
OMPTargetDirective, ProfileNode, Routine, Schedule)
from psyclone.psyir.transformations import OMPTargetTrans, ProfileTrans
from psyclone.transformations import OMPLoopTrans, TransformationError

Expand All @@ -50,9 +49,6 @@
sys.path.insert(0, str(NEMO_SCRIPTS_DIR))


PROFILING_ENABLED = os.environ.get("ENABLE_PROFILING", False)


def add_omp_region_profiling_markers(children: Union[List[Node], Schedule]):
"""Insert profiling markers around all top-level OpenMP directives.

Expand Down Expand Up @@ -94,8 +90,16 @@ def add_omp_region_profiling_markers(children: Union[List[Node], Schedule]):
add_omp_region_profiling_markers(child.children)


def trans(psyir):
"""Apply OpenMP offloading and insert profiling around target regions."""
def trans(psyir: FileContainer, profiling=False):
"""
Apply OpenMP offloading and insert profiling around target regions.

:param psyir: the PSyIR of the file container to modify.
:param profiling: if set to True (using the PSyclone command line option
--scripts-kwargs "profiling: True"), also adds profiling
instrumentation to the generated code.
"""

from utils import normalise_loops, insert_explicit_loop_parallelism

omp_target_trans = OMPTargetTrans()
Expand All @@ -119,5 +123,5 @@ def trans(psyir):
collapse=True,
enable_reductions=True
)
if PROFILING_ENABLED:
if profiling:
add_omp_region_profiling_markers(subroutine.children)
Loading
Loading