Skip to content

Commit

Permalink
[cmake] Use SIRIUS namespace convention for options and other SIRIUS …
Browse files Browse the repository at this point in the history
…internal variables

- updated README.md file to reflect the new convention
- updated the spack recipe
- removed multiple versions of the spack recipe
- updated the docker files when needed
  • Loading branch information
mtaillefumier committed Jul 24, 2023
1 parent 30132cc commit 68ca5c4
Show file tree
Hide file tree
Showing 53 changed files with 272 additions and 771 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
cd ${GITHUB_WORKSPACE}
mkdir build
cd build
spack --color always build-env $DEVSPEC -- cmake .. -DUSE_SCALAPACK=1 -DUSE_VDWXC=1 -DBUILD_TESTING=1 -DCREATE_FORTRAN_BINDINGS=1 -DCREATE_PYTHON_MODULE=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo
spack --color always build-env $DEVSPEC -- cmake .. -DSIRIUS_USE_SCALAPACK=1 -DSIRIUS_USE_VDWXC=1 -DBUILD_TESTING=1 -DCREATE_FORTRAN_BINDINGS=1 -DCREATE_PYTHON_MODULE=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo
- name: Build SIRIUS
run: |
cd ${GITHUB_WORKSPACE}/build
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
cd ${GITHUB_WORKSPACE}
mkdir build
cd build
spack --color always build-env $DEVSPEC -- cmake .. -DUSE_SCALAPACK=1 -DUSE_CUDA=1 -DUSE_VDWXC=1 -DBUILD_TESTING=1 -DCREATE_FORTRAN_BINDINGS=1 -DCREATE_PYTHON_MODULE=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo
spack --color always build-env $DEVSPEC -- cmake .. -DSIRIUS_USE_SCALAPACK=1 -DSIRIUS_USE_CUDA=1 -DSIRIUS_USE_VDWXC=1 -DBUILD_TESTING=1 -DCREATE_FORTRAN_BINDINGS=1 -DCREATE_PYTHON_MODULE=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo
- name: Build SIRIUS
run: |
cd ${GITHUB_WORKSPACE}/build
Expand Down
122 changes: 62 additions & 60 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@ endif()

# user variables

option(CREATE_PYTHON_MODULE "create sirius Python module" OFF)
option(CREATE_FORTRAN_BINDINGS "build Fortran bindings" ON)
option(BUILD_DOCS "build doxygen doc" OFF)
option(USE_ELPA "use elpa" OFF)
option(USE_MAGMA "use MAGMA" OFF)
option(USE_NLCGLIB "enable nlcglib" OFF)
option(USE_CUDA "use CUDA" OFF)
option(USE_ROCM "use ROCM AMD GPU code" OFF)
option(USE_NVTX "use Nvidia profiling tools library" OFF)
option(USE_VDWXC "use libvdwxc for van der Walls corrections" OFF)
option(USE_MKL "use Intel MKL" OFF)
option(USE_CRAY_LIBSCI "use LAPACK/SCALAPACK from Cray LIBSCI" OFF)
option(USE_SCALAPACK "use scalapack" OFF)
option(BUILD_APPS "build apps" ON)
option(USE_OPENMP "use OpenMP" ON)
option(USE_PROFILER "measure execution of functions with timer" ON)
option(USE_MEMORY_POOL "use memory pool" ON)
option(USE_POWER_COUNTER "measure energy consumption with power counters" OFF)
option(BUILD_TESTING "build test executables" OFF) # override default setting in CTest module
option(USE_VCSQNM "use variable cell stabilized quasi Newton method" OFF)

set(GPU_MEMORY_ALIGMENT "512" CACHE STRING "memory alignment of the GPU")
set(USE_FP32 "AUTO" CACHE STRING "Enable single precision support.")

