Skip to content

Commit

Permalink
fix: set rpath for libtorch and protobuf (deepmodeling#3636)
Browse files Browse the repository at this point in the history
Fix deepmodeling#3568.

Set run path for libtorch and protobuf. Refactor the original
`TensorFlow_LIBRARY_PATH` to `BACKEND_LIBRARY_PATH` (list).

---------

Signed-off-by: Jinzhe Zeng <[email protected]>
(cherry picked from commit 4c546d0)
Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz committed Jul 2, 2024
1 parent 644cc52 commit dbf5d4a
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 20 deletions.
4 changes: 4 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ endif(USE_TF_PYTHON_LIBS)
# find tensorflow, I need tf abi info
if(NOT DEEPMD_C_ROOT)
find_package(tensorflow REQUIRED)
list(APPEND BACKEND_LIBRARY_PATH ${TensorFlow_LIBRARY_PATH})
list(APPEND BACKEND_INCLUDE_DIRS ${TENSORFLOW_INCLUDE_DIRS})
endif()

# find threads
Expand Down Expand Up @@ -233,7 +235,9 @@ if(DEEPMD_C_ROOT)
# use variable for TF path to set deepmd_c path
set(TENSORFLOW_ROOT "${DEEPMD_C_ROOT}")
set(TensorFlow_LIBRARY_PATH "${DEEPMD_C_ROOT}/lib")
set(BACKEND_LIBRARY_PATH "${DEEPMD_C_ROOT}/lib")
set(TENSORFLOW_INCLUDE_DIRS "${DEEPMD_C_ROOT}/include")
set(BACKEND_INCLUDE_DIRS "${DEEPMD_C_ROOT}/include")
endif()

if(NOT DEEPMD_C_ROOT)
Expand Down
4 changes: 2 additions & 2 deletions source/api_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ target_include_directories(
${libname} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

set_target_properties(
${libname} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}")
set_target_properties(${libname} PROPERTIES INSTALL_RPATH
"$ORIGIN;${BACKEND_LIBRARY_PATH}")
if(CMAKE_TESTING_ENABLED)
target_link_libraries(${libname} PRIVATE coverage_config)
endif()
Expand Down
2 changes: 1 addition & 1 deletion source/api_c/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(deepmd_api_c_test)
file(GLOB TEST_SRC test_*.cc)

set_target_properties(
${LIB_DEEPMD_C} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}")
${LIB_DEEPMD_C} PROPERTIES INSTALL_RPATH "$ORIGIN;${BACKEND_LIBRARY_PATH}")

add_executable(runUnitTests_c ${TEST_SRC})
target_link_libraries(runUnitTests_c PRIVATE GTest::gtest_main ${LIB_DEEPMD_C}
Expand Down
6 changes: 4 additions & 2 deletions source/api_cc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ if(Protobuf_LIBRARY)
endif()

set_target_properties(
${libname} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}"
BUILD_RPATH "$ORIGIN/../op")
${libname}
PROPERTIES INSTALL_RPATH "$ORIGIN;${BACKEND_LIBRARY_PATH}"
INSTALL_RPATH_USE_LINK_PATH TRUE
BUILD_RPATH "$ORIGIN/../op")
target_compile_definitions(${libname} PRIVATE TF_PRIVATE)
if(CMAKE_TESTING_ENABLED)
target_link_libraries(${libname} PRIVATE coverage_config)
Expand Down
2 changes: 1 addition & 1 deletion source/gmx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ target_include_directories(${libgmxname}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/)

set_target_properties(
${libgmxname} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}")
${libgmxname} PROPERTIES INSTALL_RPATH "$ORIGIN;${BACKEND_LIBRARY_PATH}")

install(
FILES dp_gmx_patch
Expand Down
4 changes: 2 additions & 2 deletions source/ipi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ if(APPLE)
${ipiname}
PROPERTIES LINK_FLAGS "${extra_link_flags}"
INSTALL_RPATH
"@loader_path/../${LIB_DIR}:${TensorFlow_LIBRARY_PATH}")
"@loader_path/../${LIB_DIR};${BACKEND_LIBRARY_PATH}")
else()
set_target_properties(
${ipiname}
PROPERTIES LINK_FLAGS
"-Wl,-rpath,'$ORIGIN'/../${LIB_DIR} ${extra_link_flags}"
INSTALL_RPATH "$ORIGIN/../${LIB_DIR}:${TensorFlow_LIBRARY_PATH}")
INSTALL_RPATH "$ORIGIN/../${LIB_DIR};${BACKEND_LIBRARY_PATH}")
endif()

