From 77be7f66d5884c30efbbcad657da5e1d1d851590 Mon Sep 17 00:00:00 2001 From: Stefano Frambati Date: Fri, 6 Oct 2023 17:59:56 +0200 Subject: [PATCH] Solve compilation issue with NVCC on some PowerPC machines (#2702) * Introduced workaround for compilation issue due to fmt * Update comment * Addressed review comments * added flag to host config for P3 * Added preprocessor define for FMT workaround * Updated preprocessor tag * correction in host-config * Added corresponding cmakedefine in GeosxConfig.hpp.in --- .../pangea3-gcc8.4.1-openmpi-4.1.2.cmake | 3 +++ src/cmake/GeosxConfig.cmake | 1 + src/coreComponents/common/GeosxConfig.hpp.in | 3 +++ .../dataRepository/DataContext.hpp | 22 +++++++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/host-configs/TOTAL/pangea3-gcc8.4.1-openmpi-4.1.2.cmake b/host-configs/TOTAL/pangea3-gcc8.4.1-openmpi-4.1.2.cmake index 5f3c90ce11f..ee75f9079b7 100644 --- a/host-configs/TOTAL/pangea3-gcc8.4.1-openmpi-4.1.2.cmake +++ b/host-configs/TOTAL/pangea3-gcc8.4.1-openmpi-4.1.2.cmake @@ -108,4 +108,7 @@ set(ENABLE_PETSC OFF CACHE BOOL "") set(ENABLE_HYPRE ON CACHE BOOL "") set(ENABLE_HYPRE_DEVICE "CUDA" CACHE BOOL "") +# activate workaround for fmt formatter +set(ENABLE_FMT_CONST_FORMATTER_WORKAROUND ON CACHE BOOL "") + include( ${CMAKE_CURRENT_LIST_DIR}/../tpls.cmake ) diff --git a/src/cmake/GeosxConfig.cmake b/src/cmake/GeosxConfig.cmake index c6760667f37..124b5da4b8d 100644 --- a/src/cmake/GeosxConfig.cmake +++ b/src/cmake/GeosxConfig.cmake @@ -4,6 +4,7 @@ set( PREPROCESSOR_DEFINES ARRAY_BOUNDS_CHECK CUDA CUDA_NVTOOLSEXT HIP + FMT_CONST_FORMATTER_WORKAROUND FORTRAN_MANGLE_NO_UNDERSCORE FPE HYPRE diff --git a/src/coreComponents/common/GeosxConfig.hpp.in b/src/coreComponents/common/GeosxConfig.hpp.in index 6e366aa3020..2e0bad1a7f9 100644 --- a/src/coreComponents/common/GeosxConfig.hpp.in +++ b/src/coreComponents/common/GeosxConfig.hpp.in @@ -41,6 +41,9 @@ /// Enables use of HIP (CMake option ENABLE_HIP) #cmakedefine GEOS_USE_HIP +/// Workaround for FMT compilation issue on some NVCC/PowerPC machines (CMake option ENABLE_FMT_CONST_FORMATTER_WORKAROUND) +#cmakedefine GEOS_USE_FMT_CONST_FORMATTER_WORKAROUND + /// Enables use of PVTPackage (CMake option ENABLE_PVTPackage) #cmakedefine GEOSX_USE_PVTPackage diff --git a/src/coreComponents/dataRepository/DataContext.hpp b/src/coreComponents/dataRepository/DataContext.hpp index 6b30face341..f04de33375c 100644 --- a/src/coreComponents/dataRepository/DataContext.hpp +++ b/src/coreComponents/dataRepository/DataContext.hpp @@ -223,4 +223,26 @@ struct GEOS_FMT_NS::formatter< geos::dataRepository::DataContext > : GEOS_FMT_NS } }; +// The following workaround is needed to fix compilation with NVCC on some PowerPC machines. +// The issue causes the following assertion error message: +// "Cannot format an argument. To make type T formattable provide a formatter specialization" +// The standard definition of the has_const_formatter check of fmt fails due to a compiler bug, see the issue below: +// https://github.com/fmtlib/fmt/issues/2746 +// The workaround was originally implemented in fmt: +// https://github.com/fmtlib/fmt/commit/70de324aa801eaf52e94c402d526a3849797c620 +// but later removed: +// https://github.com/fmtlib/fmt/commit/466e0650ec2d153d255a40ec230eb77d7f1c3334 +// This workaround provides a specialization of the const formatter check for the DataContext object. +// The formatter is defined within this file, and therefore the check is not needed. +// The scope of the check override is as small as possible to solve the current issue. +#ifdef GEOS_USE_FMT_CONST_FORMATTER_WORKAROUND +template<> +constexpr auto GEOS_FMT_NS::detail::has_const_formatter< geos::dataRepository::DataContext, GEOS_FMT_NS::format_context >() -> bool +{ + return true; +} +#endif +// End of the workaround for fmt compilation issues + + #endif /* GEOS_DATAREPOSITORY_DATACONTEXT_HPP_ */