Issue |
90795
|
Summary |
[Python Binding] error while printing a python generated module in c++
|
Labels |
new issue
|
Assignees |
|
Reporter |
ravil-mobile
|
Hi all,
I would like to build a small EDSL. The idea is to have the dsl frontend in python and handle lowering in c++.
Here is a small example:
```python
from mlir.ir import Context, Module, get_dialect_registry
from mlir.ir import InsertionPoint, Location, F32Type
from mlir.dialects import func, arith
from mlir.dialects import arith
from edsl_cpp import entry
def main():
registry = get_dialect_registry()
context = Context()
context.append_dialect_registry(registry)
module = None
with context:
module = Module.create(Location.unknown())
with InsertionPoint(module.body), Location.unknown():
fp_type = F32Type.get()
function = func.FuncOp("test", ([fp_type, fp_type, fp_type], [fp_type]))
with InsertionPoint(function.add_entry_block()) as block:
_one_ = function.arguments[0]
two = function.arguments[1]
mult_res = arith.MulFOp(one, two)
three = function.arguments[2]
res = arith.AddFOp(mult_res, three)
func.ReturnOp([res])
entry(module._CAPIPtr)
if __name__ == "__main__":
main()
```
```cpp
#include <pybind11/pybind11.h>
#include "mlir/CAPI/IR.h"
#include "mlir-c/IR.h"
#include "mlir-c/RegisterEverything.h"
#include "mlir-c/Bindings/Python/Interop.h"
#include "mlir/CAPI/Support.h"
#include <stdexcept>
PYBIND11_MODULE(edsl_cpp, m) {
m.doc() = "edsl python bindings";
m.def("entry", [](pybind11::object capsule){
MlirModule mlirModule = mlirPythonCapsuleToModule(capsule.ptr());
if (mlirModuleIsNull(mlirModule)) {
throw std::runtime_error("empty module");
}
MlirContext context = mlirModuleGetContext(mlirModule);
if (mlirContextIsNull(context)) {
throw std::runtime_error("empty context");
}
auto module = unwrap(mlirModule);
mlir::AsmState state(module);
module->dump();
});
}
```
If necessary, I can share the whole source code. Anyway, when I am executing the python script I get the following error:
```bash
dialect has no registered type printing hook
UNREACHABLE executed at <path-to-llvm>/llvm-project/mlir/include/mlir/IR/Dialect.h:111!
```
Does anybody have an idea what is missing in my example?
I can dump a module in python without any problem by something is wrong in the cpp-part.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs