Skip to content

Commit 4db024a

Browse files
committed
Revert changelog conflict
2 parents f2f0c02 + 11eaa13 commit 4db024a

32 files changed

Lines changed: 1061 additions & 507 deletions

changelog

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
2) PR #3464 towards #3463. Reverse the order to build maximal regions.
1+
4) PR #3465 for #2757. Adds the --script-kwargs command line
2+
option to pass arguments to transformation scripts.
3+
4+
3) PR #3480 for #3478. Updates OMPParallelLoopTrans to correctly
5+
use the kwargs approach.
6+
7+
2) PR #3455 for #3170. Adds support for fields and operators with
8+
explicit real32 and real64 kinds.
29

310
1) PR #3472 for #3471. Let the transformations get_options method
411
account for sub-transformation options.

config/psyclone.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ precision_map = i_def: 4,
9191
r_solver: 4,
9292
r_tran: 8,
9393
r_bl: 8,
94-
r_um: 8
94+
r_um: 8,
95+
real64: 8,
96+
real32: 4
9597

9698
# Specify whether we generate code to perform runtime correctness checks.
9799
# Allowed values:

doc/user_guide/getting_going.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ command. To list the available options run: ``psyclone -h``, it should output::
191191
-v, --version display version information
192192
-c CONFIG, --config CONFIG
193193
config file with PSyclone specific options
194-
-s SCRIPT, --script SCRIPT
195-
filename of a PSyclone optimisation recipe
196194
--enable-cache whether to enable caching of imported module dependencies (if
197195
enabled, it will generate a .psycache file of each imported module in
198196
the same location as the imported source file).
@@ -230,6 +228,12 @@ command. To list the available options run: ``psyclone -h``, it should output::
230228
--fixed-form forces PSyclone to parse this file as fixed format (default is to
231229
look at the input file extension).
232230

231+
Transformation scripts:
232+
-s SCRIPT, --script SCRIPT
233+
filename of a PSyclone optimisation recipe
234+
--script-kwargs SCRIPT_KWARGS
235+
Keyword arguments for the transformation script.
236+
233237
Directory management:
234238
-I INCLUDE, --include INCLUDE
235239
path to Fortran INCLUDE or module files

doc/user_guide/lfric.rst

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ Mixed Precision
432432

433433
The LFRic API supports the ability to specify the precision required
434434
by the model via precision variables. To make use of this, the code
435-
developer must declare scalars, arrays, fields and operators in the algorithm
435+
developer must declare scalars, arrays, fields and operators in the Algorithm
436436
layer with the required LFRic-supported precision. In the current
437437
implementation there are two supported precisions for ``REAL`` data and
438438
one each for ``INTEGER`` and ``LOGICAL`` data. The actual precision used in
@@ -471,6 +471,10 @@ associated kernel metadata description and their precision:
471471
+--------------------------+---------------------------------------+-----------+
472472
| R_TRAN_FIELD_TYPE | GH_FIELD, GH_REAL | R_TRAN |
473473
+--------------------------+---------------------------------------+-----------+
474+
| FIELD_REAL32_TYPE | GH_FIELD, GH_REAL | REAL32 |
475+
+--------------------------+---------------------------------------+-----------+
476+
| FIELD_REAL64_TYPE | GH_FIELD, GH_REAL | REAL64 |
477+
+--------------------------+---------------------------------------+-----------+
474478
| INTEGER_FIELD_TYPE | GH_FIELD, GH_INTEGER | I_DEF |
475479
+--------------------------+---------------------------------------+-----------+
476480
| OPERATOR_TYPE | GH_OPERATOR, GH_REAL | R_DEF |
@@ -479,13 +483,18 @@ associated kernel metadata description and their precision:
479483
+--------------------------+---------------------------------------+-----------+
480484
| R_TRAN_OPERATOR_TYPE | GH_OPERATOR, GH_REAL | R_TRAN |
481485
+--------------------------+---------------------------------------+-----------+
486+
| OPERATOR_REAL32_TYPE | GH_OPERATOR, GH_REAL | REAL32 |
487+
+--------------------------+---------------------------------------+-----------+
488+
| OPERATOR_REAL64_TYPE | GH_OPERATOR, GH_REAL | REAL64 |
489+
+--------------------------+---------------------------------------+-----------+
482490
| COLUMNWISE_OPERATOR_TYPE | GH_COLUMNWISE_OPERATOR, GH_REAL | R_SOLVER |
483491
+--------------------------+---------------------------------------+-----------+
484492

