Skip to content

Commit 5a7588f

Browse files
malfetpytorchmergebot
authored andcommitted
[Build] Remove pre-CXX11 ABI logic from build script (pytorch#149888)
Only keep one in check_binary_symbols to make sure there are no pre-CXX11 ABI symbols in the library Pull Request resolved: pytorch#149888 Approved by: https://github.com/atalman, https://github.com/seemethere ghstack dependencies: pytorch#149887
1 parent 280e487 commit 5a7588f

File tree

12 files changed

+11
-150
lines changed

12 files changed

+11
-150
lines changed

.ci/pytorch/check_binary.sh

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -78,47 +78,7 @@ fi
7878

7979
echo "Checking that the gcc ABI is what we expect"
8080
if [[ "$(uname)" != 'Darwin' ]]; then
81-
function is_expected() {
82-
if [[ "$1" -gt 0 || "$1" == "ON " ]]; then
83-
echo 1
84-
fi
85-
}
86-
87-
# First we check that the env var in TorchConfig.cmake is correct
88-
89-
# We search for D_GLIBCXX_USE_CXX11_ABI=1 in torch/TorchConfig.cmake
90-
torch_config="${install_root}/share/cmake/Torch/TorchConfig.cmake"
91-
if [[ ! -f "$torch_config" ]]; then
92-
echo "No TorchConfig.cmake found!"
93-
ls -lah "$install_root/share/cmake/Torch"
94-
exit 1
95-
fi
96-
echo "Checking the TorchConfig.cmake"
97-
cat "$torch_config"
98-
99-
# The sed call below is
100-
# don't print lines by default (only print the line we want)
101-
# -n
102-
# execute the following expression
103-
# e
104-
# replace lines that match with the first capture group and print
105-
# s/.*D_GLIBCXX_USE_CXX11_ABI=\(.\)".*/\1/p
106-
# any characters, D_GLIBCXX_USE_CXX11_ABI=, exactly one any character, a
107-
# quote, any characters
108-
# Note the exactly one single character after the '='. In the case that the
109-
# variable is not set the '=' will be followed by a '"' immediately and the
110-
# line will fail the match and nothing will be printed; this is what we
111-
# want. Otherwise it will capture the 0 or 1 after the '='.
112-
# /.*D_GLIBCXX_USE_CXX11_ABI=\(.\)".*/
113-
# replace the matched line with the capture group and print
114-
# /\1/p
115-
actual_gcc_abi="$(sed -ne 's/.*D_GLIBCXX_USE_CXX11_ABI=\(.\)".*/\1/p' < "$torch_config")"
116-
if [[ "$(is_expected "$actual_gcc_abi")" != 1 ]]; then
117-
echo "gcc ABI $actual_gcc_abi not as expected."
118-
exit 1
119-
fi
120-
121-
# We also check that there are [not] cxx11 symbols in libtorch
81+
# We also check that there are cxx11 symbols in libtorch
12282
#
12383
echo "Checking that symbols in libtorch.so have the right gcc abi"
12484
python3 "$(dirname ${BASH_SOURCE[0]})/smoke_test/check_binary_symbols.py"

.ci/pytorch/smoke_test/check_binary_symbols.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,36 +80,20 @@ def _get_symbols_chunk(i):
8080
return functools.reduce(list.__add__, (x.result() for x in tasks), [])
8181

8282

83-
def check_lib_symbols_for_abi_correctness(lib: str, pre_cxx11_abi: bool = True) -> None:
83+
def check_lib_symbols_for_abi_correctness(lib: str) -> None:
8484
print(f"lib: {lib}")
8585
cxx11_symbols = grep_symbols(lib, LIBTORCH_CXX11_PATTERNS)
8686
pre_cxx11_symbols = grep_symbols(lib, LIBTORCH_PRE_CXX11_PATTERNS)
8787
num_cxx11_symbols = len(cxx11_symbols)
8888
num_pre_cxx11_symbols = len(pre_cxx11_symbols)
8989
print(f"num_cxx11_symbols: {num_cxx11_symbols}")
9090
print(f"num_pre_cxx11_symbols: {num_pre_cxx11_symbols}")
91-
if pre_cxx11_abi:
92-
if num_cxx11_symbols > 0:
93-
raise RuntimeError(
94-
f"Found cxx11 symbols, but there shouldn't be any, see: {cxx11_symbols[:100]}"
95-
)
96-
if num_pre_cxx11_symbols < 1000:
97-
raise RuntimeError("Didn't find enough pre-cxx11 symbols.")
98-
# Check for no recursive iterators, regression test for https://github.com/pytorch/pytorch/issues/133437
99-
rec_iter_symbols = grep_symbols(
100-
lib, [re.compile("std::filesystem::recursive_directory_iterator.*")]
91+
if num_pre_cxx11_symbols > 0:
92+
raise RuntimeError(
93+
f"Found pre-cxx11 symbols, but there shouldn't be any, see: {pre_cxx11_symbols[:100]}"
10194
)
102-
if len(rec_iter_symbols) > 0:
103-
raise RuntimeError(
104-
f"recursive_directory_iterator in used pre-CXX11 binaries, see; {rec_iter_symbols}"
105-
)
106-
else:
107-
if num_pre_cxx11_symbols > 0:
108-
raise RuntimeError(
109-
f"Found pre-cxx11 symbols, but there shouldn't be any, see: {pre_cxx11_symbols[:100]}"
110-
)
111-
if num_cxx11_symbols < 100:
112-
raise RuntimeError("Didn't find enought cxx11 symbols")
95+
if num_cxx11_symbols < 100:
96+
raise RuntimeError("Didn't find enought cxx11 symbols")
11397

11498

11599
def main() -> None:
@@ -122,8 +106,7 @@ def main() -> None:
122106
install_root = Path(distutils.sysconfig.get_python_lib()) / "torch"
123107

124108
libtorch_cpu_path = str(install_root / "lib" / "libtorch_cpu.so")
125-
# NOTE: All binaries are built with cxx11abi now
126-
check_lib_symbols_for_abi_correctness(libtorch_cpu_path, False)
109+
check_lib_symbols_for_abi_correctness(libtorch_cpu_path)
127110

128111

129112
if __name__ == "__main__":

CMakeLists.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,7 @@ string(APPEND CMAKE_CUDA_FLAGS
6969
" -DLIBCUDACXX_ENABLE_SIMPLIFIED_COMPLEX_OPERATIONS")
7070

7171
if(LINUX)
72-
include(cmake/CheckAbi.cmake)
73-
string(APPEND CMAKE_CXX_FLAGS
74-
" -D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")
75-
string(APPEND CMAKE_CUDA_FLAGS
76-
" -D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")
77-
if(${GLIBCXX_USE_CXX11_ABI} EQUAL 1)
78-
set(CXX_STANDARD_REQUIRED ON)
79-
else()
80-
# Please note this is required in order to ensure compatibility between gcc
81-
# 9 and gcc 7 This could be removed when all Linux PyTorch binary builds are
82-
# compiled by the same toolchain again
83-
append_cxx_flag_if_supported("-fabi-version=11" CMAKE_CXX_FLAGS)
84-
endif()
72+
set(CXX_STANDARD_REQUIRED ON)
8573
endif()
8674

8775
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,6 @@ conda install -c conda-forge libuv=1.39
274274
#### Install PyTorch
275275
**On Linux**
276276

277-
If you would like to compile PyTorch with [new C++ ABI](https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html) enabled, then first run this command:
278-
```bash
279-
export _GLIBCXX_USE_CXX11_ABI=1
280-
```
281-
282-
Please **note** that starting from PyTorch 2.5, the PyTorch build with XPU supports both new and old C++ ABIs. Previously, XPU only supported the new C++ ABI. If you want to compile with Intel GPU support, please follow [Intel GPU Support](#intel-gpu-support).
283-
284277
If you're compiling for AMD ROCm then first run this command:
285278
```bash
286279
# Only run this if you're compiling for ROCm

caffe2/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,10 +1317,6 @@ if(BUILD_TEST)
13171317
endif()
13181318
endif()
13191319

1320-
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1321-
include(../cmake/CheckAbi.cmake)
1322-
endif()
1323-
13241320
# CMake config for external projects.
13251321
configure_file(
13261322
${PROJECT_SOURCE_DIR}/cmake/TorchConfigVersion.cmake.in

cmake/CheckAbi.cmake

Lines changed: 0 additions & 27 deletions
This file was deleted.

cmake/TorchConfig.cmake.in

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ if(@USE_XPU@ AND @BUILD_SHARED_LIBS@)
147147
append_torchlib_if_found(c10_xpu torch_xpu)
148148
endif()
149149

150-
# When we build libtorch with the old libstdc++ ABI, dependent libraries must too.
151-
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
152-
set(TORCH_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=@GLIBCXX_USE_CXX11_ABI@")
153-
endif()
154-
155150
find_library(TORCH_LIBRARY torch PATHS "${TORCH_INSTALL_PREFIX}/lib")
156151
# the statements below changes target properties on
157152
# - the imported target from Caffe2Targets.cmake in shared library mode (see the find_package above)

tools/setup_helpers/cmake.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ def generate(
189189
# Key: environment variable name. Value: Corresponding variable name to be passed to CMake. If you are
190190
# adding a new build option to this block: Consider making these two names identical and adding this option
191191
# in the block below.
192-
"_GLIBCXX_USE_CXX11_ABI": "GLIBCXX_USE_CXX11_ABI",
193192
"CUDNN_LIB_DIR": "CUDNN_LIBRARY",
194193
"USE_CUDA_STATIC_LINK": "CAFFE2_STATIC_LINK_CUDA",
195194
}

torch/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,7 @@ def _assert(condition, message):
22322232

22332233
def compiled_with_cxx11_abi() -> builtins.bool:
22342234
r"""Returns whether PyTorch was built with _GLIBCXX_USE_CXX11_ABI=1"""
2235-
return _C._GLIBCXX_USE_CXX11_ABI
2235+
return True
22362236

22372237

22382238
from torch import _library as _library, _ops as _ops

torch/abi-check.cpp

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)