Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/Target/Lattigo/LattigoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2323,20 +2323,19 @@ LogicalResult LattigoEmitter::printOperation(
auto btParams = op.getBtParamsLiteral();
auto paramName = getName(op.getParams());
auto errName = getErrName();
auto numSlotsAttr = dyn_cast_or_null<IntegerAttr>(
op->getParentOfType<ModuleOp>()->getAttr(kRequestedSlotCountAttrName));
std::string resultName = getName(op.getResult());
os << resultName << ", " << errName
<< " := bootstrapping.NewParametersFromLiteral(";
os << paramName << ", ";
os << "bootstrapping.ParametersLiteral{\n";
os.indent();
os << "LogN: utils.Pointy(" << btParams.getLogN() << "),\n";
if (numSlotsAttr) {
int numSlots = numSlotsAttr.getInt();
int logNumSlots = (int)log2(numSlots);
os << "LogSlots: utils.Pointy(" << logNumSlots << "),\n";
}
// Deliberately no LogSlots: leave it at lattigo's default of LogN-1.
//
// LogSlots is documented as "the maximum number of slots of the ciphertext"
// and only sizes the CoeffsToSlots/SlotsToCoeffs matrices; the bootstrapping
// ring is built from LogN alone, so its LogMaxDimensions stays at LogN-1
// whatever LogSlots says.
os.unindent();
os << "})\n";
printErrPanic(errName);
Expand Down
29 changes: 29 additions & 0 deletions tests/Emitter/Lattigo/bootstrap_full_slots.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: heir-translate %s --emit-lattigo | FileCheck %s

// A module carrying scheme.requested_slot_count (set by generate-param-ckks
// from the requested ciphertext-degree, here 1024 in a LogN-16 ring whose
// actual slot count is 32768) must NOT turn that hint into a sparse
// bootstrapping LogSlots.

// CHECK: bootstrapping.NewParametersFromLiteral
// CHECK: LogN: utils.Pointy(16)
// CHECK-NOT: LogSlots
// CHECK: })

!params = !lattigo.ckks.parameter
!bt_params = !lattigo.ckks.bootstrapping_parameter

#paramsLiteral = #lattigo.ckks.parameters_literal<
logN = 16,
logQ = [55, 45, 45],
logP = [61],
logDefaultScale = 45
>

module attributes {scheme.ckks, scheme.requested_slot_count = 1024 : i64} {
func.func @make_bt_params() -> !bt_params {
%params = lattigo.ckks.new_parameters_from_literal {paramsLiteral = #paramsLiteral} : () -> !params
%bt_params = lattigo.ckks.new_bootstrapping_parameters_from_literal %params {btParamsLiteral = #lattigo.ckks.bootstrapping_parameters_literal<logN = 16>} : (!params) -> !bt_params
return %bt_params : !bt_params
}
}
9 changes: 8 additions & 1 deletion tests/Examples/lattigo/ckks/bootstrapping/bootstrap.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@
// CHECK-SAME: , %[[ct:\w+]]: ![[ctType]])
// CHECK: lattigo.ckks.bootstrap %[[bEval]], %[[ct]]

module attributes {backend.lattigo, ckks.schemeParam = #ckks.scheme_param<logN = 14, Q = [0x200000440001, 0x7fff80001, 0x800280001], P = [0x3ffffffb80001, 0x4000000800001], logDefaultScale = 60>, scheme.ckks} {
// scheme.requested_slot_count is what generate-param-ckks records for a
// requested ciphertext-degree below the ring's slot capacity (here 2048 of the
// 8192 slots of a logN-14 ring). It must not be turned into a sparse
// bootstrapping LogSlots: lattigo sizes only the CoeffsToSlots/SlotsToCoeffs
// matrices from LogSlots while Bootstrap relabels its input to the full
// LogMaxDimensions, so a sparse value mixes slot values and this test decrypts
// to garbage.
module attributes {backend.lattigo, ckks.schemeParam = #ckks.scheme_param<logN = 14, Q = [0x200000440001, 0x7fff80001, 0x800280001], P = [0x3ffffffb80001, 0x4000000800001], logDefaultScale = 60>, scheme.ckks, scheme.requested_slot_count = 2048 : i64} {
func.func @bootstrap(%ct: !ct_L2) -> !ct_L13 {
%ct_0 = ckks.bootstrap %ct : !ct_L2 -> !ct_L13
return %ct_0 : !ct_L13
Expand Down
6 changes: 3 additions & 3 deletions tests/Transforms/layout_optimization/pad_hoist_explicit.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ module attributes {backend.lattigo, scheme.ckks} {
^body(%input0: tensor<1x10x48xf32>):
debug.validate %input0 {metadata = "input", name = "input", tensor_ext.layout = []} : tensor<1x10x48xf32>
%collapsed = tensor.collapse_shape %input0 [[0, 1], [2]] {heir.kernel_info = {gap_factor = 1 : i64, result_shape = array<i64: 10, 48>}, tensor_ext.layout = #layout2} : tensor<1x10x48xf32> into tensor<10x48xf32>

// Pad outputs layout2
%padded = tensor.pad %collapsed low[0, 1] high[0, 1] {
^bb0(%arg1: index, %arg2: index):
tensor.yield %cst : f32
} {heir.kernel_info = {gap_factor = 1 : i64, result_shape = array<i64: 10, 48>}, tensor_ext.layout = #layout2} : tensor<10x48xf32> to tensor<10x50xf32>

// Explicit convert_layout from layout2 to layout
// CHECK-NOT: tensor_ext.convert_layout
%converted = tensor_ext.convert_layout %padded {from_layout = #layout2, tensor_ext.layout = #layout, to_layout = #layout} : tensor<10x50xf32>

secret.yield %converted : tensor<10x50xf32>
} -> (!secret.secret<tensor<10x50xf32>> {tensor_ext.layout = #layout})
return %0 : !secret.secret<tensor<10x50xf32>>
Expand Down
Loading