485493
As can be seen from the above table, the kernel metadata does not
486494
capture all of the precision options. For example, from the metadata
487495
it is not possible to determine whether a ``REAL`` scalar, ``REAL`` field
488-
or ``REAL`` operator has precision ``R_DEF``, ``R_SOLVER`` or ``R_TRAN``.
496+
or ``REAL`` operator has precision ``R_DEF``, ``R_SOLVER``, ``R_TRAN``
497+
or one of the Fortran intrinsic precisions (``REAL32``, ``REAL64``).
489498

490499
If a scalar, array, field, or operator is specified with a particular
491500
precision in the algorithm layer then any associated kernels that it
@@ -601,6 +610,10 @@ outlined in the table below:
601610
+-------------------------+------------------+--------------+
602611
| ``r_tran_field_type`` | ``real`` | ``r_tran`` |
603612
+-------------------------+------------------+--------------+
613+
| ``field_real32_type`` | ``real`` | ``real32`` |
614+
+-------------------------+------------------+--------------+
615+
| ``field_real64_type`` | ``real`` | ``real64`` |
616+
+-------------------------+------------------+--------------+
604617
| ``integer_field_type`` | ``integer`` | ``i_def`` |
605618
+-------------------------+------------------+--------------+
606619

@@ -701,7 +714,8 @@ a message that indicates the problem.
701714
| Fortran Datatype | Supported Precision |
702715
+==================+==========================+
703716
| ``real`` | ``r_def``, ``r_bl``, |
704-
| | ``r_solver``, ``r_tran`` |
717+
| | ``r_solver``, ``r_tran``,|
718+
| | ``real32``, ``real64`` |
705719
+------------------+--------------------------+
706720
| ``integer`` | ``i_def`` |
707721
+------------------+--------------------------+
@@ -731,6 +745,10 @@ outlined in the table below:
731745
+----------------------------+------------------+--------------+
732746
| ``r_tran_operator_type`` | ``real`` | ``r_tran`` |
733747
+----------------------------+------------------+--------------+
748+
| ``operator_real32_type`` | ``real`` | ``real32`` |
749+
+----------------------------+------------------+--------------+
750+
| ``operator_real64_type`` | ``real`` | ``real64`` |
751+
+----------------------------+------------------+--------------+
734752

735753
.. _lfric-mixed-precision-cma-operators:
736754

doc/user_guide/psyclone_command.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ by the command:
7474
-v, --version display version information
7575
-c CONFIG, --config CONFIG
7676
config file with PSyclone specific options
77-
-s SCRIPT, --script SCRIPT
78-
filename of a PSyclone optimisation recipe
7977
--enable-cache whether to enable caching of imported module dependencies (if
8078
enabled, it will generate a .psycache file of each imported module in
8179
the same location as the imported source file).
@@ -115,6 +113,12 @@ by the command:
115113
--fixed-form forces PSyclone to parse this file as fixed format (default is to
116114
look at the input file extension).
117115
116+
Transformation scripts:
117+
-s SCRIPT, --script SCRIPT
118+
filename of a PSyclone optimisation recipe
119+
--script-kwargs SCRIPT_KWARGS
120+
Keyword arguments for the transformation script.
121+
118122
Directory management:
119123
-I INCLUDE, --include INCLUDE
120124
path to Fortran INCLUDE or module files

doc/user_guide/user_scripts.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,46 @@ and/or kernels) contained within the provided tree.
8989
The :ref:`examples section<examples>` provides a list of psyclone user scripts
9090
and associated usage instructions for multiple applications.
9191

