feat(compiler): Add pass for Minimal Arithmetic Noise Padding

This pass calculates the squared Minimal Arithmetic Noise Padding
(MANP) for each operation of a function and stores the result in an
integer attribute named "sqMANP". This metric is identical to the
squared 2-norm of the constant vector of an equivalent dot product
between a vector of encrypted integers resulting directly from an
encryption and a vector of plaintext constants.

The pass supports the following operations:

 - HLFHE.dot_eint_int
 - HLFHE.zero
 - HLFHE.add_eint_int
 - HLFHE.add_eint
 - HLFHE.sub_int_eint
 - HLFHE.mul_eint_int
 - HLFHE.apply_lookup_table

If any other operation is encountered, the pass conservatively
fails. The pass further makes the optimistic assumption that all
values passed to a function are either the direct result of an
encryption of a noise-refreshing operation.
This commit is contained in:
Andi Drebes
2021-09-03 12:01:56 +02:00
committed by Quentin Bourgerie
parent 30374ebb2c
commit ed762942c1
9 changed files with 643 additions and 3 deletions

View File

@@ -15,6 +15,7 @@
#include "mlir/IR/BuiltinOps.h"
#include "zamalang/Conversion/Passes.h"
#include "zamalang/Conversion/Utils/GlobalFHEContext.h"
#include "zamalang/Dialect/HLFHE/Analysis/MANP.h"
#include "zamalang/Dialect/HLFHE/IR/HLFHEDialect.h"
#include "zamalang/Dialect/HLFHE/IR/HLFHETypes.h"
#include "zamalang/Dialect/LowLFHE/IR/LowLFHEDialect.h"
@@ -30,6 +31,7 @@ enum EntryDialect { HLFHE, MIDLFHE, LOWLFHE, STD, LLVM };
enum Action {
ROUND_TRIP,
DEBUG_MANP,
DUMP_MIDLFHE,
DUMP_LOWLFHE,
DUMP_STD,
@@ -84,6 +86,9 @@ static llvm::cl::opt<enum Action> action(
llvm::cl::values(
clEnumValN(Action::ROUND_TRIP, "roundtrip",
"Parse input module and regenerate textual representation")),
llvm::cl::values(clEnumValN(
Action::DEBUG_MANP, "debug-manp",
"Minimal Arithmetic Noise Padding for each HLFHE operation")),
llvm::cl::values(clEnumValN(Action::DUMP_MIDLFHE, "dump-midlfhe",
"Lower to MidLFHE and dump result")),
llvm::cl::values(clEnumValN(Action::DUMP_LOWLFHE, "dump-lowlfhe",
@@ -253,10 +258,28 @@ mlir::LogicalResult processInputBuffer(
// a fallthrough mechanism to the next stage. Actions act as exit
// points from the pipeline.
switch (entryDialect) {
case EntryDialect::HLFHE:
case EntryDialect::HLFHE: {
bool debugMANP = (action == Action::DEBUG_MANP);
mlir::LogicalResult manpRes =
mlir::zamalang::invokeMANPPass(module, debugMANP);
if (action == Action::DEBUG_MANP) {
if (manpRes.failed()) {
mlir::zamalang::log_error()
<< "Could not calculate Minimal Arithmetic Noise Padding";
if (!verifyDiagnostics)
return mlir::failure();
} else {
return mlir::success();
}
}
if (mlir::zamalang::pipeline::lowerHLFHEToMidLFHE(context, module, verbose)
.failed())
return mlir::failure();
}
// fallthrough
case EntryDialect::MIDLFHE: