Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions mlir/examples/standalone/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ declare_mlir_python_extension(StandalonePythonSources.Pybind11Extension
StandaloneExtensionPybind11.cpp
EMBED_CAPI_LINK_LIBS
StandaloneCAPI
MLIRCAPITransforms
MLIRCAPIArith
PYTHON_BINDINGS_LIBRARY pybind11
)

Expand All @@ -38,6 +40,8 @@ declare_mlir_python_extension(StandalonePythonSources.NanobindExtension
StandaloneExtensionNanobind.cpp
EMBED_CAPI_LINK_LIBS
StandaloneCAPI
MLIRCAPITransforms
MLIRCAPIArith
PYTHON_BINDINGS_LIBRARY nanobind
GENERATE_TYPE_STUBS
)
Expand All @@ -54,9 +58,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
)
Expand All @@ -70,9 +71,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
Expand Down
13 changes: 9 additions & 4 deletions mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//===----------------------------------------------------------------------===//

#include "Standalone-c/Dialects.h"
#include "mlir-c/Dialect/Arith.h"
#include "mlir/Bindings/Python/Nanobind.h"
#include "mlir/Bindings/Python/NanobindAdaptors.h"

Expand All @@ -22,12 +23,16 @@ NB_MODULE(_standaloneDialectsNanobind, 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);
mlirDialectHandleLoadDialect(standaloneHandle, context);
mlirDialectHandleLoadDialect(arithHandle, context);
}
},
nb::arg("context").none() = nb::none(), nb::arg("load") = true);
Expand Down
13 changes: 9 additions & 4 deletions mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,12 +22,16 @@ 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);
mlirDialectHandleLoadDialect(standaloneHandle, context);
mlirDialectHandleLoadDialect(arithHandle, context);
}
},
py::arg("context") = py::none(), py::arg("load") = true);
Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/standalone/test/python/smoketest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


with Context():
standalone_d.register_dialect()
standalone_d.register_dialects()
module = Module.parse(
"""
%0 = arith.constant 2 : i32
Expand Down
Loading