if(CMAKE_TESTING_ENABLED)
Expand Down
4 changes: 2 additions & 2 deletions source/lmp/env.sh.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DEEPMD_ROOT=@CMAKE_INSTALL_PREFIX@
TENSORFLOW_INCLUDE_DIRS="@TensorFlow_INCLUDE_DIRS@"
TENSORFLOW_LIBRARY_PATH="@TensorFlow_LIBRARY_PATH@"
TENSORFLOW_INCLUDE_DIRS="@BACKEND_INCLUDE_DIRS@"
TENSORFLOW_LIBRARY_PATH="@BACKEND_LIBRARY_PATH@"

TF_INCLUDE_DIRS=`echo $TENSORFLOW_INCLUDE_DIRS | sed "s/;/ -I/g"`
TF_LIBRARY_PATH=`echo $TENSORFLOW_LIBRARY_PATH | sed "s/;/ -L/g"`
Expand Down
4 changes: 2 additions & 2 deletions source/lmp/env_c.sh.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DEEPMD_ROOT=@CMAKE_INSTALL_PREFIX@
TENSORFLOW_INCLUDE_DIRS="@TensorFlow_INCLUDE_DIRS@"
TENSORFLOW_LIBRARY_PATH="@TensorFlow_LIBRARY_PATH@"
TENSORFLOW_INCLUDE_DIRS="@BACKEND_INCLUDE_DIRS@"
TENSORFLOW_LIBRARY_PATH="@BACKEND_LIBRARY_PATH@"

TF_INCLUDE_DIRS=`echo $TENSORFLOW_INCLUDE_DIRS | sed "s/;/ -I/g"`
TF_LIBRARY_PATH=`echo $TENSORFLOW_LIBRARY_PATH | sed "s/;/ -L/g"`
Expand Down
4 changes: 2 additions & 2 deletions source/lmp/env_py.sh.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DEEPMD_ROOT=@CMAKE_INSTALL_PREFIX@
TENSORFLOW_INCLUDE_DIRS="@TensorFlow_INCLUDE_DIRS@"
TENSORFLOW_LIBRARY_PATH="@TensorFlow_LIBRARY_PATH@"
TENSORFLOW_INCLUDE_DIRS="@BACKEND_INCLUDE_DIRS@"
TENSORFLOW_LIBRARY_PATH="@BACKEND_LIBRARY_PATH@"
PYTHON_LIBRARY_PATH="@Python_LIBRARY_DIRS@"

TF_INCLUDE_DIRS=`echo $TENSORFLOW_INCLUDE_DIRS | sed "s/;/ -I/g"`
Expand Down
4 changes: 2 additions & 2 deletions source/lmp/env_py_c.sh.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DEEPMD_ROOT=@CMAKE_INSTALL_PREFIX@
TENSORFLOW_INCLUDE_DIRS="@TensorFlow_INCLUDE_DIRS@"
TENSORFLOW_LIBRARY_PATH="@TensorFlow_LIBRARY_PATH@"
TENSORFLOW_INCLUDE_DIRS="@BACKEND_INCLUDE_DIRS@"
TENSORFLOW_LIBRARY_PATH="@BACKEND_LIBRARY_PATH@"
PYTHON_LIBRARY_PATH="@Python_LIBRARY_DIRS@"

TF_INCLUDE_DIRS=`echo $TENSORFLOW_INCLUDE_DIRS | sed "s/;/ -I/g"`
Expand Down
2 changes: 1 addition & 1 deletion source/lmp/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ if(DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION)
"-Wl,-undefined,dynamic_lookup")
else()
set_target_properties(
${libname} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}"
${libname} PROPERTIES INSTALL_RPATH "$ORIGIN;${BACKEND_LIBRARY_PATH}"
LINK_FLAGS "-rdynamic")
endif()
target_compile_definitions(
Expand Down
5 changes: 2 additions & 3 deletions source/op/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ endif()
if(APPLE)
set_target_properties(
${LIB_DEEPMD_OP} PROPERTIES INSTALL_RPATH
"@loader_path;${TensorFlow_LIBRARY_PATH}")
"@loader_path;${BACKEND_LIBRARY_PATH}")
else()
set_target_properties(
${LIB_DEEPMD_OP} PROPERTIES INSTALL_RPATH
"$ORIGIN;${TensorFlow_LIBRARY_PATH}")
${LIB_DEEPMD_OP} PROPERTIES INSTALL_RPATH "$ORIGIN;${BACKEND_LIBRARY_PATH}")
endif()
if(CMAKE_TESTING_ENABLED)
target_link_libraries(${LIB_DEEPMD_OP} PRIVATE coverage_config)
Expand Down

0 comments on commit dbf5d4a

Please sign in to comment.