[cpp_wrapper] Swap to new PyBind11 simple GIL header (#161063)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/161063
Approved by: https://github.com/Skylion007
ghstack dependencies: #160754
This commit is contained in:
Benjamin Glass
2025-08-27 15:37:33 +00:00
committed by PyTorch MergeBot
parent cbc53b7696
commit 007935a802
5 changed files with 6 additions and 7 deletions

View File

@ -583,7 +583,7 @@ exclude_patterns = [
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=#include <pybind11\/(^|[^(gil\.h)])',
'--pattern=#include <pybind11\/(^|[^(gil_simple\.h)])',
'--allowlist-pattern=#include <torch\/csrc\/utils\/pybind.h>',
'--linter-name=PYBIND11_INCLUDE',
'--match-first-only',

View File

@ -268,7 +268,7 @@ if RUN_CPU:
"test_multi_threading",
condition=not IS_WINDOWS,
# Two threads compile, so we expect the output code to be printed twice.
code_string_count={"py::gil_scoped_release release;": 2},
code_string_count={"py::gil_scoped_release_simple release;": 2},
),
BaseTest("test_profiler_mark_wrapper_call"),
BaseTest(

View File

@ -584,7 +584,7 @@ class CppWrapperCpu(PythonWrapperCodegen):
# Weights are promoted in the JIT mode
num_args = len(V.graph.graph_inputs) + len(V.graph.constants)
# release GIL to support multiple instances inference (in different threads of the same process)
self.prefix.splice("py::gil_scoped_release release;")
self.prefix.splice("py::gil_scoped_release_simple release;")
self.prefix.splice(
f"""
@ -2261,7 +2261,7 @@ class CppWrapperCpu(PythonWrapperCodegen):
scoped_lines.writeline("{")
with scoped_lines.indent():
scoped_lines.writeline("py::gil_scoped_acquire acquire;")
scoped_lines.writeline("py::gil_scoped_acquire_simple acquire;")
scoped_lines.writelines(lines_in_scope.split("\n"))
scoped_lines.writelines("}")
return scoped_lines._lines

View File

@ -297,7 +297,7 @@ class CppWrapperCpuArrayRef(CppWrapperCpu):
# Weights are promoted in the JIT mode
num_args = len(V.graph.graph_inputs) + len(V.graph.constants)
# release GIL to support multiple instances inference (in different threads of the same process)
self.prefix.splice("py::gil_scoped_release release;")
self.prefix.splice("py::gil_scoped_release_simple release;")
self.prefix.splice(
f"""

View File

@ -6,8 +6,7 @@
#include <utility>
#include <Python.h>
#define PYBIND11_SIMPLE_GIL_MANAGEMENT
#include <pybind11/gil.h>
#include <pybind11/gil_simple.h>
// Include some often-used cpp_wrapper headers, for precompiling.
#include <c10/util/BFloat16.h>