-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[MLIR][Python][NOMERGE] demo building bindings with no bundled CAPI aggregate and using other bindings aggregate #161782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,5 @@ add_mlir_dialect_library(MLIRStandalone | |
DEPENDS | ||
MLIRStandaloneOpsIncGen | ||
MLIRStandalonePassesIncGen | ||
|
||
LINK_LIBS PUBLIC | ||
MLIRIR | ||
MLIRInferTypeOpInterface | ||
MLIRFuncDialect | ||
) | ||
target_link_options(obj.MLIRStandalone PUBLIC --unresolved-symbols=ignore-all) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to build without failing to link and instead hope the symbols are found at runtime... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=mlir.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to set |
||
|
||
declare_mlir_python_sources(StandReallyAlonePythonSources) | ||
declare_mlir_dialect_python_bindings( | ||
ADD_TO_PARENT StandReallyAlonePythonSources | ||
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir_standreallyalone" | ||
SOURCES | ||
dialects/standalonereallyalone.py | ||
dialects/_ods_common.py | ||
) | ||
|
||
declare_mlir_python_extension(StandReallyAlonePythonSources.NanobindExtension | ||
MODULE_NAME _standReallyAloneDialectsNanobind | ||
ADD_TO_PARENT StandReallyAlonePythonSources | ||
SOURCES | ||
StandReallyAloneExtensionNanobind.cpp | ||
PRIVATE_LINK_LIBS | ||
StandaloneCAPI | ||
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to fully link |
||
PYTHON_BINDINGS_LIBRARY nanobind | ||
) | ||
|
||
set(StandReallyAlonePythonModules_ROOT_PREFIX "${MLIR_BINARY_DIR}/${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}") | ||
add_mlir_python_modules(StandReallyAlonePythonModules | ||
ROOT_PREFIX "${StandReallyAlonePythonModules_ROOT_PREFIX}/../mlir_standreallyalone" | ||
INSTALL_PREFIX "${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}/../mlir_standreallyalone" | ||
DECLARED_SOURCES | ||
StandReallyAlonePythonSources | ||
StandReallyAlonePythonSources.NanobindExtension | ||
StandalonePythonSources.standalone.ops_gen | ||
StandalonePythonSources.standalone.tablegen | ||
MLIRPythonSources.Dialects.builtin | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//===- StandaloneExtension.cpp - Extension module -------------------------===// | ||
// | ||
// This is the nanobind version of the example module. There is also a pybind11 | ||
// example in StandaloneExtensionPybind11.cpp. | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "Standalone-c/Dialects.h" | ||
#include "mlir-c/Dialect/Arith.h" | ||
#include "mlir/Bindings/Python/Nanobind.h" | ||
#include "mlir/Bindings/Python/NanobindAdaptors.h" | ||
|
||
namespace nb = nanobind; | ||
|
||
NB_MODULE(_standReallyAloneDialectsNanobind, m) { | ||
//===--------------------------------------------------------------------===// | ||
// standalone dialect | ||
//===--------------------------------------------------------------------===// | ||
auto standaloneM = m.def_submodule("standalone"); | ||
|
||
standaloneM.def( | ||
"register_dialects", | ||
[](MlirContext context, bool load) { | ||
MlirDialectHandle arithHandle = mlirGetDialectHandle__arith__(); | ||
MlirDialectHandle standaloneHandle = | ||
mlirGetDialectHandle__standalone__(); | ||
mlirDialectHandleRegisterDialect(arithHandle, context); | ||
mlirDialectHandleRegisterDialect(standaloneHandle, context); | ||
if (load) { | ||
mlirDialectHandleLoadDialect(arithHandle, context); | ||
mlirDialectHandleRegisterDialect(standaloneHandle, context); | ||
} | ||
}, | ||
nb::arg("context").none() = nb::none(), nb::arg("load") = true, | ||
// clang-format off | ||
nb::sig("def register_dialects(context: " MAKE_MLIR_PYTHON_QUALNAME("ir.Context") ", load: bool = True) -> None") | ||
// clang-format on | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove so that the code can be "looked up" in
libMLIRPythonCAPI.so
at runtime.