|
48 | 48 | from psyclone.domain.lfric.transformations import LFRicLoopFuseTrans |
49 | 49 | from psyclone.gocean1p0 import GOInvokeSchedule |
50 | 50 | 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) |
57 | 58 | from psyclone.tests.utilities import get_invoke |
58 | | -from psyclone.transformations import (GOceanOMPLoopTrans, |
59 | | - OMPParallelTrans) |
| 59 | +from psyclone.transformations import ( |
| 60 | + GOceanOMPLoopTrans, OMPParallelTrans, LFRicOMPLoopTrans) |
60 | 61 |
|
61 | 62 |
|
62 | 63 | # ----------------------------------------------------------------------------- |
@@ -367,6 +368,35 @@ def test_profile_invokes_lfric(fortran_writer): |
367 | 368 | Profiler._options = [] |
368 | 369 |
|
369 | 370 |
|
| 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 | + |
370 | 400 | # ----------------------------------------------------------------------------- |
371 | 401 | def test_profile_kernels_lfric(fortran_writer): |
372 | 402 | '''Check that all kernels are instrumented correctly in a |
|
0 commit comments