Skip to content

Commit 57d91aa

Browse files
committed
Remove some configure warnings, and update comments.
This change also more accurately screens for when `torch._C` doesn't have the attribute `_PYBIND11_BUILD_ABI`. Signed-off-by: zjgarvey <[email protected]>
1 parent c7bfa8f commit 57d91aa

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

build_tools/cmake/TorchMLIRPyTorch.cmake

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ endfunction()
3939
# Separately, pybind11 keeps an internal variable which records its ABI info
4040
# (PYBIND11_INTERNALS_ID in include/pybind11/detail/internals.h). Differences
4141
# in this variable between torch-mlir and PyTorch will cause type errors.
42-
# Thus, our best option is to:
42+
# Note: as of version 2.9.0.dev20250826, torch has updated to pybind11 ver 3.0.
43+
# This simplifies compatibility considerably. For reference, see
44+
# https://github.com/pybind/pybind11/pull/5439
45+
# For pre-version 3.0 pybind11, our best option is to:
4346
# a) Identify which ABI version PyTorch was compiled with
4447
# b) Tell gcc to use that version
4548
# or
@@ -70,15 +73,18 @@ function(TorchMLIRConfigurePyTorch)
7073
# Check ABI compatibility version
7174
execute_process(
7275
COMMAND ${Python3_EXECUTABLE}
73-
-c "import torch; import sys; abi=torch._C._PYBIND11_BUILD_ABI; abi.startswith('_cxxabi10') or sys.exit(1); sys.stdout.write(str(abi[-2:]))"
76+
-c "import torch; import sys; abi=getattr(torch._C, '_PYBIND11_BUILD_ABI', '-1'); abi=='-1' or abi.startswith('_cxxabi10') or sys.exit(1); sys.stdout.write(str(abi[-2:]))"
7477
RESULT_VARIABLE _result
7578
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
7679
OUTPUT_VARIABLE _cxx_abi_version)
7780
if(_result)
78-
message(WARNING "Could not infer torch._C._PYBIND_BUILD_ABI. This was removed after pytorch updated to pybind11 version 3.0.1, and the TORCH_CXX_FLAGS manipulation is no longer required.")
81+
message(FATAL_ERROR "Failed to determine C++ ABI version")
82+
elseif(${_cxx_abi_version} STREQUAL "-1")
83+
message(STATUS "Could not find `torch._C._PYBIND_BUILD_ABI`. This was removed in torch 2.9.0 (as of nightly release: dev20250826), and the TORCH_CXX_FLAGS manipulation is no longer required.")
84+
# Everyone involved should be using cxx11 abi by default, but specify this just in case.
85+
set(TORCH_CXXFLAGS "-D_GLIBCXX_USE_CXX11_ABI=${_use_cxx11_abi}")
7986
else()
8087
message(STATUS "PyTorch C++ ABI version: \"${_cxx_abi_version}\"")
81-
8288
# Specialize compile flags for compiler
8389
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
8490
set(TORCH_CXXFLAGS "-D_GLIBCXX_USE_CXX11_ABI=${_use_cxx11_abi} -fabi-version=${_cxx_abi_version}")
@@ -88,8 +94,8 @@ function(TorchMLIRConfigurePyTorch)
8894
message(WARNING "Unrecognized compiler. Cannot determine ABI flags.")
8995
return()
9096
endif()
91-
set(TORCH_CXXFLAGS "${TORCH_CXXFLAGS}" PARENT_SCOPE)
9297
endif()
98+
set(TORCH_CXXFLAGS "${TORCH_CXXFLAGS}" PARENT_SCOPE)
9399
endif()
94100
endfunction()
95101

0 commit comments

Comments
 (0)