Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(closes #1010, #1910, #719, #798, #1648) Generate PSy-layers and Kernel Subs using PSyIR lowering (instead of gen_code/f2pygen) #2834

Open
wants to merge 154 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
bc49de6
#1010 Start converting LFRic PSy-layer declarations and initialisatio…
sergisiso Apr 9, 2024
a3e1b35
Merge remote-tracking branch 'origin/1495_type_bound_methods' into 10…
sergisiso Apr 14, 2024
e864bc2
#1010 Continue porting LFRic declarations and initialisations to PSyIR
sergisiso Apr 22, 2024
df68488
#1010 Pass one more test using backend declarations instead of f2pygen
sergisiso Apr 30, 2024
cd515be
#1010 Bring to master
sergisiso Apr 30, 2024
0b90f7b
#1010 More tests use backend declarations instead of f2pygen
sergisiso Apr 30, 2024
96c1aa6
#1010 More tests use backend declarations instead of f2pygen
sergisiso Apr 30, 2024
5c74c42
#1010 More tests use backend declarations instead of f2pygen, pass cu…
sergisiso May 3, 2024
e661950
#1010 More tests use backend declarations instead of f2pygen, and add…
sergisiso May 6, 2024
64a6bfd
#1010 More tests use backend declarations instead of f2pygen
sergisiso May 7, 2024
6c55316
#1010 Update dynamo0p3_basis test to the fortran backend syntax
sergisiso May 13, 2024
93f88f3
#1010 Start updating stub generation tests for new backend
sergisiso May 21, 2024
77fe7ff
#1010 Bring to master
sergisiso Jun 11, 2024
99ffbbe
Merge remote-tracking branch 'origin/1010_remaining_lfric_lowering' i…
sergisiso Jun 11, 2024
99422e6
#1010 Fix tests in psyir
sergisiso Jun 18, 2024
9be02af
Merge remote-tracking branch 'origin/master' into 1010_remaining_lfri…
sergisiso Jun 18, 2024
2481022
#1010 Fix tests in psyir introduced by lastest update to master
sergisiso Jun 18, 2024
decd073
#1010 Merge master and refactored builtin tests
sergisiso Jul 2, 2024
0e05a0b
#1010 Fix output syntax in gocean opencl trans tests
sergisiso Jul 2, 2024
ef34fa1
#1010 Start updating dynamo0p3_transformations_test to check output w…
sergisiso Jul 2, 2024
62e41e5
#1010 Update more dynamo0p3_transformations_test test to use the psyi…
sergisiso Jul 4, 2024
8908239
#1010 Update more dynamo0p3_transformations_test test to use the psyi…
sergisiso Jul 10, 2024
930ddb9
#1010 Bring to master
sergisiso Jul 18, 2024
a2942f1
#1010 Fix some issues introduced due to previous merge with master
sergisiso Jul 19, 2024
cf63302
#1010 Fix issues with reference_element
sergisiso Jul 19, 2024
3d8969c
#1010 Start porting reductions to generic PSyIR
sergisiso Jul 19, 2024
98a899c
#1010 Remove file mistakenly introduced when brining the branch to ma…
sergisiso Jul 19, 2024
ddef4de
#1010 Move LFRic reductions to OpenMP classes
sergisiso Jul 24, 2024
b697236
#1010 Bring to master
sergisiso Jul 25, 2024
6ab2c8c
#1010 Modifications to pass more LFRic OpenMP reduction tests
sergisiso Jul 25, 2024
bbb31da
#1010 Modify the starting kernels comment in the invoke schedule
sergisiso Jul 25, 2024
6bf1383
#1010 Fix more LFRic OpenMP tests
sergisiso Jul 25, 2024
6787c5e
#1010 Fix a few more LFRic tests using the PSyIR backend
sergisiso Jul 25, 2024
960855f
#1010 Update more lfric transformations tests
sergisiso Aug 2, 2024
0d0d8e3
#1010 Continue fixing lfric tests after switching to PSyIR backend
sergisiso Aug 2, 2024
0cdb879
#1010 Fix more LFRic test syntax to match Fortran backend
sergisiso Aug 5, 2024
4c74023
Merge remote-tracking branch 'origin/master' into 1010_remaining_lfri…
sergisiso Aug 5, 2024
5c08043
#1010 Continue porting LFRic to PSyIR backend
sergisiso Aug 9, 2024
35180f8
Merge remote-tracking branch 'origin/master' into 1010_remaining_lfri…
sergisiso Aug 9, 2024
2a556b2
#1010 Fix more LFRic tests
sergisiso Aug 13, 2024
990afa5
#1010 Fix LFRic stencil tests for PSyIR backend
sergisiso Aug 14, 2024
46eee5c
Merge remote-tracking branch 'origin/master' into 1010_remaining_lfri…
sergisiso Aug 14, 2024
d3dab2d
#1010 Fix LFRic stencil stubs tests for PSyIR backend
sergisiso Aug 15, 2024
3ac82c5
#1010 LFRic uses wildcard import for constants_mod
sergisiso Aug 15, 2024
e8bfe66
#1010 Fix more LFRic tests for PSyIR backend
sergisiso Aug 15, 2024
d83f380
Merge remote-tracking branch 'origin/master' into 1010_remaining_lfri…
sergisiso Sep 12, 2024
8183b8a
1010 Fix test after moving LFRic to use the new backend
sergisiso Sep 12, 2024
55a4eaa
1010 Set LFRic loop bounds during lowering bounds initialisation
sergisiso Sep 16, 2024
225d346
1010 Fix some LFRic stub tests
sergisiso Sep 16, 2024
17f6749
1010 Fix more tests after switching to new PSyIR backend
sergisiso Sep 16, 2024
84f96e3
1010 Fix tests after moving LFRic to use the new backend
sergisiso Sep 16, 2024
c9938f3
1010 Fix psydata tests (except loop bounds and a few driver creator t…
sergisiso Sep 18, 2024
50ad16c
1010 Fix more LFRic tests
sergisiso Sep 18, 2024
3cc4589
1010 Fix LFRic quadrature tests
sergisiso Sep 19, 2024
c719f11
1010 Use generic symbol table in LFRic and fix more tests
sergisiso Sep 24, 2024
f0c87d2
1010 Fix more LFRic tests
sergisiso Sep 24, 2024
d398ed2
1010 Fix more LFRic tests and start updating mesh map code
sergisiso Sep 25, 2024
2a3fe85
#1010 Bring to master
sergisiso Oct 4, 2024
b0d5e98
#1010 Update more LFRic test to new backend
sergisiso Oct 4, 2024
009006f
#1010 Fix more LFRic test for the new backend
sergisiso Oct 5, 2024
14e0b23
#1010 Fix more LFRic test for the new backend
sergisiso Oct 5, 2024
eee5c9c
#1010 Do not store InvokeSchedules and SymbolTables inside other classes
sergisiso Oct 9, 2024
e3d2f2e
#1010 Fix issues with compilation tests
sergisiso Oct 12, 2024
501655a
#1010 Start cleaning up PR
sergisiso Oct 12, 2024
82d8706
#1010 Bring the failing tests down to 0 again (but some with xfails/e…
sergisiso Oct 14, 2024
a5c50fd
#1010 Bring the failing tests down to 0 again (but some with xfails/e…
sergisiso Oct 14, 2024
b134171
#2730 Generalise acc_parallel lfric script to also accept openmp dire…
sergisiso Oct 2, 2024
300afee
#2730 Add gen_code support for OpenMP target directives
sergisiso Oct 2, 2024
08e9221
#2730 Fix issues with LFRic OMP offloading and add it to the integrat…
sergisiso Oct 3, 2024
a0d5e2f
#2730 Fix CI failures
sergisiso Oct 3, 2024
0fb3098
#2730 Add tests for missing code coverage
sergisiso Oct 3, 2024
1f97c15
#2730 Update LFRic offloading envvar and fix comments and docstrings
sergisiso Oct 7, 2024
cfcc44d
#2730 Fix lfric nvfortran.mk syntax
sergisiso Oct 7, 2024
39c3037
#2733 update UG and changelog
arporter Oct 8, 2024
9edd419
Sorted the fspaces in the LFRic algorithm generation
DrTVockerodtMO Oct 10, 2024
298fa90
Added my name to modified by list
DrTVockerodtMO Oct 10, 2024
ea78b6f
Modified test to check for correct function space ordering
DrTVockerodtMO Oct 10, 2024
cf32395
Made the test use a shuffled input
DrTVockerodtMO Oct 10, 2024
9558dc4
#2743 update changelog and UG
arporter Oct 11, 2024
43a0e83
#1010 Restore missing set halo dirty comment
sergisiso Oct 14, 2024
d1ab352
#1010 Bring to master
sergisiso Oct 14, 2024
7cae96a
#1010 Start cleaning up PR
sergisiso Oct 14, 2024
ecd20d3
#1010 Cleaning up PR
sergisiso Oct 14, 2024
b81e2ed
#1010 Cleaning up PR
sergisiso Oct 14, 2024
b3a3d82
#1010 Bring to master
sergisiso Nov 1, 2024
dbac36c
#1010 Bring to master
sergisiso Nov 12, 2024
5a7b0a6
1010 Bring to master (with issues)
sergisiso Nov 17, 2024
36af0bf
#1010 Bring to master
sergisiso Dec 20, 2024
abc2feb
#1010 Fix flake8 errors
sergisiso Dec 20, 2024
0ffbb70
#1010 Fix some issues with the LFRic HaloEx tests
sergisiso Dec 29, 2024
65afad9
#1010 Fix remaining issues with LFRic lowering backend
sergisiso Dec 29, 2024
c754874
#1010 Clean up old comments and improve docstrings
sergisiso Dec 29, 2024
713a758
#1010 Fix compilation errors
sergisiso Dec 29, 2024
bbf58ab
#1010 Fix example and resolve some fixmes
sergisiso Dec 29, 2024
f3d3574
#1010 Temporary disable lfric psydata compilation
sergisiso Dec 30, 2024
b7cb593
#1010 Revert skipped example/tutorial and remove some unused code
sergisiso Dec 30, 2024
7d3ab2a
#1010 Remove unused code
sergisiso Dec 30, 2024
b9a64c1
#1010 Fix test
sergisiso Dec 30, 2024
9ff9eae
Merge remote-tracking branch 'origin/master' into 1010_remaining_lfri…
sergisiso Dec 30, 2024
dc1c142
#1010 Fix merge issue
sergisiso Dec 30, 2024
3ab9c4d
#1010 Fix flake8 issues
sergisiso Dec 30, 2024
852a826
#1010 Improve test coverage and fix integration test issue
sergisiso Dec 31, 2024
1dd394e
#1010 Remove some more old code and fix tests
sergisiso Jan 6, 2025
5d7d712
#1010 Do not generate th_idx and nthreads variables when not needed
sergisiso Jan 6, 2025
5dc9ec0
#1010 Fix some xfail tests
sergisiso Jan 9, 2025
e90cbcf
Merge remote-tracking branch 'origin/master' into 1010_remaining_lfri…
sergisiso Jan 12, 2025
3a4b983
#1010 Resolve some issues with psy_data
sergisiso Jan 22, 2025
3a18bb3
#1010 Move LFRic loop_start/stop symbols at the beginning
sergisiso Jan 22, 2025
cd18e86
#1010 Remove NOT_INITIALISED integer literals
sergisiso Jan 22, 2025
6ddb65e
Merge remote-tracking branch 'origin/master' into 1010_remaining_lfri…
sergisiso Jan 23, 2025
c345f0a
#1010 Clean up psy_data_node
sergisiso Jan 23, 2025
9ec3f54
#1010 Convert some array types to pointers
sergisiso Jan 23, 2025
57db171
#1010 Clean up PR
sergisiso Jan 23, 2025
92fed41
#1010 Improve naming, docstrings and comments
sergisiso Jan 27, 2025
bb53018
#1010 Clean up LFRicLoop code
sergisiso Jan 28, 2025
1a06860
#1010 Refactor LFRicCollections.declarations
sergisiso Jan 29, 2025
cdb2399
#1010 Clean up PR
sergisiso Jan 29, 2025
0614d93
#1010 Fix flake8 issues
sergisiso Jan 29, 2025
d7fcd56
#1010 Bring to master
sergisiso Jan 29, 2025
1a67f95
#1010 Fix typing issue with python3.8
sergisiso Jan 30, 2025
5d66448
#1010 Remove cursor argument from invoke_declarations
sergisiso Jan 30, 2025
ac88bd0
#1010 Improve tests and documentation
sergisiso Jan 30, 2025
6ac84f3
#1010 Remove leftover f2pygen in gocean and updated test syntax
sergisiso Jan 31, 2025
6cef2df
#1010 Fix compilation tests
sergisiso Jan 31, 2025
fe26a76
#1010 Remove remaining references to the gen_code method
sergisiso Feb 3, 2025
7040b7c
#1010 Rename gen_code variable to code in tests
sergisiso Feb 3, 2025
5996da2
#1010 Delete f2pygen classes
sergisiso Feb 3, 2025
8db5dfa
#1010 Clean up f2pygen mentions and fix some tests/coverage
sergisiso Feb 3, 2025
bbae102
#1010 Fix typos and tests
sergisiso Feb 10, 2025
0bdb80c
#1010 Change LFRic compilation assert location and add output global …
sergisiso Feb 10, 2025
973d654
#1010 Remove unneeded symbols from stub tests
sergisiso Feb 10, 2025
8ac5de3
#1010 Improve LFRic tests
sergisiso Feb 10, 2025
6dccea4
#1010 Remove commented out code
sergisiso Feb 10, 2025
0fcbc51
Merge remote-tracking branch 'origin/master' into 1010_remaining_lfri…
sergisiso Feb 10, 2025
b2049ad
#1010 Fix flake8 issues
sergisiso Feb 10, 2025
4fd0beb
#1010 Fix issue with older python versions
sergisiso Feb 10, 2025
ada35dc
#1010 Fix tests that had changed behaviour
sergisiso Feb 13, 2025
71f85e2
#1010 Revert some Compilation deletion and fix some coverage
sergisiso Feb 14, 2025
55341ea
#1010 LFric bounds names are now given by the index of counting only …
sergisiso Feb 14, 2025
b005d8f
Merge remote-tracking branch 'origin/master' into 1010_remaining_lfri…
sergisiso Feb 14, 2025
c1481f1
#1010 Remove unneeded code
sergisiso Feb 14, 2025
cd5b832
#1010 Fix flake8 issue
sergisiso Feb 14, 2025
17b73c1
#1010 Remove spurious nlayers delcaration from LFRic stubs
sergisiso Feb 14, 2025
b6d1ff9
#1010 Bring to master
sergisiso Feb 19, 2025
9e1a888
#1010 Bring to master
sergisiso Feb 24, 2025
b09a941
Merge remote-tracking branch 'origin/master' into 1010_remaining_lfri…
sergisiso Feb 24, 2025
e2c7464
#1010 Fix output syntax of extraction test
sergisiso Feb 24, 2025
434b0c3
#1010 Fix issues with symbols
sergisiso Feb 26, 2025
f4c2ebf
Merge remote-tracking branch 'origin/master' into 1010_remaining_lfri…
sergisiso Feb 26, 2025
ba10989
#1010 Fix arg_ordering tag lookup
sergisiso Feb 26, 2025
eff7b5c
#1010 Fix a wrong test and clean up code
sergisiso Feb 27, 2025
226302a
#1010 Recover missing test coverage
sergisiso Feb 27, 2025
8033d65
#1010 Use signatures for unused symbol removal in the LoopFuseTrans
sergisiso Feb 27, 2025
f8bc89a
Merge remote-tracking branch 'origin/master' into 1010_remaining_lfri…
sergisiso Feb 27, 2025
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
8 changes: 8 additions & 0 deletions src/psyclone/domain/lfric/arg_ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@
from psyclone.domain.lfric import LFRicTypes
if tag is None:
tag = name
else:
# If it has a tag, first try to look up for it
try:
sym = self._symtab.lookup_with_tag("tag")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you meant tag without the quotes? That might then fix the coverage issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, that's embarrassing, that also fixes the first issue reported by @TeranIvy

self.psyir_append(Reference(sym))
return sym

Check warning on line 210 in src/psyclone/domain/lfric/arg_ordering.py

View check run for this annotation

Codecov / codecov/patch

src/psyclone/domain/lfric/arg_ordering.py#L209-L210

Added lines #L209 - L210 were not covered by tests
except KeyError:
pass
sym = self._symtab.find_or_create(
name, tag=tag, symbol_type=DataSymbol,
datatype=LFRicTypes("LFRicIntegerScalarDataType")())
Expand Down
63 changes: 28 additions & 35 deletions src/psyclone/domain/lfric/lfric_cell_iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,28 @@ def __init__(self, kern_or_invoke):
# (for invokes) the kernel argument to which each corresponds.
self._nlayers_names = {}

if not self._invoke:
# We are dealing with a single Kernel so there is only one
# 'nlayers' variable and we don't need to store the associated
if self._invoke:
# Each kernel that operates on either the domain or cell-columns
# needs an 'nlayers' obtained from the first field/operator
# argument.
self._nlayers_names[self.symtab.find_or_create_tag(
"nlayers",
symbol_type=LFRicTypes("MeshHeightDataSymbol")).name] = None
# We're not generating a PSy layer so we're done here.
return

# Each kernel that operates on either the domain or cell-columns needs
# an 'nlayers' obtained from the first field/operator argument.
for kern in self._invoke.schedule.walk(LFRicKern):
if kern.iterates_over != "dof":
arg = kern.arguments.first_field_or_operator
sym = self.symtab.find_or_create_tag(
f"nlayers_{arg.name}",
symbol_type=LFRicTypes("MeshHeightDataSymbol"))
self._nlayers_names[sym.name] = arg

first_var = None
for var in self._invoke.psy_unique_vars:
if not var.is_scalar:
first_var = var
break
if not first_var:
raise GenerationError(
"Cannot create an Invoke with no field/operator arguments.")
self._first_var = first_var
for kern in self._invoke.schedule.walk(LFRicKern):
if kern.iterates_over != "dof":
arg = kern.arguments.first_field_or_operator
sym = self.symtab.find_or_create_tag(
f"nlayers_{arg.name}",
symbol_type=LFRicTypes("MeshHeightDataSymbol"))
self._nlayers_names[sym.name] = arg

first_var = None
for var in self._invoke.psy_unique_vars:
if not var.is_scalar:
first_var = var
break
if not first_var:
raise GenerationError(
"Cannot create an Invoke with no field/operator "
"arguments.")
self._first_var = first_var

def stub_declarations(self):
'''
Expand All @@ -104,13 +97,13 @@ def stub_declarations(self):
'''
super().stub_declarations()
if self._kernel.cma_operation not in ["apply", "matrix-matrix"]:
for name in self._nlayers_names:
sym = self.symtab.lookup(name)
# Symbols are created as though for an Invoke context, so make
# sure they are arguments when we are in a Stub context.
sym.interface = ArgumentInterface(
ArgumentInterface.Access.READ)
self.symtab.append_argument(sym)
nlayers = self.symtab.find_or_create_tag(
"nlayers",
symbol_type=LFRicTypes("MeshHeightDataSymbol")
)
nlayers.interface = ArgumentInterface(
ArgumentInterface.Access.READ)
self.symtab.append_argument(nlayers)

def initialise(self, cursor):
'''
Expand Down
9 changes: 8 additions & 1 deletion src/psyclone/domain/lfric/lfric_dofmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,14 @@ def stub_declarations(self):
symbol.interface = ArgumentInterface(ArgumentInterface.Access.READ)
self.symtab.append_argument(symbol)

nlayers = self.symtab.lookup("nlayers")
nlayers = self.symtab.find_or_create_tag(
"nlayers",
symbol_type=LFRicTypes("MeshHeightDataSymbol")
)
nlayers.interface = ArgumentInterface(
ArgumentInterface.Access.READ)
self.symtab.append_argument(nlayers)

dmap_symbol = self.symtab.find_or_create(
dmap, symbol_type=DataSymbol,
datatype=ArrayType(LFRicTypes("LFRicIntegerScalarDataType")(),
Expand Down
8 changes: 1 addition & 7 deletions src/psyclone/domain/lfric/lfric_kern.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
Loop, Literal, Reference, KernelSchedule, Container, Routine)
from psyclone.psyir.symbols import (
DataSymbol, ScalarType, ArrayType, UnsupportedFortranType, DataTypeSymbol,
UnresolvedType, ContainerSymbol, UnknownInterface, INTEGER_TYPE,
UnresolvedInterface)
UnresolvedType, ContainerSymbol, INTEGER_TYPE, UnresolvedInterface)


class LFRicKern(CodedKern):
Expand Down Expand Up @@ -719,11 +718,6 @@ def gen_stub(self) -> Container:
arg_list = []
for argument_name in create_arg_list.arglist:
arg_list.append(stub_routine.symbol_table.lookup(argument_name))
# If a previous argument has not been given an order by KernStubArgList
# ignore it.
for argument in stub_routine.symbol_table.argument_list:
if argument not in arg_list:
argument.interface = UnknownInterface()
stub_routine.symbol_table.specify_argument_list(arg_list)

return stub_module
Expand Down
13 changes: 5 additions & 8 deletions src/psyclone/domain/lfric/lfric_loop_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
''' This module provides the LFRicLoopBounds Class that handles all variables
required for specifying loop limits within an LFRic PSy-layer routine.'''

from psyclone.domain.lfric import LFRicCollection
from psyclone.psyir.nodes import Assignment, Reference, Loop
from psyclone.domain.lfric import LFRicCollection, LFRicLoop
from psyclone.psyir.nodes import Assignment, Reference


class LFRicLoopBounds(LFRicCollection):
Expand All @@ -59,16 +59,13 @@ def initialise(self, cursor: int) -> int:
:returns: Updated cursor value.

'''
loops = self._invoke.schedule.loops()

if not loops:
return cursor
loops = filter(lambda x: isinstance(x, LFRicLoop),
self._invoke.schedule.loops())

first = True
for idx, loop in enumerate(loops):

# pylint: disable=unidiomatic-typecheck
if type(loop) is Loop or loop.loop_type == "null":
if loop.loop_type == "null":
# Generic or 'null' loops don't need any variables to be set
continue

Expand Down
3 changes: 2 additions & 1 deletion src/psyclone/dynamo0p3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3616,7 +3616,8 @@ def initialise(self, cursor):
Assignment.create(
lhs=Reference(self.symtab.lookup(name)),
rhs=dofs.argument.generate_method_call(
"get_boundary_dofs"),
"get_boundary_dofs",
function_space=dofs.function_space),
is_pointer=True
),
cursor)
Expand Down
4 changes: 2 additions & 2 deletions src/psyclone/psyGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ def zero_reduction_variable(self):
f"'{var_arg.intrinsic_type}'.")

