Skip to content

change mixed-precision kernels to use iso-ieee kinds - #393

Merged
Ed Hone (EdHone) merged 11 commits into
MetOffice:mainfrom
mattatmet:iso-ieee-kinds
Aug 21, 2026
Merged

change mixed-precision kernels to use iso-ieee kinds#393
Ed Hone (EdHone) merged 11 commits into
MetOffice:mainfrom
mattatmet:iso-ieee-kinds

Conversation

@mattatmet

@mattatmet Matthew Walker (mattatmet) commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

PR Summary

Sci/Tech Reviewer: Benjamin Went (@MetBenjaminWent)
Code Reviewer: Ed Hone (@EdHone)

This PR is a replica of the Trac ticket #4463:

Some of the mixed precision kernels are using LFRic defined kinds of r_single and r_double. These are just labels in constants_mod.F90 and resolve to real32 and real64 respectively. However, the other mixed precision code is using the iso-ieee kinds. Moreover, we want to be explicit and unambiguous for compiler performance, especially for performance on GPUs where we may also want further reduced kinds. This ticket will re-write the kernels in the native kinds of real32 and real64.

Code Quality Checklist

  • I have performed a self-review of my own code
  • My code follows the project's style guidelines
  • Comments have been included that aid understanding and enhance the readability of the code
  • My changes generate no new warnings
  • All automated checks in the CI pipeline have completed successfully

Testing

  • I have tested this change locally, using the LFRic Core rose-stem suite
  • If required (e.g. API changes) I have also run the LFRic Apps test suite using this branch
  • If any tests fail (rose-stem or CI) the reason is understood and acceptable (e.g. kgo changes)
  • I have added tests to cover new functionality as appropriate (e.g. system tests, unit tests, etc.)
  • Any new tests have been assigned an appropriate amount of compute resource and have been allocated to an appropriate testing group (i.e. the developer tests are for jobs which use a small amount of compute resource and complete in a matter of minutes)

trac.log

Test Suite Results - lfric_core - mixed-precision2-core/run1

Suite Information

Item Value
Suite Name mixed-precision2-core/run1
Suite User matthew.walker
Workflow Start 2026-06-12T12:47:13
Groups Run developer
Dependency Reference Main Like
lfric_core mattatmet/lfric_core@iso-ieee-kinds False
SimSys_Scripts MetOffice/SimSys_Scripts@cab3315 True

Task Information

✅ succeeded tasks - 422

Security Considerations

  • I have reviewed my changes for potential security issues
  • Sensitive data is properly handled (if applicable)
  • Authentication and authorisation are properly implemented (if applicable)

Performance Impact

  • Performance of the code has been considered and, if applicable, suitable performance measurements have been conducted

AI Assistance and Attribution

  • Some of the content of this change has been produced with the assistance of Generative AI tool name (e.g., Met Office Github Copilot Enterprise, Github Copilot Personal, ChatGPT GPT-4, etc) and I have followed the Simulation Systems AI policy (including attribution labels)

Documentation

  • Where appropriate I have updated documentation related to this change and confirmed that it builds correctly

PSyclone Approval

  • If you have edited any PSyclone-related code (e.g. PSyKAl-lite, Kernel interface, optimisation scripts, LFRic data structure code) then please contact the TCD Team

Sci/Tech Review

  • I understand this area of code and the changes being added
  • The proposed changes correspond to the pull request description
  • Documentation is sufficient (do documentation papers need updating)
  • Sufficient testing has been completed

(Please alert the code reviewer via a tag when you have approved the SR)

Code Review

  • All dependencies have been resolved
  • Related Issues have been properly linked and addressed
  • CLA compliance has been confirmed
  • Code quality standards have been met
  • Tests are adequate and have passed
  • Documentation is complete and accurate
  • Security considerations have been addressed
  • Performance impact is acceptable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems like a sensible change, thanks for making it.

My only comment is that just replacing r_single with real32 and similar for r_double means that there are now quite a few code sections which aren't aligned. Sorry to be tedious, but could you go through your changed kernels and realign any changed sections? I have posted a couple of examples so you see what I mean.

