From 0ab91593df8a9ca5df6ccd7b9e25c7f087603cdb Mon Sep 17 00:00:00 2001 From: Maksim Levental Date: Tue, 9 Sep 2025 10:09:44 -0500 Subject: [PATCH 1/7] [MLIR][Standalone] don't register everything We only need to register `builtin`. --- mlir/examples/standalone/python/CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mlir/examples/standalone/python/CMakeLists.txt b/mlir/examples/standalone/python/CMakeLists.txt index cb10518e94e33..33e2640300043 100644 --- a/mlir/examples/standalone/python/CMakeLists.txt +++ b/mlir/examples/standalone/python/CMakeLists.txt @@ -54,9 +54,6 @@ add_mlir_python_common_capi_library(StandalonePythonCAPI RELATIVE_INSTALL_ROOT "../../../.." DECLARED_SOURCES StandalonePythonSources - # TODO: Remove this in favor of showing fine grained registration once - # available. - MLIRPythonExtension.RegisterEverything MLIRPythonSources.Core MLIRPythonSources.Dialects.builtin ) @@ -70,9 +67,6 @@ add_mlir_python_modules(StandalonePythonModules INSTALL_PREFIX "${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}" DECLARED_SOURCES StandalonePythonSources - # TODO: Remove this in favor of showing fine grained registration once - # available. - MLIRPythonExtension.RegisterEverything MLIRPythonSources.Core MLIRPythonSources.Dialects.builtin COMMON_CAPI_LINK_LIBS From ef55a39efe518b05b543cf905c576ef3eeb9e143 Mon Sep 17 00:00:00 2001 From: Maksim Levental Date: Tue, 9 Sep 2025 08:21:19 -0700 Subject: [PATCH 2/7] Update CMakeLists.txt --- mlir/examples/standalone/python/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mlir/examples/standalone/python/CMakeLists.txt b/mlir/examples/standalone/python/CMakeLists.txt index 33e2640300043..2c6a2ffde10b7 100644 --- a/mlir/examples/standalone/python/CMakeLists.txt +++ b/mlir/examples/standalone/python/CMakeLists.txt @@ -28,6 +28,7 @@ declare_mlir_python_extension(StandalonePythonSources.Pybind11Extension StandaloneExtensionPybind11.cpp EMBED_CAPI_LINK_LIBS StandaloneCAPI + MLIRCAPITransforms PYTHON_BINDINGS_LIBRARY pybind11 ) @@ -38,6 +39,7 @@ declare_mlir_python_extension(StandalonePythonSources.NanobindExtension StandaloneExtensionNanobind.cpp EMBED_CAPI_LINK_LIBS StandaloneCAPI + MLIRCAPITransforms PYTHON_BINDINGS_LIBRARY nanobind GENERATE_TYPE_STUBS ) From a9af4175818437564c599d1cf201e5e261cb8c69 Mon Sep 17 00:00:00 2001 From: Maksim Levental Date: Tue, 9 Sep 2025 08:58:59 -0700 Subject: [PATCH 3/7] Update StandaloneExtensionNanobind.cpp --- .../standalone/python/StandaloneExtensionNanobind.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp index 189ebac368bf5..aad44dc7f2137 100644 --- a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp +++ b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp @@ -12,6 +12,7 @@ #include "Standalone-c/Dialects.h" #include "mlir/Bindings/Python/Nanobind.h" #include "mlir/Bindings/Python/NanobindAdaptors.h" +#include "mlir-c/Dialect/Arith.h namespace nb = nanobind; @@ -22,9 +23,10 @@ NB_MODULE(_standaloneDialectsNanobind, m) { auto standaloneM = m.def_submodule("standalone"); standaloneM.def( - "register_dialect", + "register_dialects", [](MlirContext context, bool load) { - MlirDialectHandle handle = mlirGetDialectHandle__standalone__(); + MlirDialectHandle standaloneHandle = mlirGetDialectHandle__standalone__(); + MlirDialectHandle arithHandle = mlirGetDialectHandle__arith__(); mlirDialectHandleRegisterDialect(handle, context); if (load) { mlirDialectHandleLoadDialect(handle, context); From a039b2807265fbdfd436191cd8944d943135d47b Mon Sep 17 00:00:00 2001 From: Maksim Levental Date: Tue, 9 Sep 2025 08:59:52 -0700 Subject: [PATCH 4/7] Update StandaloneExtensionPybind11.cpp --- .../standalone/python/StandaloneExtensionPybind11.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp b/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp index 397db4c20e743..02f23d758c44f 100644 --- a/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp +++ b/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp @@ -10,6 +10,7 @@ //===----------------------------------------------------------------------===// #include "Standalone-c/Dialects.h" +#include "mlir-c/Dialect/Arith.h #include "mlir/Bindings/Python/PybindAdaptors.h" using namespace mlir::python::adaptors; @@ -21,10 +22,12 @@ PYBIND11_MODULE(_standaloneDialectsPybind11, m) { auto standaloneM = m.def_submodule("standalone"); standaloneM.def( - "register_dialect", + "register_dialects", [](MlirContext context, bool load) { - MlirDialectHandle handle = mlirGetDialectHandle__standalone__(); - mlirDialectHandleRegisterDialect(handle, context); + MlirDialectHandle standaloneHandle = mlirGetDialectHandle__standalone__(); + MlirDialectHandle arithHandle = mlirGetDialectHandle__arith__(); + mlirDialectHandleRegisterDialect(standaloneHandle, context); + mlirDialectHandleRegisterDialect(arithHandle, context); if (load) { mlirDialectHandleLoadDialect(handle, context); } From 7df2c4af60793d2ff77de78aef60333eab25beaf Mon Sep 17 00:00:00 2001 From: Maksim Levental Date: Tue, 9 Sep 2025 09:00:06 -0700 Subject: [PATCH 5/7] Update StandaloneExtensionNanobind.cpp --- .../examples/standalone/python/StandaloneExtensionNanobind.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp index aad44dc7f2137..3dc067377f32f 100644 --- a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp +++ b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp @@ -27,7 +27,8 @@ NB_MODULE(_standaloneDialectsNanobind, m) { [](MlirContext context, bool load) { MlirDialectHandle standaloneHandle = mlirGetDialectHandle__standalone__(); MlirDialectHandle arithHandle = mlirGetDialectHandle__arith__(); - mlirDialectHandleRegisterDialect(handle, context); + mlirDialectHandleRegisterDialect(standaloneHandle, context); + mlirDialectHandleRegisterDialect(arithHandle, context); if (load) { mlirDialectHandleLoadDialect(handle, context); } From 926dba3b88bc3152c4654ba72d73416a184892f0 Mon Sep 17 00:00:00 2001 From: Maksim Levental Date: Tue, 9 Sep 2025 09:00:20 -0700 Subject: [PATCH 6/7] Update smoketest.py --- mlir/examples/standalone/test/python/smoketest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/examples/standalone/test/python/smoketest.py b/mlir/examples/standalone/test/python/smoketest.py index bd40c65d16164..6d41ecc11c540 100644 --- a/mlir/examples/standalone/test/python/smoketest.py +++ b/mlir/examples/standalone/test/python/smoketest.py @@ -14,7 +14,7 @@ with Context(): - standalone_d.register_dialect() + standalone_d.register_dialects() module = Module.parse( """ %0 = arith.constant 2 : i32 From b0d890a50496861954eceb2c39f457604df9b81b Mon Sep 17 00:00:00 2001 From: makslevental Date: Tue, 9 Sep 2025 09:06:45 -0700 Subject: [PATCH 7/7] reformat --- mlir/examples/standalone/python/CMakeLists.txt | 2 ++ .../standalone/python/StandaloneExtensionNanobind.cpp | 8 +++++--- .../standalone/python/StandaloneExtensionPybind11.cpp | 8 +++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mlir/examples/standalone/python/CMakeLists.txt b/mlir/examples/standalone/python/CMakeLists.txt index 2c6a2ffde10b7..4dc4f7ae0cff6 100644 --- a/mlir/examples/standalone/python/CMakeLists.txt +++ b/mlir/examples/standalone/python/CMakeLists.txt @@ -29,6 +29,7 @@ declare_mlir_python_extension(StandalonePythonSources.Pybind11Extension EMBED_CAPI_LINK_LIBS StandaloneCAPI MLIRCAPITransforms + MLIRCAPIArith PYTHON_BINDINGS_LIBRARY pybind11 ) @@ -40,6 +41,7 @@ declare_mlir_python_extension(StandalonePythonSources.NanobindExtension EMBED_CAPI_LINK_LIBS StandaloneCAPI MLIRCAPITransforms + MLIRCAPIArith PYTHON_BINDINGS_LIBRARY nanobind GENERATE_TYPE_STUBS ) diff --git a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp index 3dc067377f32f..63b49d03cb835 100644 --- a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp +++ b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp @@ -10,9 +10,9 @@ //===----------------------------------------------------------------------===// #include "Standalone-c/Dialects.h" +#include "mlir-c/Dialect/Arith.h" #include "mlir/Bindings/Python/Nanobind.h" #include "mlir/Bindings/Python/NanobindAdaptors.h" -#include "mlir-c/Dialect/Arith.h namespace nb = nanobind; @@ -25,12 +25,14 @@ NB_MODULE(_standaloneDialectsNanobind, m) { standaloneM.def( "register_dialects", [](MlirContext context, bool load) { - MlirDialectHandle standaloneHandle = mlirGetDialectHandle__standalone__(); + MlirDialectHandle standaloneHandle = + mlirGetDialectHandle__standalone__(); MlirDialectHandle arithHandle = mlirGetDialectHandle__arith__(); mlirDialectHandleRegisterDialect(standaloneHandle, context); mlirDialectHandleRegisterDialect(arithHandle, context); if (load) { - mlirDialectHandleLoadDialect(handle, context); + mlirDialectHandleLoadDialect(standaloneHandle, context); + mlirDialectHandleLoadDialect(arithHandle, context); } }, nb::arg("context").none() = nb::none(), nb::arg("load") = true); diff --git a/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp b/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp index 02f23d758c44f..88493f4f18f00 100644 --- a/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp +++ b/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp @@ -10,7 +10,7 @@ //===----------------------------------------------------------------------===// #include "Standalone-c/Dialects.h" -#include "mlir-c/Dialect/Arith.h +#include "mlir-c/Dialect/Arith.h" #include "mlir/Bindings/Python/PybindAdaptors.h" using namespace mlir::python::adaptors; @@ -24,12 +24,14 @@ PYBIND11_MODULE(_standaloneDialectsPybind11, m) { standaloneM.def( "register_dialects", [](MlirContext context, bool load) { - MlirDialectHandle standaloneHandle = mlirGetDialectHandle__standalone__(); + MlirDialectHandle standaloneHandle = + mlirGetDialectHandle__standalone__(); MlirDialectHandle arithHandle = mlirGetDialectHandle__arith__(); mlirDialectHandleRegisterDialect(standaloneHandle, context); mlirDialectHandleRegisterDialect(arithHandle, context); if (load) { - mlirDialectHandleLoadDialect(handle, context); + mlirDialectHandleLoadDialect(standaloneHandle, context); + mlirDialectHandleLoadDialect(arithHandle, context); } }, py::arg("context") = py::none(), py::arg("load") = true);