Skip to content

Commit

Permalink
Added free-threading CPython mode support in Python bindings
Browse files Browse the repository at this point in the history
- temporarily updated requirements
  • Loading branch information
vfdev-5 committed Sep 18, 2024
1 parent 43c9203 commit 4496221
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 19 deletions.
4 changes: 3 additions & 1 deletion mlir/lib/Bindings/Python/AsyncPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#include <pybind11/detail/common.h>
#include <pybind11/pybind11.h>

namespace py = pybind11;

// -----------------------------------------------------------------------------
// Module initialization.
// -----------------------------------------------------------------------------

PYBIND11_MODULE(_mlirAsyncPasses, m) {
PYBIND11_MODULE(_mlirAsyncPasses, m, py::mod_gil_not_used()) {
m.doc() = "MLIR Async Dialect Passes";

// Register all Async passes on load.
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Bindings/Python/DialectGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using namespace mlir::python::adaptors;
// Module initialization.
// -----------------------------------------------------------------------------

PYBIND11_MODULE(_mlirDialectsGPU, m) {
PYBIND11_MODULE(_mlirDialectsGPU, m, py::mod_gil_not_used()) {
m.doc() = "MLIR GPU Dialect";
//===-------------------------------------------------------------------===//
// AsyncTokenType
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Bindings/Python/DialectLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void populateDialectLLVMSubmodule(const pybind11::module &m) {
});
}

PYBIND11_MODULE(_mlirDialectsLLVM, m) {
PYBIND11_MODULE(_mlirDialectsLLVM, m, py::mod_gil_not_used()) {
m.doc() = "MLIR LLVM Dialect";

populateDialectLLVMSubmodule(m);
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Bindings/Python/DialectLinalg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void populateDialectLinalgSubmodule(py::module m) {
"op.");
}

PYBIND11_MODULE(_mlirDialectsLinalg, m) {
PYBIND11_MODULE(_mlirDialectsLinalg, m, py::mod_gil_not_used()) {
m.doc() = "MLIR Linalg dialect.";

populateDialectLinalgSubmodule(m);
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Bindings/Python/DialectNVGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void populateDialectNVGPUSubmodule(const pybind11::module &m) {
py::arg("ctx") = py::none());
}

PYBIND11_MODULE(_mlirDialectsNVGPU, m) {
PYBIND11_MODULE(_mlirDialectsNVGPU, m, py::mod_gil_not_used()) {
m.doc() = "MLIR NVGPU dialect.";

populateDialectNVGPUSubmodule(m);
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Bindings/Python/DialectPDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void populateDialectPDLSubmodule(const pybind11::module &m) {
py::arg("context") = py::none());
}

PYBIND11_MODULE(_mlirDialectsPDL, m) {
PYBIND11_MODULE(_mlirDialectsPDL, m, py::mod_gil_not_used()) {
m.doc() = "MLIR PDL dialect.";
populateDialectPDLSubmodule(m);
}
2 changes: 1 addition & 1 deletion mlir/lib/Bindings/Python/DialectQuant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ static void populateDialectQuantSubmodule(const py::module &m) {
});
}

PYBIND11_MODULE(_mlirDialectsQuant, m) {
PYBIND11_MODULE(_mlirDialectsQuant, m, py::mod_gil_not_used()) {
m.doc() = "MLIR Quantization dialect";

populateDialectQuantSubmodule(m);
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Bindings/Python/DialectSparseTensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static void populateDialectSparseTensorSubmodule(const py::module &m) {
});
}

PYBIND11_MODULE(_mlirDialectsSparseTensor, m) {
PYBIND11_MODULE(_mlirDialectsSparseTensor, m, py::mod_gil_not_used()) {
m.doc() = "MLIR SparseTensor dialect.";
populateDialectSparseTensorSubmodule(m);
}
2 changes: 1 addition & 1 deletion mlir/lib/Bindings/Python/DialectTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void populateDialectTransformSubmodule(const pybind11::module &m) {
"Get the type this ParamType is associated with.");
}

PYBIND11_MODULE(_mlirDialectsTransform, m) {
PYBIND11_MODULE(_mlirDialectsTransform, m, py::mod_gil_not_used()) {
m.doc() = "MLIR Transform dialect.";
populateDialectTransformSubmodule(m);
}
2 changes: 1 addition & 1 deletion mlir/lib/Bindings/Python/ExecutionEngineModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class PyExecutionEngine {
} // namespace

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

//----------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion mlir/lib/Bindings/Python/GPUPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#include <pybind11/detail/common.h>
#include <pybind11/pybind11.h>

namespace py = pybind11;

// -----------------------------------------------------------------------------
// Module initialization.
// -----------------------------------------------------------------------------

PYBIND11_MODULE(_mlirGPUPasses, m) {
PYBIND11_MODULE(_mlirGPUPasses, m, py::mod_gil_not_used()) {
m.doc() = "MLIR GPU Dialect Passes";

// Register all GPU passes on load.
Expand Down
4 changes: 3 additions & 1 deletion mlir/lib/Bindings/Python/LinalgPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

#include <pybind11/pybind11.h>

namespace py = pybind11;

// -----------------------------------------------------------------------------
// Module initialization.
// -----------------------------------------------------------------------------

PYBIND11_MODULE(_mlirLinalgPasses, m) {
PYBIND11_MODULE(_mlirLinalgPasses, m, py::mod_gil_not_used()) {
m.doc() = "MLIR Linalg Dialect Passes";

// Register all Linalg passes on load.
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Bindings/Python/MainModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using namespace mlir::python;
// Module initialization.
// -----------------------------------------------------------------------------

PYBIND11_MODULE(_mlir, m) {
PYBIND11_MODULE(_mlir, m, py::mod_gil_not_used()) {
m.doc() = "MLIR Python Native Extension";

py::class_<PyGlobals>(m, "_Globals", py::module_local())
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Bindings/Python/RegisterEverything.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "mlir-c/RegisterEverything.h"
#include "mlir/Bindings/Python/PybindAdaptors.h"

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

m.def("register_dialects", [](MlirDialectRegistry registry) {
Expand Down
4 changes: 3 additions & 1 deletion mlir/lib/Bindings/Python/SparseTensorPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

#include <pybind11/pybind11.h>

namespace py = pybind11;

// -----------------------------------------------------------------------------
// Module initialization.
// -----------------------------------------------------------------------------

PYBIND11_MODULE(_mlirSparseTensorPasses, m) {
PYBIND11_MODULE(_mlirSparseTensorPasses, m, py::mod_gil_not_used()) {
m.doc() = "MLIR SparseTensor Dialect Passes";

// Register all SparseTensor passes on load.
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Bindings/Python/TransformInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void populateTransformInterpreterSubmodule(py::module &m) {
py::arg("target"), py::arg("other"));
}

PYBIND11_MODULE(_mlirTransformInterpreter, m) {
PYBIND11_MODULE(_mlirTransformInterpreter, m, py::mod_gil_not_used()) {
m.doc() = "MLIR Transform dialect interpreter functionality.";
populateTransformInterpreterSubmodule(m);
}
8 changes: 5 additions & 3 deletions mlir/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
numpy>=1.19.5, <=1.26
pybind11>=2.9.0, <=2.10.3
numpy>=1.19.5, <3.0
# pybind11>=2.14.0, <2.15.0
# Temporarily set pybind11 version to master waiting the next release to 2.13.6
pybind11 @ git+https://github.com/pybind/pybind11@master
PyYAML>=5.4.0, <=6.0.1
ml_dtypes>=0.1.0, <=0.4.0 # provides several NumPy dtype extensions, including the bf16
ml_dtypes>=0.5.0, <=0.6.0 # provides several NumPy dtype extensions, including the bf16

0 comments on commit 4496221

Please sign in to comment.