# Retrieve the variable and precision information
kind_str = f"kind={var_arg.precision}" if var_arg.precision else ""
kind_str = f"(kind={var_arg.precision})" if var_arg.precision else ""
variable = self.scope.symbol_table.lookup(variable_name)
insert_loc = self.ancestor(PSyLoop)
# If it has ancestor directive keep going up
Expand All @@ -1138,7 +1138,7 @@ def zero_reduction_variable(self):
local_var = self.scope.symbol_table.find_or_create_tag(
local_var_name, symbol_type=DataSymbol,
datatype=UnsupportedFortranType(
f"{var_data_type}({kind_str}), allocatable, "
f"{var_data_type}{kind_str}, allocatable, "
f"dimension(:,:) :: {local_var_name}"
))
nthreads = \
Expand Down
7 changes: 6 additions & 1 deletion src/psyclone/psyir/symbols/symbol_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,12 @@ def deep_copy(self):

# Prepare the new tag dict
for tag, symbol in self._tags.items():
new_st._tags[tag] = new_st.lookup(symbol.name)
try:
new_st._tags[tag] = new_st.lookup(symbol.name)
except KeyError:
# TODO 898: If the lookup fails it means that the symbol was
# removed from the symbol table but not the tags dictionary
pass

# Update any references to Symbols within Symbols (initial values,
# precision etc.)
Expand Down
17 changes: 16 additions & 1 deletion src/psyclone/psyir/transformations/loop_fuse_trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class for all API-specific loop fusion transformations.

from psyclone.core import SymbolicMaths
from psyclone.domain.common.psylayer import PSyLoop
from psyclone.psyir.nodes import Reference
from psyclone.psyir.nodes import Reference, Routine
from psyclone.psyir.tools import DependencyTools
from psyclone.psyir.transformations.loop_trans import LoopTrans
from psyclone.psyir.transformations.transformation_error import \
Expand Down Expand Up @@ -198,6 +198,21 @@ def apply(self, node1, node2, options=None):
# Add loop contents of node2 to node1
node1.loop_body.children.extend(node2.loop_body.pop_all_children())

# We need to remove all leftover references because lfric is compiled
# with '-Werror=unused-variable'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add: ". Since we have fused loops, we only need to look at the symbols appearing in the loop control of the second loop."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

routine = node1.ancestor(Routine)
if routine:
remaining_syms = [r.symbol for r in routine.walk(Reference)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure whether it would be better here to use:

    vai = VariablesAccessInfo(routine)
    all_names = [sig.var_name for sig in vai.all_signatures]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am slightly nervous that Signatures still operate on strings and can't differentiate between symbols with the same name in different scopes, but I think is the right thing to do here, so I updated to it.

del_syms = [r.symbol for r in node2.start_expr.walk(Reference) +
node2.stop_expr.walk(Reference)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking, we should allow for step too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

for rsym in del_syms:
if rsym not in remaining_syms:
if rsym.is_automatic:
symtab = rsym.find_symbol_table(node1)
# TODO #898: Implement symbol removal
# pylint: disable=protected-access
symtab._symbols.pop(rsym.name)


# For automatic documentation generation
__all__ = ["LoopFuseTrans"]
3 changes: 2 additions & 1 deletion src/psyclone/psyir/transformations/omp_loop_trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
from psyclone.configuration import Config
from psyclone.psyir.nodes import (
OMPDoDirective, OMPLoopDirective, OMPParallelDoDirective,
OMPTeamsDistributeParallelDoDirective, OMPScheduleClause)
OMPTeamsLoopDirective, OMPTeamsDistributeParallelDoDirective,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted

OMPScheduleClause)
from psyclone.psyir.transformations.parallel_loop_trans import \
ParallelLoopTrans

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def test_single_node_ompparalleldo_gocean1p0():
code = str(psy.gen)
output = """
CALL extract_psy_data % PreStart("psy_single_invoke_three_kernels", """ \
""""invoke_0-compute_cv_code-r0", 6, 3)
""""invoke_0-compute_cv_code-r0", 9, 3)
CALL extract_psy_data % PreDeclareVariable("cv_fld%internal%xstart", """ \
"""cv_fld % internal % xstart)
CALL extract_psy_data % PreDeclareVariable("cv_fld%internal%xstop", """ \
Expand All @@ -236,6 +236,9 @@ def test_single_node_ompparalleldo_gocean1p0():
"""cv_fld % internal % ystop)
CALL extract_psy_data % PreDeclareVariable("p_fld", p_fld)
CALL extract_psy_data % PreDeclareVariable("v_fld", v_fld)
CALL extract_psy_data % PreDeclareVariable("cv_fld", cv_fld)
CALL extract_psy_data % PreDeclareVariable("i", i)
CALL extract_psy_data % PreDeclareVariable("j", j)
CALL extract_psy_data % PreDeclareVariable("cv_fld_post", cv_fld)
CALL extract_psy_data % PreDeclareVariable("i_post", i)
CALL extract_psy_data % PreDeclareVariable("j_post", j)
Expand All @@ -250,6 +253,9 @@ def test_single_node_ompparalleldo_gocean1p0():
"""cv_fld % internal % ystop)
CALL extract_psy_data % ProvideVariable("p_fld", p_fld)
CALL extract_psy_data % ProvideVariable("v_fld", v_fld)
CALL extract_psy_data % ProvideVariable("cv_fld", cv_fld)
CALL extract_psy_data % ProvideVariable("i", i)
CALL extract_psy_data % ProvideVariable("j", j)
CALL extract_psy_data % PreEnd
!$omp parallel do default(shared), private(i,j), schedule(static)
do j = cv_fld%internal%ystart, cv_fld%internal%ystop, 1
Expand Down Expand Up @@ -297,11 +303,14 @@ def test_single_node_ompparalleldo_gocean1p0_const_loop():
code = str(psy.gen)
output = """
CALL extract_psy_data % PreStart("psy_single_invoke_three_kernels", """ \
""""invoke_0-compute_cv_code-r0", 4, 3)
""""invoke_0-compute_cv_code-r0", 7, 3)
CALL extract_psy_data % PreDeclareVariable("istop", istop)
CALL extract_psy_data % PreDeclareVariable("jstop", jstop)
CALL extract_psy_data % PreDeclareVariable("p_fld", p_fld)
CALL extract_psy_data % PreDeclareVariable("v_fld", v_fld)
CALL extract_psy_data % PreDeclareVariable("cv_fld", cv_fld)
CALL extract_psy_data % PreDeclareVariable("i", i)
CALL extract_psy_data % PreDeclareVariable("j", j)
CALL extract_psy_data % PreDeclareVariable("cv_fld_post", cv_fld)
CALL extract_psy_data % PreDeclareVariable("i_post", i)
CALL extract_psy_data % PreDeclareVariable("j_post", j)
Expand All @@ -310,6 +319,9 @@ def test_single_node_ompparalleldo_gocean1p0_const_loop():
CALL extract_psy_data % ProvideVariable("jstop", jstop)
CALL extract_psy_data % ProvideVariable("p_fld", p_fld)
CALL extract_psy_data % ProvideVariable("v_fld", v_fld)
CALL extract_psy_data % ProvideVariable("cv_fld", cv_fld)
CALL extract_psy_data % ProvideVariable("i", i)
CALL extract_psy_data % ProvideVariable("j", j)
CALL extract_psy_data % PreEnd
!$omp parallel do default(shared), private(i,j), schedule(static)
do j = 2, jstop + 1, 1
Expand Down Expand Up @@ -360,12 +372,16 @@ def test_node_list_ompparallel_gocean1p0():
code = str(psy.gen)
output = """
CALL extract_psy_data % PreStart("psy_single_invoke_three_kernels", """ \
""""invoke_0-r0", 5, 4)
""""invoke_0-r0", 9, 4)
CALL extract_psy_data % PreDeclareVariable("istop", istop)
CALL extract_psy_data % PreDeclareVariable("jstop", jstop)
CALL extract_psy_data % PreDeclareVariable("p_fld", p_fld)
CALL extract_psy_data % PreDeclareVariable("u_fld", u_fld)
CALL extract_psy_data % PreDeclareVariable("v_fld", v_fld)
CALL extract_psy_data % PreDeclareVariable("cu_fld", cu_fld)
CALL extract_psy_data % PreDeclareVariable("cv_fld", cv_fld)
CALL extract_psy_data % PreDeclareVariable("i", i)
CALL extract_psy_data % PreDeclareVariable("j", j)
CALL extract_psy_data % PreDeclareVariable("cu_fld_post", cu_fld)
CALL extract_psy_data % PreDeclareVariable("cv_fld_post", cv_fld)
CALL extract_psy_data % PreDeclareVariable("i_post", i)
Expand All @@ -376,6 +392,10 @@ def test_node_list_ompparallel_gocean1p0():
CALL extract_psy_data % ProvideVariable("p_fld", p_fld)
CALL extract_psy_data % ProvideVariable("u_fld", u_fld)
CALL extract_psy_data % ProvideVariable("v_fld", v_fld)
CALL extract_psy_data % ProvideVariable("cu_fld", cu_fld)
CALL extract_psy_data % ProvideVariable("cv_fld", cv_fld)
CALL extract_psy_data % ProvideVariable("i", i)
CALL extract_psy_data % ProvideVariable("j", j)
CALL extract_psy_data % PreEnd
!$omp parallel default(shared), private(i,j)
!$omp do schedule(static)
Expand Down
16 changes: 12 additions & 4 deletions src/psyclone/tests/domain/lfric/dofkern_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def test_indexed_field_args(tmpdir):
code = str(psy.gen)

expected = ("call testkern_dofs_code(f1_data(df), f2_data(df), "
"f3_data(df), f4_data(df), scalar_arg)")
"f3_data(df), f4_data(df), field_vec_1_data(df), "
"field_vec_2_data(df), field_vec_3_data(df), scalar_arg)")

assert expected in code
# Check compilation
Expand Down Expand Up @@ -268,6 +269,7 @@ def test_multi_invoke_cell_dof_builtin(tmpdir, monkeypatch, annexed, dist_mem):
type(field_type), intent(in) :: f2
type(field_type), intent(in) :: f3
type(field_type), intent(in) :: f4
type(field_type), dimension(3), intent(in) :: field_vec
real(kind=r_def), intent(in) :: scalar_arg
real(kind=r_def), intent(in) :: a
type(field_type), intent(in) :: m1
Expand All @@ -278,6 +280,9 @@ def test_multi_invoke_cell_dof_builtin(tmpdir, monkeypatch, annexed, dist_mem):
real(kind=r_def), pointer, dimension(:) :: f2_data => null()
real(kind=r_def), pointer, dimension(:) :: f3_data => null()
real(kind=r_def), pointer, dimension(:) :: f4_data => null()
real(kind=r_def), pointer, dimension(:) :: field_vec_1_data => null()
real(kind=r_def), pointer, dimension(:) :: field_vec_2_data => null()
real(kind=r_def), pointer, dimension(:) :: field_vec_3_data => null()
real(kind=r_def), pointer, dimension(:) :: m1_data => null()
real(kind=r_def), pointer, dimension(:) :: m2_data => null()
""" in code
Expand All @@ -286,7 +291,8 @@ def test_multi_invoke_cell_dof_builtin(tmpdir, monkeypatch, annexed, dist_mem):
output = (
" do df = loop0_start, loop0_stop, 1\n"
" call testkern_dofs_code(f1_data(df), f2_data(df), "
"f3_data(df), f4_data(df), scalar_arg)\n"
"f3_data(df), f4_data(df), field_vec_1_data(df), "
"field_vec_2_data(df), field_vec_3_data(df), scalar_arg)\n"
" enddo\n"
)
assert output in code
Expand All @@ -299,7 +305,8 @@ def test_multi_invoke_cell_dof_builtin(tmpdir, monkeypatch, annexed, dist_mem):
output = (
" do df = loop0_start, loop0_stop, 1\n"
" call testkern_dofs_code(f1_data(df), f2_data(df), "
"f3_data(df), f4_data(df), scalar_arg)\n"
"f3_data(df), f4_data(df), field_vec_1_data(df), "
"field_vec_2_data(df), field_vec_3_data(df), scalar_arg)\n"
" enddo\n"
"\n"
" ! Set halos dirty/clean for fields modified in the "
Expand All @@ -312,7 +319,8 @@ def test_multi_invoke_cell_dof_builtin(tmpdir, monkeypatch, annexed, dist_mem):
output = (
" do df = loop0_start, loop0_stop, 1\n"
" call testkern_dofs_code(f1_data(df), f2_data(df), "
"f3_data(df), f4_data(df), scalar_arg)\n"
"f3_data(df), f4_data(df), field_vec_1_data(df), "
"field_vec_2_data(df), field_vec_3_data(df), scalar_arg)\n"
" enddo\n"
"\n"
" ! Set halos dirty/clean for fields modified in the "
Expand Down
Loading
Loading