feat: implement MANP calculation for tensor.insert op

This commit is contained in:
Umut
2022-06-21 09:40:51 +02:00
parent bcc5c750a1
commit 8f8a57d220

View File

@@ -966,6 +966,20 @@ static llvm::APInt getSqMANP(
operandMANPs[1]->getValue().getMANP().getValue());
}
static llvm::APInt getSqMANP(
mlir::tensor::InsertOp op,
llvm::ArrayRef<mlir::LatticeElement<MANPLatticeValue> *> operandMANPs) {
assert(
operandMANPs.size() >= 2 &&
operandMANPs[0]->getValue().getMANP().hasValue() &&
operandMANPs[1]->getValue().getMANP().hasValue() &&
"Missing squared Minimal Arithmetic Noise Padding for encrypted operand");
return APIntUMax(operandMANPs[0]->getValue().getMANP().getValue(),
operandMANPs[1]->getValue().getMANP().getValue());
}
static llvm::APInt getSqMANP(
mlir::tensor::CollapseShapeOp op,
llvm::ArrayRef<mlir::LatticeElement<MANPLatticeValue> *> operandMANPs) {
@@ -1274,6 +1288,18 @@ struct MANPAnalysis : public mlir::ForwardDataFlowAnalysis<MANPLatticeValue> {
isDummy = true;
}
}
// InsertOp
else if (auto insertOp = llvm::dyn_cast<mlir::tensor::InsertOp>(op)) {
if (insertOp.result()
.getType()
.cast<mlir::TensorType>()
.getElementType()
.isa<mlir::concretelang::FHE::EncryptedIntegerType>()) {
norm2SqEquiv = getSqMANP(insertOp, operands);
} else {
isDummy = true;
}
}
// InsertSliceOp
else if (auto insertSliceOp =
llvm::dyn_cast<mlir::tensor::InsertSliceOp>(op)) {