refactor(python): rework the bindings with latest MLIR version

- Go through CAPI for python bindings
- Consuming LLVM errors in CAPI: fixes previous issue which made this
  impossible in the python bindings
This commit is contained in:
youben11
2021-09-24 15:23:19 +01:00
committed by Ayoub Benaissa
parent 3406b322d5
commit 2972fa4403
24 changed files with 366 additions and 255 deletions

View File

@@ -11,14 +11,29 @@ def main():
zamalang.register_dialects(ctx)
module = Module.create()
eint16 = hlfhe.EncryptedIntegerType.get(ctx, 16)
eint6 = hlfhe.EncryptedIntegerType.get(ctx, 6)
with InsertionPoint(module.body):
func_types = [RankedTensorType.get((10, 10), eint16) for _ in range(2)]
func_types = [MemRefType.get((10, 10), eint6) for _ in range(2)]
@builtin.FuncOp.from_py_func(*func_types)
def fhe_circuit(*arg):
def main(*arg):
return arg[0]
print(module)
m = """
func @main(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> {
%0 = constant 1 : i3
%1 = "HLFHE.add_eint_int"(%arg0, %0): (!HLFHE.eint<2>, i3) -> (!HLFHE.eint<2>)
return %1: !HLFHE.eint<2>
}"""
## Working when HFLFHE and MLIR aren't linked
zamalang.compiler.round_trip("module{}")
zamalang.compiler.round_trip(str(module))
## END OF WORKING
## Doesn't work yet for both modules
engine = zamalang.CompilerEngine()
engine.compile_fhe(m)
# engine.compile_fhe(str(module))
print(engine.run(2))
if __name__ == "__main__":