Skip to content

Commit d71f632

Browse files
authored
Build: support DeePMD-kit C library (#1742)
* Build: support DeePMD-kit C library Signed-off-by: Jinzhe Zeng <[email protected]> * use wget Signed-off-by: Jinzhe Zeng <[email protected]> * create temp directory Signed-off-by: Jinzhe Zeng <[email protected]> * --no-check-certificate Signed-off-by: Jinzhe Zeng <[email protected]> * fix directory Signed-off-by: Jinzhe Zeng <[email protected]> * fix Signed-off-by: Jinzhe Zeng <[email protected]> * vxzf Signed-off-by: Jinzhe Zeng <[email protected]> * fix cmake Signed-off-by: Jinzhe Zeng <[email protected]> * fix Signed-off-by: Jinzhe Zeng <[email protected]> * set the default value of TensorFlow_DIR Signed-off-by: Jinzhe Zeng <[email protected]> * fix header Signed-off-by: Jinzhe Zeng <[email protected]> * revert build_test.yml Signed-off-by: Jinzhe Zeng <[email protected]>
1 parent 6d96228 commit d71f632

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,23 @@ if(DEFINED DeePMD_DIR)
384384
add_compile_options(-Wl,--no-as-needed)
385385
find_package(DeePMD REQUIRED)
386386
include_directories(${DeePMD_DIR}/include)
387+
if (DeePMDC_FOUND)
388+
target_link_libraries(${ABACUS_BIN_NAME}
389+
DeePMD::deepmd_c
390+
)
391+
add_compile_definitions(
392+
__DPMDC
393+
)
394+
else()
387395
target_link_libraries(${ABACUS_BIN_NAME}
388396
DeePMD::deepmd_cc
389397
DeePMD::deepmd_op
390398
DeePMD::deepmd_op_cuda
391399
DeePMD::tensorflow_cc
392400
)
401+
endif()
393402
if(NOT DEFINED TensorFlow_DIR)
394-
message(FATAL_ERROR "Please define TensorFlow_DIR!")
403+
set(TensorFlow_DIR ${DeePMD_DIR})
395404
endif()
396405
endif()
397406

cmake/FindDeePMD.cmake

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,24 @@
33
# Find the native DeePMD headers and libraries.
44
#
55
# DeePMD_FOUND - True if lib is found.
6+
# DeePMDC_FOUND - True if C API is found.
67
# DeePMD_LIBRARIES - List of libraries
78
# DeePMD_INCLUDE_DIR - Where to find DeePMD headers.
89
#
910

11+
# C API
12+
find_path(DeePMD_INCLUDE_C_DIR
13+
deepmd/deepmd.hpp
14+
deepmd/c_api.h
15+
HINTS ${DeePMD_DIR}
16+
PATH_SUFFIXES "include"
17+
)
18+
find_library(deepmd_c
19+
NAMES deepmd_c
20+
HINTS ${DeePMD_DIR}
21+
PATH_SUFFIXES "lib"
22+
)
23+
# C++ API
1024
find_path(DeePMD_INCLUDE_DIR
1125
deepmd/DeepPot.h
1226
HINTS ${DeePMD_DIR}
@@ -36,6 +50,18 @@ find_library(tensorflow_cc
3650
# Handle the QUIET and REQUIRED arguments and
3751
# set DeePMD_FOUND to TRUE if all variables are non-zero.
3852
include(FindPackageHandleStandardArgs)
53+
find_package_handle_standard_args(DeePMD DEFAULT_MSG deepmd_c DeePMD_INCLUDE_C_DIR)
54+
if (DEEPMD_FOUND)
55+
set(DeePMDC_FOUND TRUE)
56+
set(DeePMD_INCLUDE_DIR ${DeePMD_INCLUDE_C_DIR})
57+
if(NOT TARGET DeePMD::deepmd_c)
58+
add_library(DeePMD::deepmd_c UNKNOWN IMPORTED)
59+
set_target_properties(DeePMD::deepmd_c PROPERTIES
60+
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
61+
IMPORTED_LOCATION "${deepmd_c}"
62+
INTERFACE_INCLUDE_DIRECTORIES "${DeePMD_INCLUDE_DIR}")
63+
endif()
64+
else()
3965
find_package_handle_standard_args(DeePMD DEFAULT_MSG deepmd_cc deepmd_op deepmd_op_cuda tensorflow_cc DeePMD_INCLUDE_DIR)
4066

4167
# Copy the results to the output variables and target.
@@ -72,7 +98,8 @@ if(DeePMD_FOUND)
7298
INTERFACE_INCLUDE_DIRECTORIES "${DeePMD_INCLUDE_DIR}")
7399
endif()
74100
endif()
101+
endif()
75102

76103
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${DeePMD_INCLUDE_DIR})
77104

78-
mark_as_advanced(DeePMD_INCLUDE_DIR deepmd_cc deepmd_op deepmd_op_cuda tensorflow_cc)
105+
mark_as_advanced(DeePMD_INCLUDE_DIR deepmd_c deepmd_cc deepmd_op deepmd_op_cuda tensorflow_cc)

source/module_esolver/esolver_dp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
#include "./esolver.h"
55
#ifdef __DPMD
6+
#ifdef __DPMDC
7+
#include "deepmd/deepmd.hpp"
8+
#else
69
#include "deepmd/DeepPot.h"
710
#endif
11+
#endif
812

913
namespace ModuleESolver
1014
{
@@ -33,7 +37,11 @@ namespace ModuleESolver
3337

3438
//--------------temporary----------------------------
3539
#ifdef __DPMD
40+
#ifdef __DPMDC
41+
deepmd::hpp::DeepPot dp;
42+
#else
3643
deepmd::DeepPot dp;
44+
#endif
3745
#endif
3846
std::vector<double> cell;
3947
std::vector<int> atype;

0 commit comments

Comments
 (0)