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).
38 lines
1.3 KiB
C++
38 lines
1.3 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/Bindings/Python/DialectModules.h"
|
|
|
|
#include "mlir-c/BuiltinAttributes.h"
|
|
#include "mlir/Bindings/Python/PybindAdaptors.h"
|
|
#include "mlir/IR/Diagnostics.h"
|
|
#include "llvm/ADT/SmallString.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <pybind11/pybind11.h>
|
|
#include <pybind11/pytypes.h>
|
|
#include <pybind11/stl.h>
|
|
|
|
using namespace mlir::concretelang;
|
|
using namespace mlir::python::adaptors;
|
|
|
|
/// Populate the fhe python module.
|
|
void mlir::concretelang::python::populateDialectFHESubmodule(
|
|
pybind11::module &m) {
|
|
m.doc() = "FHE dialect Python native extension";
|
|
|
|
mlir_type_subclass(m, "EncryptedIntegerType", fheTypeIsAnEncryptedIntegerType)
|
|
.def_classmethod("get", [](pybind11::object cls, MlirContext ctx,
|
|
unsigned width) {
|
|
MlirTypeOrError typeOrError =
|
|
fheEncryptedIntegerTypeGetChecked(ctx, width);
|
|
if (typeOrError.isError) {
|
|
throw std::invalid_argument("can't create eint with the given width");
|
|
}
|
|
return cls(typeOrError.type);
|
|
});
|
|
}
|