Skip to content

Commit

Permalink
pt: Fix compilation with libtorch (#3405)
Browse files Browse the repository at this point in the history
Backported from
conda-forge/deepmd-kit-feedstock#71.
1. The rpath of libdeepmd_cc should contain the libtorch directory if it
differs from the path of libdeepmd_cc. Setting
`INSTALL_RPATH_USE_LINK_PATH` to `true` resolves the problem.
2. `${TORCH_CXX_FLAGS}` is empty in macOS, so the variable with quotes,
i.e. `"${TORCH_CXX_FLAGS}"`, should be used.

---------

Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz authored Mar 4, 2024
1 parent bd79dec commit 32a86ac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ endif()
if(ENABLE_PYTORCH AND NOT DEEPMD_C_ROOT)
find_package(Torch REQUIRED)
string(REGEX MATCH "_GLIBCXX_USE_CXX11_ABI=([0-9]+)" CXXABI_PT_MATCH
${TORCH_CXX_FLAGS})
"${TORCH_CXX_FLAGS}")
if(CXXABI_PT_MATCH)
message(STATUS "PyTorch CXX11 ABI: ${CMAKE_MATCH_1}")
if(DEFINED OP_CXX_ABI)
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 @@ -33,8 +33,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;${TensorFlow_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

0 comments on commit 32a86ac

Please sign in to comment.