Skip to content

Commit

Permalink
Opt into free-threaded Python (iree-org#18770)
Browse files Browse the repository at this point in the history
With this patch the compiler and runtime opt into free-threaded Python
(aka. "nogil") which was added with Python 3.13. For more information
about free-threaded Python see https://py-free-threading.github.io/.

The patch
* Bumps the pybind11 submodule to version 2.13.6 and pins the pip
installed version
* Pins nanobind to version 2.2.0
* Enables building with free-threading support
  • Loading branch information
marbre authored Oct 17, 2024
1 parent 05bbcf1 commit 258cdb8
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ if(IREE_BUILD_PYTHON_BINDINGS)
# Some parts of the build use FindPython instead of FindPython3. Why? No
# one knows, but they are different. So make sure to bootstrap this one too.
# Not doing this here risks them diverging, which on multi-Python systems,
# can be troublesome. Note that nanobind requires FindPython.
# can be troublesome. Note that pybind11 and nanobind require FindPython.
set(Python_EXECUTABLE "${Python3_EXECUTABLE}")
find_package(Python 3.9 COMPONENTS Interpreter Development.Module NumPy REQUIRED)
elseif(IREE_BUILD_COMPILER OR IREE_BUILD_TESTS)
Expand Down Expand Up @@ -926,6 +926,7 @@ if(IREE_BUILD_PYTHON_BINDINGS)
if(IREE_BUILD_COMPILER)
if(NOT TARGET pybind11::module)
message(STATUS "Using bundled pybind11")
set(PYBIND11_FINDPYTHON ON)
add_subdirectory(third_party/pybind11 EXCLUDE_FROM_ALL)
else()
message(STATUS "Not including bundled pybind11 (already configured)")
Expand Down
2 changes: 1 addition & 1 deletion compiler/bindings/python/IREECompilerRegistration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GlobalInitializer {

} // namespace

PYBIND11_MODULE(_site_initialize_0, m) {
PYBIND11_MODULE(_site_initialize_0, m, py::mod_gil_not_used()) {
m.doc() = "iree-compile registration";

// Make sure that GlobalInitialize and GlobalShutdown are called with module
Expand Down
4 changes: 2 additions & 2 deletions compiler/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ requires = [
# Note that the compiler wheel does not presently need nanobind, but
# it's build is enabled by the same flag which enables the runtime
# configuration, which does.
"nanobind==2.0",
"nanobind==2.2.0",
"ninja",
# MLIR build depends.
"numpy",
"packaging",
"pybind11>=2.10.1",
"pybind11==2.13.6",
"sympy",
]
build-backend = "setuptools.build_meta"
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace py = pybind11;
using namespace mlir::python::adaptors;

PYBIND11_MODULE(_ireeDialects, m) {
PYBIND11_MODULE(_ireeDialects, m, py::mod_gil_not_used()) {
m.doc() = "iree-dialects main python extension";

auto irModule = py::module::import(MAKE_MLIR_PYTHON_QUALNAME("ir"));
Expand Down
2 changes: 1 addition & 1 deletion runtime/bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ iree_select_compiler_opts(_RTTI_AND_EXCEPTION_COPTS
)

nanobind_add_module(iree_runtime_bindings_python_PyExtRt
NB_STATIC LTO
NB_STATIC LTO FREE_THREADED
"binding.h"
"initialize_module.cc"
"invoke.h"
Expand Down
4 changes: 2 additions & 2 deletions runtime/bindings/python/iree/runtime/build_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

pip>=21.3
setuptools>=62.4.0
nanobind==2.0
nanobind==2.2.0
numpy>=2.0.0b1
requests>=2.28.0
wheel>=0.36.2
sympy==1.12.1

# TODO: nanobind is used in the runtime but the compiler uses pybind and
# removing this breaks CI bots; remove this.
pybind11>=2.10.1
pybind11==2.13.6
2 changes: 1 addition & 1 deletion runtime/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = [
"setuptools>=42",
"wheel",
"cmake",
"nanobind==2.0",
"nanobind==2.2.0",
"ninja",
"numpy>=2.0.0b1",
"packaging",
Expand Down
2 changes: 1 addition & 1 deletion third_party/pybind11
Submodule pybind11 updated 193 files

0 comments on commit 258cdb8

Please sign in to comment.