mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 12:15:09 -05:00
feat(compiler): Python bindings (#53)
- feat(compiler): python bindings - build: update docker image for python bindings - pin pybind11 to 2.6.2, 2.7 is not having correct include_dirs set (still a question why?) - using generated parser/printer
This commit is contained in:
35
compiler/python/ZamalangModule.cpp
Normal file
35
compiler/python/ZamalangModule.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "DialectModules.h"
|
||||
|
||||
#include "mlir-c/Bindings/Python/Interop.h"
|
||||
#include "mlir-c/Registration.h"
|
||||
#include "mlir/Bindings/Python/PybindAdaptors.h"
|
||||
#include "zamalang-c/Dialect/HLFHE.h"
|
||||
|
||||
#include "llvm-c/ErrorHandling.h"
|
||||
#include "llvm/Support/Signals.h"
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
namespace py = pybind11;
|
||||
|
||||
PYBIND11_MODULE(_zamalang, m) {
|
||||
m.doc() = "Zamalang Python Native Extension";
|
||||
llvm::sys::PrintStackTraceOnErrorSignal(/*argv=*/"");
|
||||
LLVMEnablePrettyStackTrace();
|
||||
|
||||
m.def(
|
||||
"register_dialects",
|
||||
[](py::object capsule) {
|
||||
// Get the MlirContext capsule from PyMlirContext capsule.
|
||||
auto wrappedCapsule = capsule.attr(MLIR_PYTHON_CAPI_PTR_ATTR);
|
||||
MlirContext context = mlirPythonCapsuleToContext(wrappedCapsule.ptr());
|
||||
|
||||
// Collect Zamalang dialects to register.
|
||||
MlirDialectHandle hlfhe = mlirGetDialectHandle__hlfhe__();
|
||||
mlirDialectHandleRegisterDialect(hlfhe, context);
|
||||
mlirDialectHandleLoadDialect(hlfhe, context);
|
||||
},
|
||||
"Register Zamalang dialects on a PyMlirContext.");
|
||||
|
||||
py::module hlfhe = m.def_submodule("_hlfhe", "HLFHE API");
|
||||
zamalang::python::populateDialectHLFHESubmodule(hlfhe);
|
||||
}
|
||||
Reference in New Issue
Block a user