[Mlir-commits] [mlir] 8dca953 - [mlir] Apply py::module_local() to a few more classes.

Sean Silva llvmlistbot at llvm.org
Tue Sep 14 15:26:43 PDT 2021


Author: Sean Silva
Date: 2021-09-14T21:56:14Z
New Revision: 8dca953dd39c0cd8c80decbeb38753f58a4de580

URL: https://github.com/llvm/llvm-project/commit/8dca953dd39c0cd8c80decbeb38753f58a4de580
DIFF: https://github.com/llvm/llvm-project/commit/8dca953dd39c0cd8c80decbeb38753f58a4de580.diff

LOG: [mlir] Apply py::module_local() to a few more classes.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D109776

Added: 
    

Modified: 
    mlir/lib/Bindings/Python/DialectSparseTensor.cpp
    mlir/lib/Bindings/Python/IRModule.h
    mlir/lib/Bindings/Python/PybindUtils.h

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
index faf240e1a6633..6afd0815de2ad 100644
--- a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
+++ b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
@@ -20,7 +20,7 @@ void mlir::python::populateDialectSparseTensorSubmodule(
     py::module m, const py::module &irModule) {
   auto attributeClass = irModule.attr("Attribute");
 
-  py::enum_<MlirSparseTensorDimLevelType>(m, "DimLevelType")
+  py::enum_<MlirSparseTensorDimLevelType>(m, "DimLevelType", py::module_local())
       .value("dense", MLIR_SPARSE_TENSOR_DIM_LEVEL_DENSE)
       .value("compressed", MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED)
       .value("singleton", MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON);

diff  --git a/mlir/lib/Bindings/Python/IRModule.h b/mlir/lib/Bindings/Python/IRModule.h
index 9d217c872191d..702870487d751 100644
--- a/mlir/lib/Bindings/Python/IRModule.h
+++ b/mlir/lib/Bindings/Python/IRModule.h
@@ -678,7 +678,8 @@ class PyConcreteAttribute : public BaseTy {
   }
 
   static void bind(pybind11::module &m) {
-    auto cls = ClassTy(m, DerivedTy::pyClassName, pybind11::buffer_protocol());
+    auto cls = ClassTy(m, DerivedTy::pyClassName, pybind11::buffer_protocol(),
+                       pybind11::module_local());
     cls.def(pybind11::init<PyAttribute &>(), pybind11::keep_alive<0, 1>());
     DerivedTy::bindDerived(cls);
   }
@@ -741,7 +742,7 @@ class PyConcreteType : public BaseTy {
   }
 
   static void bind(pybind11::module &m) {
-    auto cls = ClassTy(m, DerivedTy::pyClassName);
+    auto cls = ClassTy(m, DerivedTy::pyClassName, pybind11::module_local());
     cls.def(pybind11::init<PyType &>(), pybind11::keep_alive<0, 1>());
     cls.def_static("isinstance", [](PyType &otherType) -> bool {
       return DerivedTy::isaFunction(otherType);

diff  --git a/mlir/lib/Bindings/Python/PybindUtils.h b/mlir/lib/Bindings/Python/PybindUtils.h
index 7a9b8ecb9b019..9fecc7ce37af0 100644
--- a/mlir/lib/Bindings/Python/PybindUtils.h
+++ b/mlir/lib/Bindings/Python/PybindUtils.h
@@ -262,7 +262,8 @@ class Sliceable {
 
   /// Binds the indexing and length methods in the Python class.
   static void bind(pybind11::module &m) {
-    auto clazz = pybind11::class_<Derived>(m, Derived::pyClassName)
+    auto clazz = pybind11::class_<Derived>(m, Derived::pyClassName,
+                                           pybind11::module_local())
                      .def("__len__", &Sliceable::dunderLen)
                      .def("__getitem__", &Sliceable::dunderGetItem)
                      .def("__getitem__", &Sliceable::dunderGetItemSlice);


        


More information about the Mlir-commits mailing list