Skip to content

Commit 56ab538

Browse files
j2kuncopybara-github
authored andcommitted
Bump params for lattigo when bootstrapping is present
PiperOrigin-RevId: 895960176
1 parent cd9d446 commit 56ab538

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

lib/Dialect/Lattigo/IR/LattigoCKKSOps.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ def Lattigo_CKKSMulOp : Lattigo_CKKSBinaryInPlaceOp<"mul", [IncreasesMulDepthOpI
215215
}];
216216
}
217217

218-
class Lattigo_CKKSUnaryOp<string mnemonic> :
219-
Lattigo_CKKSOp<mnemonic> {
218+
class Lattigo_CKKSUnaryOp<string mnemonic, list<Trait> traits = []> :
219+
Lattigo_CKKSOp<mnemonic, traits> {
220220
let arguments = (ins
221221
Lattigo_CKKSEvaluator:$evaluator,
222222
Lattigo_RLWECiphertext:$input
@@ -322,7 +322,7 @@ def Lattigo_CKKSRotateOp : Lattigo_CKKSUnaryInPlaceOp<"rotate", [
322322
let hasVerifier = 1;
323323
}
324324

325-
def Lattigo_CKKSBootstrapOp : Lattigo_CKKSUnaryOp<"bootstrap"> {
325+
def Lattigo_CKKSBootstrapOp : Lattigo_CKKSUnaryOp<"bootstrap", [ResetsMulDepthOpInterface]> {
326326
let summary = "Bootstrap a ciphertext in the Lattigo CKKS dialect";
327327
let description = [{
328328
Bootstraps a ciphertext value in the Lattigo CKKS dialect.

lib/Transforms/GenerateParam/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ cc_library(
2828
"@heir//lib/Analysis/NoiseAnalysis/BGV:NoiseCanEmbModel",
2929
"@heir//lib/Analysis/RangeAnalysis",
3030
"@heir//lib/Analysis/SecretnessAnalysis",
31+
"@heir//lib/Dialect:HEIRInterfaces",
3132
"@heir//lib/Dialect:ModuleAttributes",
3233
"@heir//lib/Dialect/BGV/IR:Dialect",
3334
"@heir//lib/Dialect/CKKS/IR:Dialect",
@@ -37,6 +38,7 @@ cc_library(
3738
"@heir//lib/Dialect/Secret/IR:Dialect",
3839
"@heir//lib/Parameters/BGV:Params",
3940
"@heir//lib/Parameters/CKKS:Params",
41+
"@heir//lib/Utils",
4042
"@heir//lib/Utils:LogArithmetic",
4143
"@llvm-project//llvm:Support",
4244
"@llvm-project//mlir:Analysis",

lib/Transforms/GenerateParam/GenerateParamCKKS.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "lib/Dialect/CKKS/IR/CKKSAttributes.h"
88
#include "lib/Dialect/CKKS/IR/CKKSDialect.h"
99
#include "lib/Dialect/CKKS/IR/CKKSEnums.h"
10+
#include "lib/Dialect/HEIRInterfaces.h"
1011
#include "lib/Dialect/Mgmt/IR/MgmtAttributes.h"
1112
#include "lib/Dialect/ModuleAttributes.h"
1213
#include "lib/Parameters/CKKS/Params.h"
@@ -17,10 +18,12 @@
1718
#include "mlir/include/mlir/Analysis/DataFlowFramework.h" // from @llvm-project
1819
#include "mlir/include/mlir/IR/Builders.h" // from @llvm-project
1920
#include "mlir/include/mlir/IR/BuiltinAttributes.h" // from @llvm-project
21+
#include "mlir/include/mlir/IR/BuiltinOps.h" // from @llvm-project
2022
#include "mlir/include/mlir/IR/Diagnostics.h" // from @llvm-project
2123
#include "mlir/include/mlir/IR/Operation.h" // from @llvm-project
2224
#include "mlir/include/mlir/IR/Value.h" // from @llvm-project
2325
#include "mlir/include/mlir/Support/LLVM.h" // from @llvm-project
26+
#include "mlir/include/mlir/Support/WalkResult.h" // from @llvm-project
2427

2528
// IWYU pragma: begin_keep
2629
#include "lib/Transforms/GenerateParam/GenerateParam.h"
@@ -36,6 +39,18 @@ namespace heir {
3639
#define GEN_PASS_DEF_GENERATEPARAMCKKS
3740
#include "lib/Transforms/GenerateParam/GenerateParam.h.inc"
3841

42+
namespace {
43+
bool containsBootstrap(Operation* op) {
44+
auto result = op->walk([&](Operation* walkOp) {
45+
if (isa<ResetsMulDepthOpInterface>(walkOp)) {
46+
return WalkResult::interrupt();
47+
}
48+
return WalkResult::advance();
49+
});
50+
return result.wasInterrupted();
51+
}
52+
} // namespace
53+
3954
struct GenerateParamCKKS : impl::GenerateParamCKKSBase<GenerateParamCKKS> {
4055
using GenerateParamCKKSBase::GenerateParamCKKSBase;
4156

@@ -132,6 +147,17 @@ struct GenerateParamCKKS : impl::GenerateParamCKKSBase<GenerateParamCKKS> {
132147
if (moduleIsLattigo(getOperation())) {
133148
encryptionTechniqueExtended = true;
134149
LDBG() << "For lattigo, fixing extended encryption technique";
150+
151+
// Lattigo bootstrapping requires LogN >= 14, i.e., ringDim >= 16384.
152+
// Since ringDim is computed from slotNumber (minRingDim = 2 *
153+
// slotNumber), we bump slotNumber to 8192 if bootstrapping is present.
154+
if (containsBootstrap(getOperation())) {
155+
if (slotNumber < 8192) {
156+
LDBG() << "Lattigo bootstrapping detected, bumping slotNumber from "
157+
<< slotNumber << " to 8192";
158+
slotNumber = 8192;
159+
}
160+
}
135161
}
136162

137163
auto schemeParam = ckks::SchemeParam::getConcreteSchemeParam(

tests/Transforms/generate_param_ckks/rolled_matvec.mlir

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
// CHECK: module
88
// CHECK-SAME: #ckks.scheme_param
9-
// CHECK-SAME: logN = 13
9+
10+
// because the pass has bootstrapping, lattigo bumps the parameters to 2**14 at a minimum
11+
// CHECK-SAME: logN = 14
12+
1013
// CHECK-SAME: Q = [{{[0-9]*}}, {{[0-9]*}}]
1114
// CHECK-SAME: P = [{{[0-9]*}}]
1215
// CHECK-SAME: logDefaultScale = 45

0 commit comments

Comments
 (0)