From a3f8d95b25a31b49024635a47c3c3b4af2444d8a Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sat, 25 Dec 2021 20:44:06 -0500 Subject: [PATCH 01/12] dynamically load op library in C++ interface C++ interface will dynamically load OP libraries, just like Python interface, so it no longer needs linking. --- source/api_cc/CMakeLists.txt | 1 - source/api_cc/include/common.h | 6 ++++++ source/api_cc/src/DataModifier.cc | 1 + source/api_cc/src/DeepPot.cc | 1 + source/api_cc/src/DeepTensor.cc | 1 + source/api_cc/src/common.cc | 10 ++++++++++ source/api_cc/tests/CMakeLists.txt | 6 +++--- 7 files changed, 22 insertions(+), 4 deletions(-) diff --git a/source/api_cc/CMakeLists.txt b/source/api_cc/CMakeLists.txt index 895a06baea..830ecd6b78 100644 --- a/source/api_cc/CMakeLists.txt +++ b/source/api_cc/CMakeLists.txt @@ -17,7 +17,6 @@ add_library(${libname} SHARED ${LIB_SRC}) # link: libdeepmd libdeepmd_op libtensorflow_cc libtensorflow_framework target_link_libraries (${libname} PUBLIC ${LIB_DEEPMD} ${TensorFlow_LIBRARY} ${TensorFlowFramework_LIBRARY}) -target_link_libraries (${libname} PRIVATE ${LIB_DEEPMD_OP}) target_include_directories(${libname} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR} ${TensorFlow_INCLUDE_DIRS}) set_target_properties( diff --git a/source/api_cc/include/common.h b/source/api_cc/include/common.h index 96f6057358..a07caac546 100644 --- a/source/api_cc/include/common.h +++ b/source/api_cc/include/common.h @@ -116,6 +116,12 @@ void get_env_nthreads(int & num_intra_nthreads, int & num_inter_nthreads); +/** + * @brief Dynamically load OP library. This should be called before loading graphs. + */ +void +load_op_library(); + /** @struct deepmd::deepmd_exception **/ diff --git a/source/api_cc/src/DataModifier.cc b/source/api_cc/src/DataModifier.cc index f704ba599e..c6c009b0d8 100644 --- a/source/api_cc/src/DataModifier.cc +++ b/source/api_cc/src/DataModifier.cc @@ -33,6 +33,7 @@ init (const std::string & model, get_env_nthreads(num_intra_nthreads, num_inter_nthreads); options.config.set_inter_op_parallelism_threads(num_inter_nthreads); options.config.set_intra_op_parallelism_threads(num_intra_nthreads); + deepmd::load_op_library(); deepmd::check_status(NewSession(options, &session)); deepmd::check_status(ReadBinaryProto(Env::Default(), model, &graph_def)); deepmd::check_status(session->Create(graph_def)); diff --git a/source/api_cc/src/DeepPot.cc b/source/api_cc/src/DeepPot.cc index d1126d3844..b3faadcfa7 100644 --- a/source/api_cc/src/DeepPot.cc +++ b/source/api_cc/src/DeepPot.cc @@ -185,6 +185,7 @@ init (const std::string & model, const int & gpu_rank, const std::string & file_ get_env_nthreads(num_intra_nthreads, num_inter_nthreads); options.config.set_inter_op_parallelism_threads(num_inter_nthreads); options.config.set_intra_op_parallelism_threads(num_intra_nthreads); + deepmd::load_op_library(); if(file_content.size() == 0) check_status (ReadBinaryProto(Env::Default(), model, &graph_def)); diff --git a/source/api_cc/src/DeepTensor.cc b/source/api_cc/src/DeepTensor.cc index 419c97aa65..316b6ec3a9 100644 --- a/source/api_cc/src/DeepTensor.cc +++ b/source/api_cc/src/DeepTensor.cc @@ -33,6 +33,7 @@ init (const std::string & model, get_env_nthreads(num_intra_nthreads, num_inter_nthreads); options.config.set_inter_op_parallelism_threads(num_inter_nthreads); options.config.set_intra_op_parallelism_threads(num_intra_nthreads); + deepmd::load_op_library(); deepmd::check_status (NewSession(options, &session)); deepmd::check_status (ReadBinaryProto(Env::Default(), model, &graph_def)); deepmd::check_status (session->Create(graph_def)); diff --git a/source/api_cc/src/common.cc b/source/api_cc/src/common.cc index 8693c14b5c..7c4f7dcb90 100644 --- a/source/api_cc/src/common.cc +++ b/source/api_cc/src/common.cc @@ -228,6 +228,16 @@ get_env_nthreads(int & num_intra_nthreads, } } +void +deepmd:: +load_op_library() +{ + tensorflow::Env* env = tensorflow::Env::Default(); + void* dso_handle; + std::string dso_path = env->FormatLibraryFileName("deepmd_op", NULL); + deepmd::check_status(env->LoadDynamicLibrary(dso_path.c_str(), &dso_handle)); +} + std::string deepmd:: name_prefix(const std::string & scope) diff --git a/source/api_cc/tests/CMakeLists.txt b/source/api_cc/tests/CMakeLists.txt index caa62c82f8..424bff3e9e 100644 --- a/source/api_cc/tests/CMakeLists.txt +++ b/source/api_cc/tests/CMakeLists.txt @@ -99,11 +99,11 @@ else() endif() if (USE_CUDA_TOOLKIT) - target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} ${opname} pthread ${TensorFlow_LIBRARY} rt deepmd_op_cuda coverage_config) + target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} pthread ${TensorFlow_LIBRARY} rt deepmd_op_cuda coverage_config) elseif(USE_ROCM_TOOLKIT) - target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} ${opname} pthread ${TensorFlow_LIBRARY} rt deepmd_op_rocm coverage_config) + target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} pthread ${TensorFlow_LIBRARY} rt deepmd_op_rocm coverage_config) else() - target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} ${opname} pthread ${TensorFlow_LIBRARY} rt coverage_config) + target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} pthread ${TensorFlow_LIBRARY} rt coverage_config) endif() find_package(Protobuf) From 3f33fa5712f54dc8eb16350b88f1b6fd7de43ef3 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sat, 25 Dec 2021 20:59:49 -0500 Subject: [PATCH 02/12] version cannot be NULL... --- source/api_cc/src/common.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/api_cc/src/common.cc b/source/api_cc/src/common.cc index 7c4f7dcb90..05efe56ea6 100644 --- a/source/api_cc/src/common.cc +++ b/source/api_cc/src/common.cc @@ -234,7 +234,7 @@ load_op_library() { tensorflow::Env* env = tensorflow::Env::Default(); void* dso_handle; - std::string dso_path = env->FormatLibraryFileName("deepmd_op", NULL); + std::string dso_path = env->FormatLibraryFileName("deepmd_op", ""); deepmd::check_status(env->LoadDynamicLibrary(dso_path.c_str(), &dso_handle)); } From 12bcccbad52f313bb98123a87d7e9cf4647af18c Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sat, 25 Dec 2021 21:56:01 -0500 Subject: [PATCH 03/12] set LD_LIBRARY_PATH --- source/install/test_cc.sh | 2 +- source/install/test_cc_local.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/install/test_cc.sh b/source/install/test_cc.sh index 60463c5bc9..38eada8135 100755 --- a/source/install/test_cc.sh +++ b/source/install/test_cc.sh @@ -29,7 +29,7 @@ make -j${NPROC} #------------------ cd ${SCRIPT_PATH}/../api_cc/tests -${BUILD_TMP_DIR}/runUnitTests +LD_LIBRARY_PATH=${BUILD_TMP_DIR}:$LD_LIBRARY_PATH ${BUILD_TMP_DIR}/runUnitTests #------------------ # upload to codecov diff --git a/source/install/test_cc_local.sh b/source/install/test_cc_local.sh index 71d6954d46..490a3630f3 100755 --- a/source/install/test_cc_local.sh +++ b/source/install/test_cc_local.sh @@ -29,4 +29,4 @@ make -j${NPROC} #------------------ cd ${SCRIPT_PATH}/../api_cc/tests -${BUILD_TMP_DIR}/runUnitTests +LD_LIBRARY_PATH=${BUILD_TMP_DIR}:$LD_LIBRARY_PATH ${BUILD_TMP_DIR}/runUnitTests From 186ed82016f592699e40b6a92a7644b88ddf48af Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sat, 8 Jan 2022 04:21:49 -0500 Subject: [PATCH 04/12] install runUnitTest --- .gitignore | 2 ++ source/api_cc/tests/CMakeLists.txt | 13 +++++++++++++ source/install/test_cc.sh | 11 +++++++---- source/install/test_cc_local.sh | 14 ++++++++------ source/lib/tests/CMakeLists.txt | 3 +++ 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index b5c08d1f7a..d515e1c5ca 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,8 @@ _templates API_CC doc/api_py/ dp/ +dp_test/ +dp_test_cc/ build_lammps/ .idea/ build_tests/ diff --git a/source/api_cc/tests/CMakeLists.txt b/source/api_cc/tests/CMakeLists.txt index 424bff3e9e..714a7ff160 100644 --- a/source/api_cc/tests/CMakeLists.txt +++ b/source/api_cc/tests/CMakeLists.txt @@ -134,3 +134,16 @@ if(NOT GTEST_LIBRARIES) else () include_directories(${GTEST_INCLUDE_DIRS}) endif () + +set_target_properties( + runUnitTests + PROPERTIES + INSTALL_RPATH "$ORIGIN/../lib" +) +set_target_properties( + ${apiname} + PROPERTIES + INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}" +) +install(TARGETS runUnitTests DESTINATION bin/) +install(TARGETS ${libname} ${apiname} ${opname} DESTINATION lib/) diff --git a/source/install/test_cc.sh b/source/install/test_cc.sh index 38eada8135..6b07b802ba 100755 --- a/source/install/test_cc.sh +++ b/source/install/test_cc.sh @@ -7,29 +7,32 @@ NPROC=$(nproc --all) #------------------ +INSTALL_PREFIX=${SCRIPT_PATH}/../../dp_test BUILD_TMP_DIR=${SCRIPT_PATH}/../build_tests mkdir -p ${BUILD_TMP_DIR} cd ${BUILD_TMP_DIR} -cmake ../lib/tests +cmake ../lib/tests -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} make -j${NPROC} +make install #------------------ -${BUILD_TMP_DIR}/runUnitTests +${INSTALL_PREFIX}/bin/runUnitTests #------------------ BUILD_TMP_DIR=${SCRIPT_PATH}/../build_cc_tests -INSTALL_PREFIX=${SCRIPT_PATH}/../../dp +INSTALL_PREFIX=${SCRIPT_PATH}/../../dp_test_cc mkdir -p ${BUILD_TMP_DIR} mkdir -p ${INSTALL_PREFIX} cd ${BUILD_TMP_DIR} cmake -DINSTALL_TENSORFLOW=TRUE -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} ../api_cc/tests make -j${NPROC} +make install #------------------ cd ${SCRIPT_PATH}/../api_cc/tests -LD_LIBRARY_PATH=${BUILD_TMP_DIR}:$LD_LIBRARY_PATH ${BUILD_TMP_DIR}/runUnitTests +${INSTALL_PREFIX}/bin/runUnitTests #------------------ # upload to codecov diff --git a/source/install/test_cc_local.sh b/source/install/test_cc_local.sh index 490a3630f3..e5a1070186 100755 --- a/source/install/test_cc_local.sh +++ b/source/install/test_cc_local.sh @@ -6,27 +6,29 @@ SCRIPT_PATH=$(dirname $(realpath -s $0)) NPROC=$(nproc --all) #------------------ - +INSTALL_PREFIX=${SCRIPT_PATH}/../../dp_test BUILD_TMP_DIR=${SCRIPT_PATH}/../build_tests mkdir -p ${BUILD_TMP_DIR} cd ${BUILD_TMP_DIR} -cmake ../lib/tests +cmake ../lib/tests -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} make -j${NPROC} +make install #------------------ -${BUILD_TMP_DIR}/runUnitTests +${INSTALL_PREFIX}/bin/runUnitTests #------------------ echo "try to find tensorflow in ${tensorflow_root}" BUILD_TMP_DIR=${SCRIPT_PATH}/../build_cc_tests -INSTALL_PREFIX=${SCRIPT_PATH}/../../dp +INSTALL_PREFIX=${SCRIPT_PATH}/../../dp_test_cc mkdir -p ${BUILD_TMP_DIR} cd ${BUILD_TMP_DIR} -cmake -DINSTALL_TENSORFLOW=FALSE -DTENSORFLOW_ROOT=${tensorflow_root} ../api_cc/tests +cmake -DINSTALL_TENSORFLOW=FALSE -DTENSORFLOW_ROOT=${tensorflow_root} ../api_cc/tests -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} make -j${NPROC} +make install #------------------ cd ${SCRIPT_PATH}/../api_cc/tests -LD_LIBRARY_PATH=${BUILD_TMP_DIR}:$LD_LIBRARY_PATH ${BUILD_TMP_DIR}/runUnitTests +${INSTALL_PREFIX}/bin/runUnitTests diff --git a/source/lib/tests/CMakeLists.txt b/source/lib/tests/CMakeLists.txt index b5a0460c54..8c3a3e4c16 100644 --- a/source/lib/tests/CMakeLists.txt +++ b/source/lib/tests/CMakeLists.txt @@ -106,3 +106,6 @@ if(NOT GTEST_LIBRARIES) else () include_directories(${GTEST_INCLUDE_DIRS}) endif () + +install(TARGETS runUnitTests DESTINATION bin/) +install(TARGETS runUnitTests DESTINATION lib/) From b674ce9c7007d97a65dc74e781a7aa37acee6108 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 9 Jan 2022 02:02:11 -0500 Subject: [PATCH 05/12] remove CMAKE_LINK_WHAT_YOU_USE It is not necessary anymore. --- source/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index a3d62c09b4..d706a6d292 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1,8 +1,5 @@ cmake_minimum_required(VERSION 3.7) project(DeePMD) -if (CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_LINK_WHAT_YOU_USE TRUE) -endif () # build cpp or python interfaces if (NOT DEFINED BUILD_CPP_IF) From 0f615277d3491fd0ef6bfc29a7725a09a79578b0 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 9 Jan 2022 06:24:45 -0500 Subject: [PATCH 06/12] also remove CMAKE_LINK_WHAT_YOU_USE in api_cc/tests --- source/api_cc/tests/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/source/api_cc/tests/CMakeLists.txt b/source/api_cc/tests/CMakeLists.txt index 714a7ff160..bd7c23a5a3 100644 --- a/source/api_cc/tests/CMakeLists.txt +++ b/source/api_cc/tests/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.9) project(deepmd_api_test) -set(CMAKE_LINK_WHAT_YOU_USE TRUE) if (NOT DEFINED BUILD_CPP_IF) set(BUILD_CPP_IF TRUE) From e988c401f4432082ef2fca0a06d15aebef75be67 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 17 Jan 2022 14:19:31 -0500 Subject: [PATCH 07/12] change the type of op library to MODULE --- source/op/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/op/CMakeLists.txt b/source/op/CMakeLists.txt index 96c02ec71c..8b483b2e5d 100644 --- a/source/op/CMakeLists.txt +++ b/source/op/CMakeLists.txt @@ -8,7 +8,7 @@ file(GLOB OP_GRADS_SRC custom_op.cc prod_force_grad.cc prod_force_grad_multi_dev file(GLOB OP_PY *.py) if (BUILD_CPP_IF) - add_library(${LIB_DEEPMD_OP} SHARED ${OP_SRC}) + add_library(${LIB_DEEPMD_OP} MODULE ${OP_SRC}) # link: libdeepmd libtensorflow_cc libtensorflow_framework target_link_libraries (${LIB_DEEPMD_OP} PUBLIC ${TensorFlow_LIBRARY} ${TensorFlowFramework_LIBRARY}) target_link_libraries (${LIB_DEEPMD_OP} PRIVATE ${LIB_DEEPMD}) @@ -17,8 +17,8 @@ if (BUILD_CPP_IF) endif (BUILD_CPP_IF) if (BUILD_PY_IF) - add_library(op_abi SHARED ${OP_SRC} ${OP_LIB}) - add_library(op_grads SHARED ${OP_GRADS_SRC}) + add_library(op_abi MODULE ${OP_SRC} ${OP_LIB}) + add_library(op_grads MODULE ${OP_GRADS_SRC}) message(STATUS ${TensorFlowFramework_LIBRARY}) # link: libdeepmd libtensorflow_framework From fabdac91d42004409042c87456930797fdc39880 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 17 Jan 2022 21:35:27 -0500 Subject: [PATCH 08/12] add the absolute path of library directory to cc rpath --- source/api_cc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/api_cc/CMakeLists.txt b/source/api_cc/CMakeLists.txt index 830ecd6b78..4085680c92 100644 --- a/source/api_cc/CMakeLists.txt +++ b/source/api_cc/CMakeLists.txt @@ -23,7 +23,7 @@ set_target_properties( ${libname} PROPERTIES COMPILE_DEFINITIONS ${prec_def} - INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}" + INSTALL_RPATH "$ORIGIN;${CMAKE_INSTALL_PREFIX}/lib;${TensorFlow_LIBRARY_PATH}" ) install(TARGETS ${libname} DESTINATION lib/) From c01d11ad5695a7eb547ff5c061b9eafecb39e7a8 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 18 Jan 2022 04:22:56 -0500 Subject: [PATCH 09/12] Revert "add the absolute path of library directory to cc rpath" This reverts commit fabdac91d42004409042c87456930797fdc39880. --- source/api_cc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/api_cc/CMakeLists.txt b/source/api_cc/CMakeLists.txt index 4085680c92..830ecd6b78 100644 --- a/source/api_cc/CMakeLists.txt +++ b/source/api_cc/CMakeLists.txt @@ -23,7 +23,7 @@ set_target_properties( ${libname} PROPERTIES COMPILE_DEFINITIONS ${prec_def} - INSTALL_RPATH "$ORIGIN;${CMAKE_INSTALL_PREFIX}/lib;${TensorFlow_LIBRARY_PATH}" + INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}" ) install(TARGETS ${libname} DESTINATION lib/) From ecccb578ed959b44fea7aa52222f821b65739239 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 18 Jan 2022 07:31:04 -0500 Subject: [PATCH 10/12] add `-Wl,--disable-new-dtags` --- source/lmp/env.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lmp/env.sh.in b/source/lmp/env.sh.in index b419154a32..4f537e2693 100644 --- a/source/lmp/env.sh.in +++ b/source/lmp/env.sh.in @@ -8,4 +8,4 @@ TF_RPATH=`echo $TENSORFLOW_LIBRARY_PATH | sed "s/;/ -Wl,-rpath=/g"` NNP_INC=" -std=c++@CMAKE_CXX_STANDARD@ -D@prec_def@ @TTM_DEF@ -DLAMMPS_VERSION_NUMBER=@LAMMPS_VERSION_NUMBER@ -I$TF_INCLUDE_DIRS -I$DEEPMD_ROOT/include/ " NNP_PATH=" -L$TF_LIBRARY_PATH -L$DEEPMD_ROOT/lib" -NNP_LIB=" -Wl,--no-as-needed -l@LIB_DEEPMD_CC@@variant_name@ -ltensorflow_cc -ltensorflow_framework -Wl,-rpath=$TF_RPATH -Wl,-rpath=$DEEPMD_ROOT/lib" +NNP_LIB=" -Wl,--no-as-needed -l@LIB_DEEPMD_CC@@variant_name@ -ltensorflow_cc -ltensorflow_framework -Wl,-rpath=$TF_RPATH -Wl,-rpath=$DEEPMD_ROOT/lib -Wl,--disable-new-dtags" From 3362f99b014259d25b981ad6fa04fe26e5ed3873 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 19 Jan 2022 04:14:55 -0500 Subject: [PATCH 11/12] Revert "add `-Wl,--disable-new-dtags`" This reverts commit ecccb578ed959b44fea7aa52222f821b65739239. --- source/lmp/env.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lmp/env.sh.in b/source/lmp/env.sh.in index 4f537e2693..b419154a32 100644 --- a/source/lmp/env.sh.in +++ b/source/lmp/env.sh.in @@ -8,4 +8,4 @@ TF_RPATH=`echo $TENSORFLOW_LIBRARY_PATH | sed "s/;/ -Wl,-rpath=/g"` NNP_INC=" -std=c++@CMAKE_CXX_STANDARD@ -D@prec_def@ @TTM_DEF@ -DLAMMPS_VERSION_NUMBER=@LAMMPS_VERSION_NUMBER@ -I$TF_INCLUDE_DIRS -I$DEEPMD_ROOT/include/ " NNP_PATH=" -L$TF_LIBRARY_PATH -L$DEEPMD_ROOT/lib" -NNP_LIB=" -Wl,--no-as-needed -l@LIB_DEEPMD_CC@@variant_name@ -ltensorflow_cc -ltensorflow_framework -Wl,-rpath=$TF_RPATH -Wl,-rpath=$DEEPMD_ROOT/lib -Wl,--disable-new-dtags" +NNP_LIB=" -Wl,--no-as-needed -l@LIB_DEEPMD_CC@@variant_name@ -ltensorflow_cc -ltensorflow_framework -Wl,-rpath=$TF_RPATH -Wl,-rpath=$DEEPMD_ROOT/lib" From de00e04206b93bf87e9c4b64a097266455ccb015 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 19 Jan 2022 04:52:07 -0500 Subject: [PATCH 12/12] dlopen from dp lib but not TF --- source/api_cc/src/common.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/api_cc/src/common.cc b/source/api_cc/src/common.cc index 05efe56ea6..b19f79d42e 100644 --- a/source/api_cc/src/common.cc +++ b/source/api_cc/src/common.cc @@ -1,6 +1,7 @@ #include "common.h" #include "AtomMap.h" #include "device.h" +#include using namespace tensorflow; @@ -233,9 +234,11 @@ deepmd:: load_op_library() { tensorflow::Env* env = tensorflow::Env::Default(); - void* dso_handle; std::string dso_path = env->FormatLibraryFileName("deepmd_op", ""); - deepmd::check_status(env->LoadDynamicLibrary(dso_path.c_str(), &dso_handle)); + void* dso_handle = dlopen(dso_path.c_str(), RTLD_NOW | RTLD_LOCAL); + if (!dso_handle) { + throw deepmd::deepmd_exception(dso_path + " is not found! You can add the library directory to LD_LIBRARY_PATH"); + } } std::string