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"
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+
3954struct 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 (
0 commit comments