! REAL64 PRECISION
! ==================
subroutine dg_inc_matrix_vector_code_r_double(cell, &
subroutine dg_inc_matrix_vector_code_real64(cell, &

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
subroutine dg_inc_matrix_vector_code_real64(cell, &
subroutine dg_inc_matrix_vector_code_real64( cell, &

! REAL32 PRECISION
! ==================
subroutine dg_inc_matrix_vector_code_r_single(cell, &
subroutine dg_inc_matrix_vector_code_real32(cell, &

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
subroutine dg_inc_matrix_vector_code_real32(cell, &
subroutine dg_inc_matrix_vector_code_real32( cell, &

! REAL64 PRECISION
! ==================
subroutine restrict_scalar_unweighted_code_r_double( &
subroutine restrict_scalar_unweighted_code_real64( &

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
subroutine restrict_scalar_unweighted_code_real64( &
subroutine restrict_scalar_unweighted_code_real64( &

Comment on lines +155 to +156
real(kind=real64), intent(inout) :: coarse_field(undf_coarse)
real(kind=real64), intent(in) :: fine_field(undf_fine)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
real(kind=real64), intent(inout) :: coarse_field(undf_coarse)
real(kind=real64), intent(in) :: fine_field(undf_fine)
real(kind=real64), intent(inout) :: coarse_field(undf_coarse)
real(kind=real64), intent(in) :: fine_field(undf_fine)


integer(kind=i_def) :: df, k, x_idx, y_idx, top_df
real(kind=r_double) :: denom, coarse_value(nlayers-1+ndf)
real(kind=real64) :: denom, coarse_value(nlayers-1+ndf)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
real(kind=real64) :: denom, coarse_value(nlayers-1+ndf)
real(kind=real64) :: denom, coarse_value(nlayers-1+ndf)

@mattatmet

Copy link
Copy Markdown
Contributor Author

My only comment is that just replacing r_single with real32 and similar for r_double means that there are now quite a few code sections which aren't aligned. Sorry to be tedious, but could you go through your changed kernels and realign any changed sections? I have posted a couple of examples so you see what I mean.

Thanks for this Tom, I hadn't noticed that these changes had knocked everything out of alignment. Have gone through it carefully and I think I've fixed everything. Let me know if I missed anything though, cheers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great, thanks for neatening that up!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes look good! I've checked this out locally and confirmed that all of these are removed from the kernels as advised in the PR summary.

I have however also noticed a few small formatting changes which could be updated?

Also whats the plan for lfric apps? I appreciate it's out of scope for this ticket, just some context present, like a linked issue apps side could be good here?

Besides these small changes, it's otherwise approved! Thanks

Co-authored-by: Benjamin Went <136574563+MetBenjaminWent@users.noreply.github.com>
@mattatmet

Copy link
Copy Markdown
Contributor Author

I have however also noticed a few small formatting changes which could be updated?

Also whats the plan for lfric apps? I appreciate it's out of scope for this ticket, just some context present, like a linked issue apps side could be good here?

Benjamin Went (@MetBenjaminWent) Thanks Ben! I've made those changes now. With regards to lfric apps, there is no plan to extend this to apps yet I don't think.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks Matthew! Changes look good, SR approved.

@EdHone Ed Hone (EdHone) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All changes look fine - the only request I would have would be for all the new use statements for iso_fortran_env be moved to the top in their own block, so they aren't confused with lfric modules: i.e., the first instance would become:

module dg_inc_matrix_vector_kernel_mod

  use, intrinsic :: iso_fortran_env, only: real32, real64

  use argument_mod,            only : arg_type,                  &
                                      GH_FIELD, GH_OPERATOR,     &
                                      GH_REAL, GH_READ,          &
                                      GH_READWRITE, ANY_SPACE_1, &
                                      ANY_DISCONTINUOUS_SPACE_1, &
                                      CELL_COLUMN
  use constants_mod,           only : i_def
  use kernel_mod,              only : kernel_type

@mattatmet

Copy link
Copy Markdown
Contributor Author

All changes look fine - the only request I would have would be for all the new use statements for iso_fortran_env be moved to the top in their own block, so they aren't confused with lfric modules: i.e., the first instance would become:

Thanks for the suggestion Ed Hone (@EdHone), I've made these changes and pushed them.

@EdHone Ed Hone (EdHone) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mattatmet

Copy link
Copy Markdown
Contributor Author

@EdHone

Copy link
Copy Markdown
Contributor

There were a few final whitespace issues to fix but I sorted them out

@EdHone
Ed Hone (EdHone) merged commit a117080 into MetOffice:main Aug 21, 2026
6 checks passed
@mattatmet

Copy link
Copy Markdown
Contributor Author

Thanks very much Ed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants