Skip to content

Commit

Permalink
#2641 Updated documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiker committed Jul 9, 2024
1 parent 15f6aa9 commit b9d3358
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 110 deletions.
183 changes: 86 additions & 97 deletions doc/user_guide/profiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,30 @@ The automatic name generation depends on whether you are using a
PSyKAl DSL or only the transformation capabilities of PSyclone. If
you are transforming existing code:

* the ``module_name`` string is set to the name of the parent
function/subroutine/program. This name is unique as Fortran requires
* the ``module_name`` string is set to the module which contains the
current code. If there is no module (e.g. a stand-alone subroutine),
the subroutine name is used instead. This name is unique as Fortran requires
these names to be unique within a program.

* the ``region_name`` is set to an ``r`` (standing for region) followed by
an integer which uniquely identifies the profile within the parent
function/subroutine/program (based on the profile node's position in
the PSyIR representation relative to any other profile nodes).
* the ``region_name`` is set to the name of the subroutine, followed by
an ``r`` (standing for region) followed by an integer which uniquely identifies
the profile within the parent function/subroutine/program (based on the
profile node's position in the PSyIR representation relative to any other
profile nodes). If there is no module name (which means the ``module_name``
is already set to the subroutine name), only the ``r`` followed by an
integer number is specified.

Example:
.. code-block::
:caption: Profiling names used when transforming existing code.
:emphasize-lines: 2,4
! If the subroutine tra_adv is contained in module tra_adv_mod:
CALL profile_psy_data % PreStart("tra_adv_mod", "tra_adv-r0", 0, 0)
! If the subroutinetra_adv is not contained in a module:
CALL profile_psy_data % PreStart("tra_adv", "r0", 0, 0)
For the :ref:`LFRic <lfric-api>` and
:ref:`GOcean <gocean-api>` APIs:
Expand All @@ -486,96 +502,69 @@ For the :ref:`LFRic <lfric-api>` and
node's position in the PSyIR representation relative to any other
profile nodes). For example:

.. code-block::
:caption: PSyIR with profiling nodes.
:emphasize-lines: 2
InvokeSchedule[invoke='invoke_0', dm=True]
0: Profile[]
Schedule[]
0: Profile[]
Schedule[]
0: HaloExchange[field='f2', type='region', depth=1,
check_dirty=True]
1: HaloExchange[field='m1', type='region', depth=1,
check_dirty=True]
2: HaloExchange[field='m2', type='region', depth=1,
check_dirty=True]
1: Profile[]
Schedule[]
0: Loop[type='', field_space='w1', it_space='cells',
upper_bound='cell_halo(1)']
Literal[value:'1', DataType.INTEGER]
Literal[value:'mesh%get_last_halo_cell(1)',
DataType.INTEGER]
Literal[value:'1', DataType.INTEGER]
Schedule[]
0: CodedKern testkern_code(a,f1,f2,m1,m2)
[module_inline=False]
1: Profile[]
Schedule[]
0: Loop[type='', field_space='w1',
it_space='cells',
upper_bound='cell_halo(1)']
Literal[value:'1', DataType.INTEGER]
Literal[value:'mesh%get_last_halo_cell(1)',
DataType.INTEGER]
Literal[value:'1', DataType.INTEGER]
Schedule[]
0: CodedKern testkern_code(a,f1,f2,m1,m2)
[module_inline=False]
2: Loop[type='', field_space='w1', it_space='cells',
upper_bound='cell_halo(1)']
Literal[value:'1', DataType.INTEGER]
Literal[value:'mesh%get_last_halo_cell(1)', DataType.INTEGER]
Literal[value:'1', DataType.INTEGER]
Schedule[]
0: CodedKern testkern_qr_code(f1,f2,m1,a,m2,istp)
[module_inline=False]
This is the code created for this example:

.. code-block::
:caption: Created Fortran source code with profiling regions.
:emphasize-lines: 5,6,7,18,19,24,25
MODULE container
CONTAINS
SUBROUTINE invoke_0(a, f1, f2, m1, m2, istp, qr)
...
CALL psy_data_3%PreStart("multi_functions_multi_invokes_psy", "invoke_0-r0", &
.. code-block::
:caption: PSyIR with profiling nodes.
:emphasize-lines: 2,4,12
InvokeSchedule[invoke='invoke_0', dm=True]
0: Profile[]
Schedule[]
0: Profile[]
Schedule[]
0: HaloExchange[field='f2', type='region', depth=1,
check_dirty=True]
1: HaloExchange[field='m1', type='region', depth=1,
check_dirty=True]
2: HaloExchange[field='m2', type='region', depth=1,
check_dirty=True]
1: Profile[]
Schedule[]
0: Loop[type='', field_space='w1', it_space='cells',
upper_bound='cell_halo(1)']
Literal[value:'1', DataType.INTEGER]
Literal[value:'mesh%get_last_halo_cell(1)',
DataType.INTEGER]
Literal[value:'1', DataType.INTEGER]
Schedule[]
0: CodedKern testkern_code(a,f1,f2,m1,m2)
[module_inline=False]
This is the code created for this example:

.. code-block::
:caption: Created Fortran source code with profiling regions.
:emphasize-lines: 5,6,7,17,18,19,24,30
MODULE container
CONTAINS
SUBROUTINE invoke_0(a, f1, f2, m1, m2, istp, qr)
...
CALL psy_data_2%PreStart("multi_functions_multi_invokes_psy", "invoke_0-r0", &
0, 0)
CALL psy_data%PreStart("multi_functions_multi_invokes_psy", "invoke_0-r1", 0, 0)
IF (f2_proxy%is_dirty(depth=1)) THEN
CALL f2_proxy%halo_exchange(depth=1)
END IF
IF (m1_proxy%is_dirty(depth=1)) THEN
CALL m1_proxy%halo_exchange(depth=1)
END IF
IF (m2_proxy%is_dirty(depth=1)) THEN
CALL m2_proxy%halo_exchange(depth=1)
END IF
CALL psy_data%PreEnd()
CALL psy_data_1%PreStart("multi_functions_multi_invokes_psy", "invoke_0-r2", &
CALL psy_data%PreStart("multi_functions_multi_invokes_psy", "invoke_0-r1", 0, 0)
IF (f2_proxy%is_dirty(depth=1)) THEN
CALL f2_proxy%halo_exchange(depth=1)
END IF
IF (m1_proxy%is_dirty(depth=1)) THEN
CALL m1_proxy%halo_exchange(depth=1)
END IF
IF (m2_proxy%is_dirty(depth=1)) THEN
CALL m2_proxy%halo_exchange(depth=1)
END IF
CALL psy_data%PreEnd()
CALL psy_data_1%PreStart("multi_functions_multi_invokes_psy", "invoke_0-r2", &
0, 0)
DO cell=1,mesh%get_last_halo_cell(1)
CALL testkern_code(...)
END DO
...
CALL psy_data_2%PreStart("multi_functions_multi_invokes_psy", &
"invoke_0-testkern_code-r3", 0, 0)
DO cell=1,mesh%get_last_halo_cell(1)
CALL testkern_code(...)
END DO
...
CALL psy_data_2%PostEnd()
CALL psy_data_1%PostEnd()
...
DO cell=1,mesh%get_last_halo_cell(1)
CALL testkern_qr_code(...)
END DO
...
CALL psy_data_3%PostEnd()
...
END SUBROUTINE invoke_0
END MODULE container
DO cell=1,mesh%get_last_halo_cell(1)
CALL testkern_code(...)
END DO
CALL psy_data_1%PostEnd()
...
DO cell=1,mesh%get_last_halo_cell(1)
CALL testkern_qr_code(...)
END DO
...
CALL psy_data_2%PostEnd()
...
END SUBROUTINE invoke_0
END MODULE container
4 changes: 2 additions & 2 deletions examples/gocean/eg5/profile/test.x90
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
!> profile_PSyDataInit called
!> PreStart called for module 'psy_test' region 'invoke_0-r0'
!> PostEnd called for module 'psy_test' region 'invoke_0-r0'
!> PreStart called for module 'psy_test' region 'invoke_1_update_field:update_field_code-r0'
!> PostEnd called for module 'psy_test' region 'invoke_1_update_field:update_field_code-r0'
!> PreStart called for module 'psy_test' region 'invoke_1_update_field-r0'
!> PostEnd called for module 'psy_test' region 'invoke_1_update_field-r0'

Program test
USE field_mod
Expand Down
6 changes: 3 additions & 3 deletions src/psyclone/psyir/nodes/psy_data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,9 @@ def gen_type_bound_call(typename, methodname, argument_list=None,
module_name = self._module_name
if module_name is None:
container = routine_schedule.ancestor(Container)
# See if there current code is inside of a module. If so,
# use this module as module name, otherwise (e.g. subroutine
# outside of any module) use the routine name as 'module_name'
# If the current code is inside a module use the module name,
# otherwise (e.g. subroutine outside of any module) use the
# routine name as 'module_name'
if container and not isinstance(container, FileContainer):
module_name = container.name
else:
Expand Down
19 changes: 11 additions & 8 deletions tutorial/practicals/nemo/2_nemo_profiling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ this session.)
see timing information printed to the terminal, e.g.:

===========================================
module::region count sum min average max
tra_adv::r0 1 0.718750000 0.718750000 0.718750000 0.718750000
module::region count sum min average max
tra_adv_mod::tra_adv-r0 1 0.718750000 0.718750000 0.718750000 0.718750000
===========================================

Timings are only reported for a single region because our mini-app consists
Expand All @@ -99,7 +99,7 @@ in this tutorial.

===========================================
module::region count sum min average max
tra_adv::r0 1 0.718750000 0.718750000 0.718750000 0.718750000
tra_adv_mod::tra_adv-r0 1 0.718750000 0.718750000 0.718750000 0.718750000
===========================================

If you examine the PSyIR that is displayed when running PSyclone with
Expand Down Expand Up @@ -168,15 +168,18 @@ transformation script to perform finer-grained profiling.
regions (r0-r13) reported by the timing library:

===========================================
module::region count sum min average max
tra_adv::r0 1 3.12500000E-02 3.12500000E-02 3.12500000E-02 3.12500000E-02
tra_adv::r1 1 0.00000000 0.00000000 0.00000000 0.00000000
tra_adv::r2 10 3.12500000E-02 0.00000000 3.12500005E-03 3.12500000E-02
module::region count sum min average max
tra_adv_mod::tra_adv-r0 1 2.24609375E-02 2.24609375E-02 2.24609375E-02 2.24609375E-02
tra_adv_mod::tra_adv-r1 1 0.00000000 0.00000000 0.00000000 0.00000000
tra_adv_mod::tra_adv-r2 10 5.66406250E-02 3.90625000E-03 5.66406269E-03 1.07421875E-02
tra_adv_mod::tra_adv-r3 10 5.17578125E-02 2.92968750E-03 5.17578144E-03 1.17187500E-02
...
tra_adv::r13 1 0.187500000 0.187500000 0.187500000 0.187500000
tra_adv_mod::tra_adv-r12 10 2.73437500E-02 9.76562500E-04 2.73437495E-03 3.90625000E-03
tra_adv_mod::tra_adv-r13 1 0.449218750 0.449218750 0.449218750 0.449218750
===========================================



2. Many PSyclone transformations allow additional options to be supplied
via a dictionary argument to the `apply()` method. The
profiling transformation, for instance, allows the user to supply a
Expand Down

0 comments on commit b9d3358

Please sign in to comment.