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 128 commits into
base: master
Choose a base branch
from

Conversation

sergisiso
Copy link
Collaborator

No description provided.

sergisiso added 30 commits April 9, 2024 13:47
…rsor on invokes declarations and initialisations
@sergisiso sergisiso changed the title (closes #1010) Generate PSy-layers and Kernel Subs using PSyIR lowering (instead of gen_code/f2pygen) (closes #1010, #1910) Generate PSy-layers and Kernel Subs using PSyIR lowering (instead of gen_code/f2pygen) Jan 27, 2025
@sergisiso sergisiso changed the title (closes #1010, #1910) Generate PSy-layers and Kernel Subs using PSyIR lowering (instead of gen_code/f2pygen) (closes #1010, #1910, #719) Generate PSy-layers and Kernel Subs using PSyIR lowering (instead of gen_code/f2pygen) Jan 27, 2025
@sergisiso
Copy link
Collaborator Author

Regarding cursor:

  • I remove the shared "declarations" in favour of "stub_decalrations" and "invoke_declarations" as I think they are sufficiently different to be explicit about which one we are calling.
  • I removed "cursor" from all declaration methods.
  • I moved the check that it comes from invoke or kernel to the base implementations and call super() in all these methods, as this was not consistently checked.

However:

  • I have not merged it with "initialisations" because I am not sure we were sure about it, but more importantly a quick test merging the loops below make many tests fails. Some with wrong output asserts (expected because we change the order that symbols are declared), some with symbol_table lookup errors. I expect we will change the order again when we move this logic to happen before the transformations, so I don't thing it is worth to change all test declaration order now to do it again soon.

for entities in [self.scalar_args, self.fields, self.lma_ops,
self.stencil, self.meshes,
self.function_spaces, self.dofmaps, self.cma_ops,
self.boundary_conditions, self.evaluators,
self.halo_depths,
self.proxies, self.cell_iterators,
self.reference_element_properties,
self.mesh_properties, self.loop_bounds,
self.run_time_checks]:
cursor = entities.invoke_declarations(cursor)
for entities in [self.proxies, self.run_time_checks,
self.cell_iterators, self.meshes,
self.stencil, self.dofmaps,
self.cma_ops, self.boundary_conditions,
self.function_spaces, self.evaluators,
self.reference_element_properties,
self.mesh_properties, self.loop_bounds]:
cursor = entities.initialise(cursor)

@sergisiso sergisiso changed the title (closes #1010, #1910, #719) Generate PSy-layers and Kernel Subs using PSyIR lowering (instead of gen_code/f2pygen) (closes #1010, #1910, #719, #798) Generate PSy-layers and Kernel Subs using PSyIR lowering (instead of gen_code/f2pygen) Jan 31, 2025
@sergisiso sergisiso changed the title (closes #1010, #1910, #719, #798) Generate PSy-layers and Kernel Subs using PSyIR lowering (instead of gen_code/f2pygen) (closes #1010, #1910, #719, #798, #1648) Generate PSy-layers and Kernel Subs using PSyIR lowering (instead of gen_code/f2pygen) Feb 3, 2025
@sergisiso
Copy link
Collaborator Author

@arporter This is ready for another review. The PR has increased a bit from last time but mostly with the same syntax changes applied to GOcean tests and lots of deletions - which is satisfying. As a result, a few more issues can be closed (updated in the PR title).

Copy link
Member

@arporter arporter left a comment

Choose a reason for hiding this comment

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

Phew, I've made it. There are a couple of changes that worry me a bit but other than that it's just small things. To cover myself, I have asked (a lot) for modified tests to have compilation checks added where possible.

``LFRicInvoke``. In both cases these methods make use of the subclasses
of ``LFRicCollection`` to declare variables.
the ``stub_declarations`` and ``invoke_declarations`` methods in the
appropirate ``LFRicCollection``.
Copy link
Member

Choose a reason for hiding this comment

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

"appropriate"

if self._kernel.cma_operation not in ["apply", "matrix-matrix"]:
for name in self._nlayers_names:
sym = self.symtab.lookup(name)
# Symbols are created thinking for the Invoke context, so make
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding. Perhaps: "Some Symbols are created as though for an Invoke context, so make sure they are..."

@@ -145,6 +148,10 @@ def reference_accesses(self, var_accesses):
# Use the KernelCallArgList class, which can also provide variable
# access information:
create_arg_list = KernCallArgList(self)
# KernCallArgList creates symbols (sometimes with wrong type), we don't
Copy link
Member

Choose a reason for hiding this comment

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

You've not added a TODO here?

src/psyclone/domain/lfric/lfric_kern.py Show resolved Hide resolved
@@ -469,12 +469,9 @@ def is_intergrid(self):
return self._intergrid_ref is not None

@property
def colourmap(self):
def colourmap(self: DataSymbol):
Copy link
Member

Choose a reason for hiding this comment

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

I think you meant -> DataSymbol:?

PSyData node to add the declaration (which the PSyData node added to the
symbol table, but since the symbol table is not used by gen_code, it
would otherwise be missing).
already be generated by PSyIR).
Copy link
Member

Choose a reason for hiding this comment

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

You've shortened this docstring a bit too much :-)

assert ("'symbol' argument to StructureReference.create() should be a "
"DataSymbol but found 'NoneType'" in str(err.value))
assert ("A StructureReference must refer to a symbol that is (or could be)"
" a structure, has been given a 'None' with name: 'unknown'")
Copy link
Member

Choose a reason for hiding this comment

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

"...but has been given a ..."

assert ("symbol that is (or could be) a structure, however symbol "
"'fake' has type 'Scalar" in str(err.value))
assert ("A StructureReference must refer to a symbol that is (or could be)"
" a structure, has been given a 'Scalar' with name: 'unknown'")
Copy link
Member

Choose a reason for hiding this comment

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

"..., but has been given a ..."


groups = re.search(correct_re, code, re.I)
assert groups is not None
# groups = re.search(correct_re, code, re.I)
Copy link
Member

Choose a reason for hiding this comment

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

This needs reinstating?

code = str(psy_ast.gen)
psy_file.write(fll.process(code))

# Not everything is captured by PSyIR as Symbols (e.g. multiple
Copy link
Member

Choose a reason for hiding this comment

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

I don't quite understand this comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LFRic Issue relates to the LFRic domain reviewed with actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants