Skip to content

Commit 4496221

Browse files
committed
Added free-threading CPython mode support in Python bindings
- temporarily updated requirements
1 parent 43c9203 commit 4496221

17 files changed

+29
-19
lines changed

mlir/lib/Bindings/Python/AsyncPasses.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
#include <pybind11/detail/common.h>
1212
#include <pybind11/pybind11.h>
1313

14+
namespace py = pybind11;
15+
1416
// -----------------------------------------------------------------------------
1517
// Module initialization.
1618
// -----------------------------------------------------------------------------
1719

18-
PYBIND11_MODULE(_mlirAsyncPasses, m) {
20+
PYBIND11_MODULE(_mlirAsyncPasses, m, py::mod_gil_not_used()) {
1921
m.doc() = "MLIR Async Dialect Passes";
2022

2123
// Register all Async passes on load.

mlir/lib/Bindings/Python/DialectGPU.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using namespace mlir::python::adaptors;
2323
// Module initialization.
2424
// -----------------------------------------------------------------------------
2525

26-
PYBIND11_MODULE(_mlirDialectsGPU, m) {
26+
PYBIND11_MODULE(_mlirDialectsGPU, m, py::mod_gil_not_used()) {
2727
m.doc() = "MLIR GPU Dialect";
2828
//===-------------------------------------------------------------------===//
2929
// AsyncTokenType

mlir/lib/Bindings/Python/DialectLLVM.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void populateDialectLLVMSubmodule(const pybind11::module &m) {
134134
});
135135
}
136136

137-
PYBIND11_MODULE(_mlirDialectsLLVM, m) {
137+
PYBIND11_MODULE(_mlirDialectsLLVM, m, py::mod_gil_not_used()) {
138138
m.doc() = "MLIR LLVM Dialect";
139139

140140
populateDialectLLVMSubmodule(m);

mlir/lib/Bindings/Python/DialectLinalg.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static void populateDialectLinalgSubmodule(py::module m) {
2121
"op.");
2222
}
2323

24-
PYBIND11_MODULE(_mlirDialectsLinalg, m) {
24+
PYBIND11_MODULE(_mlirDialectsLinalg, m, py::mod_gil_not_used()) {
2525
m.doc() = "MLIR Linalg dialect.";
2626

2727
populateDialectLinalgSubmodule(m);

mlir/lib/Bindings/Python/DialectNVGPU.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static void populateDialectNVGPUSubmodule(const pybind11::module &m) {
3434
py::arg("ctx") = py::none());
3535
}
3636

37-
PYBIND11_MODULE(_mlirDialectsNVGPU, m) {
37+
PYBIND11_MODULE(_mlirDialectsNVGPU, m, py::mod_gil_not_used()) {
3838
m.doc() = "MLIR NVGPU dialect.";
3939

4040
populateDialectNVGPUSubmodule(m);

mlir/lib/Bindings/Python/DialectPDL.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void populateDialectPDLSubmodule(const pybind11::module &m) {
100100
py::arg("context") = py::none());
101101
}
102102

103-
PYBIND11_MODULE(_mlirDialectsPDL, m) {
103+
PYBIND11_MODULE(_mlirDialectsPDL, m, py::mod_gil_not_used()) {
104104
m.doc() = "MLIR PDL dialect.";
105105
populateDialectPDLSubmodule(m);
106106
}

mlir/lib/Bindings/Python/DialectQuant.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static void populateDialectQuantSubmodule(const py::module &m) {
307307
});
308308
}
309309

310-
PYBIND11_MODULE(_mlirDialectsQuant, m) {
310+
PYBIND11_MODULE(_mlirDialectsQuant, m, py::mod_gil_not_used()) {
311311
m.doc() = "MLIR Quantization dialect";
312312

313313
populateDialectQuantSubmodule(m);

mlir/lib/Bindings/Python/DialectSparseTensor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static void populateDialectSparseTensorSubmodule(const py::module &m) {
142142
});
143143
}
144144

145-
PYBIND11_MODULE(_mlirDialectsSparseTensor, m) {
145+
PYBIND11_MODULE(_mlirDialectsSparseTensor, m, py::mod_gil_not_used()) {
146146
m.doc() = "MLIR SparseTensor dialect.";
147147
populateDialectSparseTensorSubmodule(m);
148148
}

mlir/lib/Bindings/Python/DialectTransform.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void populateDialectTransformSubmodule(const pybind11::module &m) {
117117
"Get the type this ParamType is associated with.");
118118
}
119119

120-
PYBIND11_MODULE(_mlirDialectsTransform, m) {
120+
PYBIND11_MODULE(_mlirDialectsTransform, m, py::mod_gil_not_used()) {
121121
m.doc() = "MLIR Transform dialect.";
122122
populateDialectTransformSubmodule(m);
123123
}

mlir/lib/Bindings/Python/ExecutionEngineModule.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class PyExecutionEngine {
6464
} // namespace
6565

6666
/// Create the `mlir.execution_engine` module here.
67-
PYBIND11_MODULE(_mlirExecutionEngine, m) {
67+
PYBIND11_MODULE(_mlirExecutionEngine, m, py::mod_gil_not_used()) {
6868
m.doc() = "MLIR Execution Engine";
6969

7070
//----------------------------------------------------------------------------

mlir/lib/Bindings/Python/GPUPasses.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
#include <pybind11/detail/common.h>
1212
#include <pybind11/pybind11.h>
1313

14+
namespace py = pybind11;
15+
1416
// -----------------------------------------------------------------------------
1517
// Module initialization.
1618
// -----------------------------------------------------------------------------
1719

18-
PYBIND11_MODULE(_mlirGPUPasses, m) {
20+
PYBIND11_MODULE(_mlirGPUPasses, m, py::mod_gil_not_used()) {
1921
m.doc() = "MLIR GPU Dialect Passes";
2022

2123
// Register all GPU passes on load.

mlir/lib/Bindings/Python/LinalgPasses.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010

1111
#include <pybind11/pybind11.h>
1212

13+
namespace py = pybind11;
14+
1315
// -----------------------------------------------------------------------------
1416
// Module initialization.
1517
// -----------------------------------------------------------------------------
1618

17-
PYBIND11_MODULE(_mlirLinalgPasses, m) {
19+
PYBIND11_MODULE(_mlirLinalgPasses, m, py::mod_gil_not_used()) {
1820
m.doc() = "MLIR Linalg Dialect Passes";
1921

2022
// Register all Linalg passes on load.

mlir/lib/Bindings/Python/MainModule.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using namespace mlir::python;
2222
// Module initialization.
2323
// -----------------------------------------------------------------------------
2424

25-
PYBIND11_MODULE(_mlir, m) {
25+
PYBIND11_MODULE(_mlir, m, py::mod_gil_not_used()) {
2626
m.doc() = "MLIR Python Native Extension";
2727

2828
py::class_<PyGlobals>(m, "_Globals", py::module_local())

mlir/lib/Bindings/Python/RegisterEverything.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "mlir-c/RegisterEverything.h"
1010
#include "mlir/Bindings/Python/PybindAdaptors.h"
1111

12-
PYBIND11_MODULE(_mlirRegisterEverything, m) {
12+
PYBIND11_MODULE(_mlirRegisterEverything, m, py::mod_gil_not_used()) {
1313
m.doc() = "MLIR All Upstream Dialects, Translations and Passes Registration";
1414

1515
m.def("register_dialects", [](MlirDialectRegistry registry) {

mlir/lib/Bindings/Python/SparseTensorPasses.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010

1111
#include <pybind11/pybind11.h>
1212

13+
namespace py = pybind11;
14+
1315
// -----------------------------------------------------------------------------
1416
// Module initialization.
1517
// -----------------------------------------------------------------------------
1618

17-
PYBIND11_MODULE(_mlirSparseTensorPasses, m) {
19+
PYBIND11_MODULE(_mlirSparseTensorPasses, m, py::mod_gil_not_used()) {
1820
m.doc() = "MLIR SparseTensor Dialect Passes";
1921

2022
// Register all SparseTensor passes on load.

mlir/lib/Bindings/Python/TransformInterpreter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static void populateTransformInterpreterSubmodule(py::module &m) {
9999
py::arg("target"), py::arg("other"));
100100
}
101101

102-
PYBIND11_MODULE(_mlirTransformInterpreter, m) {
102+
PYBIND11_MODULE(_mlirTransformInterpreter, m, py::mod_gil_not_used()) {
103103
m.doc() = "MLIR Transform dialect interpreter functionality.";
104104
populateTransformInterpreterSubmodule(m);
105105
}

mlir/python/requirements.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
numpy>=1.19.5, <=1.26
2-
pybind11>=2.9.0, <=2.10.3
1+
numpy>=1.19.5, <3.0
2+
# pybind11>=2.14.0, <2.15.0
3+
# Temporarily set pybind11 version to master waiting the next release to 2.13.6
4+
pybind11 @ git+https://github.com/pybind/pybind11@master
35
PyYAML>=5.4.0, <=6.0.1
4-
ml_dtypes>=0.1.0, <=0.4.0 # provides several NumPy dtype extensions, including the bf16
6+
ml_dtypes>=0.5.0, <=0.6.0 # provides several NumPy dtype extensions, including the bf16

0 commit comments

Comments
 (0)