Skip to content

Commit a9f77e2

Browse files
authored
Merge pull request #3053 from stfc/fix_missing_th_idx_symbols
(closes #3052) Fix missing psylayer openmp symbols
2 parents c16ab26 + d19ad0d commit a9f77e2

2 files changed

Lines changed: 42 additions & 8 deletions

File tree

src/psyclone/psyir/nodes/psy_data_node.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,10 @@ def gen_type_bound_call(typename, methodname, argument_list=None,
715715
# end calls
716716
for child in self.psy_data_body.pop_all_children():
717717
self.parent.children.insert(self.position, child)
718+
# If there is any symbol in the PSyData scope (it could have been
719+
# added by any posterior modification writing to child.scope) it needs
720+
# to be moved together with the nodes
721+
self.scope.symbol_table.merge(self.psy_data_body.symbol_table)
718722

719723
if has_var:
720724
# Only add PostStart() if there is at least one variable.

src/psyclone/tests/psyir/transformations/profile_test.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,16 @@
4848
from psyclone.domain.lfric.transformations import LFRicLoopFuseTrans
4949
from psyclone.gocean1p0 import GOInvokeSchedule
5050
from psyclone.profiler import Profiler
51-
from psyclone.psyir.nodes import (colored, ProfileNode, Loop, Literal,
52-
Assignment, Return, Reference,
53-
KernelSchedule, Routine, Schedule)
54-
from psyclone.psyir.symbols import (SymbolTable, REAL_TYPE, DataSymbol)
55-
from psyclone.psyir.transformations import (ACCKernelsTrans, ProfileTrans,
56-
TransformationError)
51+
from psyclone.psyir.nodes import (
52+
colored, ProfileNode, Loop, Literal, Assignment, Return, Reference,
53+
OMPDoDirective, KernelSchedule, Routine, Schedule)
54+
from psyclone.psyir.symbols import (
55+
SymbolTable, REAL_TYPE, DataSymbol, INTEGER_TYPE)
56+
from psyclone.psyir.transformations import (
57+
ACCKernelsTrans, ProfileTrans, TransformationError)
5758
from psyclone.tests.utilities import get_invoke
58-
from psyclone.transformations import (GOceanOMPLoopTrans,
59-
OMPParallelTrans)
59+
from psyclone.transformations import (
60+
GOceanOMPLoopTrans, OMPParallelTrans, LFRicOMPLoopTrans)
6061

6162

6263
# -----------------------------------------------------------------------------
@@ -367,6 +368,35 @@ def test_profile_invokes_lfric(fortran_writer):
367368
Profiler._options = []
368369

369370

371+
def test_profile_with_symbols_declared_in_the_profiler_scope(tmpdir):
372+
''' Test that Symbols that are declared in the Profiler schedule node end
373+
up in the output code. For example, LFRic OpenMP with reprod reductions
374+
declares symbols in there. '''
375+
file_name = "15.19.1_three_builtins_two_reductions.f90"
376+
psy, invoke = get_invoke(file_name, "lfric", idx=0)
377+
schedule = invoke.schedule
378+
rtrans = OMPParallelTrans()
379+
otrans = LFRicOMPLoopTrans()
380+
for child in schedule.children:
381+
if isinstance(child, Loop):
382+
otrans.apply(child, {"reprod": True})
383+
for child in schedule.children:
384+
if isinstance(child, OMPDoDirective):
385+
rtrans.apply(child)
386+
profile_trans = ProfileTrans()
387+
options = {"region_name": (psy.name, invoke.name)}
388+
profile_trans.apply(schedule.children, options=options)
389+
# In addition to the OpenMP symbols, manually add one in that scope
390+
schedule.children[0].psy_data_body.symbol_table.new_symbol(
391+
"profiler_scoped_symbol", symbol_type=DataSymbol,
392+
datatype=INTEGER_TYPE)
393+
code = str(psy.gen)
394+
395+
assert "omp_lib, only : omp_get_max_threads, omp_get_thread_num" in code
396+
assert "integer :: th_idx" in code
397+
assert "integer :: profiler_scoped_symbol" in code
398+
399+
370400
# -----------------------------------------------------------------------------
371401
def test_profile_kernels_lfric(fortran_writer):
372402
'''Check that all kernels are instrumented correctly in a

0 commit comments

Comments
 (0)