set_property(CACHE USE_FP32 PROPERTY STRINGS "AUTO" "ON" "OFF")
option(SIRIUS_CREATE_PYTHON_MODULE "create sirius Python module" OFF)
option(SIRIUS_CREATE_FORTRAN_BINDINGS "build Fortran bindings" ON)
option(SIRIUS_BUILD_DOCS "build doxygen doc" OFF)
option(SIRIUS_USE_ELPA "use elpa" OFF)
option(SIRIUS_USE_MAGMA "use MAGMA" OFF)
option(SIRIUS_USE_NLCGLIB "enable nlcglib" OFF)
option(SIRIUS_USE_CUDA "use CUDA" OFF)
option(SIRIUS_USE_ROCM "use ROCM AMD GPU code" OFF)
option(SIRIUS_USE_NVTX "use Nvidia profiling tools library" OFF)
option(SIRIUS_USE_VDWXC "use libvdwxc for van der Walls corrections" OFF)
option(SIRIUS_USE_MKL "use Intel MKL" OFF)
option(SIRIUS_USE_CRAY_LIBSCI "use LAPACK/SCALAPACK from Cray LIBSCI" OFF)
option(SIRIUS_USE_SCALAPACK "use scalapack" OFF)
option(SIRIUS_BUILD_APPS "build apps" ON)
option(SIRIUS_USE_OPENMP "use OpenMP" ON)
option(SIRIUS_USE_PROFILER "measure execution of functions with timer" ON)
option(SIRIUS_USE_MEMORY_POOL "use memory pool" ON)
option(SIRIUS_USE_POWER_COUNTER "measure energy consumption with power counters" OFF)
option(SIRIUS_BUILD_TESTING "build test executables" OFF) # override default setting in CTest module
option(SIRIUS_USE_VCSQNM "use variable cell stabilized quasi Newton method" OFF)

set(SIRIUS_GPU_MEMORY_ALIGMENT "512" CACHE STRING "memory alignment of the GPU")
set(SIRIUS_USE_FP32 "AUTO" CACHE STRING "Enable single precision support.")

set_property(CACHE SIRIUS_USE_FP32 PROPERTY STRINGS "AUTO" "ON" "OFF")

# set language and standard

if(CREATE_FORTRAN_BINDINGS)
if(SIRIUS_CREATE_FORTRAN_BINDINGS)
enable_language(Fortran)
endif()

Expand All @@ -64,8 +64,8 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
endif()

if(USE_CUDA AND USE_ROCM)
message(FATAL_ERROR "USE_CUDA and USE_ROCM must not be enabled at the same time!")
if(SIRIUS_USE_CUDA AND SIRIUS_USE_ROCM)
message(FATAL_ERROR "SIRIUS_USE_CUDA and SIRIUS_USE_ROCM must not be enabled at the same time!")
endif()

