diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 652b1907378..da102ea6d13 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -77,7 +77,7 @@ jobs: - name: Install external tools from toolchain run: | cd toolchain - ./install_abacus_toolchain_new.sh --with-dftd4=install --dry-run -j8 + ./install_abacus_toolchain_new.sh --with-dftd4 --with-nep --dry-run -j8 ./scripts/stage4/install_stage4.sh cd .. @@ -131,6 +131,7 @@ jobs: -DENABLE_FLOAT_FFTW=ON \ -DENABLE_DFTD4=ON \ -DENABLE_PEXSI=ON \ + -DENABLE_NEP=ON \ -Werror=dev - name: Build diff --git a/CMakeLists.txt b/CMakeLists.txt index 4db27108ce7..08d6042db08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,8 @@ option(ENABLE_DFTD4 "Enable DFT-D4 dispersion correction" OFF) option(ENABLE_PLUMED "Enable using the PLUMED enhanced-sampling library" OFF) option(ENABLE_JSON "Enable JSON output" OFF) option(ENABLE_CNPY "Enable cnpy usage" OFF) +option(ENABLE_NEP "Enable NEP_CPU" OFF) +option(ENABLE_DEEPMD "Enable DeePMD-kit" OFF) option(DEBUG_INFO "Print message to debug" OFF) option(COMMIT_INFO "Print commit information in log" ON) @@ -509,78 +511,24 @@ if(ENABLE_ASAN) endif() if(ENABLE_MLALGO) - find_path(libnpy_SOURCE_DIR npy.hpp HINTS ${libnpy_INCLUDE_DIR}) - if(NOT libnpy_SOURCE_DIR) - include(FetchContent) - FetchContent_Declare( - libnpy - GIT_REPOSITORY https://github.com/llohse/libnpy.git - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE) - FetchContent_MakeAvailable(libnpy) - else() - - endif() -endif() - -# Torch uses outdated components to detect CUDA arch, causing failure on -# latest CUDA kits. Set CMake variable TORCH_CUDA_ARCH_LIST in the form of -# "major.minor" if required. -if(ENABLE_MLALGO OR DEFINED Torch_DIR) + find_package(Libnpy REQUIRED) + # Torch's CUDA architecture detection may need TORCH_CUDA_ARCH_LIST on + # recent CUDA toolkits. find_package(Torch REQUIRED) if(NOT Torch_VERSION VERSION_LESS "2.1.0") set_if_higher(CMAKE_CXX_STANDARD 17) elseif(NOT Torch_VERSION VERSION_LESS "1.5.0") set_if_higher(CMAKE_CXX_STANDARD 14) endif() - set(ABACUS_TORCH_CXX_FLAGS "${TORCH_CXX_FLAGS}") endif() if(ENABLE_CNPY) - find_path(cnpy_SOURCE_DIR cnpy.h HINTS ${libnpy_INCLUDE_DIR}) - if(NOT cnpy_SOURCE_DIR) - include(FetchContent) - FetchContent_Declare( - cnpy - GIT_REPOSITORY https://github.com/rogersce/cnpy.git - GIT_PROGRESS TRUE) - FetchContent_MakeAvailable(cnpy) - else() - - endif() - - # find ZLIB and link - find_package(ZLIB REQUIRED) + find_package(CNPY REQUIRED) endif() -function(git_submodule_update) - if(GIT_SUBMOD_RESULT EQUAL "0") - message(DEBUG "Submodule init'ed") - else() - find_package(Git REQUIRED) - if(NOT EXISTS "${PROJECT_SOURCE_DIR}/.git") - message(FATAL_ERROR "Not a git repository; cannot update submodules") - endif() - - message(STATUS "Updating submodules") - execute_process( - COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - RESULT_VARIABLE GIT_SUBMOD_RESULT) - if(NOT GIT_SUBMOD_RESULT EQUAL "0") - message( - FATAL_ERROR - "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}." - ) - endif() - endif() -endfunction() - if(ENABLE_LIBRI) set_if_higher(CMAKE_CXX_STANDARD 14) find_package(LibRI REQUIRED) - find_package(LibComm REQUIRED) - find_package(cereal REQUIRED CONFIG) endif() if(ENABLE_LIBXC) @@ -591,16 +539,13 @@ if(ENABLE_LIBXC) endif() endif() -if(DEFINED DeePMD_DIR) - find_package(DeePMD REQUIRED) -endif() - -if(DEFINED NEP_DIR) - find_package(NEP REQUIRED) +if(ENABLE_DEEPMD) + find_package(DeePMD CONFIG REQUIRED) + include(SetupDeePMD) endif() -if(DEFINED TensorFlow_DIR) - find_package(TensorFlow REQUIRED) +if(ENABLE_NEP) + find_package(NEP_CPU CONFIG REQUIRED) endif() if(ENABLE_PLUMED) diff --git a/cmake/CollectBuildInfoVars.cmake b/cmake/CollectBuildInfoVars.cmake index d74e8c0243b..1caec7e43c0 100644 --- a/cmake/CollectBuildInfoVars.cmake +++ b/cmake/CollectBuildInfoVars.cmake @@ -324,52 +324,28 @@ else() set(ABACUS_MLALGO "Disabled") endif() -if((DEFINED Torch_DIR OR ENABLE_MLALGO) AND Torch_VERSION) +if(ENABLE_MLALGO AND Torch_VERSION) set(ABACUS_LIBTORCH_VERSION "yes (v${Torch_VERSION})") -elseif(DEFINED Torch_DIR OR ENABLE_MLALGO) +elseif(ENABLE_MLALGO) set(ABACUS_LIBTORCH_VERSION "yes (path: ${Torch_DIR})") else() set(ABACUS_LIBTORCH_VERSION "no") endif() -if(DEFINED DeePMD_DIR) - set(ABACUS_DEEPMD_VERSION "yes (version unknown)") - set(DEEPMD_VERSION_HEADER "${DeePMD_DIR}/include/deepmd/version.h") - if(EXISTS ${DEEPMD_VERSION_HEADER}) - file(STRINGS "${DEEPMD_VERSION_HEADER}" DEEPMD_VERSION_LINE - REGEX "global_install_prefix") - if(DEEPMD_VERSION_LINE) - string( - REGEX - MATCH - "global_install_prefix=\".*deepmd-kit-([0-9]+\\.[0-9]+\\.[0-9]+)\"" _ - "${DEEPMD_VERSION_LINE}") - if(CMAKE_MATCH_1) - set(ABACUS_DEEPMD_VERSION "yes (v${CMAKE_MATCH_1})") - endif() - endif() - endif() - if(ABACUS_DEEPMD_VERSION STREQUAL "yes (version unknown)") - set(ABACUS_DEEPMD_VERSION "yes (path: ${DeePMD_DIR})") - endif() +if(ENABLE_DEEPMD AND DeePMD_VERSION MATCHES "^[0-9]+\\.[0-9]+") + set(ABACUS_DEEPMD_VERSION "yes (v${DeePMD_VERSION})") +elseif(ENABLE_DEEPMD) + set(ABACUS_DEEPMD_VERSION "yes (path: ${DeePMD_DIR})") else() set(ABACUS_DEEPMD_VERSION "no") endif() -if(DEFINED NEP_DIR AND NEP_VERSION) - set(ABACUS_NEP_VERSION "yes (v${NEP_VERSION})") -elseif(DEFINED NEP_DIR) - set(ABACUS_NEP_VERSION "yes (path: ${NEP_DIR})") +if(ENABLE_NEP) + set(ABACUS_NEP_VERSION "yes") else() set(ABACUS_NEP_VERSION "no") endif() -if(DEFINED TensorFlow_DIR) - set(ABACUS_TENSORFLOW_VERSION "yes (path: ${TensorFlow_DIR})") -else() - set(ABACUS_TENSORFLOW_VERSION "no") -endif() - # Testing & Other Libraries if(BUILD_TESTING) set(ABACUS_GTEST_VERSION "yes (from git origin/main)") @@ -392,7 +368,7 @@ else() endif() if(ENABLE_MLALGO) - set(ABACUS_LIBNPY_VERSION "yes (path: ${libnpy_SOURCE_DIR})") + set(ABACUS_LIBNPY_VERSION "yes (path: ${libnpy_INCLUDE_DIR})") else() set(ABACUS_LIBNPY_VERSION "no") endif() @@ -404,7 +380,7 @@ else() endif() if(ENABLE_CNPY) - set(ABACUS_CNPY_VERSION "yes (path: ${cnpy_SOURCE_DIR})") + set(ABACUS_CNPY_VERSION "yes (path: ${CNPY_INCLUDE_DIR})") else() set(ABACUS_CNPY_VERSION "no") endif() diff --git a/cmake/modules/FindCNPY.cmake b/cmake/modules/FindCNPY.cmake new file mode 100644 index 00000000000..f8016e5d9aa --- /dev/null +++ b/cmake/modules/FindCNPY.cmake @@ -0,0 +1,35 @@ +find_package(ZLIB REQUIRED) + +find_path( + CNPY_INCLUDE_DIR cnpy.h + HINTS ${CNPY_DIR} ${cnpy_SOURCE_DIR} + PATH_SUFFIXES include) +find_library( + CNPY_LIBRARY + NAMES cnpy + HINTS ${CNPY_DIR} "${CNPY_INCLUDE_DIR}/.." + PATH_SUFFIXES lib lib64) + +if(NOT CNPY_INCLUDE_DIR OR NOT CNPY_LIBRARY) + include(FetchContent) + FetchContent_Declare( + cnpy + GIT_REPOSITORY https://github.com/rogersce/cnpy.git + GIT_PROGRESS TRUE) + FetchContent_MakeAvailable(cnpy) + set(CNPY_INCLUDE_DIR "${cnpy_SOURCE_DIR}") + set(CNPY_LIBRARY cnpy) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CNPY DEFAULT_MSG CNPY_INCLUDE_DIR + CNPY_LIBRARY) + +if(CNPY_FOUND AND NOT TARGET CNPY::cnpy) + add_library(CNPY::cnpy INTERFACE IMPORTED) + set_target_properties( + CNPY::cnpy PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CNPY_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${CNPY_LIBRARY};ZLIB::ZLIB") +endif() + +mark_as_advanced(CNPY_INCLUDE_DIR CNPY_LIBRARY) diff --git a/cmake/modules/FindDeePMD.cmake b/cmake/modules/FindDeePMD.cmake deleted file mode 100644 index 7d803e1f34b..00000000000 --- a/cmake/modules/FindDeePMD.cmake +++ /dev/null @@ -1,186 +0,0 @@ -############################################################################### -# - Find DeePMD -# Find the native DeePMD headers and libraries. -# -# DeePMD_FOUND - True if lib is found. -# DeePMDC_FOUND - True if C API is found. -# DeePMD_LIBRARIES - List of libraries -# DeePMD_INCLUDE_DIR - Where to find DeePMD headers. -# - -# C API -find_path( - DeePMD_INCLUDE_C_DIR deepmd/deepmd.hpp deepmd/c_api.h - HINTS ${DeePMD_DIR} - PATH_SUFFIXES "include") -find_library( - deepmd_c - NAMES deepmd_c - HINTS ${DeePMD_DIR} - PATH_SUFFIXES "lib") -# C++ API -find_path( - DeePMD_INCLUDE_DIR deepmd/DeepPot.h - HINTS ${DeePMD_DIR} - PATH_SUFFIXES "include") -find_library( - deepmd_cc - NAMES deepmd_cc - HINTS ${DeePMD_DIR} - PATH_SUFFIXES "lib") - -# Handle the QUIET and REQUIRED arguments and -# set DeePMD_FOUND to TRUE if all variables are non-zero. -include(FindPackageHandleStandardArgs) -include(CheckCXXSourceCompiles) -if(DeePMD_INCLUDE_DIR AND deepmd_cc) - set(_abacus_saved_required_includes ${CMAKE_REQUIRED_INCLUDES}) - set(_abacus_saved_required_libraries ${CMAKE_REQUIRED_LIBRARIES}) - set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${DeePMD_INCLUDE_DIR}) - set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${deepmd_cc}) - check_cxx_source_compiles( - "#include - int main() { deepmd::DeepPot model; return model.is_aparam_nall(); }" - DeePMD_CXX_API_USABLE) - set(CMAKE_REQUIRED_INCLUDES ${_abacus_saved_required_includes}) - set(CMAKE_REQUIRED_LIBRARIES ${_abacus_saved_required_libraries}) - unset(_abacus_saved_required_includes) - unset(_abacus_saved_required_libraries) -endif() -# The C++ API exposes is_aparam_nall() on an initialized model. Prefer it -# when both libraries are installed to avoid loading a second model for this -# property in the C API compatibility path. -if(DeePMD_CXX_API_USABLE) - find_package_handle_standard_args(DeePMD DEFAULT_MSG deepmd_cc - DeePMD_INCLUDE_DIR) - if(DeePMD_FOUND) - set(DeePMDC_FOUND FALSE) - if(NOT TARGET DeePMD::deepmd_cc) - add_library(DeePMD::deepmd_cc UNKNOWN IMPORTED) - set_target_properties( - DeePMD::deepmd_cc - PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" - IMPORTED_LOCATION "${deepmd_cc}" - INTERFACE_INCLUDE_DIRECTORIES "${DeePMD_INCLUDE_DIR}") - endif() - endif() -else() - find_package_handle_standard_args(DeePMD DEFAULT_MSG deepmd_c - DeePMD_INCLUDE_C_DIR) - if(DeePMD_FOUND) - set(DeePMDC_FOUND TRUE) - set(DeePMD_INCLUDE_DIR ${DeePMD_INCLUDE_C_DIR}) - if(NOT TARGET DeePMD::deepmd_c) - add_library(DeePMD::deepmd_c UNKNOWN IMPORTED) - set_target_properties( - DeePMD::deepmd_c - PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${deepmd_c}" - INTERFACE_INCLUDE_DIRECTORIES "${DeePMD_INCLUDE_DIR}") - endif() - endif() -endif() - -set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${DeePMD_INCLUDE_DIR}) - -if(DeePMD_FOUND) - # The communication constructor is inline and calls into the DeePMD - # library, so the feature probe must link against the selected API library. - set(_abacus_saved_required_libraries ${CMAKE_REQUIRED_LIBRARIES}) - if(DeePMDC_FOUND) - set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${deepmd_c}) - else() - set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${deepmd_cc}) - endif() - if(DeePMDC_FOUND) - set(_abacus_dp_nlist_type "deepmd::hpp::InputNlist") - set(_abacus_dp_nlist_header "#include ") - else() - set(_abacus_dp_nlist_type "deepmd::InputNlist") - set(_abacus_dp_nlist_header "#include ") - endif() - check_cxx_source_compiles( - "${_abacus_dp_nlist_header} - int main() - { - ${_abacus_dp_nlist_type} nlist(0, nullptr, nullptr, nullptr, - 0, nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr, nullptr, 1); - return 0; - }" - DeePMD_HAS_COMM_NLIST_13) - if(DeePMD_HAS_COMM_NLIST_13) - set(DeePMD_INPUT_NLIST_COMM_ARGS 13) - else() - check_cxx_source_compiles( - "${_abacus_dp_nlist_header} - int main() - { - ${_abacus_dp_nlist_type} nlist(0, nullptr, nullptr, nullptr, - 0, nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr, nullptr); - return 0; - }" - DeePMD_HAS_COMM_NLIST_12) - if(DeePMD_HAS_COMM_NLIST_12) - set(DeePMD_INPUT_NLIST_COMM_ARGS 12) - else() - set(DeePMD_INPUT_NLIST_COMM_ARGS 0) - endif() - endif() - check_cxx_source_compiles( - "${_abacus_dp_nlist_header} - int main() - { - ${_abacus_dp_nlist_type} nlist(0, nullptr, nullptr, nullptr); - nlist.set_mapping(nullptr); - return 0; - }" - DeePMD_HAS_NLIST_MAPPING) - - # The InputNlist constructor can exist even when the PyTorch operator was - # built without USE_MPI. In that build its embedding exchange is local only. - # Require a direct MPI dependency of the operator before enabling the - # distributed inference path. - unset(DeePMD_PT_OPERATOR CACHE) - find_file( - DeePMD_PT_OPERATOR - NAMES libdeepmd_op_pt.so - HINTS ${DeePMD_DIR} - PATH_SUFFIXES lib lib64 - NO_DEFAULT_PATH) - set(DeePMD_PT_OPERATOR_MPI FALSE) - if(DeePMD_PT_OPERATOR AND CMAKE_READELF) - execute_process( - COMMAND ${CMAKE_READELF} -d ${DeePMD_PT_OPERATOR} - RESULT_VARIABLE _abacus_dp_readelf_result - OUTPUT_VARIABLE _abacus_dp_operator_dynamic) - if(_abacus_dp_readelf_result EQUAL 0 - AND _abacus_dp_operator_dynamic MATCHES "NEEDED[^\n]*libmpi\\.so") - set(DeePMD_PT_OPERATOR_MPI TRUE) - endif() - unset(_abacus_dp_readelf_result) - unset(_abacus_dp_operator_dynamic) - endif() - if(NOT DeePMD_PT_OPERATOR_MPI) - set(DeePMD_INPUT_NLIST_COMM_ARGS 0) - endif() - set(CMAKE_REQUIRED_LIBRARIES ${_abacus_saved_required_libraries}) - unset(_abacus_saved_required_libraries) - unset(_abacus_dp_nlist_type) - unset(_abacus_dp_nlist_header) -endif() - -if(DeePMD_FOUND AND NOT DeePMD_PT_OPERATOR_MPI) - message(WARNING - "Distributed PyTorch DeePMD inference is disabled: the operator's " - "direct libmpi.so dependency could not be verified.") -elseif(DeePMD_FOUND - AND DEFINED DeePMD_INPUT_NLIST_COMM_ARGS - AND DeePMD_INPUT_NLIST_COMM_ARGS EQUAL 0) - message(WARNING - "Distributed PyTorch DeePMD inference is disabled: communication-capable " - "InputNlist is unavailable.") -endif() - -mark_as_advanced(DeePMD_INCLUDE_DIR deepmd_c deepmd_cc) diff --git a/cmake/modules/FindELPA.cmake b/cmake/modules/FindELPA.cmake index 42a16b9e83d..45bfceeaf8c 100644 --- a/cmake/modules/FindELPA.cmake +++ b/cmake/modules/FindELPA.cmake @@ -3,86 +3,13 @@ # Find the native ELPA headers and libraries through pkg-config. # -# ======================================================================== -# Deprecated (TODO: Remove this part) -# ======================================================================== +find_package(PkgConfig REQUIRED) -# Migrate caches created when FindPkgConfig used the public ELPA prefix. -if(DEFINED CACHE{ELPA_LIBRARIES}) - get_property( - _elpa_libraries_cache_type - CACHE ELPA_LIBRARIES - PROPERTY TYPE) - if(_elpa_libraries_cache_type STREQUAL "INTERNAL") - unset(ELPA_LIBRARIES CACHE) - unset(ELPA_INCLUDE_DIRS CACHE) - unset(ELPA_LINK_LIBRARIES CACHE) - endif() -endif() -unset(_elpa_libraries_cache_type) - -# Compatible layer towards old manual routines -if(DEFINED ELPA_DIR) - message( - WARNING "ELPA_DIR is deprecated and will be removed in the future release.") -endif() -if(DEFINED ELPA_INCLUDE_DIR) - set(ELPA_INCLUDE_DIRS ${ELPA_INCLUDE_DIR}) -endif() -if(DEFINED ELPA_LIBRARIES) - set(ELPA_LINK_LIBRARIES ${ELPA_LIBRARIES}) -endif() - -find_path( - ELPA_INCLUDE_DIRS elpa/elpa.h - HINTS ${ELPA_DIR} - PATH_SUFFIXES "include" "include/elpa") -# Fix #3589 -# First if judges if ELPA dir specified -if(ELPA_INCLUDE_DIRS MATCHES "^/usr/include/elpa/.*") - # Second if judges if global visible ELPA header found - if(DEFINED ELPA_DIR OR CMAKE_PREFIX_PATH MATCHES ".*elpa.*") - unset(ELPA_INCLUDE_DIRS) - endif() -endif() +# Find preferred library corresponding with ABACUS configuration first if(ENABLE_OPENMP) - find_library( - ELPA_LINK_LIBRARIES - NAMES elpa_openmp elpa - HINTS ${ELPA_DIR} - PATH_SUFFIXES "lib") + pkg_search_module(ELPA REQUIRED IMPORTED_TARGET GLOBAL elpa_openmp elpa) else() - find_library( - ELPA_LINK_LIBRARIES - NAMES elpa - HINTS ${ELPA_DIR} - PATH_SUFFIXES "lib") -endif() - -# ======================================================================== - -# TODO: Make pkg-config discovery unconditional after removing the deprecated -# manual discovery path. -if(NOT ELPA_INCLUDE_DIRS) - find_package(PkgConfig) - if(NOT PKG_CONFIG_FOUND) - message( - FATAL_ERROR - "Pkg-config is needed to get all information about the ELPA library") - endif() - # Find preferred library corresponding with ABACUS configuration first - if(ENABLE_OPENMP) - pkg_search_module(ELPA_PKG REQUIRED IMPORTED_TARGET GLOBAL elpa_openmp elpa) - else() - pkg_search_module(ELPA_PKG REQUIRED IMPORTED_TARGET GLOBAL elpa) - endif() - if(ELPA_PKG_VERSION VERSION_LESS "2021.05.001") - message(FATAL_ERROR "ELPA version >= 2021.05.001 is required.") - endif() - set(ELPA_INCLUDE_DIRS ${ELPA_PKG_INCLUDE_DIRS}) - set(ELPA_LINK_LIBRARIES ${ELPA_PKG_LINK_LIBRARIES}) - set(ELPA_LIBRARIES ${ELPA_PKG_LIBRARIES}) - set(ELPA_VERSION ${ELPA_PKG_VERSION}) + pkg_search_module(ELPA REQUIRED IMPORTED_TARGET GLOBAL elpa) endif() # Handle the QUIET and REQUIRED arguments and @@ -91,42 +18,16 @@ include(FindPackageHandleStandardArgs) find_package_handle_standard_args(ELPA DEFAULT_MSG ELPA_LINK_LIBRARIES ELPA_INCLUDE_DIRS) -# Copy the results to the output variables and target. -if(ELPA_FOUND) - list(GET ELPA_LINK_LIBRARIES 0 ELPA_LIBRARY) - set(ELPA_INCLUDE_DIR ${ELPA_INCLUDE_DIRS}) - if(NOT TARGET ELPA::ELPA) - # TODO: Remove the manual target fallback with the deprecated ELPA inputs. - if(TARGET PkgConfig::ELPA_PKG) - add_library(ELPA::ELPA ALIAS PkgConfig::ELPA_PKG) - else() - add_library(ELPA::ELPA UNKNOWN IMPORTED) - set_target_properties( - ELPA::ELPA - PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${ELPA_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${ELPA_INCLUDE_DIR}") - endif() - endif() +if(ELPA_FOUND AND NOT TARGET ELPA::ELPA) + add_library(ELPA::ELPA INTERFACE IMPORTED) + # TODO: Clean up INTERFACE_COMPILE_OPTIONS + set_target_properties( + ELPA::ELPA + PROPERTIES INTERFACE_LINK_LIBRARIES PkgConfig::ELPA + INTERFACE_INCLUDE_DIRECTORIES "${ELPA_INCLUDE_DIRS}" + INTERFACE_COMPILE_OPTIONS "${ELPA_CFLAGS_OTHER}") endif() -set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${ELPA_INCLUDE_DIR}) - -# Compability workaround for ELPA_DIR -# TODO: Remove this check with the deprecated ELPA_DIR path. -include(CheckCXXSourceCompiles) -check_cxx_source_compiles( - " -#include -#if ELPA_API_VERSION < 20210430 -#error ELPA version is too old. -#endif -int main(){} -" - ELPA_VERSION_SATISFIES) -if(NOT ELPA_VERSION_SATISFIES) - message( - FATAL_ERROR "ELPA version is too old. We support version 2021 or higher.") -endif() +set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${ELPA_INCLUDE_DIRS}) mark_as_advanced(ELPA_INCLUDE_DIR ELPA_LIBRARY) diff --git a/cmake/modules/FindFFTW3.cmake b/cmake/modules/FindFFTW3.cmake index 1eebe8ee549..126d226381c 100644 --- a/cmake/modules/FindFFTW3.cmake +++ b/cmake/modules/FindFFTW3.cmake @@ -93,7 +93,8 @@ if(FFTW3_FOUND) FFTW3::FFTW3_OMP PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION "${FFTW3_OMP_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${FFTW3_INCLUDE_DIRS}") + INTERFACE_INCLUDE_DIRECTORIES "${FFTW3_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES FFTW3::FFTW3) endif() endif() endif() diff --git a/cmake/modules/FindLibComm.cmake b/cmake/modules/FindLibComm.cmake index 334b8dbd742..385211379a9 100644 --- a/cmake/modules/FindLibComm.cmake +++ b/cmake/modules/FindLibComm.cmake @@ -24,5 +24,14 @@ endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(LibComm DEFAULT_MSG LIBCOMM_DIR) +if(LibComm_FOUND) + if(NOT TARGET LibComm::LibComm) + add_library(LibComm::LibComm INTERFACE IMPORTED) + set_target_properties( + LibComm::LibComm PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${LIBCOMM_DIR}/include") + endif() +endif() + # Copy the results to the output variables and target. mark_as_advanced(LIBCOMM_DIR) diff --git a/cmake/modules/FindLibRI.cmake b/cmake/modules/FindLibRI.cmake index 32d60116259..3bf6a112591 100644 --- a/cmake/modules/FindLibRI.cmake +++ b/cmake/modules/FindLibRI.cmake @@ -5,6 +5,9 @@ # LIBRI_FOUND - True if LibRI is found. # LIBRI_DIR - Where to find LibRI files. +find_package(cereal CONFIG REQUIRED) +find_package(LibComm REQUIRED) + find_path( LIBRI_DIR include/RI/version.h HINTS ${LIBRI_DIR} @@ -23,5 +26,15 @@ endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(LibRI DEFAULT_MSG LIBRI_DIR) +if(LibRI_FOUND) + if(NOT TARGET LibRI::LibRI) + add_library(LibRI::LibRI INTERFACE IMPORTED) + target_link_libraries(LibRI::LibRI INTERFACE LibComm::LibComm + cereal::cereal) + set_target_properties(LibRI::LibRI PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${LIBRI_DIR}/include") + endif() +endif() + # Copy the results to the output variables and target. mark_as_advanced(LIBRI_DIR) diff --git a/cmake/modules/FindLibnpy.cmake b/cmake/modules/FindLibnpy.cmake new file mode 100644 index 00000000000..e9df9e8557c --- /dev/null +++ b/cmake/modules/FindLibnpy.cmake @@ -0,0 +1,30 @@ +find_path( + libnpy_INCLUDE_DIR npy.hpp + HINTS ${libnpy_SOURCE_DIR} + PATH_SUFFIXES include libnpy include/libnpy) +if(NOT libnpy_INCLUDE_DIR) + include(FetchContent) + FetchContent_Declare( + libnpy + GIT_REPOSITORY https://github.com/llohse/libnpy.git + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE) + FetchContent_MakeAvailable(libnpy) + find_path( + libnpy_INCLUDE_DIR npy.hpp + PATHS "${libnpy_SOURCE_DIR}/include" + NO_DEFAULT_PATH) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Libnpy DEFAULT_MSG libnpy_INCLUDE_DIR) + +if(Libnpy_FOUND) + if(NOT TARGET libnpy::npy) + add_library(libnpy::npy INTERFACE IMPORTED) + set_target_properties(libnpy::npy PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${libnpy_INCLUDE_DIR}") + endif() +endif() + +mark_as_advanced(libnpy_INCLUDE_DIR) diff --git a/cmake/modules/FindNEP.cmake b/cmake/modules/FindNEP.cmake deleted file mode 100644 index c37dd5e3559..00000000000 --- a/cmake/modules/FindNEP.cmake +++ /dev/null @@ -1,47 +0,0 @@ -############################################################################### -# - Find NEP -# Finds the NEP header and library. -# -# This module will search for the NEP library, looking for a hint -# from the NEP_DIR environment variable or CMake variable. -# -# This module defines the following variables: -# -# NEP_FOUND - True if the NEP library and headers were found. -# NEP_INCLUDE_DIR - The directory where nep.h is located. -# NEP_LIBRARY - The full path to the NEP library. -# -# It also defines the following imported target: -# -# NEP::nep - The NEP library target. -# -############################################################################### -# Note: Currently only CPU version is supported, Since the NEP interface with GPU support is not available yet. -# In feature, if available, we can use USE_CUDA to switch between CPU and GPU version. - -find_path( - NEP_INCLUDE_DIR nep.h - HINTS ${NEP_DIR} - PATH_SUFFIXES "include") - -find_library( - NEP_LIBRARY - NAMES nep - HINTS ${NEP_DIR} - PATH_SUFFIXES "lib") - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(NEP DEFAULT_MSG NEP_LIBRARY NEP_INCLUDE_DIR) - -if(NEP_FOUND) - if(NOT TARGET NEP::nep) - add_library(NEP::nep UNKNOWN IMPORTED) - set_target_properties( - NEP::nep - PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${NEP_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${NEP_INCLUDE_DIR}") - endif() -endif() - -mark_as_advanced(NEP_INCLUDE_DIR NEP_LIBRARY) diff --git a/cmake/modules/FindPLUMED.cmake b/cmake/modules/FindPLUMED.cmake index b905f8d0a4c..6a5618ac3dc 100644 --- a/cmake/modules/FindPLUMED.cmake +++ b/cmake/modules/FindPLUMED.cmake @@ -13,14 +13,17 @@ # find_package(PkgConfig QUIET) +set(_plumed_use_pkgconfig FALSE) if(PkgConfig_FOUND) pkg_check_modules(PLUMED_PKG QUIET IMPORTED_TARGET GLOBAL plumed) + set(_plumed_use_pkgconfig ${PLUMED_PKG_FOUND}) endif() -if(PLUMED_PKG_FOUND) +if(_plumed_use_pkgconfig) set(PLUMED_INCLUDE_DIRS ${PLUMED_PKG_INCLUDE_DIRS}) set(PLUMED_LIBRARIES ${PLUMED_PKG_LINK_LIBRARIES}) set(PLUMED_VERSION ${PLUMED_PKG_VERSION}) + set(_plumed_required_vars PLUMED_PKG_FOUND) else() # Fallback: manual discovery, e.g. -DPLUMED_ROOT=/path/to/prefix find_path( @@ -32,20 +35,27 @@ else() NAMES plumed HINTS ${PLUMED_ROOT} PATH_SUFFIXES "lib") + set(_plumed_required_vars PLUMED_LIBRARIES PLUMED_INCLUDE_DIRS) endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args( PLUMED - REQUIRED_VARS PLUMED_LIBRARIES PLUMED_INCLUDE_DIRS + REQUIRED_VARS ${_plumed_required_vars} VERSION_VAR PLUMED_VERSION) if(PLUMED_FOUND AND NOT TARGET PLUMED::plumed) - add_library(PLUMED::plumed UNKNOWN IMPORTED) - set_target_properties( - PLUMED::plumed - PROPERTIES IMPORTED_LOCATION "${PLUMED_LIBRARIES}" - INTERFACE_INCLUDE_DIRECTORIES "${PLUMED_INCLUDE_DIRS}") + if(_plumed_use_pkgconfig) + add_library(PLUMED::plumed ALIAS PkgConfig::PLUMED_PKG) + else() + add_library(PLUMED::plumed INTERFACE IMPORTED) + set_target_properties( + PLUMED::plumed + PROPERTIES INTERFACE_LINK_LIBRARIES "${PLUMED_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${PLUMED_INCLUDE_DIRS}") + endif() endif() +unset(_plumed_required_vars) +unset(_plumed_use_pkgconfig) mark_as_advanced(PLUMED_INCLUDE_DIRS PLUMED_LIBRARIES) diff --git a/cmake/modules/FindScaLAPACK.cmake b/cmake/modules/FindScaLAPACK.cmake index 55db7507ebc..ce785255b3c 100644 --- a/cmake/modules/FindScaLAPACK.cmake +++ b/cmake/modules/FindScaLAPACK.cmake @@ -25,7 +25,6 @@ find_package_handle_standard_args(ScaLAPACK REQUIRED_VARS ScaLAPACK_LIBRARY) # Copy the results to the output variables and target. if(ScaLAPACK_FOUND) set(ScaLAPACK_LIBRARIES ${ScaLAPACK_LIBRARY}) - if(NOT TARGET ScaLAPACK::ScaLAPACK) add_library(ScaLAPACK::ScaLAPACK UNKNOWN IMPORTED) set_target_properties(ScaLAPACK::ScaLAPACK diff --git a/cmake/modules/FindTensorFlow.cmake b/cmake/modules/FindTensorFlow.cmake deleted file mode 100644 index f29a96c3947..00000000000 --- a/cmake/modules/FindTensorFlow.cmake +++ /dev/null @@ -1,28 +0,0 @@ -############################################################################### -# - Find TensorFlow -# Find the native TensorFlow libraries. -# -# TensorFlow_FOUND - True if lib is found. -# TensorFlow_LIBRARIES - List of libraries - -find_library( - tensorflow_cc - NAMES tensorflow_cc libtensorflow_cc.so.2 - HINTS ${TensorFlow_DIR} - PATH_SUFFIXES "lib") - -# Handle the QUIET and REQUIRED arguments and -# set TensorFlow_FOUND to TRUE if all variables are non-zero. -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(TensorFlow DEFAULT_MSG tensorflow_cc) - -if(TensorFlow_FOUND) - if(NOT TARGET TensorFlow::tensorflow_cc) - add_library(TensorFlow::tensorflow_cc UNKNOWN IMPORTED) - set_target_properties( - TensorFlow::tensorflow_cc PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${tensorflow_cc}") - endif() -endif() - -mark_as_advanced(tensorflow_cc) diff --git a/cmake/modules/SetupDeePMD.cmake b/cmake/modules/SetupDeePMD.cmake new file mode 100644 index 00000000000..95faaec6966 --- /dev/null +++ b/cmake/modules/SetupDeePMD.cmake @@ -0,0 +1,132 @@ +# ABACUS-specific API selection and distributed-inference capabilities. +# Library discovery and usage requirements come from DeePMDConfig.cmake. +include(CheckCXXSourceCompiles) +include(CMakePushCheckState) +cmake_push_check_state(RESET) + +# Do not reuse results from a different DeePMD installation. +foreach(_abacus_dp_check IN + ITEMS DeePMD_CXX_API_USABLE DeePMD_HAS_COMM_NLIST_13 + DeePMD_HAS_COMM_NLIST_12 DeePMD_HAS_NLIST_MAPPING) + unset(${_abacus_dp_check} CACHE) +endforeach() + +if(TARGET DeePMD::deepmd_cc) + # TODO: Remove when DeePMD keeps its build-only common.h PCH private. + set_property(TARGET DeePMD::deepmd_cc PROPERTY INTERFACE_PRECOMPILE_HEADERS + "") + set(CMAKE_REQUIRED_LIBRARIES DeePMD::deepmd_cc) + check_cxx_source_compiles( + "#include + int main() { deepmd::DeepPot model; return model.is_aparam_nall(); }" + DeePMD_CXX_API_USABLE) +endif() + +# Prefer the C++ API when it exposes the required property, retaining the +# C-wrapper fallback for installations with an older C++ interface. +set(ABACUS_DEEPMD_TARGET) +set(DeePMDC_FOUND FALSE) +if(DeePMD_CXX_API_USABLE) + set(ABACUS_DEEPMD_TARGET DeePMD::deepmd_cc) + set(_abacus_dp_nlist_type "deepmd::InputNlist") + set(_abacus_dp_nlist_header "#include ") +elseif(TARGET DeePMD::deepmd_c) + set(ABACUS_DEEPMD_TARGET DeePMD::deepmd_c) + set(DeePMDC_FOUND TRUE) + set(_abacus_dp_nlist_type "deepmd::hpp::InputNlist") + set(_abacus_dp_nlist_header "#include ") +endif() + +if(NOT ABACUS_DEEPMD_TARGET) + message( + FATAL_ERROR "DeePMD must provide a usable C++ API or the C API target.") +endif() + +set(CMAKE_REQUIRED_LIBRARIES ${ABACUS_DEEPMD_TARGET}) +check_cxx_source_compiles( + "${_abacus_dp_nlist_header} + int main() + { + ${_abacus_dp_nlist_type} nlist(0, nullptr, nullptr, nullptr, + 0, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, 1); + return 0; + }" + DeePMD_HAS_COMM_NLIST_13) +set(DeePMD_INPUT_NLIST_COMM_ARGS 0) +if(DeePMD_HAS_COMM_NLIST_13) + set(DeePMD_INPUT_NLIST_COMM_ARGS 13) +else() + check_cxx_source_compiles( + "${_abacus_dp_nlist_header} + int main() + { + ${_abacus_dp_nlist_type} nlist(0, nullptr, nullptr, nullptr, + 0, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr); + return 0; + }" + DeePMD_HAS_COMM_NLIST_12) + if(DeePMD_HAS_COMM_NLIST_12) + set(DeePMD_INPUT_NLIST_COMM_ARGS 12) + endif() +endif() +check_cxx_source_compiles( + "${_abacus_dp_nlist_header} + int main() + { + ${_abacus_dp_nlist_type} nlist(0, nullptr, nullptr, nullptr); + nlist.set_mapping(nullptr); + return 0; + }" + DeePMD_HAS_NLIST_MAPPING) + +# A communication constructor alone does not establish that the PyTorch +# operator exchanges embeddings through MPI. Inspect the operator beside the +# selected API library. +get_target_property(_abacus_dp_api_library ${ABACUS_DEEPMD_TARGET} LOCATION) +get_filename_component(_abacus_dp_library_dir "${_abacus_dp_api_library}" + DIRECTORY) +unset(DeePMD_PT_OPERATOR CACHE) +find_file( + DeePMD_PT_OPERATOR libdeepmd_op_pt.so + PATHS "${_abacus_dp_library_dir}" + NO_DEFAULT_PATH) +set(DeePMD_PT_OPERATOR_MPI FALSE) +if(DeePMD_PT_OPERATOR AND CMAKE_READELF) + execute_process( + COMMAND "${CMAKE_READELF}" -d "${DeePMD_PT_OPERATOR}" + RESULT_VARIABLE _abacus_dp_readelf_result + OUTPUT_VARIABLE _abacus_dp_operator_dynamic) + if(_abacus_dp_readelf_result EQUAL 0 AND _abacus_dp_operator_dynamic MATCHES + "NEEDED[^\n]*libmpi\\.so") + set(DeePMD_PT_OPERATOR_MPI TRUE) + endif() +endif() +if(NOT DeePMD_PT_OPERATOR_MPI) + set(DeePMD_INPUT_NLIST_COMM_ARGS 0) +endif() + +if(ENABLE_MPI AND DeePMD_PT_OPERATOR) + if(NOT DeePMD_PT_OPERATOR_MPI) + message( + WARNING + "Distributed PyTorch DeePMD inference is disabled: the operator's " + "direct libmpi.so dependency could not be verified.") + elseif(DeePMD_INPUT_NLIST_COMM_ARGS EQUAL 0) + message( + WARNING + "Distributed PyTorch DeePMD inference is disabled: communication-capable " + "InputNlist is unavailable.") + endif() +endif() + +cmake_pop_check_state() +unset(_abacus_dp_check) +unset(_abacus_dp_nlist_type) +unset(_abacus_dp_nlist_header) +unset(_abacus_dp_api_library) +unset(_abacus_dp_library_dir) +unset(_abacus_dp_readelf_result) +unset(_abacus_dp_operator_dynamic) +mark_as_advanced(DeePMD_PT_OPERATOR) diff --git a/docs/advanced/install.md b/docs/advanced/install.md index 86d63cfd1ee..7ba929230fe 100644 --- a/docs/advanced/install.md +++ b/docs/advanced/install.md @@ -33,7 +33,7 @@ If machine learning algorithms, including DeePKS and machine learning based kine - [Libnpy](https://github.com/llohse/libnpy/) ```bash -cmake -B build -DENABLE_MLALGO=1 -DTorch_DIR=~/libtorch/share/cmake/Torch/ -Dlibnpy_INCLUDE_DIR=~/libnpy/include +cmake -B build -DENABLE_MLALGO=ON -DTorch_DIR=~/libtorch/share/cmake/Torch/ -Dlibnpy_INCLUDE_DIR=~/libnpy/include ``` > CMake will try to download Libnpy if it cannot be found locally. @@ -45,59 +45,26 @@ cmake -B build -DENABLE_MLALGO=1 -DTorch_DIR=~/libtorch/share/cmake/Torch/ -Dlib If the Deep Potential model is employed in Molecule Dynamics calculations, the following prerequisites and steps are needed: - [DeePMD-kit](https://github.com/deepmodeling/deepmd-kit) -- [TensorFlow](https://www.tensorflow.org/) (optional) -- [LibTorch](https://pytorch.org/) (optional) -In the simplest case, the `tensorflow_cc` and `torch` libraries are in the same directory as the `deepmd_c`/`deepmd_cc` libraries, then -```bash -cmake -B build -DDeePMD_DIR=/dir_to_deepmd-kit -``` -DeePMD-kit supports TensorFlow backend but its libraries are placed at another directory, then +ABACUS support both [LibTorch](https://pytorch.org/) and [TensorFlow](https://www.tensorflow.org/) backend of DeePMD, depending on how DeePMD library was built. -```bash -cmake -B build -DDeePMD_DIR=/dir_to_deepmd-kit -DTensorFlow_DIR=/dir_to_tensorflow -``` -Similarly, DeePMD-kit supports PyTorch backend but its libraries are placed at another directory, then -```bash -cmake -B build -DDeePMD_DIR=/dir_to_deepmd-kit -DTorch_DIR=/dir_to_pytorch -``` +To build ABACUS with DeePMD support, pass `-DENABLE_ELPA=ON` to CMake. ## Build with NEP -This interface enables running MD simulations with the NEP model. It requires the [NEP_CPU](https://github.com/brucefan1983/NEP_CPU) library, which can be easily installed using toolchain as shown below: -```bash -./install_abacus_toolchain_new.sh --with-nep=install -``` -To build ABACUS: -```bash -cmake -B build -DNEP_DIR=/path/to/nep_cpu -``` +This interface enables running MD simulations with the NEP model. It requires the [NEP_CPU](https://github.com/brucefan1983/NEP_CPU) library version 1.5.1 or newer. To build ABACUS with NEP support, pass `-DENABLE_NEP=ON` to CMake. ## Build with LibRI support The new EXX implementation directly depends on [LibRI](https://github.com/abacusmodeling/LibRI) to provide RI implementation, while LibRI requires two external dependencies: [LibComm](https://github.com/abacusmodeling/LibComm) for inter-process communication, and [cereal](https://github.com/USCiLab/cereal) for serialization. Set `-DENABLE_LIBRI=ON` to build with these libraries. -```{note} -`ENABLE_LIBCOMM` is deprecated because LibComm is not a standalone ABACUS feature. CMake locates it automatically as a dependency of LibRI. If you prefer using manually downloaded libraries, enable LibRI and provide their locations via `-DLIBRI_DIR=/path/to/LibRI` and `-DLIBCOMM_DIR=/path/to/LibComm`. -``` - ## Build with DFT-D4 support ABACUS can use the external [DFT-D4](https://github.com/dftd4/dftd4) library for Grimme's DFT-D4 dispersion correction. DFT-D4 support is optional and disabled by default. DFT-D4 must be built and installed with CMake, so that ABACUS can locate it through the exported `dftd4-config.cmake` package. Meson-built installations, including the Conda package of `dftd4`, are not supported unless they provide a compatible CMake package file. -To build ABACUS with DFT-D4 support, pass `-DENABLE_DFTD4=ON` to CMake and provide `CMAKE_PREFIX_PATH` environment variable. - -In the input file, enable DFT-D4 with: - -```text -vdw_method d4 -vdw_d4_xc pbe -vdw_d4_model d4 # or d4s for the smooth D4S model -``` - -If `vdw_d4_xc` is set to `default`, ABACUS will infer the functional name from `dft_functional` or pseudopotential metadata and pass it to the DFT-D4 library. The `vdw_d4_model` keyword selects the dispersion model inside the DFT-D4 library; the default is `d4`, while `d4s` enables the smooth D4S model. +To build ABACUS with DFT-D4 support, pass `-DENABLE_DFTD4=ON` to CMake. ## Build with JSON support @@ -108,22 +75,22 @@ ABACUS uses [nlohmann-json](https://github.com/nlohmann/json) for optional JSON To build tests for ABACUS, define `BUILD_TESTING` flag. You can also specify path to local installation of [Googletest](https://github.com/google/googletest) by setting `GTEST_DIR` flags. If not found in local, the configuration process will try to download it automatically. ```bash -cmake -B build -DBUILD_TESTING=1 +cmake -B build -DBUILD_TESTING=ON ``` After building, unit tests can be performed with `ctest`. To run a subset of unit test, use `ctest -R ` to perform tests with name matched by given pattern. -## Build Performance Tests +### Build Performance Tests -To build performance tests for ABACUS, define `ENABLE_GOOGLEBENCH` flag. You can also specify the path to a local installation of [Google Benchmark](https://github.com/google/benchmark.git) by setting `BENCHMARK_DIR` flags. If not found locally, the configuration process will try to download it automatically. +To build performance tests for ABACUS, also enable `ENABLE_GOOGLEBENCH`. You can also specify the path to a local installation of [Google Benchmark](https://github.com/google/benchmark.git) by setting `BENCHMARK_DIR` flags. If not found locally, the configuration process will try to download it automatically. ```bash -cmake -B build -DENABLE_GOOGLEBENCH=1 +cmake -B build -DBUILD_TESTING=ON -DENABLE_GOOGLEBENCH=ON ``` -Google Benchmark requires Google Test to build and run the tests. When setting `ENABLE_GOOGLEBENCH` to ON, `BUILD_TESTING` is automatically enabled. After building and installing, performance tests can be executed with `ctest`. +Google Benchmark requires Google Test to build and run the tests. After building and installing, performance tests can be executed with `ctest`. ## Build with CUDA support diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index ae735fb8d83..3a40a277bcc 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -67,12 +67,13 @@ set(_abacus_feature_definitions $<$:TEST_EXX_RADIAL=1> $<$:__LIBXC> $<$:__DFTD4> + $<$:__NEP> $<$:GATHER_INFO>) if(ABACUS_COMMIT_INFO_INCLUDE_DIR) list(APPEND _abacus_feature_definitions COMMIT_INFO) endif() -if(DEFINED DeePMD_DIR) +if(ENABLE_DEEPMD) list(APPEND _abacus_feature_definitions __DPMD HIGH_PREC) if(DEFINED DeePMD_INPUT_NLIST_COMM_ARGS AND DeePMD_INPUT_NLIST_COMM_ARGS GREATER 0) @@ -86,9 +87,6 @@ if(DEFINED DeePMD_DIR) list(APPEND _abacus_feature_definitions __DPMDC) endif() endif() -if(DEFINED NEP_DIR AND NEP_FOUND) - list(APPEND _abacus_feature_definitions __NEP) -endif() target_include_directories( abacus_compile_requirements @@ -172,9 +170,10 @@ if(USE_DSP) endif() list(APPEND _abacus_linalg_libs ${_abacus_cpack_library}) else() - message(STATUS - "USE_DSP without MT_CPACK_DIR: C_PACK disabled, the serial generalized " - "eigensolver falls back to the configured LAPACK provider (zhegvx).") + message( + STATUS + "USE_DSP without MT_CPACK_DIR: C_PACK disabled, the serial generalized " + "eigensolver falls back to the configured LAPACK provider (zhegvx).") endif() endif() @@ -185,7 +184,6 @@ if(USE_KML) list(APPEND _abacus_linalg_libs KML::LAPACK) endif() list(APPEND _abacus_linalg_libs KML::FFTW3) - list(APPEND _abacus_linalg_include_dirs ${KML_INCLUDE_DIRS}) if(ENABLE_FLOAT_FFTW) list(APPEND _abacus_linalg_libs KML::FFTW3_FLOAT) endif() @@ -213,7 +211,6 @@ else() list(APPEND _abacus_linalg_libs FFTW3::FFTW3_OMP) endif() list(APPEND _abacus_linalg_libs FFTW3::FFTW3 LAPACK::LAPACK BLAS::BLAS) - list(APPEND _abacus_linalg_include_dirs ${FFTW3_INCLUDE_DIRS}) if(ENABLE_FLOAT_FFTW) list(APPEND _abacus_linalg_libs FFTW3::FFTW3_FLOAT) endif() @@ -292,63 +289,14 @@ set(_abacus_feature_libs $<$:nlohmann_json::nlohmann_json> $<$:ELPA::ELPA> $<$:PEXSI::PEXSI> - $<$:cnpy> - $<$:ZLIB::ZLIB> - $<$:cereal::cereal> + $<$:CNPY::cnpy> + $<$:LibRI::LibRI> $<$:Libxc::xc> - $<$:PLUMED::plumed>) + $<$:PLUMED::plumed> + $<$:${ABACUS_DEEPMD_TARGET}> + $<$:nep::nep_cpu> + $<$:libnpy::npy>) set(_abacus_feature_include_dirs) -set(_abacus_feature_compile_options) - -if(ENABLE_ELPA) - list(APPEND _abacus_feature_include_dirs ${ELPA_INCLUDE_DIR}) -endif() - -if(ENABLE_MLALGO) - if(libnpy_INCLUDE_DIR) - list(APPEND _abacus_feature_include_dirs ${libnpy_INCLUDE_DIR}) - endif() - if(libnpy_SOURCE_DIR) - list(APPEND _abacus_feature_include_dirs ${libnpy_SOURCE_DIR}/include) - endif() -endif() - -if(ENABLE_MLALGO OR DEFINED Torch_DIR) - list(APPEND _abacus_feature_include_dirs ${TORCH_INCLUDE_DIRS}) - list(APPEND _abacus_feature_compile_options ${ABACUS_TORCH_CXX_FLAGS}) -endif() - -if(ENABLE_CNPY) - if(cnpy_INCLUDE_DIR) - list(APPEND _abacus_feature_include_dirs ${cnpy_INCLUDE_DIR}) - endif() - if(cnpy_SOURCE_DIR) - list(APPEND _abacus_feature_include_dirs ${cnpy_SOURCE_DIR}) - endif() -endif() - -if(ENABLE_LIBRI) - list(APPEND _abacus_feature_include_dirs ${LIBRI_DIR}/include - ${LIBCOMM_DIR}/include) -endif() - -if(DEFINED DeePMD_DIR) - if(DeePMDC_FOUND) - list(APPEND _abacus_feature_libs DeePMD::deepmd_c) - else() - list(APPEND _abacus_feature_libs DeePMD::deepmd_cc) - endif() - list(APPEND _abacus_feature_include_dirs ${DeePMD_DIR}/include) -endif() - -if(DEFINED NEP_DIR AND NEP_FOUND) - list(APPEND _abacus_feature_libs NEP::nep) -endif() - -if(DEFINED TensorFlow_DIR AND TensorFlow_FOUND) - list(APPEND _abacus_feature_libs TensorFlow::tensorflow_cc) - list(APPEND _abacus_feature_include_dirs ${TensorFlow_DIR}/include) -endif() if(USE_DSP) list(APPEND _abacus_feature_libs ${OMPI_LIBRARY1} @@ -404,28 +352,24 @@ endif() target_link_libraries(abacus_feature_libs INTERFACE ${_abacus_feature_libs}) -if(DEFINED DeePMD_DIR - AND UNIX - AND NOT APPLE) - target_link_options(abacus_feature_libs INTERFACE "LINKER:--no-as-needed") -endif() - target_include_directories(abacus_compile_requirements INTERFACE ${_abacus_feature_include_dirs}) -target_compile_options(abacus_compile_requirements - INTERFACE ${_abacus_feature_compile_options}) foreach( _abacus_feature_target IN ITEMS nlohmann_json::nlohmann_json cereal::cereal + LibRI::LibRI + LibComm::LibComm + libnpy::npy + CNPY::cnpy + torch ELPA::ELPA + PLUMED::plumed Libxc::xc dftd4::dftd4 - DeePMD::deepmd_c - DeePMD::deepmd_cc - NEP::nep - TensorFlow::tensorflow_cc + ${ABACUS_DEEPMD_TARGET} + nep::nep_cpu ZLIB::ZLIB PEXSI::PEXSI NCCL::NCCL @@ -440,6 +384,12 @@ foreach( abacus_add_target_compile_requirements(${_abacus_feature_target}) endforeach() +# The C++ API inherits its ABI definition from the core library. The C wrapper +# does not impose the core library's C++ ABI on ABACUS. +if(ABACUS_DEEPMD_TARGET STREQUAL "DeePMD::deepmd_cc") + abacus_add_target_compile_requirements(DeePMD::deepmd) +endif() + # ------------------------------------------------------------------------------ # Per-target feature definitions and common compile usage requirements # ------------------------------------------------------------------------------ @@ -852,7 +802,7 @@ endif() target_link_libraries(${ABACUS_BIN_NAME} PRIVATE abacus::link_libs) # Torch includes some LAPACK routines, but with floating-point exceptions. -if(ENABLE_MLALGO OR DEFINED Torch_DIR) +if(ENABLE_MLALGO) target_link_libraries(${ABACUS_BIN_NAME} PRIVATE ${TORCH_LIBRARIES}) endif() diff --git a/source/source_io/build_info.h.in b/source/source_io/build_info.h.in index 543ef3e1b41..cb41de40170 100644 --- a/source/source_io/build_info.h.in +++ b/source/source_io/build_info.h.in @@ -48,7 +48,6 @@ #define ABACUS_LIBNPY_VERSION "@ABACUS_LIBNPY_VERSION@" #define ABACUS_DEEPMD_VERSION "@ABACUS_DEEPMD_VERSION@" #define ABACUS_NEP_VERSION "@ABACUS_NEP_VERSION@" -#define ABACUS_TENSORFLOW_VERSION "@ABACUS_TENSORFLOW_VERSION@" // --- Other Libraries --- #define ABACUS_DFTD4_VERSION "@ABACUS_DFTD4_VERSION@" diff --git a/source/source_io/parse_args.cpp b/source/source_io/parse_args.cpp index 54b77c1bdb8..6714bfba1fc 100644 --- a/source/source_io/parse_args.cpp +++ b/source/source_io/parse_args.cpp @@ -161,7 +161,6 @@ void print_build_info() print_info("Libnpy Support", ABACUS_LIBNPY_VERSION); print_info("DeePMD-kit Support", ABACUS_DEEPMD_VERSION); print_info("NEP Support", ABACUS_NEP_VERSION); - print_info("TensorFlow Support", ABACUS_TENSORFLOW_VERSION); // --- 11. Other Libraries --- print_section("Other Libraries"); diff --git a/source/source_md/unittests/CMakeLists.txt b/source/source_md/unittests/CMakeLists.txt index 1e36657408d..12c84ed6f4a 100644 --- a/source/source_md/unittests/CMakeLists.txt +++ b/source/source_md/unittests/CMakeLists.txt @@ -124,12 +124,8 @@ addtest( ${depend_files}) set(_md_dp_test_libs parameter psi device) -if(DEFINED DeePMD_DIR) - if(DeePMDC_FOUND) - list(APPEND _md_dp_test_libs DeePMD::deepmd_c) - else() - list(APPEND _md_dp_test_libs DeePMD::deepmd_cc) - endif() +if(ENABLE_DEEPMD) + list(APPEND _md_dp_test_libs ${ABACUS_DEEPMD_TARGET}) endif() addtest( @@ -145,8 +141,9 @@ addtest( SOURCES test_dp_aparam.cpp ../module_dp/dp_aparam.cpp) set(_md_nep_test_libs parameter psi device) -if(DEFINED NEP_DIR AND NEP_FOUND) - list(APPEND _md_nep_test_libs NEP::nep) +if(ENABLE_NEP) + list(APPEND _md_nep_test_libs nep::nep_cpu) + configure_file("${ABACUS_TEST_DIR}/PP_ORB/nep_hfo2.txt" nep_hfo2.txt COPYONLY) endif() addtest( diff --git a/source/source_md/unittests/test_nep_forcefield.cpp b/source/source_md/unittests/test_nep_forcefield.cpp index 9038a344e56..cba5df324aa 100644 --- a/source/source_md/unittests/test_nep_forcefield.cpp +++ b/source/source_md/unittests/test_nep_forcefield.cpp @@ -11,11 +11,7 @@ TEST(NEPPotential, UnitCellCalculationOrMissingBackend) { - const std::string source_file = __FILE__; - const std::string marker = "/source/source_md/"; - const std::size_t marker_pos = source_file.find(marker); - ASSERT_NE(marker_pos, std::string::npos); - const std::string model_file = source_file.substr(0, marker_pos) + "/tests/PP_ORB/nep_hfo2.txt"; + const std::string model_file = "nep_hfo2.txt"; UnitCell cell; Setcell::setupcell(cell); diff --git a/tests/04_FF/CASES_CPU.txt b/tests/04_FF/CASES_CPU.txt index 4f66a60ae0a..1a297373a67 100644 --- a/tests/04_FF/CASES_CPU.txt +++ b/tests/04_FF/CASES_CPU.txt @@ -19,7 +19,7 @@ 19_LJ_RE_stop 20_LJ_dry_run #50_DP_Al -#101_NEP_HfO2 +101_NEP_HfO2 102_SNAP_base 103_SNAP_pbc 104_SNAP_inner diff --git a/tests/PP_ORB/nep_hfo2.txt b/tests/PP_ORB/nep_hfo2.txt index 9fdcc26c3af..f5cad2c09f9 100644 --- a/tests/PP_ORB/nep_hfo2.txt +++ b/tests/PP_ORB/nep_hfo2.txt @@ -1,10 +1,14 @@ -nep4_zbl 2 O Hf +nep 2 O Hf +format_version 1 +model nep zbl 0.75 1.5 cutoff 8 4 250 44 n_max 4 4 basis_size 12 12 l_max 4 2 0 -ANN 30 0 +ann 30 0 +energy_reference 0 0 +@ parameters 2441 -1.5533842e+00 -1.3961171e+00 3.3405685e+00 @@ -1927,525 +1931,526 @@ ANN 30 0 2.8927937e+00 3.9155262e+00 1.4099131e+00 - -2.2940616e-01 - -2.3978636e-01 - -2.3748500e+00 2.8657326e-01 - 1.9563338e-02 - -9.0910614e-02 - -2.5686588e+00 9.5408869e-01 - -1.3727081e+00 - -1.6112269e+00 - 2.0881071e+00 -9.1908938e-01 - -3.5890895e-01 - -2.6843009e+00 - 6.2789547e-01 5.8642173e-01 - 1.5076664e-02 - 4.0120059e-01 - 4.1221350e-01 -4.4466174e-01 - 2.1918561e+00 - 1.7434669e+00 - 4.5529962e-01 6.8173546e-01 - -2.0915875e+00 - -9.0331662e-01 - 2.6639309e+00 4.4237590e-01 - -5.5111068e-01 - -6.4363921e-01 - -1.2755105e+00 -8.9477026e-01 - 5.1817203e-01 - 2.6136322e+00 - -1.1172168e+00 -1.0446937e-01 - -7.5461930e-01 - 1.5463486e+00 - 3.7316844e-01 -1.2297275e-01 - -1.8357255e+00 - 3.5172743e-01 - 6.5976131e-01 -9.3726027e-01 - 1.8453962e+00 - -7.4409175e-01 - 1.1922665e+00 -9.3923581e-01 - 1.9594451e+00 - 4.7260043e-01 - 2.1009294e-02 2.4724874e-01 - -3.0114096e-01 - -2.5038543e+00 - 3.0408671e+00 -8.0764284e-03 - -9.3323708e-02 - -1.5286725e+00 - 1.0986918e+00 -5.2158380e-01 - -1.4115039e-01 - 1.4201791e+00 - -1.9050267e+00 6.1161137e-01 - -7.7248119e-02 - 3.1418616e-01 - 1.0913959e+00 3.0320907e-01 - -9.3435459e-03 - -3.1722436e+00 - 2.2108128e+00 -7.1060014e-01 - -2.6849186e-02 - -3.5458228e-01 - -4.3493447e-01 1.0016899e+00 - -4.5686325e-01 - -9.1456942e-02 - 4.3866372e-01 4.5825163e-01 - 9.5142975e-02 - 2.0926287e+00 - 9.9394280e-01 -2.9810932e-02 - -5.2124584e-01 - 9.2470419e-01 - 8.0457723e-01 1.2161284e-01 - -2.3214631e-01 - 6.4427666e-02 - 2.7944240e-01 3.8537703e-02 - -2.5530109e-02 - -3.9351457e-01 - 2.9069493e+00 4.1782182e-02 - -4.5735043e-02 - -4.0495887e-01 - 9.4710332e-01 1.1381063e+00 - 3.5268404e-02 - -8.6834326e-02 - 3.9066190e-01 5.6377345e-01 - -7.3526132e-01 - -4.5397755e-02 - -1.0005380e+00 6.8412679e-01 - -3.4439933e+00 - 1.6043544e+00 - 4.5449706e-03 -1.0303997e+00 - 3.8943484e+00 - -2.7824140e+00 - 2.5553635e-01 7.1907926e-01 - -4.6824656e-02 - 3.4129581e-01 - 1.3005282e-01 1.6339422e+00 - -3.6333210e+00 - 8.7921940e-02 - 1.4450583e-03 7.2421896e-01 - -2.5398893e+00 - 6.3356566e-01 - 3.1766063e-01 -1.0837486e+00 - -5.5443758e-01 - 2.2252049e-02 - -3.6091042e-01 -5.6914908e-01 - 5.6063231e-02 - 1.0298314e-03 - 2.4238717e-02 9.6030992e-01 - -9.6268421e-01 - 2.3460650e+00 - -1.2383690e-02 7.6861513e-01 - -1.9391581e+00 - 1.6428167e+00 - -3.4467268e-01 2.0037541e+00 - -4.6746913e-01 - 1.8533632e-01 - 1.9925807e-02 1.6490299e+00 - -1.7445420e+00 - -1.2992331e+00 - -1.8981735e-03 -7.4854843e-02 - -5.1788747e-01 - -8.7893617e-01 - -1.2539268e+00 1.0828738e+00 - 1.3129176e+00 - 8.9214385e-01 - 2.1309783e+00 -3.2122394e-01 - 1.7049128e+00 - 2.0584841e+00 - -8.9311349e-01 2.7157090e+00 - -2.7663317e+00 - -1.1899577e+00 - 5.2453309e-01 -3.6286643e-01 - 7.0048344e-01 - -1.5496627e+00 - -1.0139318e+00 -1.0544126e+00 - 2.6645690e-01 - 3.2083485e+00 - -2.2817013e+00 -1.1081134e+00 - -3.3196729e-01 - 7.3396498e-01 - 2.3466904e+00 -2.8135803e-02 - 2.4156838e-03 - -1.2590913e+00 - 7.0327646e-01 -2.7724099e-01 - 8.1643122e-01 - 6.6101395e-02 - -2.3891058e-02 4.8915258e-01 - -1.4709608e-01 - 1.4207890e+00 - -1.1855311e+00 -1.6165118e-01 - 1.2200035e+00 - 1.4572439e+00 - -1.3971887e+00 1.9258641e+00 - 2.0958705e-01 - -7.2139484e-01 - -7.2869855e-01 -9.9423409e-01 - -1.2502786e+00 - -1.5623587e+00 - -1.7265791e+00 -1.4523365e-01 - -1.0325271e+00 - -1.3077756e+00 - 1.2025254e-02 -4.0335053e-01 - -1.1523438e+00 - -1.7147996e+00 - -6.5376842e-01 2.9556179e+00 - -2.3046103e+00 - -1.5913094e+00 - -4.1656005e-03 -1.5665205e+00 - 5.1338243e+00 - 1.2152119e+00 - 8.0084456e-03 -2.5743428e-01 - -2.0259600e+00 - -6.0789630e-02 - 2.3534586e+00 2.7328367e+00 - -4.9503961e+00 - -1.5224886e+00 - 2.7951398e-01 9.1023594e-01 - -8.7686402e-01 - -2.8532007e+00 - -1.6088476e-02 -4.0433988e-01 - 1.9681743e+00 - -6.2602729e-01 - 1.2792153e+00 -2.5801936e-01 - -1.0092305e-01 - 1.7260052e-01 - 8.4814884e-02 8.2048684e-01 - -4.2905843e-01 - 7.4386853e-01 - 5.4550028e-01 1.6546834e+00 - 9.3235427e-01 - -2.3978453e-02 - 5.6542766e-01 2.6399046e-01 - -5.8003461e-01 - -4.2401415e-01 - -4.1585934e-01 -2.3292341e+00 - 2.8095278e-01 - -3.7381209e-02 - 4.8540604e-01 -4.3058190e-01 + -2.2940616e-01 + 1.9563338e-02 + -1.3727081e+00 + -3.5890895e-01 + 1.5076664e-02 + 2.1918561e+00 + -2.0915875e+00 + -5.5111068e-01 + 5.1817203e-01 + -7.5461930e-01 + -1.8357255e+00 + 1.8453962e+00 + 1.9594451e+00 + -3.0114096e-01 + -9.3323708e-02 + -1.4115039e-01 + -7.7248119e-02 + -9.3435459e-03 + -2.6849186e-02 + -4.5686325e-01 + 9.5142975e-02 + -5.2124584e-01 + -2.3214631e-01 + -2.5530109e-02 + -4.5735043e-02 + 3.5268404e-02 + -7.3526132e-01 + -3.4439933e+00 + 3.8943484e+00 + -4.6824656e-02 + -3.6333210e+00 + -2.5398893e+00 + -5.5443758e-01 + 5.6063231e-02 + -9.6268421e-01 + -1.9391581e+00 + -4.6746913e-01 + -1.7445420e+00 + -5.1788747e-01 + 1.3129176e+00 + 1.7049128e+00 + -2.7663317e+00 + 7.0048344e-01 + 2.6645690e-01 + -3.3196729e-01 + 2.4156838e-03 + 8.1643122e-01 + -1.4709608e-01 + 1.2200035e+00 + 2.0958705e-01 + -1.2502786e+00 + -1.0325271e+00 + -1.1523438e+00 + -2.3046103e+00 + 5.1338243e+00 + -2.0259600e+00 + -4.9503961e+00 + -8.7686402e-01 + 1.9681743e+00 + -1.0092305e-01 + -4.2905843e-01 + 9.3235427e-01 + -5.8003461e-01 + 2.8095278e-01 3.0663306e-02 + -2.3978636e-01 + -9.0910614e-02 + -1.6112269e+00 + -2.6843009e+00 + 4.0120059e-01 + 1.7434669e+00 + -9.0331662e-01 + -6.4363921e-01 + 2.6136322e+00 + 1.5463486e+00 + 3.5172743e-01 + -7.4409175e-01 + 4.7260043e-01 + -2.5038543e+00 + -1.5286725e+00 + 1.4201791e+00 + 3.1418616e-01 + -3.1722436e+00 + -3.5458228e-01 + -9.1456942e-02 + 2.0926287e+00 + 9.2470419e-01 + 6.4427666e-02 + -3.9351457e-01 + -4.0495887e-01 + -8.6834326e-02 + -4.5397755e-02 + 1.6043544e+00 + -2.7824140e+00 + 3.4129581e-01 + 8.7921940e-02 + 6.3356566e-01 + 2.2252049e-02 + 1.0298314e-03 + 2.3460650e+00 + 1.6428167e+00 + 1.8533632e-01 + -1.2992331e+00 + -8.7893617e-01 + 8.9214385e-01 + 2.0584841e+00 + -1.1899577e+00 + -1.5496627e+00 + 3.2083485e+00 + 7.3396498e-01 + -1.2590913e+00 + 6.6101395e-02 + 1.4207890e+00 + 1.4572439e+00 + -7.2139484e-01 + -1.5623587e+00 + -1.3077756e+00 + -1.7147996e+00 + -1.5913094e+00 + 1.2152119e+00 + -6.0789630e-02 + -1.5224886e+00 + -2.8532007e+00 + -6.2602729e-01 + 1.7260052e-01 + 7.4386853e-01 + -2.3978453e-02 + -4.2401415e-01 + -3.7381209e-02 -1.6223869e-01 + -2.3748500e+00 + -2.5686588e+00 + 2.0881071e+00 + 6.2789547e-01 + 4.1221350e-01 + 4.5529962e-01 + 2.6639309e+00 + -1.2755105e+00 + -1.1172168e+00 + 3.7316844e-01 + 6.5976131e-01 + 1.1922665e+00 + 2.1009294e-02 + 3.0408671e+00 + 1.0986918e+00 + -1.9050267e+00 + 1.0913959e+00 + 2.2108128e+00 + -4.3493447e-01 + 4.3866372e-01 + 9.9394280e-01 + 8.0457723e-01 + 2.7944240e-01 + 2.9069493e+00 + 9.4710332e-01 + 3.9066190e-01 + -1.0005380e+00 + 4.5449706e-03 + 2.5553635e-01 + 1.3005282e-01 + 1.4450583e-03 + 3.1766063e-01 + -3.6091042e-01 + 2.4238717e-02 + -1.2383690e-02 + -3.4467268e-01 + 1.9925807e-02 + -1.8981735e-03 + -1.2539268e+00 + 2.1309783e+00 + -8.9311349e-01 + 5.2453309e-01 + -1.0139318e+00 + -2.2817013e+00 + 2.3466904e+00 + 7.0327646e-01 + -2.3891058e-02 + -1.1855311e+00 + -1.3971887e+00 + -7.2869855e-01 + -1.7265791e+00 + 1.2025254e-02 + -6.5376842e-01 + -4.1656005e-03 + 8.0084456e-03 + 2.3534586e+00 + 2.7951398e-01 + -1.6088476e-02 + 1.2792153e+00 + 8.4814884e-02 + 5.4550028e-01 + 5.6542766e-01 + -4.1585934e-01 + 4.8540604e-01 1.0673543e+00 -3.2270724e-01 + -8.6658448e-01 + -4.8507249e-01 + -7.8170061e-01 + -1.1520298e+00 + 1.2422403e+00 + 5.5944973e-01 + -6.7864263e-01 + -1.8522002e+00 + -8.9412475e-01 + -1.3485178e+00 + -1.4263954e+00 + -7.7234089e-01 + -1.2952981e+00 + -2.2568528e-02 + 1.7096540e+00 + -9.2771471e-01 + -1.0045508e-02 + -6.1810076e-01 + 1.0606502e-01 + 1.5824664e-01 + 9.2054254e-01 + 3.9360362e-01 + 5.3959233e-01 + 3.7539884e-01 + 1.8888235e-01 + -9.9117738e-01 + -6.5255439e-01 + 6.6553319e-01 + -1.0562721e+00 + -1.5344197e+00 + 2.9541078e+00 + -1.2878127e+00 + -2.4095502e+00 + -9.5952678e-01 + 9.8164451e-01 + -1.2405845e+00 + -1.9599315e+00 + -9.5725805e-01 + -7.6509431e-02 + 5.4049317e-02 + -5.1446116e-01 + 1.3117826e-01 + 1.7163970e+00 + -1.5993770e+00 + 4.7730151e-01 + 1.1395724e+00 + 3.8936225e-01 + -3.0346897e-01 + 4.2881086e-01 + 9.9328347e-03 + -2.2609261e-01 + 7.2406143e-02 + -1.1794700e-01 + 1.8234780e+00 + 7.2431898e-01 + -2.4203742e+00 + 1.4702298e-02 + 2.2277474e+00 + -1.8962531e+00 + -1.2740175e+00 + 1.5537256e+00 + 1.3044652e+00 + -7.4026924e-01 + -6.1715835e-01 1.6096928e+00 + 1.6230518e+00 + 4.5344341e-01 + 1.3807112e+00 + 2.0514281e+00 + 1.1010884e+00 + -4.9849726e-02 + 6.7467374e-01 + 1.1910535e+00 + -1.5555643e-02 + -2.2061069e-01 + -4.8576653e-02 + 9.3939744e-02 + -2.2496290e+00 + -5.0419599e-01 + 2.0812116e+00 + -5.9655833e-01 + 3.5521922e-01 + -7.2760032e-03 + -2.1872017e+00 + -6.9883293e-01 + -3.1092903e-01 + -5.3563565e-01 + -1.3020818e+00 + -7.9382402e-01 + -3.7149054e-01 + 1.2416965e-01 + -2.8357333e-02 + 2.6627953e+00 + 5.1625454e-01 + 5.0960559e-01 + 7.8359121e-01 + -2.3101887e-01 + 5.7583090e-02 + 9.8995632e-01 + 2.2056359e-01 + -1.1847482e-02 + 8.6801358e-02 + 1.7035109e-01 + 6.1647040e-01 + -1.2632349e+00 + 1.7515757e+00 + -1.4545732e+00 + -2.1161871e+00 + 2.5635638e+00 + -1.1859236e+00 + -1.5923337e+00 + -2.4042067e-01 + -4.4122183e-01 + -1.5606081e+00 + -1.2500426e+00 + -1.7763856e-01 + -7.9275995e-01 + -2.7929199e-01 + 3.6582991e-02 + -4.3476064e-02 + -1.8088571e+00 + 8.5589492e-01 + 6.4718942e-03 + 9.2306399e-01 + -8.4185861e-02 + -2.9375482e-01 + -1.8310229e+00 + -1.0798825e+00 + -7.9118240e-01 7.0881331e-01 - -1.3262657e+00 - -8.6658448e-01 - 1.6230518e+00 1.2062315e+00 - 3.0736292e-02 - -4.8507249e-01 - 4.5344341e-01 -1.7728055e+00 - -5.8851665e-01 - -7.8170061e-01 - 1.3807112e+00 9.6331704e-01 - -7.3222792e-01 - -1.1520298e+00 - 2.0514281e+00 2.6125135e+00 - -1.5638385e+00 - 1.2422403e+00 - 1.1010884e+00 -1.8981603e+00 - 4.6118131e-01 - 5.5944973e-01 - -4.9849726e-02 8.7087512e-01 - -3.2569520e+00 - -6.7864263e-01 - 6.7467374e-01 2.2641261e-01 - 5.7670671e-01 - -1.8522002e+00 - 1.1910535e+00 1.4858695e+00 - -1.4665792e+00 - -8.9412475e-01 - -1.5555643e-02 4.9453866e-01 - -4.9826938e-01 - -1.3485178e+00 - -2.2061069e-01 1.9170229e-01 - 1.3705933e-02 - -1.4263954e+00 - -4.8576653e-02 9.5411420e-02 - -5.1099718e-01 - -7.7234089e-01 - 9.3939744e-02 -7.5306031e-03 - -8.4642690e-01 - -1.2952981e+00 - -2.2496290e+00 -9.5707327e-01 - -7.8080469e-01 - -2.2568528e-02 - -5.0419599e-01 -1.5813330e-01 - 1.2654436e-02 - 1.7096540e+00 - 2.0812116e+00 -9.0956151e-01 - -2.7438506e-01 - -9.2771471e-01 - -5.9655833e-01 -2.1653114e-01 - -2.0754540e-02 - -1.0045508e-02 - 3.5521922e-01 -4.9730367e-03 - -3.0306621e-02 - -6.1810076e-01 - -7.2760032e-03 -2.4689667e-01 - -9.3479287e-03 - 1.0606502e-01 - -2.1872017e+00 -2.3451116e+00 - -5.4334048e-03 - 1.5824664e-01 - -6.9883293e-01 -1.0507596e+00 - -1.2689747e-01 - 9.2054254e-01 - -3.1092903e-01 -1.7526303e-01 - -2.2519223e-02 - 3.9360362e-01 - -5.3563565e-01 3.8229361e-01 - -4.3745410e-02 - 5.3959233e-01 - -1.3020818e+00 -2.7115783e-01 - -2.8851228e-03 - 3.7539884e-01 - -7.9382402e-01 -7.2198820e-01 - -1.5458927e-02 - 1.8888235e-01 - -3.7149054e-01 -7.6774979e-01 - -6.1468780e-01 - -9.9117738e-01 - 1.2416965e-01 -3.5376068e-02 - 1.4645875e-01 - -6.5255439e-01 - -2.8357333e-02 -1.6877948e+00 - 1.2905836e-02 - 6.6553319e-01 - 2.6627953e+00 2.2042987e+00 - 6.0230404e-01 - -1.0562721e+00 - 5.1625454e-01 -1.3156476e+00 - -8.4150290e-01 - -1.5344197e+00 - 5.0960559e-01 -1.1831834e+00 - 1.4424776e+00 - 2.9541078e+00 - 7.8359121e-01 3.1802005e-01 - -9.7326213e-01 - -1.2878127e+00 - -2.3101887e-01 -8.3778602e-01 - 3.0522365e-02 - -2.4095502e+00 - 5.7583090e-02 -8.2950598e-01 - 3.4058121e-01 - -9.5952678e-01 - 9.8995632e-01 1.6555600e-01 - -4.8826955e-02 - 9.8164451e-01 - 2.2056359e-01 6.1222214e-01 - -2.2871600e-02 - -1.2405845e+00 - -1.1847482e-02 -7.0693541e-01 - 3.5584363e-01 - -1.9599315e+00 - 8.6801358e-02 -9.8468047e-01 - -4.7543454e-01 - -9.5725805e-01 - 1.7035109e-01 -6.1086416e-01 - 9.6900873e-03 - -7.6509431e-02 - 6.1647040e-01 -8.5837252e-02 - -1.0432316e+00 - 5.4049317e-02 - -1.2632349e+00 1.7477356e-02 - -7.1644142e-02 - -5.1446116e-01 - 1.7515757e+00 4.4124016e-01 - -1.0891576e-01 - 1.3117826e-01 - -1.4545732e+00 1.5600188e-01 - -1.0264823e+00 - 1.7163970e+00 - -2.1161871e+00 -2.7659209e+00 - 1.1914859e-02 - -1.5993770e+00 - 2.5635638e+00 1.2586774e+00 - -2.1482437e+00 - 4.7730151e-01 - -1.1859236e+00 1.6749135e+00 - -4.9972497e-02 - 1.1395724e+00 - -1.5923337e+00 -1.3794301e+00 - -1.8817082e-01 - 3.8936225e-01 - -2.4042067e-01 -8.5450149e-01 - -5.9953374e-01 - -3.0346897e-01 - -4.4122183e-01 8.8261575e-01 - -8.0668241e-01 - 4.2881086e-01 - -1.5606081e+00 4.2859793e-01 - -1.3742676e+00 - 9.9328347e-03 - -1.2500426e+00 -1.0895256e+00 - -7.3715031e-01 - -2.2609261e-01 - -1.7763856e-01 -1.1882263e+00 - 1.6049725e-01 - 7.2406143e-02 - -7.9275995e-01 1.9274653e+00 - -1.0577695e+00 - -1.1794700e-01 - -2.7929199e-01 3.0877551e-01 - -1.2493926e-01 - 1.8234780e+00 - 3.6582991e-02 -1.1440312e+00 - -1.6081604e-01 - 7.2431898e-01 - -4.3476064e-02 5.7223046e-01 - -3.0296910e+00 - -2.4203742e+00 - -1.8088571e+00 7.9032326e-01 - 3.2279447e-02 - 1.4702298e-02 - 8.5589492e-01 -4.4538689e-01 - -1.6863515e+00 - 2.2277474e+00 - 6.4718942e-03 -5.3397065e-01 - -5.3375709e-01 - -1.8962531e+00 - 9.2306399e-01 6.1104411e-01 - -9.9028684e-03 - -1.2740175e+00 - -8.4185861e-02 2.9369900e-01 - -3.2829079e-01 - 1.5537256e+00 - -2.9375482e-01 1.9377233e-02 - -7.7071440e-01 - 1.3044652e+00 - -1.8310229e+00 -5.2994013e-01 - -3.1108278e-01 - -7.4026924e-01 - -1.0798825e+00 4.3720734e-01 - -7.8779936e-01 - -6.1715835e-01 - -7.9118240e-01 1.4634629e-01 + -1.3262657e+00 + 3.0736292e-02 + -5.8851665e-01 + -7.3222792e-01 + -1.5638385e+00 + 4.6118131e-01 + -3.2569520e+00 + 5.7670671e-01 + -1.4665792e+00 + -4.9826938e-01 + 1.3705933e-02 + -5.1099718e-01 + -8.4642690e-01 + -7.8080469e-01 + 1.2654436e-02 + -2.7438506e-01 + -2.0754540e-02 + -3.0306621e-02 + -9.3479287e-03 + -5.4334048e-03 + -1.2689747e-01 + -2.2519223e-02 + -4.3745410e-02 + -2.8851228e-03 + -1.5458927e-02 + -6.1468780e-01 + 1.4645875e-01 + 1.2905836e-02 + 6.0230404e-01 + -8.4150290e-01 + 1.4424776e+00 + -9.7326213e-01 + 3.0522365e-02 + 3.4058121e-01 + -4.8826955e-02 + -2.2871600e-02 + 3.5584363e-01 + -4.7543454e-01 + 9.6900873e-03 + -1.0432316e+00 + -7.1644142e-02 + -1.0891576e-01 + -1.0264823e+00 + 1.1914859e-02 + -2.1482437e+00 + -4.9972497e-02 + -1.8817082e-01 + -5.9953374e-01 + -8.0668241e-01 + -1.3742676e+00 + -7.3715031e-01 + 1.6049725e-01 + -1.0577695e+00 + -1.2493926e-01 + -1.6081604e-01 + -3.0296910e+00 + 3.2279447e-02 + -1.6863515e+00 + -5.3375709e-01 + -9.9028684e-03 + -3.2829079e-01 + -7.7071440e-01 + -3.1108278e-01 + -7.8779936e-01 -1.3045032e+00 +@ q_scaler 30 4.9530282e-03 4.9530282e-03 4.9530282e-03 diff --git a/toolchain/build_abacus_aocc-aocl.sh b/toolchain/build_abacus_aocc-aocl.sh index 970a077912e..d104b104b53 100755 --- a/toolchain/build_abacus_aocc-aocl.sh +++ b/toolchain/build_abacus_aocc-aocl.sh @@ -28,7 +28,7 @@ FFTW3="${AOCLhome}" LIBRI="${LIBRI_ROOT}" LIBCOMM="${LIBCOMM_ROOT}" USE_CUDA=OFF # set ON to enable gpu-abacus -# NEP_DIR="${INSTALL_DIR}/NEP_CPU-main" +ENABLE_NEP=OFF # set ON to enable NEP # LIBTORCH="${INSTALL_DIR}/libtorch-2.1.2/share/cmake/Torch" # LIBNPY="${INSTALL_DIR}/libnpy-1.0.1/include" # DEEPMD="${HOME}/apps/anaconda3/envs/deepmd" @@ -76,7 +76,7 @@ cmake_args=( -DLIBRI_DIR="${LIBRI}" -DLIBCOMM_DIR="${LIBCOMM}" -DUSE_CUDA="${USE_CUDA}" - # -DNEP_DIR="${NEP_DIR}" + -DENABLE_NEP="${ENABLE_NEP}" # -DTorch_DIR="${LIBTORCH}" # -DDeePMD_DIR="${DEEPMD}" # -DENABLE_MLALGO=1 diff --git a/toolchain/build_abacus_gcc-aocl.sh b/toolchain/build_abacus_gcc-aocl.sh index 956c33cef18..f5f18d7aded 100755 --- a/toolchain/build_abacus_gcc-aocl.sh +++ b/toolchain/build_abacus_gcc-aocl.sh @@ -27,7 +27,7 @@ FFTW3="${AOCLhome}" LIBRI="${LIBRI_ROOT}" LIBCOMM="${LIBCOMM_ROOT}" USE_CUDA=OFF # set ON to enable gpu-abacus -# NEP_DIR="${INSTALL_DIR}/NEP_CPU-main" +ENABLE_NEP=OFF # set ON to enable NEP # LIBTORCH="${INSTALL_DIR}/libtorch-2.1.2/share/cmake/Torch" # LIBNPY="${INSTALL_DIR}/libnpy-1.0.1/include" # DEEPMD="${HOME}/apps/anaconda3/envs/deepmd" @@ -72,7 +72,7 @@ cmake_args=( -DLIBRI_DIR="${LIBRI}" -DLIBCOMM_DIR="${LIBCOMM}" -DUSE_CUDA="${USE_CUDA}" - # -DNEP_DIR="${NEP_DIR}" + -DENABLE_NEP="${ENABLE_NEP}" # -DTorch_DIR="${LIBTORCH}" # -DDeePMD_DIR="${DEEPMD}" # -DENABLE_MLALGO=1 diff --git a/toolchain/build_abacus_gcc-mkl.sh b/toolchain/build_abacus_gcc-mkl.sh index f57dfacdd97..ebb9e8b0a05 100755 --- a/toolchain/build_abacus_gcc-mkl.sh +++ b/toolchain/build_abacus_gcc-mkl.sh @@ -25,7 +25,7 @@ PREFIX="${ABACUS_DIR}" LIBRI="${LIBRI_ROOT}" LIBCOMM="${LIBCOMM_ROOT}" USE_CUDA=OFF # set ON to enable gpu-abacus -# NEP_DIR="${INSTALL_DIR}/NEP_CPU-main" +ENABLE_NEP=OFF # set ON to enable NEP # LIBTORCH="${INSTALL_DIR}/libtorch-2.1.2/share/cmake/Torch" # LIBNPY="${INSTALL_DIR}/libnpy-1.0.1/include" # DEEPMD="${HOME}/apps/anaconda3/envs/deepmd" @@ -71,7 +71,7 @@ cmake_args=( -DLIBRI_DIR="${LIBRI}" -DLIBCOMM_DIR="${LIBCOMM}" -DUSE_CUDA="${USE_CUDA}" - # -DNEP_DIR="${NEP_DIR}" + -DENABLE_NEP="${ENABLE_NEP}" # -DTorch_DIR="${LIBTORCH}" # -DDeePMD_DIR="${DEEPMD}" # -DENABLE_MLALGO=1 diff --git a/toolchain/build_abacus_gnu.sh b/toolchain/build_abacus_gnu.sh index 6973b3c2855..6dfcdd85a15 100755 --- a/toolchain/build_abacus_gnu.sh +++ b/toolchain/build_abacus_gnu.sh @@ -25,7 +25,7 @@ FFTW3="${FFTW_ROOT}" LIBRI="${LIBRI_ROOT}" LIBCOMM="${LIBCOMM_ROOT}" USE_CUDA=OFF # set ON to enable gpu-abacus -# NEP_DIR="${INSTALL_DIR}/NEP_CPU-main" +ENABLE_NEP=OFF # set ON to enable NEP # LIBTORCH="${INSTALL_DIR}/libtorch-2.1.2/share/cmake/Torch" # LIBNPY="${INSTALL_DIR}/libnpy-1.0.1/include" # DEEPMD="${HOME}/apps/anaconda3/envs/deepmd" # @@ -71,7 +71,7 @@ cmake_args=( -DLIBRI_DIR="${LIBRI}" -DLIBCOMM_DIR="${LIBCOMM}" -DUSE_CUDA="${USE_CUDA}" - # -DNEP_DIR="${NEP_DIR}" + -DENABLE_NEP="${ENABLE_NEP}" # -DTorch_DIR="${LIBTORCH}" # -DDeePMD_DIR="${DEEPMD}" # -DENABLE_MLALGO=1 diff --git a/toolchain/build_abacus_intel.sh b/toolchain/build_abacus_intel.sh index 40fa99492f8..cd897e5b118 100755 --- a/toolchain/build_abacus_intel.sh +++ b/toolchain/build_abacus_intel.sh @@ -25,7 +25,7 @@ PREFIX="${ABACUS_DIR}" LIBRI="${LIBRI_ROOT}" LIBCOMM="${LIBCOMM_ROOT}" USE_CUDA=OFF # set ON to enable gpu-abacus -# NEP_DIR="${INSTALL_DIR}/NEP_CPU-main" +ENABLE_NEP=OFF # set ON to enable NEP # LIBTORCH="${INSTALL_DIR}/libtorch-2.1.2/share/cmake/Torch" # LIBNPY="${INSTALL_DIR}/libnpy-1.0.1/include" # DEEPMD="${HOME}/apps/anaconda3/envs/deepmd" # v3.0 might have problem @@ -72,7 +72,7 @@ cmake_args=( -DLIBRI_DIR="${LIBRI}" -DLIBCOMM_DIR="${LIBCOMM}" -DUSE_CUDA="${USE_CUDA}" - # -DNEP_DIR="${NEP_DIR}" + -DENABLE_NEP="${ENABLE_NEP}" # -DTorch_DIR="${LIBTORCH}" # -DDeePMD_DIR="${DEEPMD}" # -DENABLE_MLALGO=1 diff --git a/toolchain/scripts/package_versions.sh b/toolchain/scripts/package_versions.sh index e5471da0f7c..36e492c15c2 100644 --- a/toolchain/scripts/package_versions.sh +++ b/toolchain/scripts/package_versions.sh @@ -117,8 +117,8 @@ json_ver="3.12.0" json_sha256="42f6e95cad6ec532fd372391373363b62a14af6d771056dbfc86160e6dfff7aa" # NEP (Neural Evolution Potential) - CPU version -nep_ver="629ec5d" -nep_sha256="4d4d3c64211a2a39e5d5c795b77befbba987cc809786e0cd6abfa46d0f3bf8cb" +nep_ver="1.5.1" +nep_sha256="2479cf350554a3a1a958891e8681f4bdcde5e146b9b357fcfa2bf2b3e6dbb05c" # ============================================================================= # Package Variable Loading Function diff --git a/toolchain/scripts/stage4/install_nep.sh b/toolchain/scripts/stage4/install_nep.sh index 4d956ac38d0..cbbd8cf2d0c 100755 --- a/toolchain/scripts/stage4/install_nep.sh +++ b/toolchain/scripts/stage4/install_nep.sh @@ -31,8 +31,8 @@ case "$with_nep" in dirname="NEP_CPU-${nep_ver}" pkg_install_dir="${INSTALLDIR}/${dirname}" install_lock_file="${pkg_install_dir}/install_successful" - filename="nep-${nep_ver}.tar.gz" - url="https://codeload.github.com/brucefan1983/NEP_CPU/tar.gz/${nep_ver}" + filename="NEP_CPU-${nep_ver}.tar.gz" + url="https://github.com/brucefan1983/NEP_CPU/archive/v${nep_ver}/NEP_CPU-${nep_ver}.tar.gz" if verify_checksums "${install_lock_file}"; then echo "$dirname is already installed, skipping it." @@ -47,51 +47,13 @@ case "$with_nep" in [ -d $dirname ] && rm -rf $dirname tar -xzf $filename cd $dirname - - cat <Makefile -CXX ?= g++ - -# Compiler flags -CXXFLAGS = -O2 -fPIC -std=c++11 - -# Include directories -INCLUDES = -I./src - -# Source files -SRCS = ./src/nep.cpp ./src/ewald_nep.cpp ./src/neighbor_nep.cpp - -# Object files -OBJS = \$(SRCS:.cpp=.o) - -# Target shared library -TARGET = libnep.so - -# Default target -all: \$(TARGET) - -# Rule to build the shared library -\$(TARGET): \$(OBJS) - \$(CXX) -shared \$(OBJS) -o \$(TARGET) - -# Rule to compile source files into object files -%.o: %.cpp - \$(CXX) \$(CXXFLAGS) \$(INCLUDES) -c \$< -o \$@ - -# Clean up build files -clean: - rm -f \$(OBJS) \$(TARGET) - -# Install target -install: - mkdir -p \$(PREFIX)/lib - mkdir -p \$(PREFIX)/include - cp \$(TARGET) \$(PREFIX)/lib/ - cp src/*.h \$(PREFIX)/include/ -EOF - - make >make.log 2>&1 || tail -n ${LOG_LINES} make.log - make PREFIX="${pkg_install_dir}" install >install.log 2>&1 || tail -n ${LOG_LINES} install.log - + cmake -Bbuild \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR="lib" \ + -DCMAKE_BUILD_TYPE="Release" \ + -DNEP_CPU_OPENMP=ON \ + > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + cmake --build build -t install -j "$(get_nprocs)" > build.log 2>&1 || tail -n ${LOG_LINES} build.log cd .. write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" fi @@ -101,9 +63,9 @@ EOF __SYSTEM__) echo "==================== Finding NEP_CPU from system paths ====================" - check_lib -lnep "nep" + check_lib -lnep_cpu "nep" add_include_from_paths NEP_CFLAGS "nep.h" $INCLUDE_PATHS - add_lib_from_paths NEP_LDFLAGS "libnep.*" $LIB_PATHS + add_lib_from_paths NEP_LDFLAGS "libnep_cpu.*" $LIB_PATHS ;; __DONTUSE__) ;; *) @@ -123,7 +85,6 @@ if [ "$with_nep" != "__DONTUSE__" ]; then prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" -prepend_path CPATH "${pkg_install_dir}/include" prepend_path CMAKE_PREFIX_PATH "${pkg_install_dir}" EOF fi