From f9a7fe8a9ddc3e966712f74e43fe8dda5a040cb2 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 29 Jan 2024 22:44:30 -0500 Subject: [PATCH] throw errors when PyTorch CXX11 ABI is different from TensorFlow (#3201) If so, throw the following error: ``` -- PyTorch CXX11 ABI: 0 CMake Error at CMakeLists.txt:162 (message): PyTorch CXX11 ABI mismatch TensorFlow: 0 != 1 ``` Signed-off-by: Jinzhe Zeng --- source/CMakeLists.txt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index c273bc9263..6a95ce3633 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -154,7 +154,22 @@ if(ENABLE_TENSORFLOW AND NOT DEEPMD_C_ROOT) endif() if(ENABLE_PYTORCH AND NOT DEEPMD_C_ROOT) find_package(Torch REQUIRED) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") + string(REGEX MATCH "_GLIBCXX_USE_CXX11_ABI=([0-9]+)" CXXABI_PT_MATCH + ${TORCH_CXX_FLAGS}) + if(CXXABI_PT_MATCH) + message(STATUS "PyTorch CXX11 ABI: ${CMAKE_MATCH_1}") + if(DEFINED OP_CXX_ABI) + if(NOT ${CMAKE_MATCH_1} EQUAL ${OP_CXX_ABI}) + message( + FATAL_ERROR + "PyTorch CXX11 ABI mismatch TensorFlow: ${CMAKE_MATCH_1} != ${OP_CXX_ABI}" + ) + endif() + else() + set(OP_CXX_ABI ${CMAKE_MATCH_1}) + add_definitions(-D_GLIBCXX_USE_CXX11_ABI=${OP_CXX_ABI}) + endif() + endif() endif() # log enabled backends if(NOT DEEPMD_C_ROOT)