mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-08 19:44:57 -05:00
feat(concrete-compiler): add new ciphertext multiplication operator
This commit is contained in:
@@ -285,6 +285,44 @@ def FHE_MulEintIntOp : FHE_Op<"mul_eint_int", [NoSideEffect]> {
|
||||
let hasFolder = 1;
|
||||
}
|
||||
|
||||
def FHE_MulEintOp : FHE_Op<"mul_eint", [NoSideEffect]> {
|
||||
let summary = "Multiplies two encrypted integers";
|
||||
|
||||
let description = [{
|
||||
Multiplies two encrypted integers.
|
||||
|
||||
The encrypted integers and the result must have the same width and
|
||||
signedness. Also, due to the current implementation, one supplementary
|
||||
bit of width must be provided, in addition to the number of bits needed
|
||||
to encode the largest output value.
|
||||
|
||||
Example:
|
||||
```mlir
|
||||
// ok
|
||||
"FHE.mul_eint"(%a, %b): (!FHE.eint<2>, !FHE.eint<2>) -> (!FHE.eint<2>)
|
||||
"FHE.mul_eint"(%a, %b): (!FHE.eint<3>, !FHE.eint<3>) -> (!FHE.eint<3>)
|
||||
"FHE.mul_eint"(%a, %b): (!FHE.esint<3>, !FHE.esint<3>) -> (!FHE.esint<3>)
|
||||
|
||||
// error
|
||||
"FHE.mul_eint"(%a, %b): (!FHE.eint<2>, !FHE.eint<3>) -> (!FHE.eint<2>)
|
||||
"FHE.mul_eint"(%a, %b): (!FHE.eint<2>, !FHE.eint<2>) -> (!FHE.eint<3>)
|
||||
"FHE.mul_eint"(%a, %b): (!FHE.eint<2>, !FHE.eint<2>) -> (!FHE.esint<2>)
|
||||
"FHE.mul_eint"(%a, %b): (!FHE.esint<2>, !FHE.eint<2>) -> (!FHE.eint<2>)
|
||||
```
|
||||
}];
|
||||
|
||||
let arguments = (ins FHE_AnyEncryptedInteger:$a, FHE_AnyEncryptedInteger:$b);
|
||||
let results = (outs FHE_AnyEncryptedInteger);
|
||||
|
||||
let builders = [
|
||||
OpBuilder<(ins "Value":$a, "Value":$b), [{
|
||||
build($_builder, $_state, a.getType(), a, b);
|
||||
}]>
|
||||
];
|
||||
|
||||
let hasVerifier = 1;
|
||||
}
|
||||
|
||||
def FHE_ToSignedOp : FHE_Op<"to_signed", [NoSideEffect]> {
|
||||
let summary = "Cast an unsigned integer to a signed one";
|
||||
|
||||
|
||||
@@ -2,3 +2,7 @@ set(LLVM_TARGET_DEFINITIONS Boolean.td)
|
||||
mlir_tablegen(Boolean.h.inc -gen-pass-decls -name Transforms)
|
||||
add_public_tablegen_target(ConcretelangFHEBooleanPassIncGen)
|
||||
add_dependencies(mlir-headers ConcretelangFHEBooleanPassIncGen)
|
||||
set(LLVM_TARGET_DEFINITIONS EncryptedMulToDoubleTLU.td)
|
||||
mlir_tablegen(EncryptedMulToDoubleTLU.h.inc -gen-pass-decls -name Transforms)
|
||||
add_public_tablegen_target(EncryptedMulToDoubleTLUPassIncGen)
|
||||
add_dependencies(mlir-headers EncryptedMulToDoubleTLUPassIncGen)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// 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.
|
||||
|
||||
#ifndef CONCRETELANG_FHE_ENCRYPTED_MUL_TO_DOUBLE_TLU_PASS_H
|
||||
#define CONCRETELANG_FHE_ENCRYPTED_MUL_TO_DOUBLE_TLU_PASS_H
|
||||
|
||||
#include <concretelang/Dialect/FHE/IR/FHEDialect.h>
|
||||
#include <mlir/Dialect/Func/IR/FuncOps.h>
|
||||
#include <mlir/Pass/Pass.h>
|
||||
|
||||
#define GEN_PASS_CLASSES
|
||||
|
||||
#include <concretelang/Dialect/FHE/Transforms/EncryptedMulToDoubleTLU.h.inc>
|
||||
|
||||
namespace mlir {
|
||||
namespace concretelang {
|
||||
std::unique_ptr<mlir::OperationPass<mlir::func::FuncOp>>
|
||||
createEncryptedMulToDoubleTLUPass();
|
||||
} // namespace concretelang
|
||||
} // namespace mlir
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef CONCRETELANG_FHE_ENCRYPTED_MUL_TO_DOUBLE_TLU_PASS
|
||||
#define CONCRETELANG_FHE_ENCRYPTED_MUL_TO_DOUBLE_TLU_PASS
|
||||
|
||||
include "mlir/Pass/PassBase.td"
|
||||
|
||||
def EncryptedMulToDoubleTLU : Pass<"EncryptedMulToDoubleTLU", "::mlir::func::FuncOp"> {
|
||||
let summary = "Replaces encrypted multiplication with a double table lookup.";
|
||||
let constructor = "mlir::concretelang::createEncryptedMulToDoubleTLUPass()";
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -34,6 +34,10 @@ markFHELinalgForTiling(mlir::MLIRContext &context, mlir::ModuleOp &module,
|
||||
llvm::ArrayRef<int64_t> tileSizes,
|
||||
std::function<bool(mlir::Pass *)> enablePass);
|
||||
|
||||
mlir::LogicalResult
|
||||
transformHighLevelFHEOps(mlir::MLIRContext &context, mlir::ModuleOp &module,
|
||||
std::function<bool(mlir::Pass *)> enablePass);
|
||||
|
||||
mlir::LogicalResult
|
||||
lowerFHELinalgToFHE(mlir::MLIRContext &context, mlir::ModuleOp &module,
|
||||
llvm::Optional<V0FHEContext> &fheContext,
|
||||
|
||||
Reference in New Issue
Block a user