mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-18 08:31:31 -05:00
This commit: + Adds support for a protocol which enables inter-op between concrete, tfhe-rs and potentially other contributors to the fhe ecosystem. + Gets rid of hand-made serialization in the compiler, and client/server libs. + Refactors client/server libs to allow more pre/post processing of circuit inputs/outputs. The protocol is supported by a definition in the shape of a capnp file, which defines different types of objects among which: + ProgramInfo object, which is a precise description of a set of fhe circuit coming from the same compilation (understand function type information), and the associated key set. + *Key objects, which represent secret/public keys used to encrypt/execute fhe circuits. + Value object, which represent values that can be transferred between client and server to support calls to fhe circuits. The hand-rolled serialization that was previously used is completely dropped in favor of capnp in the whole codebase. The client/server libs, are refactored to introduce a modular design for pre-post processing. Reading the ProgramInfo file associated with a compilation, the client and server libs assemble a pipeline of transformers (functions) for pre and post processing of values coming in and out of a circuit. This design properly decouples various aspects of the processing, and allows these capabilities to be safely extended. In practice this commit includes the following: + Defines the specification in a concreteprotocol package + Integrate the compilation of this package as a compiler dependency via cmake + Modify the compiler to use the Encodings objects defined in the protocol + Modify the compiler to emit ProgramInfo files as compilation artifact, and gets rid of the bloated ClientParameters. + Introduces a new Common library containing the functionalities shared between the compiler and the client/server libs. + Introduces a functional pre-post processing pipeline to this common library + Modify the client/server libs to support loading ProgramInfo objects, and calling circuits using Value messages. + Drops support of JIT. + Drops support of C-api. + Drops support of Rust bindings. Co-authored-by: Nikita Frolov <nf@mkmks.org>
74 lines
2.8 KiB
C++
74 lines
2.8 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/Bindings/Python/CompilerAPIModule.h"
|
|
#include "concretelang/Bindings/Python/DialectModules.h"
|
|
#include "concretelang/Dialect/FHE/IR/FHEDialect.h"
|
|
#include "concretelang/Dialect/FHELinalg/IR/FHELinalgDialect.h"
|
|
#include "concretelang/Dialect/Tracing/IR/TracingDialect.h"
|
|
#include "concretelang/Support/Constants.h"
|
|
#include "mlir-c/Bindings/Python/Interop.h"
|
|
#include "mlir-c/IR.h"
|
|
#include "mlir-c/RegisterEverything.h"
|
|
#include "mlir/Bindings/Python/PybindAdaptors.h"
|
|
#include "mlir/CAPI/Registration.h"
|
|
#include "mlir/IR/DialectRegistry.h"
|
|
|
|
#include "llvm-c/ErrorHandling.h"
|
|
#include "llvm/Support/Signals.h"
|
|
|
|
#include <pybind11/pybind11.h>
|
|
namespace py = pybind11;
|
|
|
|
using namespace mlir::concretelang::FHE;
|
|
using namespace mlir::concretelang::FHELinalg;
|
|
using namespace mlir::concretelang::Tracing;
|
|
|
|
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(FHE, fhe);
|
|
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(FHE, fhe, FHEDialect)
|
|
|
|
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(FHELinalg, fhelinalg);
|
|
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(FHELinalg, fhelinalg, FHELinalgDialect)
|
|
|
|
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(TRACING, tracing);
|
|
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Tracing, tracing, TracingDialect)
|
|
|
|
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);
|
|
const MlirContext context =
|
|
mlirPythonCapsuleToContext(wrappedCapsule.ptr());
|
|
|
|
const MlirDialectRegistry registry = mlirDialectRegistryCreate();
|
|
mlirRegisterAllDialects(registry);
|
|
mlirContextAppendDialectRegistry(context, registry);
|
|
|
|
const MlirDialectHandle fhe = mlirGetDialectHandle__fhe__();
|
|
mlirDialectHandleRegisterDialect(fhe, context);
|
|
|
|
const MlirDialectHandle fhelinalg = mlirGetDialectHandle__fhelinalg__();
|
|
mlirDialectHandleRegisterDialect(fhelinalg, context);
|
|
|
|
const MlirDialectHandle tracing = mlirGetDialectHandle__tracing__();
|
|
mlirDialectHandleRegisterDialect(tracing, context);
|
|
|
|
mlirContextLoadAllAvailableDialects(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);
|
|
}
|