Skip to content

Commit 2b6a720

Browse files
malfetfacebook-github-bot
authored andcommitted
Update pybind to 2.6.0 (pytorch#46415)
Summary: Preserve PYBIND11 (pytorch@63ce3fb) configuration options in `torch._C._PYBIND11 (https://github.com/pytorch/pytorch/commit/63ce3fbde85672e112411ad731839e6db3c15c08)_COMPILER_TYPE` and use them when building extensions Also, use f-strings in `torch.utils.cpp_extension` "Fixes" pytorch#46367 Pull Request resolved: pytorch#46415 Reviewed By: VitalyFedyunin Differential Revision: D24605949 Pulled By: malfet fbshipit-source-id: 87340f2ed5308266a46ef8f0317316227dab9d4d
1 parent 2249a29 commit 2b6a720

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

.flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ ignore =
1212
B007,B008,
1313
# these ignores are from flake8-comprehensions; please fix!
1414
C400,C401,C402,C403,C404,C405,C407,C411,C413,C414,C415
15-
per-file-ignores = __init__.py: F401
15+
per-file-ignores = __init__.py: F401 torch/utils/cpp_extension.py: B950
1616
exclude = docs/src,venv,third_party,caffe2,scripts,docs/caffe2,torch/lib/include,torch/lib/tmp_install,build,torch/include,*.pyi,.git,build,build_test_custom_build,build_code_analyzer

third_party/pybind11

Submodule pybind11 updated 207 files

torch/csrc/Module.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,29 @@ Call this whenever a new thread is created in order to propagate values from
864864
ASSERT_TRUE(set_module_attr("_GLIBCXX_USE_CXX11_ABI", Py_False));
865865
#endif
866866

867+
// See note [Pybind11 ABI constants]
868+
#define SET_STR_DEFINE(name) \
869+
ASSERT_TRUE(set_module_attr("_" # name, THPUtils_packString(name)))
870+
871+
#ifdef PYBIND11_COMPILER_TYPE
872+
SET_STR_DEFINE(PYBIND11_COMPILER_TYPE);
873+
#else
874+
ASSERT_TRUE(set_module_attr("_" C10_STRINGIZE(PYBIND11_COMPILER_TYPE), Py_None));
875+
#endif
876+
877+
#ifdef PYBIND11_STDLIB
878+
SET_STR_DEFINE(PYBIND11_STDLIB);
879+
#else
880+
ASSERT_TRUE(set_module_attr("_" C10_STRINGIZE(PYBIND11_STDLIB), Py_None));
881+
#endif
882+
883+
#ifdef PYBIND11_BUILD_ABI
884+
SET_STR_DEFINE(PYBIND11_BUILD_ABI);
885+
#else
886+
ASSERT_TRUE(set_module_attr("_" C10_STRINGIZE(PYBIND11_BUILD_ABI), Py_None));
887+
#endif
888+
#undef SET_STR_DEFINE
889+
867890
const auto& defaultGenerator = at::detail::getDefaultCPUGenerator();
868891
THPDefaultCPUGenerator = (THPGenerator*)THPGenerator_initDefaultGenerator(defaultGenerator);
869892
// This reference is meant to be given away, so no need to incref here.

torch/utils/cpp_extension.py

+23
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ def build_extensions(self) -> None:
364364
extension.extra_compile_args[ext] = []
365365

366366
self._add_compile_flag(extension, '-DTORCH_API_INCLUDE_EXTENSION_H')
367+
# See note [Pybind11 ABI constants]
368+
for name in ["COMPILER_TYPE", "STDLIB", "BUILD_ABI"]:
369+
val = getattr(torch._C, f"_PYBIND11_{name}")
370+
if val is not None and not IS_WINDOWS:
371+
self._add_compile_flag(extension, f'-DPYBIND11_{name}="{val}"')
367372
self._define_torch_extension_name(extension)
368373
self._add_gnu_cpp_abi_flag(extension)
369374

@@ -1590,6 +1595,24 @@ def _write_ninja_file_to_build_library(path,
15901595

15911596
common_cflags = [f'-DTORCH_EXTENSION_NAME={name}']
15921597
common_cflags.append('-DTORCH_API_INCLUDE_EXTENSION_H')
1598+
1599+
# Note [Pybind11 ABI constants]
1600+
#
1601+
# Pybind11 before 2.4 used to build an ABI strings using the following pattern:
1602+
# f"__pybind11_internals_v{PYBIND11_INTERNALS_VERSION}{PYBIND11_INTERNALS_KIND}{PYBIND11_BUILD_TYPE}__"
1603+
# Since 2.4 compier type, stdlib and build abi parameters are also encoded like this:
1604+
# f"__pybind11_internals_v{PYBIND11_INTERNALS_VERSION}{PYBIND11_INTERNALS_KIND}{PYBIND11_COMPILER_TYPE}{PYBIND11_STDLIB}{PYBIND11_BUILD_ABI}{PYBIND11_BUILD_TYPE}__"
1605+
#
1606+
# This was done in order to further narrow down the chances of compiler ABI incompatibility
1607+
# that can cause a hard to debug segfaults.
1608+
# For PyTorch extensions we want to relax those restrictions and pass compiler, stdlib and abi properties
1609+
# captured during PyTorch native library compilation in torch/csrc/Module.cpp
1610+
1611+
for pname in ["COMPILER_TYPE", "STDLIB", "BUILD_ABI"]:
1612+
pval = getattr(torch._C, f"_PYBIND11_{pname}")
1613+
if pval is not None and not IS_WINDOWS:
1614+
common_cflags.append(f'-DPYBIND11_{pname}=\\"{pval}\\"')
1615+
15931616
common_cflags += [f'-I{include}' for include in user_includes]
15941617
common_cflags += [f'-isystem {include}' for include in system_includes]
15951618

0 commit comments

Comments
 (0)