Open mo-joshuacolclough opened 3 days ago
This may be related to https://github.com/stfc/PSyclone/issues/2335, since I believe a similar version to that kernel produced both of these errors.
Thanks @mo-joshuacolclough. This means that the adjoint kernel is no longer following the rules of the LFRic API (see https://psyclone.readthedocs.io/en/latest/dynamo0p3.html#lfric-gh-shape). If the function space on which the basis functions are to be provided is not that of the updated kernel argument, there will have to be some other mechanism to tell PSyclone that. This probably means an extension to the metadata. Probably, the best thing to do will be to follow what's supported for GH_SHAPE = GH_EVALUATOR
(where we have an optional GH_EVALUATOR_TARGETS
. Whatever we decide, ideally it must be backwards compatible with existing metadata. We could introduce an optional GH_BASIS_TARGETS
for instance. This would need clarification with @tommbendall and @TeranIvy.
Description
During the LFRic adjoint work, an issue was noted when
GH_BASIS
arguments are added for intended use withintent(in)
fields.The kernel metadata for the problematic case in the linear code was:
Later within the kernel arguments, the basis is accepted with the shape:
basis_B_on_A(3, ndf_B, ndf_A)
- {B on A}Which looks as expected.
Now, in the adjoint code, the kernel metadata becomes:
Field A becomes
in
, B becomesinout
. In the kernel (generated with PSyAD), the shape arguments are the same as before. This is correct because we are expecting the same basis as the forward code.The problem
Since B has become
inout
, PSyclone erroneously generates code which passes the basis function:{B on B}
rather than the required{B on A}
, to the kernel.This should instead be:
The problem results in an incorrect adjoint. This requires manual intervention using PSy-lite code.
Summary
PSyclone has implicitly chosen
B
as the other part of the basis due toB
being the inoutGH_INC
field in adjoint code, when in reality the basis should chooseA
in the adjoint case. This requires manual intervention using PSy-lite code.Tagging @DrTVockerodtMO