92+
.. _script_kwargs:
93+
94+
Arguments for Scripts
95+
---------------------
96+
Scripts can take optional keyword arguments specified on the command line
97+
using the option `--script-kwargs`. The keyword arguments are specified
98+
in a string containing comma-delimited keyword:value pairs. For example:
99+
100+
101+
.. code-block:: shell
102+
103+
psyclone -s ./optimise.py input_source.f90 \
104+
--script-kwargs "omp: True, tiling: [4,4]"
105+
106+
This will result in the additional keyword arguments for any transformation call:
107+
108+
.. code-block:: python
109+
110+
def trans(psyir, omp: bool, tiling: list[int]):
111+
# Modify psyir tree
112+
113+
The arguments specified will be converted into a Python-style dictionary, e.g.
114+
``omp: True, tiling: [4,4]`` will be parsed as ``{omp: True, tiling: [4,4]}``.
115+
Therefore, the specified keyword arguments must make a valid dictionary.
116+
For example, ``[1,2]`` is not a valid keyword argument, because ``{[1,2]}``
117+
is not valid Python (a list is not hashable), and ``1:2`` would not be valid,
118+
because the keys of keyword arguments must be strings.
119+
120+
Obviously, the called transformation functions (``trans``, but also
121+
``trans_alg``, see below) must accept the specified keyword arguments. If
122+
an undeclared keyword argument is specified on the command line, the following
123+
error will be raised:
124+
125+
.. code-block:: shell
126+
127+
psyclone -s ./omp_gpu_profile_trans.py --script-kwargs "undeclared: True" ...
128+
Traceback (most recent call last):
129+
...
130+
TypeError: trans() got an unexpected keyword argument 'undeclared'
131+
92132
93133
.. _sec_script_globals:
94134

@@ -142,3 +182,8 @@ associated with the merged invoke.
142182

143183
An example of the use of a script making use of the ``trans_alg``
144184
function can be found in ``examples/gocean/eg7``.
185+
186+
Note that the ``trans_alg`` function will receive the same keyword arguments
187+
as the ``trans`` function if the PSyclone command line option
188+
``--script-kwargs`` is used (see :ref:`script_kwargs`). It is therefore
189+
important that both functions accept the same keyword arguments.

examples/nemo/eg8/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ PSYCLONE_PROFILING_LIB ?= ${PSYCLONE_PROFILING_DIR}/libsimple_timing.a
6060
PSYCLONE_PROFILING_LIBS ?= -L${PSYCLONE_PROFILING_DIR} -lsimple_timing
6161

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

6566
compile: transform traadv.exe
6667

examples/nemo/eg8/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ make transform
1818
or explicitly:
1919

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

2425
This emits transformed Fortran code with PSyData profiling around OpenMP target

examples/nemo/eg8/omp_gpu_profile_trans.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@
3333
# POSSIBILITY OF SUCH DAMAGE.
3434
# -----------------------------------------------------------------------------
3535

36-
import os
3736
import pathlib
3837
import sys
3938
from typing import List, Union
4039
from psyclone.psyir.nodes import (
41-
Assignment, IfBlock, Node, OMPDirective, OMPTargetDirective, ProfileNode,
42-
Routine, Schedule)
40+
Assignment, FileContainer, IfBlock, Node, OMPDirective,
41+
OMPTargetDirective, ProfileNode, Routine, Schedule)
4342
from psyclone.psyir.transformations import OMPTargetTrans, ProfileTrans
4443
from psyclone.transformations import OMPLoopTrans, TransformationError
4544

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

5251

53-
PROFILING_ENABLED = os.environ.get("ENABLE_PROFILING", False)
54-
55-
5652
def add_omp_region_profiling_markers(children: Union[List[Node], Schedule]):
5753
"""Insert profiling markers around all top-level OpenMP directives.
5854
@@ -94,8 +90,16 @@ def add_omp_region_profiling_markers(children: Union[List[Node], Schedule]):
9490
add_omp_region_profiling_markers(child.children)
9591

9692

97-
def trans(psyir):
98-
"""Apply OpenMP offloading and insert profiling around target regions."""
93+
def trans(psyir: FileContainer, profiling: bool = False):
94+
"""
95+
Apply OpenMP offloading and insert profiling around target regions.
96+
97+
:param psyir: the PSyIR of the file container to modify.
98+
:param profiling: if set to True (using the PSyclone command line option
99+
--scripts-kwargs "profiling: True"), also adds profiling
100+
instrumentation to the generated code.
101+
"""
102+
99103
from utils import normalise_loops, insert_explicit_loop_parallelism
100104

101105
omp_target_trans = OMPTargetTrans()
@@ -119,5 +123,5 @@ def trans(psyir):
119123
collapse=True,
120124
enable_reductions=True
121125
)
122-
if PROFILING_ENABLED:
126+
if profiling:
123127
add_omp_region_profiling_markers(subroutine.children)

src/psyclone/domain/lfric/lfric_constants.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ def __init__(self) -> None:
384384

385385
# ---------- Infrastructure module maps -------------------------------
386386

387+
# Those kind symbols used in LFRic that are actually
388+
# Fortran intrinsics (and thus don't come from constants_mod).
389+
LFRicConstants.INTRINSIC_KINDS = ("real32", "real64")
390+
LFRicConstants.FORTRAN_ISO_MOD_NAME = "iso_fortran_env"
391+
387392
# Dictionary allowing us to look-up the name of the Fortran module,
388393
# type and proxy-type associated with each LFRic data structure type.
389394
# Data structure type mandates its proxy name, Fortran intrinsic type
@@ -420,6 +425,18 @@ def __init__(self) -> None:
420425
"proxy_type": "r_bl_field_proxy_type",
421426
"intrinsic": "real",
422427
"kind": "r_bl"},
428+
# 'real'-valued field with explicit 32-bit precision
429+
"r_32_field": {"module": "field_real32_mod",
430+
"type": "field_real32_type",
431+
"proxy_type": "field_real32_proxy_type",
432+
"intrinsic": "real",
433+
"kind": "real32"},
434+
# 'real'-valued field with explicit 64-bit precision
435+
"r_64_field": {"module": "field_real64_mod",
436+
"type": "field_real64_type",
437+
"proxy_type": "field_real64_proxy_type",
438+
"intrinsic": "real",
439+
"kind": "real64"},
423440
# 'integer'-valued field with data of kind 'i_def'
424441
"integer_field": {"module": "integer_field_mod",
425442
"type": "integer_field_type",
@@ -432,6 +449,18 @@ def __init__(self) -> None:
432449
"proxy_type": "operator_proxy_type",
433450
"intrinsic": "real",
434451
"kind": "r_def"},
452+
# 'real'-valued operator with real32 data
453+
"r_32_operator": {"module": "operator_real32_mod",
454+
"type": "operator_real32_type",
455+
"proxy_type": "operator_real32_proxy_type",
456+
"intrinsic": "real",
457+
"kind": "real32"},
458+
# 'real'-valued operator with real32 data
459+
"r_64_operator": {"module": "operator_real64_mod",
460+
"type": "operator_real64_type",
461+
"proxy_type": "operator_real64_proxy_type",
462+
"intrinsic": "real",
463+
"kind": "real64"},
435464
# 'real'-valued operator with data of kind 'r_solver'
436465
"r_solver_operator": {
437466
"module": "r_solver_operator_mod",
@@ -454,6 +483,13 @@ def __init__(self) -> None:
454483
"intrinsic": "real",
455484
"kind": "r_solver"}}
456485

486+
# Construct a reverse map from type to the name of the LFRic
487+
# data type for all real field types.
488+
LFRicConstants.REAL_DATA_TYPE_RMAP = {}
489+
for key, value in LFRicConstants.DATA_TYPE_MAP.items():
490+
if value["intrinsic"] == "real" and "field" in key:
491+
LFRicConstants.REAL_DATA_TYPE_RMAP[value["type"]] = key
492+
457493
# Mapping from a vector type used in the algorithm-layer to
458494
# the actual type used in the PSy-layer.
459495
LFRicConstants.FIELD_VECTOR_TO_FIELD_MAP = {

0 commit comments

Comments
 (0)