mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 03:55:04 -05:00
current CAPI of CompilerEngine isn't really a CAPI. It's initial need was for the python bindings to have access to the CompilerEngine through a convenient API. So we now make a clear separation of CAPI and python wrappers. So we now have wrappers functions, that can be implemented using C/C++, and will be exposed to python via pybind11. And we have a CAPI (still need fixing as it still contains C++ code), that can be used as is, or to build bindings for other languages (such as Rust).
49 lines
1.9 KiB
C++
49 lines
1.9 KiB
C++
// Part of the Concrete Compiler Project, under the BSD3 License with Zama
|
|
// Exceptions. See
|
|
// https://github.com/zama-ai/concrete-compiler-internal/blob/main/LICENSE.txt
|
|
// for license information.
|
|
|
|
#include "concretelang-c/Dialect/FHE.h"
|
|
#include "concretelang-c/Dialect/FHELinalg.h"
|
|
#include "concretelang/Bindings/Python/CompilerAPIModule.h"
|
|
#include "concretelang/Bindings/Python/DialectModules.h"
|
|
#include "concretelang/Support/Constants.h"
|
|
#include "mlir-c/Bindings/Python/Interop.h"
|
|
#include "mlir-c/Registration.h"
|
|
#include "mlir/Bindings/Python/PybindAdaptors.h"
|
|
|
|
#include "llvm-c/ErrorHandling.h"
|
|
#include "llvm/Support/Signals.h"
|
|
|
|
#include <pybind11/pybind11.h>
|
|
namespace py = pybind11;
|
|
|
|
PYBIND11_MODULE(_concretelang, m) {
|
|
m.doc() = "Concretelang 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 Concretelang dialects to register.
|
|
MlirDialectHandle fhe = mlirGetDialectHandle__fhe__();
|
|
mlirDialectHandleRegisterDialect(fhe, context);
|
|
mlirDialectHandleLoadDialect(fhe, context);
|
|
MlirDialectHandle fhelinalg = mlirGetDialectHandle__fhelinalg__();
|
|
mlirDialectHandleRegisterDialect(fhelinalg, context);
|
|
mlirDialectHandleLoadDialect(fhelinalg, context);
|
|
},
|
|
"Register Concretelang dialects on a PyMlirContext.");
|
|
|
|
py::module fhe = m.def_submodule("_fhe", "FHE API");
|
|
mlir::concretelang::python::populateDialectFHESubmodule(fhe);
|
|
|
|
py::module api = m.def_submodule("_compiler", "Compiler API");
|
|
mlir::concretelang::python::populateCompilerAPISubmodule(api);
|
|
}
|