fix(optimizer): no ceiling for MANP value given to the optimizer

This commit is contained in:
rudy
2022-08-22 13:09:14 +02:00
committed by rudy-6-4
parent 1d52bee1aa
commit e1fb417c54
5 changed files with 15 additions and 9 deletions

View File

@@ -4,6 +4,7 @@
// for license information.
#include <chrono>
#include <cmath>
#include <initializer_list>
#include <vector>
@@ -75,6 +76,7 @@ struct FunctionToDag {
for (auto &bb : func.getBody().getBlocks()) {
for (auto &op : bb.getOperations()) {
addOperation(dag, op);
op.removeAttr("SMANP");
}
}
if (index.empty()) {
@@ -178,13 +180,10 @@ struct FunctionToDag {
// Default complexity is negligible
double fixed_cost = NEGLIGIBLE_COMPLEXITY;
double lwe_dim_cost_factor = NEGLIGIBLE_COMPLEXITY;
auto manp_int = op.getAttrOfType<mlir::IntegerAttr>("MANP");
auto smanp_int = op.getAttrOfType<mlir::IntegerAttr>("SMANP");
auto loc = loc_to_string(op.getLoc());
if (!manp_int) {
DEBUG("Cannot read manp on " << op << "\n" << loc);
}
assert(manp_int && "Missing manp value on a crypto operation");
double manp = (double)manp_int.getValue().getZExtValue();
assert(smanp_int && "Missing manp value on a crypto operation");
double manp = sqrt((double)smanp_int.getValue().getZExtValue());
auto comment = std::string(op.getName().getStringRef()) + " " + loc;
index[val] =
dag->add_levelled_op(slice(inputs), lwe_dim_cost_factor, fixed_cost,

View File

@@ -1470,6 +1470,13 @@ struct MANPAnalysis : public mlir::ForwardDataFlowAnalysis<MANPLatticeValue> {
latticeRes.join(MANPLatticeValue{norm2SqEquiv});
latticeRes.markOptimisticFixpoint();
op->setAttr("SMANP",
mlir::IntegerAttr::get(
mlir::IntegerType::get(
op->getContext(), norm2SqEquiv.getBitWidth(),
mlir::IntegerType::SignednessSemantics::Unsigned),
norm2SqEquiv));
llvm::APInt norm2Equiv = APIntCeilSqrt(norm2SqEquiv);
op->setAttr("MANP",

View File

@@ -1,4 +1,4 @@
// RUN: concretecompiler --passes MANP --action=dump-fhe --split-input-file %s 2>&1 | FileCheck %s
// RUN: concretecompiler --passes MANP --passes ConcreteOptimizer --action=dump-fhe --split-input-file %s 2>&1 | FileCheck %s
func.func @single_zero() -> !FHE.eint<2>
{

View File

@@ -1,4 +1,4 @@
// RUN: concretecompiler --passes canonicalize --passes MANP --action=dump-fhe --split-input-file %s 2>&1 | FileCheck %s
// RUN: concretecompiler --passes canonicalize --passes MANP --passes ConcreteOptimizer --action=dump-fhe --split-input-file %s 2>&1 | FileCheck %s
func.func @single_cst_add_eint_int(%t: tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>>
{

View File

@@ -1,4 +1,4 @@
// RUN: concretecompiler --passes MANP --action=dump-fhe --split-input-file %s 2>&1 | FileCheck %s
// RUN: concretecompiler --passes MANP --passes ConcreteOptimizer --action=dump-fhe --split-input-file %s 2>&1 | FileCheck %s
func.func @tensor_from_elements_1(%a: !FHE.eint<2>, %b: !FHE.eint<2>, %c: !FHE.eint<2>, %d: !FHE.eint<2>) -> tensor<4x!FHE.eint<2>>
{