add_compile_definitions(SIRIUS_GPU_MEMORY_ALIGMENT=${GPU_MEMORY_ALIGMENT})
Expand All @@ -77,7 +77,7 @@ list(APPEND CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
include(GitSubmodule) # include custom defined FindPackage modules
include(GNUInstallDirs) # required to get a proper LIBDIR variable

if (CREATE_PYTHON_MODULE)
if (SIRIUS_CREATE_PYTHON_MODULE)
find_package(Python3 COMPONENTS Interpreter REQUIRED)
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
endif()
Expand Down Expand Up @@ -128,14 +128,11 @@ option(BUILD_SHARED_LIBS "Build shared libraries." ON)
# generate compile_commands.json with compile commands for each target
set(CMAKE_EXPORT_COMPILE_COMMANDS "YES")

if(USE_NLCGLIB)
if(SIRIUS_USE_NLCGLIB)
find_package(nlcglib REQUIRED)
find_package(Kokkos REQUIRED)
endif()

if(USE_MEMORY_POOL)
find_package(umpire)
endif()

find_package(MPI REQUIRED)
find_package(GSL REQUIRED)
Expand All @@ -147,11 +144,11 @@ find_package(SpFFT 1.0.2 CONFIG REQUIRED)
find_package(SPLA 1.4.0 CONFIG REQUIRED)

# Check if SpFFT support single precision if required
set(USE_FP32_BOOL OFF)
if(NOT USE_FP32 STREQUAL "OFF")
set(SIRIUS_USE_FP32 BOOL OFF)
if(NOT SIRIUS_USE_FP32 STREQUAL "OFF")
if(SPFFT_SINGLE_PRECISION)
set(USE_FP32_BOOL ON)
elseif(USE_FP32 STREQUAL "ON")
set(SIRIUS_USE_FP32 BOOL ON)
elseif(SIRIUS_USE_FP32 STREQUAL "ON")
message(FATAL_ERROR "Single precision option enabled, but SpFFT not compiled with single precision support.")
endif()
endif()
Expand All @@ -172,50 +169,50 @@ else()
target_compile_definitions(sirius::filesystem INTERFACE SIRIUS_BOOST_FILESYSTEM)
endif()

if (USE_OPENMP)
if (SIRIUS_USE_OPENMP)
find_package(OpenMP REQUIRED)
endif()

set(LINALG_LIB "")
if(USE_MKL)
set(USE_MKL_SHARED_LIBS On) # link against shared MKL libraries
if(SIRIUS_USE_MKL)
set(SIRIUS_USE_MKL_SHARED_LIBS On) # link against shared MKL libraries
find_package(MKL REQUIRED)
set(LINALG_LIB "sirius::mkl")
elseif(USE_CRAY_LIBSCI)
set(SIRIUS_LINALG_LIB "sirius::mkl")
elseif(SIRIUS_USE_CRAY_LIBSCI)
find_package(CRAY_LIBSCI REQUIRED)
set(LINALG_LIB "${CRAY_LIBSCI_LIBRARIES}")
set(SIRIUS_LINALG_LIB "${SIRIUS_CRAY_LIBSCI_LIBRARIES}")
else()
find_package(LAPACK REQUIRED)
set(LINALG_LIB "${LAPACK_LIBRARIES}")
if(USE_SCALAPACK)
set(SIRIUS_LINALG_LIB "${LAPACK_LIBRARIES}")
if(SIRIUS_USE_SCALAPACK)
find_package(SCALAPACK REQUIRED) # just sets scalapack_DIR
set(LINALG_LIB "${LINALG_LIB};${SCALAPACK_LIBRARIES}")
set(SIRIUS_LINALG_LIB "${SIRIUS_LINALG_LIB};${SIRIUS_SCALAPACK_LIBRARIES}")
endif()
endif()

if(USE_ELPA)
if(SIRIUS_USE_ELPA)
find_package(Elpa REQUIRED)
endif(USE_ELPA)
endif(SIRIUS_USE_ELPA)

if(USE_MAGMA)
if(SIRIUS_USE_MAGMA)
find_package(MAGMA REQUIRED)
endif(USE_MAGMA)
endif(SIRIUS_USE_MAGMA)

if(USE_VDWXC)
if(SIRIUS_USE_VDWXC)
find_package(LibVDWXC 0.3.0 REQUIRED)
endif(USE_VDWXC)
endif(SIRIUS_USE_VDWXC)

find_package(costa CONFIG REQUIRED)

if(USE_CUDA)
if(SIRIUS_USE_CUDA)
enable_language(CUDA)
# note find cudatoolkit is called inside the include file. the
# sirius::cuda_libs target is also defined there
include(cmake/cudalibs_target.cmake)
message(STATUS "CMAKE_CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES}")
endif(USE_CUDA)
endif(SIRIUS_USE_CUDA)

if(USE_ROCM)
if(SIRIUS_USE_ROCM)
# safegaurd.
if (NOT DEFINED CMAKE_HIP_ARCHITECTURES)
set(CMAKE_HIP_ARCHITECTURES gfx801 gfx900 gfx90a)
Expand All @@ -227,6 +224,11 @@ if(USE_ROCM)
set(CMAKE_HIP_STANDARD 14)
endif()

if(SIRIUS_USE_MEMORY_POOL)
find_package(umpire)
endif()


# check if git command exists
find_program(GIT_EXE NAMES git)

Expand Down Expand Up @@ -286,25 +288,25 @@ install(DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/modules"
# sirius library
add_subdirectory(src)

if(CREATE_PYTHON_MODULE)
if(SIRIUS_CREATE_PYTHON_MODULE)
# Python module
add_subdirectory(python_module)
endif(CREATE_PYTHON_MODULE)
endif(SIRIUS_CREATE_PYTHON_MODULE)

# applications
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
add_subdirectory(apps/tests)
add_subdirectory(apps/unit_tests)
endif(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)

if(BUILD_APPS)
if(SIRIUS_BUILD_APPS)
add_subdirectory(apps/atoms)
add_subdirectory(apps/hydrogen)
add_subdirectory(apps/dft_loop)
if(USE_NLCGLIB)
if(SIRIUS_USE_NLCGLIB)
add_subdirectory(apps/nlcg)
endif()
add_subdirectory(apps/upf)
add_subdirectory(apps/utils)
endif(BUILD_APPS)
endif(SIRIUS_BUILD_APPS)
add_subdirectory(doc)
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ and optionally any of the additional libraries:
* [Boost Filesystem](https://www.boost.org/doc/libs/1_73_0/libs/filesystem/doc/index.htm)*
* [Eigen3](https://eigen.tuxfamily.org/index.php?title=Main_Page)**

\* Only required when `BUILD_APPS=On` and your compiler does not support `std::filesystem` or `std::experimental::filesystem`.
\* Only required when `SIRIUS_BUILD_APPS=On` and your compiler does not support `std::filesystem` or `std::experimental::filesystem`.

\** Only required when `-DBUILD_TESTING=On`
\** Only required when `-DSIRIUS_BUILD_TESTING=On`

Clone the repository and build as follows:

Expand All @@ -143,25 +143,25 @@ make -j install
where `CMAKE_PREFIX_PATH` is a list of installation paths of dependencies installed in non-standard locations.

#### Adding GPU support
To enable CUDA you need to pass the following options to CMake: `-DUSE_CUDA=On -DCMAKE_CUDA_ARCHITECTURES='60;70'`, where `CMAKE_CUDA_ARCHITECTURES` is
To enable CUDA you need to pass the following options to CMake: `-DSIRIUS_USE_CUDA=On -DCMAKE_CUDA_ARCHITECTURES='60;70'`, where `CMAKE_CUDA_ARCHITECTURES` is
a list of NVIDIA architectures. Use `60`, `61`, `62` for Pascal; `70`, `72` for Volta; `75` for Turing; and `80` for Ampere.
If CUDA is installed in a non-standard directory, you have to pass additional parameter to cmake `-DCUDA_TOOLKIT_ROOT_DIR=/path/to/cuda`.

To enable MAGMA (GPU implementation of LAPACK) use `-DUSE_MAGMA=On`. Append MAGMA's installation directory to `CMAKE_PREFIX_PATH` if necessary.
To enable MAGMA (GPU implementation of LAPACK) use `-DSIRIUS_USE_MAGMA=On`. Append MAGMA's installation directory to `CMAKE_PREFIX_PATH` if necessary.

#### Parallel eigensolvers
To compile with ScaLAPACK use `-DUSE_SCALAPACK=On`. To use ELPA, both `-DUSE_SCALAPACK=On` and `-DUSE_ELPA=On` are
To compile with ScaLAPACK use `-DSIRIUS_USE_SCALAPACK=On`. To use ELPA, both `-DSIRIUS_USE_SCALAPACK=On` and `-DSIRIUS_USE_ELPA=On` are
required, as we need ScaLAPACK functionality to transform the generalized eigenvalue problem to standard form,
which can then be solved by ELPA. Append ScaLAPACK's and ELPA's install directory to `CMAKE_PREFIX_PATH` if necessary.

#### Python module
Use `-DCREATE_PYTHON_MODULE=On` to build the Python module. The SIRIUS Python module depends on `mpi4py` and
Use `-DSIRIUS_CREATE_PYTHON_MODULE=On` to build the Python module. The SIRIUS Python module depends on `mpi4py` and
`pybind11`, which need to be installed on your system.

#### Additional options
To link against Intel MKL use `-DUSE_MKL=On`. For Cray libsci use `-DUSE_CRAY_LIBSCI=On`. Building tests requires `-DBUILD_TESTING=On`.
To link against Intel MKL use `-DSIRIUS_USE_MKL=On`. For Cray libsci use `-DSIRIUS_USE_CRAY_LIBSCI=On`. Building tests requires `-DSIRIUS_BUILD_TESTING=On`.

By default example applications are built. This can be turned off via `-DBUILD_APPS=Off`, which is recommended when just building Fortran bindings.
By default example applications are built. This can be turned off via `-DSIRIUS_BUILD_APPS=Off`, which is recommended when just building Fortran bindings.

### Installation on Piz Daint
Please refer to the [SIRIUS wiki page](https://github.com/electronic-structure/SIRIUS/wiki/Build-on-Piz-Daint) and
Expand Down
9 changes: 5 additions & 4 deletions apps/dft_loop/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
if(USE_VCSQNM)
if(SIRIUS_USE_VCSQNM)
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
endif()
add_executable(sirius.scf sirius.scf.cpp)
target_link_libraries(sirius.scf PRIVATE sirius sirius::filesystem)
if(USE_VCSQNM)
if(SIRIUS_USE_VCSQNM)
target_link_libraries (sirius.scf PRIVATE Eigen3::Eigen sirius)
endif()
install(TARGETS sirius.scf RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
set_property(TARGET sirius.scf PROPERTY POSITION_INDEPENDENT_CODE OFF)

# Register verification tests as well
set(SIRIUS_SCF_LABELS cpu_serial cpu_band_parallel)
if(USE_CUDA OR USE_ROCM)
if(SIRIUS_USE_CUDA OR SIRIUS_USE_ROCM)
set(SIRIUS_SCF_LABELS ${SIRIUS_SCF_LABELS} gpu_serial gpu_band_parallel gpu_k_point_parallel)
endif()
set(SIRIUS_SCF_FLAGS_gpu_serial --control.processing_unit=gpu --control.std_evp_solver_name=cusolver --control.gen_evp_solver_name=cusolver)
Expand All @@ -21,7 +21,8 @@ set(SIRIUS_SCF_FLAGS_cpu_serial --control.processing_unit=cpu)
set(SIRIUS_SCF_FLAGS_cpu_band_parallel --control.processing_unit=cpu --control.mpi_grid_dims=2:2 --control.std_evp_solver_name=scalapack --control.gen_evp_solver_name=scalapack)

# todo: Add OMP_NUM_THREADS + srun / mpiexec flags here too?
if(BUILD_TESTING)

if(SIRIUS_BUILD_TESTING)
file(GLOB dirs LIST_DIRECTORIES true "${CMAKE_SOURCE_DIR}/verification/test*")

foreach(full_path ${dirs})
Expand Down
4 changes: 2 additions & 2 deletions apps/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ foreach(_test ${_tests})
install(TARGETS ${_test} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endforeach()

if(CREATE_FORTRAN_BINDINGS)
if(SIRIUS_CREATE_FORTRAN_BINDINGS)
add_executable(test_fortran_api test_fortran_api.f90)
target_link_libraries(test_fortran_api PRIVATE sirius MPI::MPI_Fortran)
install(TARGETS test_fortran_api RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")

add_executable(test_srvo3_pwpp test_srvo3_pwpp.f90)
target_link_libraries(test_srvo3_pwpp PRIVATE sirius MPI::MPI_Fortran)
install(TARGETS test_srvo3_pwpp RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif(CREATE_FORTRAN_BINDINGS)
endif(SIRIUS_CREATE_FORTRAN_BINDINGS)
4 changes: 2 additions & 2 deletions apps/tests/test_davidson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ void test_davidson(cmd_args const& args__)
std::cout << "precision_wf: " << precision_wf << ", precision_hs: " << precision_hs << std::endl;
}
if (precision_wf == "fp32" && precision_hs == "fp32") {
#if defined(USE_FP32)
#if defined(SIRIUS_USE_FP32)
diagonalize<float, std::complex<float>>(ctx, vk, pot, res_tol, eval_tol, only_kin, subspace_size, estimate_eval, extra_ortho);
#endif
}
if (precision_wf == "fp32" && precision_hs == "fp64") {
#if defined(USE_FP32)
#if defined(SIRIUS_USE_FP32)
diagonalize<float, std::complex<double>>(ctx, vk, pot, res_tol, eval_tol, only_kin, subspace_size, estimate_eval, extra_ortho);
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion apps/tests/test_hloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ int main(int argn, char** argv)
std::vector<r3::vector<double>>(), false, false);
for (int i = 0; i < repeat; i++) {
if (fp32) {
#if defined(USE_FP32)
#if defined(SIRIUS_USE_FP32)
test_hloc<float>(*ctx, num_bands, use_gpu);
#else
RTE_THROW("Not compiled with FP32 support");
Expand Down
2 changes: 1 addition & 1 deletion apps/tests/test_wf_ortho.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int main(int argn, char** argv)

sirius::initialize(1);
if (args.exist("fp32")) {
#if defined(USE_FP32)
#if defined(SIRIUS_USE_FP32)
call_test<float>(mpi_grid_dims, cutoff, num_bands, bs, num_mag_dims, mem, 1);
#else
RTE_THROW("Not compiled with FP32 support");
Expand Down
2 changes: 1 addition & 1 deletion apps/tests/test_wf_trans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int main(int argn, char** argv)

sirius::initialize(1);
if (args.exist("fp32")) {
#if defined(USE_FP32)
#if defined(SIRIUS_USE_FP32)
call_test<float>(mpi_grid_dims, cutoff, num_bands, bs, num_mag_dims, mem, 1);
#else
RTE_THROW("Not compiled with FP32 support");
Expand Down
2 changes: 1 addition & 1 deletion apps/unit_tests/test_fft_correctness_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int main(int argn, char **argv)
printf("running %-30s : ", argv[0]);
int result{0};
if (args.exist("fp32")) {
#if defined(USE_FP32)
#if defined(SIRIUS_USE_FP32)
result = run_test<float>(args);
#else
RTE_THROW("not compiled with FP32 support");
Expand Down
2 changes: 1 addition & 1 deletion apps/unit_tests/test_fft_correctness_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int main(int argn, char **argv)
printf("running %-30s : ", argv[0]);
int result{0};
if (args.exist("fp32")) {
#if defined(USE_FP32)
#if defined(SIRIUS_USE_FP32)
result = run_test<float>(args);
#else
RTE_THROW("not compiled with FP32 support");
Expand Down
Loading

0 comments on commit 68ca5c4

Please sign in to comment.