PSyclone
PSyclone copied to clipboard
modify Adjoint metadata
Metadata names and access patterns may need to be updated when transforming from tangent-linear metadata to adjoint metadata. When dealing with stencil codes further modications may be required. At the moment this is not easily done as the PSyIR captures the metadata as an UnknownFortranType. Work is ongoing to provide a PSyIR interface to the metadata. Once this is done the metadata can be updated.
This also includes the interface name for mixed precision kernels as the interface name is essentially metadata information.
Now that the LFRic kernel metadata PR is on master we can start working on this issue. There are a number of potential other hurdles to jump so this may need to be done in a few steps. I am thinking of 1) how to determine the metadata associated with an active variable and 2) modifying mixed precision interfaces.
Created branch 1772_adjoint_metadata
The first step will be to check that the raising and lowering of LFRic kernels works with PSyAD kernels as this has not been tested on LFRic kernels yet.
The raising doesn't work yet because of #928 (I hit this in #1892 and ended up leaving TODOs).
The raising doesn't work yet because of #928 (I hit this in #1892 and ended up leaving TODOs).
I'm going to use the metadata raising which has not yet been merged with the kernel code raising so won't be using that. However, shouldn't it be OK anyway, as the raising itself should not do any validation (I would hope)?
I think I must be misunderstanding something: in order to raise we use the LFRic kernel psyir which isn't yet complete and thus raises NotImplementedErrors. Anyway, if you're not using it then it will be fine :-)
I'm using the recently-added-to-master RaisePSyIR2LFRicKernTrans
which only raises the metadata.
Creating a new branch which will modify the adjoint metadata appropriately. This branch will create a new ArgOrdering
class which uses the new metadata to call methods representing arguments in the order in which they are expected to be found in the psy-layer, kernel-layer etc. This will then be used to create a mapping from a metadata argument index to a kernel argument index.
Created 1772_modify_adjoint_metadata
Creating a new branch which will modify the adjoint metadata appropriately. This branch will create a new
ArgOrdering
class which uses the new metadata to call methods representing arguments in the order in which they are expected to be found in the psy-layer, kernel-layer etc. This will then be used to create a mapping from a metadata argument index to a kernel argument index.
Just a quick comment that I have a PR under review that modifies ArgOrdering
(#1975) , and I think there is another minor change/bugfix in a later PR as well.
Related to this, there are cases (e.g. tl_rhs_sample_eos_kernel_mod.F90) where the modified meta-data requires that the interface to the kernel be updated too. e.g. a function space associated with a field that was previously read-only but is now written and is also associated with quadrature. In this case we gain extra ndf and mapping arguments.
Thanks for the heads up @hiker. As this is a new base class, I can develop it independently and happily introduce my ownr bugs :-). When we start working on integrating the new metadata parsing with LFRic code generation we will need to replace the existing base class with this one.
That's a good point @arporter. The same is true for code with stencils. That would be a subsequent PR I think, but I'm not sure whether the Met Office's suggesting funding regime would give us effort to fix things like this - as they just want us to do 'maintenance', unless things have changed in my absence?
No, I don't think it will give us effort to do this.
Just updated to use the new ArgIndexToMetadataIndex
class to check this works OK, which it does (for the test case). Full implementation, tidying etc will be done once the new adjoint funding is in place.