Skip to content

Define own MPI type for float16

Michael Zikeli requested to merge ab04unyc/walberla:fix-mpi_wchar into master

Until now, MPI_WCHAR was used as a placeholder for float16 since it has the same amount of bits. However, since WCHAR is no floating point type, arithmetic operations could not be used with it.


Some information about Float16 in MPI that I could find

Either an MPI implementation that has a float16 datatype or an own handling for float16 must be provided. Since relying on specific implementation is not portable, we decided to do the latter one.


This MR aims to provide an own handling MPI handling for float16 according to the solution suggested in this stackoverflow post.

MPI types and MPI operations are chosen via the struct MPITrait that maps a CType to a respective MPI_Datatype ::type() and MPI_Op ::operation( mpi::Operation ).

Both self defined MPI_Types and MPI_Ops that are needed for float16 operations are initialized in the MPIManager the first time they are used via MPITrait and automatically freed before MPI_Finalize is called.

Via the MPIManager those operations and types can be accessed anytime and place in the code. This must not be done by the user, though, since the MPITrait located in the new header MPIFloat16.h handles these calls.

To use float16 and MPI in your application, make sure to include core/mpi/MPIFloat16.h


TODO:

  • Write MPITrait specialization for float16 that creates an own MPI type.
  • Add MPI_FLOAT16 dummy type to the MPI_Wrapper, in case MPI is not activated.
  • Find out if the MPI_OP are only used for in mpi::Redaction or if there are other files, that use them.
  • Write own mpi::Operation class that handles creations of MPI_Ops.
  • Define own operations for MPI_FLOAT16:
    • MIN
    • MAX
    • SUM
    • ~~will be added when needed {PRODUCT
    • LOGICAL_AND
    • BITWISE_AND
    • LOGICAL_OR
    • BITWISE_OR
    • LOGICAL_XOR
    • BITWISE_XOR}~~
  • Make walberla choose the right operator, depending on the MPI Datatype.
  • Automate the lifetime of self generated types and operations.
  • Write Test for float16 type creation.
  • Add Test for all Operations that are implemented yet.
  • Make the Test that check if all resources are properly freed. ( Don't know how )
  • Once gcc13 is merged, enable WALBERLA_BUILD_WITH_HALF_PRECISION_SUPPORT in pipeline, to have float16 changes tested as well.
Edited by Dominik Thoennes

Merge request reports