Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CMake variables/names in our cmake macros #6014

Merged
merged 46 commits into from
Nov 15, 2023

Conversation

jgfouca
Copy link
Member

@jgfouca jgfouca commented Oct 24, 2023

This should be the last major PR in CMAKE V2 effort.

Here are the list of items from the macros remaining that are not cmake style:

  • HAS_F2008_CONTIGUOUS: Use to set ${CPRE}USE_CONTIGUOUS=contiguous. Added for flags for .F90 files. There must be a better way to do this?
  • MPICC/MPICXX/MPIFC: The mpi compilers. I think we keep these since we cannot just use CMAKE__COMPILER because we sometimes need to distinguish between serial and non-serial compilers.
  • SCC/SCXX/SFC: See above
  • CXX_LIBS: Things to add to link line if USE_CXX is on. This is mostly for -lstdc++ and -cxxlib. There is probably a better way to do this. Just add to CMAKE_EXE_LINKER_FLAGS?
  • CMAKE_OPTS: A way to communicate arbitrary CMAKE settings to the spio cmake command. Needs a better name at least. This was also used for CISM but we (E3SM) don't use that anymore.
  • FIXEDFLAGS: Added to FFLAGS for .F and .f files
  • FREEFLAGS: Added to FFLAGS for .f90 and .F90 files. I think we can replace these with the Fortran_FORMAT property?
  • PIO_FILESYSTEM_HINTS: Used to pass PIO_FILESYSTEM_HINTS to spio cmake. This is very similar to CMAKE_OPTS
  • SLIBS: Convert CMAKE_EXE_LINKER_FLAGS?
  • KOKKOS_OPTIONS: Keep this for now
  • USE_HIP: Keep
  • CXX_LINKER: Replace with CMAKE__LINKER_PREFERENCE?
  • PFUNIT_PATH: This is how some CIME stuff finds PFUNIT. Should be replaced by ENV{PFUNIT_ROOT} at some point but not urgent
  • CONFIG_ARGS: Use to specify autoconf flags to the autoconf-based sharedlibs (MCT and MPI-SERIAL). I think a better name at least is needed
  • USE_CUDA: keep
  • CPRE: Part of that weird CONTIGUOUS stuff from above
  • USE_SYCL: keep
  • SYCL_FLAGS: It looks like SYCL is not yet a known Cmake , so we can't use CMAKE_SYCL_FLAGS, so we can leave this as is for now.

Other todo:

  • Streamline cmake sharedlibs to use macros directly
  • Make sure other sharedlibs are grabbing the right names
  • Cleanup cmake core files now that names are right
  • Remove use of CFLAGS, FFLAGS, CXXFLAGS
  • Remove support for e3sm_remove_flags
  • Handle fixed/free fortran stuff better
  • Revert the oneapi changes once renamer is done.
  • gptl needs to use CMake

Changes Summary:

  • Macro structure changes
  • Add post-process step to set final values for a few items
  • Make cmake conversion more robust by storing pre-macro values and comparing instead of just looking at new variables
  • Change all macros to set variables that cmake knows about! This is a huge change with wide impacts
    • We no longer have to set flag properties on all files. This simplifies things but makes it hard to support e3sm_remove_flags so that feature has been removed. You should always be able to append flags to achieve the same effect as removing a flag.
    • Try to remove as much of the linker flag micromanagement as possible
    • We now default to cxx linker. Intel and PGI still have to use fortran unfortunately since our main function is in fortran
    • Remove as many non-cmake settings as possible from the macros
  • Add script for converting macros from the old style to new style
  • Upgrade the compare-flags tool to support parsing the e3sm.bldlog file. This is a tougher way to compare flags since you have to build the cases with -j 1, but it's more robust than looking at cmake internal files.
  • Remove lots of unneeded stuff from main cmake files (build_model and common_setup)
  • Remove unused old makefiles for COSP and MPAS
  • Move gptl build to cmake

Testing:

  • mappy_gnu: e3sm_developer, with full flag compare on a couple big cases
  • anlgce: e3sm_developer builds
  • pm-cpu_intel: e3sm_developer, with full flag compare on one big case
  • chrysalis_intel: e3sm_developer, with full flag compare on one big case
  • summit: build one big case with pgigpu, ibmgpu, pgi

@github-actions
Copy link

github-actions bot commented Oct 24, 2023

PR Preview Action v1.4.4
🚀 Deployed preview to https://E3SM-Project.github.io/E3SM/pr-preview/pr-6014/
on branch gh-pages at 2023-11-14 18:57 UTC

@jgfouca jgfouca requested a review from bartgol October 24, 2023 19:51
@bartgol
Copy link
Contributor

bartgol commented Oct 24, 2023

A few thoughts:

  • It appears USE_SYCL, USE_HIP, USE_CUDA are only used to set YAKL flags and YAKL arch. Perhaps we should unify things, doing something like set (DEVICE_TYPE "CUDA"), so that we can do
if (DEVICE_TYPE)
  set (YAKL_ARCH ${DEVICE_TYPE})
  set (YAKL_${DEVICE_TYPE}_FLAGS "${CPPDEFS} ${$DEVICE_TYPE}_FLAGS})
endif()

if nothing else, it would reduce the number of vars floating around.

  • CONFIG_ARGS: do we still need this? I thought this PR got rid of the dependence on cime/CIME/Tools/Makefile, which means no more autoconf. Did I misunderstand it?
  • CXX_LINKER: since our main is in Fortran, does it make sense to use anything other than Fortran?
  • KOKKOS_OPTIONS: long term, we should move to a CMake version of buildlib.kokkos, and make macros file set Kokkos_XYZ vars rather than provide a string with command line cmake options.
  • CXX_LIBS: I think adding to CMAKE_EXE_LINKER_FLAGS may be ok
  • SLIBS: same as CXX_LIBS, provided that these are just link line options (not cmake targets!).
  • S-vs-MP compilers: why do we need both? Why can't we just set CMAKE_<LANG>_COMPILER? Even if a lib does not need/use MPI, we can always use the mpi wrappers to build it, no? It should have the same effect as building it via serial compilers...
  • FREEFLAGS vs FIXEDFLAGS. Reading cmake docs, it seems that the Fortran_FORMAT property is set on a per-target basis. I'm not sure if some comps mix the two... Also, say you set the format, how do you specify different flags for different formats? Looking at our cmake macros files, they use a different set of values for the flags. Are those the same flags that setting the Fortran_FORMAT to FREE/FIXED would yield? I guess that'd be quite nice. If so, then I would be in favor of using the cmake property. We'd have to check if a) it can be used on a per-file basis or b) if it can't, see if there are components that use both formats.
  • PIO_FILESYSTEM_HINTS: would be nice to just append this to SPIO_CMAKE_OPTS, but I am not sure that CIME/Tools/Makefile would digest it?
  • HAS_F2008_CONTIGUOUS: why do we need to specify this in the macros file? I would assume a good old try_compile would do. I guess we may still need it if we build some sharedlib with raw Makefiles (this goes back to my first point: do we still use raw makefiles?)

@jgfouca
Copy link
Member Author

jgfouca commented Oct 25, 2023

@bartgol , thanks for looking at this.

It appears USE_SYCL, USE_HIP, USE_CUDA are only used to set YAKL flags and YAKL arch. Perhaps we should unify things, doing something like set (DEVICE_TYPE "CUDA")

I agree. This would be a nice upgrade.

CONFIG_ARGS: do we still need this? I thought this PR got rid of the dependence on cime/CIME/Tools/Makefile, which means no more autoconf. Did I misunderstand it?

Unfortunately, I think we must keep this one. mct and mpi-serial have an autoconf-based config system. The recent changes make it so autoconf is executed directly from the python build wrappers (buildlib.mct for example) instead of the wrapper invoking Tools/Makefile which then invokes autoconf.

CXX_LINKER: since our main is in Fortran, does it make sense to use anything other than Fortran?

I have no idea why this feature was added. It goes back many years. Is it possible that fortran linkers struggle to link CXX object files some times? We could remove this and see if all our main machines still work.

KOKKOS_OPTIONS: long term, we should move to a CMake version of buildlib.kokkos, and make macros file set Kokkos_XYZ vars rather than provide a string with command line cmake options.

We are already doing a CMake build of Kokkos (we used to use the generate_makefile stuff, but I changed that years ago). I agree we should move towards setting the actual Kokkos vars that Kokkos understands eventually. I don't know if I want to go there now.

S-vs-MP compilers: why do we need both? Why can't we just set CMAKE__COMPILER? Even if a lib does not need/use MPI, we can always use the mpi wrappers to build it, no? It should have the same effect as building it via serial compilers...

Good question. Once again, this feature goes back many years so I don't know why it was introduced and if it is really needed.

PIO_FILESYSTEM_HINTS: would be nice to just append this to SPIO_CMAKE_OPTS, but I am not sure that CIME/Tools/Makefile would digest it?

We don't use Tools/Makefile for anything anymore.

HAS_F2008_CONTIGUOUS: why do we need to specify this in the macros file? I would assume a good old try_compile would do. I guess we may still need it if we build some sharedlib with raw Makefiles (this goes back to my first point: do we still use raw makefiles?)

I am sure there's a better way to do this. None of the sharedlibs will be using raw Makefiles by the time this build refactor is done.

@bartgol
Copy link
Contributor

bartgol commented Oct 25, 2023

Ok, I think we can take steps toward the final goal. I am fine merging this PR, but I would strongly encourage to follow up on

  • need of MP-vs-S compilers
  • Kokkos options inside cmake macros files. Perhaps we can use what EKAT has (or copy-paste it) and machines macro files can simply include them (this avoids changing tens of mach files if (ehm...when) kokkos changes their cmake syntax)
  • Verify we can remove the CXX_LINKER option (I'm 97.43% positive we can).

HAS_F2008_CONTIGUOUS and the PIO_FILESYSTEM_HINTS are less of a priority (would be nice to fix them, and reduce the clutter and maintenance burden at some point though).

Finally, it would be nice to contribute to MCT providing a CMake build system. Since the repo is owned by ANL (I see rob as a contact for the MCSclimate org on github), we can probably find someone that can explain what the configure needs are (if the output of configure itself is too cryptic) and craft a simple CMakeLists.txt (no need to handle installation via pkg, just a simple build is enough probably).

@rljacob
Copy link
Member

rljacob commented Oct 25, 2023

I'm the only MCT developer and I had a plan to learn Cmake by adding a build for MCT but never had time.

@jgfouca
Copy link
Member Author

jgfouca commented Oct 25, 2023

@rljacob , we currently interface to the MCT build system through our python wrapper buildlib.mct. It would be slightly more convenient to do this if MCT were a CMake package, but it's really not a big problem.

@@ -11,8 +11,8 @@ set(SCXX "clang++")
set(SFC "flang")

string(APPEND CMAKE_Fortran_FLAGS " -Mflushz ")
string(APPEND FIXEDFLAGS " -Mfixed")
string(APPEND FREEFLAGS " -Mfreeform")
string(APPEND CMAKE_Fortran_FORMAT_FIXED_FLAG " -Mfixed")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. This is a CMake supported/handled variable, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. I think CMake can probably handle this automatically but I'm not 100% on that so I kept it.

list(APPEND E3SM_CMAKE_INTERNAL_VARS_BEFORE_BUILD_INTERNAL_IGNORE "${VAR_AFTER}")
set("E3SM_CMAKE_INTERNAL_${VAR_AFTER}" "${${VAR_AFTER}}")
elseif (NOT "${${VAR_AFTER}}" STREQUAL "${E3SM_CMAKE_INTERNAL_${VAR_AFTER}}")
message("CIME_SET_MAKEFILE_VAR ${VAR_AFTER} := ${${VAR_AFTER}}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these messages supposed to stay, or are they here just for debugging purposes while you are doing the port?

Copy link
Member Author

Choose a reason for hiding this comment

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

They need to stay. This hacky stuff is how we translate processed cmake macros into Makefile macros. Nothing we have is using the Makefile macros directly anymore, but they are still useful for querying macro vars which we do in a few places when "crossing" build systems (cmake -> autoconf for example) in some of the sharelib builds.

…_in_macros

* origin/master: (156 commits)
  Avoid calling add_default when no generic values present for gw_convect_hcf and hdepth_scaling_factor
  Reset hdepth_scaling_factor for MMF config
  Add settings to re-tune QBO, kPOM, and additional hyperviscosity modifier to allow use of rough topography
  Make "column_package" the default column_physics_type for BGC
  Add build-namelist default for chemdyg vertical indicies
  Add namelist definitions of UCIgaschmbudget_2D_L*
  remove unnecessary chemdyg settings in user_nl_eam for tests
  remove default chemdyg vertical indices in F90 code
  Add default chemdyg vertical indices in xml
  Update default chemdyg vertical indices in xml
  Update bld files to match Registry changes, using automated scripts
  Move some description changes from bld files to Registry
  Homme: Fix config.h comment style.
  Homme: Distinguish between F90 and C++ in HOMMEXX_ENABLE_GPU symbol use.
  Homme: Comment out two builds that aren't used in ctests.
  Hommexx: Fix issues related to qsize=0.
  Hommexx: Remove redundant HOMMEXX_ENABLE_GPU definition.
  Homme: Fix potential bad access to an array.
  Homme: Add USE_MPI_RUN_SCRIPT to standalone system.
  Homme(xx)/SL: Add SL-transport feature to doubly periodic mode.
  ...
…_in_macros

* origin/master:
  Add muller machine
  Address few reviewer comments
  Second attempt at fixing bmatrix equation
  Fixes one more equation
  Fixes eqnarray for Github
  Changes how equations are defined
  Updates references
  Adds labels to equations and cross-references
  Adds mathjax.js for equation numbering
  add mkdocs-bibtex to pip install
  Initial commit of TOP parameterization documentation
  adds syntax highlighting
  Minor updates
  Adds notes on running e3sm land developer testsuite
@rljacob
Copy link
Member

rljacob commented Nov 14, 2023

@jgfouca is this ready? Please fix the title.

@jgfouca
Copy link
Member Author

jgfouca commented Nov 14, 2023

@rljacob , yes, this has been ready for a while but I was waiting for the dashboard to get into better shape. This is going to be a disruptive PR.

@jgfouca jgfouca changed the title Jgfouca/cmake names in macros Use CMake variables/names in our cmake macros Nov 14, 2023
…_in_macros

* origin/master:
  Homme/SL: Address a warning.
  Homme: Fix latitude in dcmip2016_test1_forcing.
  Minor updates to ELM tech doc.
  Homme: Add gllfvremap_planar_ut unit test.
  Homme(xx): Set up C++-vs-F90 standalone planar pg2 test.
  Homme: Add planar capability to gllfvremap_mod.
  Homme: Modify dcmip2016_test1_pg_forcing to handle planar case.
  Change minimum concentration and mass of sea ice velocity solution
  Add single missing variable to OMP private
  Use small pe layout for TSC test
  Add size 'S' pes for chrysalis ne4 tests
jgfouca added a commit that referenced this pull request Nov 14, 2023
Use CMake variables/names in our cmake macros

This should be the last major PR in CMAKE V2 effort.

Changes Summary:
* Macro structure changes
* Add post-process step to set final values for a few items
* Make cmake conversion more robust by storing pre-macro values and comparing instead of just looking at new variables
* Change all macros to set variables that cmake knows about! This is a huge change with wide impacts
* We no longer have to set flag properties on all files. This simplifies things but makes it hard to support e3sm_remove_flags so that feature has been removed. You should always be able to append flags to achieve the same effect as removing a flag.
* Try to remove as much of the linker flag micromanagement as possible
* We now default to cxx linker. Intel and PGI still have to use fortran unfortunately since our main function is in fortran
* Remove as many non-cmake settings as possible from the macros
* Add script for converting macros from the old style to new style
* Upgrade the compare-flags tool to support parsing the e3sm.bldlog file. This is a tougher way to compare flags since you have to build the cases with -j 1, but it's more robust than looking at cmake internal files.
* Remove lots of unneeded stuff from main cmake files (build_model and common_setup)
* Remove unused old makefiles for COSP and MPAS
* Move gptl build to cmake

Testing:
* mappy_gnu: e3sm_developer, with full flag compare on a couple big cases
* anlgce: e3sm_developer builds
* pm-cpu_intel: e3sm_developer, with full flag compare on one big case
* chrysalis_intel: e3sm_developer, with full flag compare on one big case
* summit: build one big case with pgigpu, ibmgpu, pgi

[BFB]
@jgfouca
Copy link
Member Author

jgfouca commented Nov 14, 2023

Merged to next.

@rljacob
Copy link
Member

rljacob commented Nov 14, 2023

Is it going to change answers? Or just break some builds somewhere?

@jgfouca
Copy link
Member Author

jgfouca commented Nov 14, 2023

@rljacob , it should be BFB. I tested it the best I could reasonably do so on my own, but it's a major change so I'm sure something will break somewhere.

@jgfouca jgfouca merged commit 0908426 into master Nov 15, 2023
3 checks passed
@jgfouca jgfouca deleted the jgfouca/cmake_names_in_macros branch November 15, 2023 18:54
@jgfouca jgfouca mentioned this pull request Nov 15, 2023
49 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants