Repository navigation
Replies: 1 comment
|
I published a draft PR dedicated to a C++23 migration. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone,
I've recently done a research work for a possible migration to C++ version 23.
This research was first started after the discussion around the cpptrace PR (#4042), and its alternative solution (
std::stacktrace) coming with C++23, and transitioned into a report of the current state and possibilities to migrate to C++20 and C++23.This document gather information on the current state of GEOS, the readiness of the systems around it against C++20 and C++23, an inventory of the interesting features coming in both versions with their system requirements, the problems (possible or already encountered) when migrating and some actions to take or discuss.
A goal of this document is also to (re)start the discussion around these possible migrations (here or in the previous discussion for C++20), but also to have a "common" place to have deeper infos on the readiness of each system and partners.
There are some part of the document that are made to be written in (e.g. the "Action" cells in CI/
host-configs/configs to mark whether they are still relevant, should be sunsetted, etc., or the minimum compiler/libs to support)Current state
GEOS is currently on C++17. Some parts of the code already prepare for C++20.
Codebase characteristics
Format.hppboth maintain{fmt}(when__cplusplus < 202002L), andstd::format+ conceptgeos::Span(~20 call sites) (std::spancomes with C++20)enable_ifif constexpr<=>, ranges, coroutines, modules in first-party code (except Format.hpp)GEOS_THROW/GeosExceptions.hpp- nostd::expectedDocumentation drift
Some of the documentation is not up to date with the reality.
The migration could be the right time to update it.
CodeStyle.rststill claims that the CI uses Ubuntu 18.04, CentOS 7, CUDA 10.1, Xcode 11.2 while it is not the case.ContinuousIntegration.rsttalks about using Ubuntu and CentOS, while it is Ubuntu and Rocky LinuxDiscussions already started
GEOS#3223 - EPIC "Move forward to C++20":
thirdPartyLibs#351 - "move to c++20" (open):
Last task: "confirm geos compiles once it moves to c++20"
Features we might gain from C++20
Using the standard
<format>instead of {fmt}Standard string formatting (rules between
std::formatandfmtcan vary for decimals).Using
std::spaninstead ofgeos::SpanStandard non-owning view of contiguous 1D buffer.
Concepts /
requiresNamed type constraints on templates (cleaner & simpler than some complex
enable_if/traits).Spaceship operator
<=>Automatically generated comparisons operators with a single
<=>operator.constinit/constevalGuaranteed compile time init or function evaluation (
constexpris not guaranteed to be).Ranges
Composable lazy views/algorithms over sequences.
Features readiness (C++20)
-std=c++20std::formatstd::spanrequires<=>constinitconsteval* : Yes only if the linked STL meets the version requirements (libstdc++ or libc++ columns)
Features that might not be used directly (C++20)
Coroutines
Suspendable functions (
co_wait,co_yield, etc.) for async.Modules (
import)Replace header inclusion with compiled module interfaces, can reduce the compilation time.
Difficult to implement in GEOS (and pre C++20 code bases) due to large refactors required and possible lack of support with compilers, debuggers, static analyzers, build systems, etc.
Minimum compilers and standard library implementations versions (C++20)
Starting a migration to C++20 should require us to agree on a minimum compiler.
GCC & libstdc++: TBD
Clang: TBD
libc++ (MacOS /
-stdlib=libc++): TBDCCE: TBD
CUDA: TBD
HIP / ROCm: TBD
Features we might gain from C++23
std::stacktrace(potentially replacing the work on cpptrace)Capture a portable backtrace. Standard for GEOS#4042
std::expected(and monadicand_then, etc.)Return either the value or a typed error without throwing. Monadic "version" can chain success/error pipelines (
and_then,or_else, etc.) onexpectedIt could be used in this code:
std::move_only_functionType-erased callable that can hold move-only lambdas (unlike
std::function)Features that might not be used directly (C++23)
std::print/println(againstGEOS_LOG*)Directly prints a formatted string to stdout/stderr.
std::mdspan(against LvArray)Multi dimensional span, non owning-view of a flat block of memory as an N-D array.
Features readiness (C++23)
-std=c++23std::stacktracestd::expectedstd::expectedmonadic (withand_then, etc.)std::move_only_functionstd::print/printlnstd::mdspanstd::, device usescuda::std::/libhipcxx (not ISO)* : Yes only if the linked STL meets the version requirements (libstdc++ or libc++ columns)
Minimum compilers and standard library implementations versions (C++23)
Starting a migration to C++23 should require us to agree on a minimum compiler.
GCC & libstdc++: TBD
Clang: TBD
libc++ (MacOS /
-stdlib=libc++): TBDCCE: TBD
CUDA: TBD
HIP / ROCm: TBD
Configurations and their support for C++20 and C++23
This section covers the different configurations available (some of them may be outdated or not used anymore) and the support of their compilers for versions 20 and 23 of the C++ language.
A configuration labeled Ready still requires to have the TPL rebuilt with the correct language version, and to flip any variable in GEOS. Compilers themselves support the standard.
Partial, unless described further, is for configurations using a compiler that does not fully support the language standard.
CI configurations
geosx/ubuntu24.04-gcc13geosx/ubuntu24.04-clang20geosx/rockylinux8-gcc12geosx/rockylinux8-gcc13geosx/rockylinux8-clang19geosx/rockylinux9-clang22-gcc13-cuda12.9.1-clang19-cuda12.9.1-gcc13-cuda12.9.1macos-14-xlarge)host-configs/configurationsThese configurations are extracted from the
host-configs/, some may be outdated, any corrections are welcome.LLNL
dane-...-gcc@12.1.1.cmakeBLT_CXX_STD c++17dane-...-gcc@13.3.1.cmakedane-...-llvm@14.0.6.cmakedane-...-llvm@19.1.3.cmakematrix-...-gcc@12.1.1-cuda@12.6.0.cmakeCUDA_STANDARD 17matrix-...-gcc@13.3.1-cuda@12.9.1.cmakeCUDA_STANDARD 17matrix-...-llvm@14.0.6-cuda@12.6.0.cmakeCUDA_STANDARD 17matrix-...-llvm@19.1.3-cuda@12.9.1.cmakeCUDA_STANDARD 17tuolumne-...-cce@20.0.0-rocm@6.4.3.cmakeHIP_STANDARD 17tuolumne-...-llvm-amdgpu@6.4.3-rocm@6.4.3.cmakeHIP_STANDARD 17ORNL
frontier-base.cmake+frontier-cce@15.0.0.cmakeascent-gcc@8.1.1.cmakeTOTAL (Maple)
maple-gcc12.2.0-...cmakemaple-gcc12.2.0-cuda12.4.131-...cmakemaple-llvm17.0.4-...cmakemaple-llvm17.0.4-cuda12.4.131-...cmakeStanford
sherlock-gcc10.cmakesherlock-gcc10-cuda12-sm70.cmakeApple
macOS*.cmakeLBL / NERSC
cori-gcc@8.1.0.cmakecori-intel.cmake-std=c++14corigpu-gcc.cmakeanag-gcc.cmakeConfigurations
Most of the information comes from #3223.
Dependencies/TPL
Some actions have already been done for C++20.
RAJA / CHAI / Umpire / Camp versions are currently bumped for C++20 in TPL #351
fmt is being updated to fmt 12.1.0 (TPL #351), or replaceable with
std::formatOther TPL should be rebuild with C++20 or C++23 flags. I mostly didn't have any issues with TPL rebuilt on those versions (cf. next section Local attempt).
Local attempt (C++17 -> C++23)
Blocking points
I tried to migrate a local clone of GEOS from C++17 to C++23 on Pangea4, and used the gcc13 toolset for this.
Here are the problems/errors I encountered:
Migrating Format.hpp from using {fmt} to using the standard library
<format>:In C++20, std::format (and even {fmt}) requires a compile-time format string
std::format( "my msg: {}" <- this ). InTableData.cpp,columnFmt/rowFmtare built at runtime. A potential solution could be to usestd::vformat()Some classes will complain about missing a formatter when using
<format>. This is the case forPath.hppImplicit capture of
thisvia[=]is deprecated in C++20.Multiple files in GEOS have this implicit capture, I have updated them in the branch
One LvArray unitTests have this implicit capture (src/coreComponents/LvArray/unitTests/testTensorOpsEigen.cpp), it is not part of the branch
3. FailingtestCompMultiphaseFlowandtestCompMultiphaseFlowHybridBoth tests fail a single time with LvArray
CRSMatrixView.Passing procedure
The local attempt does compile and run on C++23 with a GCC 13 toolchain.
To do so, I rebuilt the TPL with the correct C++ 23 flags, with a host-config specifying the path to the GCC 13 compiler.
I however kept the {fmt} library at version 11, and did not update it to 12.1.0 (cf. Blocking points).
Then in GEOS, the Format.hpp switches (via #ifdef macros) to the
std::formaton C++ versions ≥20. This implementation causes errors so I manually forced the use of {fmt} for all versions, after a certain. Those first errors and their possible solutions are detailed in the "Blocking points" section.I replaced all the implicit capture of
thisin GEOS lambdas. One is present in src/coreComponents/LvArray/unitTests/testTensorOpsEigen.cpp and has also been modified to be able to compile.GEOS correctly compiles and launch, though further testing whether GEOS still produces the same results as before should be done.
Risks and blockers
Some systems could have incompatible drivers with CUDA and other "dependencies" (similar to Pangea3 discussed in #3223)
Needed contributions
There are still TBD (to be done) mentions in this document, they are open to anyone's contribution in order to finish this study.
Questions
Do some configs in the CI or in
host-configs/need to be sunset?Are there any drivers incompatibilities?
There doesn't seem to have a CI config for HIP
Is macOS and its configs still used?
All reactions