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) Generate PSy-layers and Kernel Subs using PSyIR lowering (instead of gen_code/f2pygen) #2834

Open
wants to merge 113 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
Copy link
Collaborator Author

@arporter This is finally ready for review, it is huge because:

  • It updates all remaining f2py/gen_code to psyir/lower_to_language_level (I coudn't find a way to split this process)
  • It produced stylistic changes to the psy-layer output syntax, and therefore lots of tests had to be slightly updated

However, most of the PR is a 1-to-1 mapping to previous code, I decided to leave the:

  • Final removal of f2py intrastructure, and other refactoring now possible (I am still abusing find_or_create instead of following a more predictable construction/lookup pattern) to avoid complicating the PR by moving things arround.

I am happy to do this in different review steps if it becomes too much (also Github slows down a lot when reviewing long PRs all at once)

There are a couple of coverage misses that I may need help constructing the LFRic examples that should trigger them.

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.

Great stuff Sergi, it's really good to see so much code being removed. I've made it through all the source files now and some of the tests.
Generally small things to tidy up although I'd like to get rid of cursor from all the declaration routines as it's not used. In fact, I'm not totally sure it's needed for the initialisation - did you have ordering issues?

@@ -877,14 +882,14 @@ def quad_rule(self, var_accesses=None):
self.append_integer_reference(arg)
elif generic_name in ["weights_xy", "weights_z"]:
# 1d arrays:
# TODO # 1910: These should be pointers
Copy link
Member

Choose a reason for hiding this comment

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

Was this TODO incorrect - i.e. it's fine that they aren't pointers? Can #1910 be closed?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, as this is the kernel-call argument list I suppose we don't care whether or not they are pointers as we just need References?

ScalarType.Intrinsic.INTEGER,
tag=tag)
symbol = self._symtab.find_or_create(
self._kern.colourmap.name, symbol_type=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'm a bit confused here. self._kern.colourmap is a call to LFRicKern.colourmap and that returns a Symbol. Perhaps it's not in the right table or perhaps symbol ends up being that same symbol? While I'm here, the docstring for LFRicKern.colourmap says it returns a str but it in fact it returns a Symbol. It's not the fault of this PR but would you mind fixing it?

@@ -984,7 +993,7 @@ def cell_ref_name(self, var_accesses=None):
AccessType.READ,
self._kern, ["colour", "cell"])

return (self._kern.colourmap + "(colour,cell)",
return (self._kern.colourmap.name + "(colour,cell)",
Copy link
Member

Choose a reason for hiding this comment

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

Could this now be array_ref.debug_string() or (better) use the FortranWriter?

Copy link
Member

Choose a reason for hiding this comment

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

I guess it should also have a TODO as this will need cleaning up somehow.

@@ -61,10 +60,6 @@ class KernStubArgList(ArgOrdering):
'''
def __init__(self, kern):
ArgOrdering.__init__(self, kern)
# TODO 719 The stub_symtab is not connected to other parts of the
Copy link
Member

Choose a reason for hiding this comment

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

Whoop! Does this mean that this PR will close #719?

def initialise(self, parent):
for name in self._nlayers_names:
sym = self.symtab.lookup(name)
sym.interface = ArgumentInterface(
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment here - I can't currently work out why you have to do this here rather than when the symbol is created in the symbol table of the kernel stub?

result = generate(os.path.join(BASE_PATH,
"columnwise_op_asm_kernel_mod.F90"),
api=TEST_API)
stub_psyir = generate(os.path.join(BASE_PATH,
Copy link
Member

Choose a reason for hiding this comment

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

It's not psyir but text at this point.

result = generate(os.path.join(BASE_PATH,
"columnwise_op_app_kernel_mod.F90"),
api=TEST_API)
stub_psyir = generate(os.path.join(BASE_PATH,
Copy link
Member

Choose a reason for hiding this comment

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

text again.

expected = " ! call our kernels\n"
assert (expected + " !\n"
" call testkern_domain_code(nlayers_f1, ncell_2d_no_halos, "
assert (" call testkern_domain_code(nlayers_f1, ncell_2d_no_halos, "
Copy link
Member

Choose a reason for hiding this comment

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

Please extend to check that it is not within a loop.

# Now call the loop handling method directly.
out = fortran_writer.loop_node(schedule.children[0])
out = fortran_writer(schedule)
Copy link
Member

Choose a reason for hiding this comment

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

Possibly this whole bit (from L301) can be removed now?

@@ -115,6 +115,7 @@ def test_create_read_in_code_missing_symbol(capsys, monkeypatch):
cntr = minfo.get_psyir()
# We can't use 'remove()' with a DataSymbol.
cntr.symbol_table._symbols.pop("module_var_b")
return
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 attention.... :-)

@arporter arporter added reviewed with actions LFRic Issue relates to the LFRic domain and removed under review labels Jan 24, 2025
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