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
Build cp2k with cmake #2364
Build cp2k with cmake #2364
Conversation
4372d4b
to
0085521
Compare
This is awesome! Adding a new build system to a grown code base is no easy feat. Great work!
Yes, we can merge this PR without tests. Over the coming weeks we can then migrate one CI test at a time. I noticed that many of the files have a BSD license from ETH. Could you reach out to the original authors and ask if they'd be ok with releasing these files directly under GPL? |
I want to wait a little so that devs (mostly) try it and tell me what is failing. I will work on the hip side further (the compilation is not the issue, nor is cmake but rocm is). Additional note : For internal reason, we are using spack + cp2k + cmake to actually build cp2k (with the default dependencies).
I blindly copy pasted the license agreement we use almost everywhere but i do not think GPL is an issue at least not on my side. |
378b9ba
to
14cb4f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice to see this! I've added a few comments that would make this a bit more idiomatic "modern" CMake, but none of the comments are blockers.
set(CP2K_USE_HIP OFF) | ||
set(CP2K_USE_CUDA OFF) | ||
|
||
set(CMAKE_POSITION_INDEPENDENT_CODE ${CP2K_SET_POSITION_INDEPENDENT_CODE}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a benefit to having CP2K_SET_POSITION_INDEPENDENT_CODE
instead of just setting CMAKE_POSITION_INDEPENDENT_CODE
directly as a user?
CMakeLists.txt
Outdated
message(STATUS " ") | ||
message(STATUS "- COSMA") | ||
message(STATUS " - include directories : " ${COSMA_INCLUDE_DIRS}) | ||
# message(STATUS " - libraries : " ${COSMA_LIBRARIES}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove or uncomment?
CMakeLists.txt
Outdated
message(STATUS " - SPGLIB") | ||
endif() | ||
|
||
# if (NOT CP2K_USE_MPI) message(STATUS " - MPI") endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove or uncomment?
@@ -0,0 +1,123 @@ | |||
if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") | |||
set(CMAKE_Fortran_FLAGS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all of these CMAKE_*_FLAGS
definitions will override any user-defined CMAKE_*_FLAGS
. I would recommend either appending to the cache variables or again using targets and target_compile_flags
(together with generator expressions for the various conditionals).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept the initial version for the time being but I will work on this to make simpler.
src/CMakeLists.txt
Outdated
${DBM_SRCS_GPU}) | ||
|
||
set_target_properties(dbm_miniapp PROPERTIES LINKER_LANGUAGE C) | ||
# target_compile_options(dbm_miniapp PUBLIC "${OpenMP_C_FLAGS}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove or uncomment? I think the OpenMP::OpenMP_<lang>
target should anyway be enough for this.
Summarizing my review comments:
|
a4fd2b6
to
695751c
Compare
e7afbde
to
5c169cf
Compare
- use option(...) instead of set(...) when possible - use cmake_dependent_option(...) instead of the if then else construct to set dependent options - remove commented out code - remove unnecessary enable_language - fix typo in CP2K_SUPPORTED_ACCELERATION_TARGETS - use target_compile_features(...) to set the different languages standards - Remove the VERSON file. The version is set directly inside CMakeLists.txt or with a tag - add cp2k.pc file - add search of libint2.mod file - rocm 5.3.0 works
5c169cf
to
9d73a0b
Compare
It is time to get this PR in the wild. Please quash all commits when the PR is merged as it is not worth keeping my internal logic.
Happy hacking. |
Note 1 : can we avoid running the full CI for the time being ?
Note 2: the two build systems will coexist for at least one or two versions.
This PR is long overdue but this work reaches the point where it become usable to build cp2k with cmake. I kept the building process as simple as possible so that other devs can look around and tinker with it a little bit.
This build system does only one task, configuring and compiling cp2k. The dependencies should be compiled separately as a first step.
I am also fully aware of that it will not necessarily work for everyone the first time that's why I am asking devs, experienced users and package managers to test it and report issues as much as they can. I will open an issue on the cp2k github repo to regroup all of them in one place.
so far all dependencies should be detected with fluctuating success. The mandatory dependencies are
libxc, libint, cosma, libxsmm, fftw are turned on by default. All the other dependencies are off
All options are prefixed with CP2K_. This rule is enforced for the build system because it can potentially interfere with others options and variables names defined by the dependencies cmake config files (BLAS in particular). The -D__OPTIONS are unchanged.
the build system supports CUDA and HIP (as much as HIP goes expect some issues)
how to compile cp2k :
cmake -DCMAKE_INSTALL_PREFIX=/myprefix -DCP2K_BLAS_VENDOR=MKL -DCP2K_SCALAPACK_VENDOR=MKL -DCP2K_USE_ACCEL=CUDA -DCP2K_WITH_GPU=V100 ..
MKL without CUDA : remove the -DCP2K_USE_ACCEL
MKL with HIP replace CUDA with HIP and set -DCP2K_WITH_GPU=Mi250 (of instance). Note that these options have default values
Cray environments
with libsci and cuda support : 'MPICC=cc MPICXX=CC MPIFORT=ftn cmake -DCMAKE_INSTALL_PREFIX=/myprefix -DCP2K_BLAS_VENDOR=SCI -DCP2K_SCALAPACK_VENDOR=SCI -DCP2K_USE_ACCEL=CUDA -DCP2K_WITH_GPU=V100 ..`
with MKL see the mkl section because it is exactly the same command line.
list of known potential issues
missing things and improvements