Skip to content

Commit 0d6f6c5

Browse files
author
liulibo.233
committed
cmake: add support for detecting PyTorch C++ ABI and adjust compilation definitions
1 parent ae6de9c commit 0d6f6c5

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ endif()
1414
find_package(Python 3.10 REQUIRED COMPONENTS Interpreter)
1515
find_package(SQLite3 REQUIRED)
1616

17+
execute_process(
18+
COMMAND ${Python_EXECUTABLE} -c
19+
"import torch; print(1 if torch._C._GLIBCXX_USE_CXX11_ABI else 0)"
20+
OUTPUT_VARIABLE FLAGFFT_TORCH_CXX11_ABI
21+
OUTPUT_STRIP_TRAILING_WHITESPACE
22+
RESULT_VARIABLE FLAGFFT_TORCH_ABI_QUERY_RESULT
23+
)
24+
if(FLAGFFT_TORCH_ABI_QUERY_RESULT EQUAL 0 AND DEFINED FLAGFFT_TORCH_CXX11_ABI)
25+
message(STATUS "Matching PyTorch libstdc++ ABI: _GLIBCXX_USE_CXX11_ABI=${FLAGFFT_TORCH_CXX11_ABI}")
26+
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=${FLAGFFT_TORCH_CXX11_ABI})
27+
else()
28+
message(WARNING "Could not determine PyTorch C++ ABI; using toolchain default. "
29+
"If C++ tests fail to link with [abi:cxx11] undefined references, "
30+
"this is the likely cause.")
31+
endif()
32+
1733
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/libtriton_jit/CMakeLists.txt")
1834
message(FATAL_ERROR "deps/libtriton_jit is required")
1935
endif()
@@ -137,18 +153,6 @@ if(FLAGFFT_BUILD_CLI)
137153
endif()
138154

139155
if(FLAGFFT_BUILD_TESTS)
140-
# Google Test is auto-fetched via FetchContent (see README dependencies).
141-
# This produces the lowercase `gtest` target that ctest/CMakeLists.txt links.
142-
include(FetchContent)
143-
FetchContent_Declare(
144-
googletest
145-
GIT_REPOSITORY https://github.com/google/googletest.git
146-
GIT_TAG v1.15.2
147-
)
148-
# Prevent overriding the parent project's compiler/linker settings on Windows.
149-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
150-
FetchContent_MakeAvailable(googletest)
151-
152156
enable_testing()
153157
add_subdirectory(ctest)
154158
endif()

0 commit comments

Comments
 (0)