diff --git a/compiler/include/zamalang/Conversion/HLFHEToMidLFHE/Patterns.h b/compiler/include/zamalang/Conversion/HLFHEToMidLFHE/Patterns.h index 87f0efe8b..a838c0ec3 100644 --- a/compiler/include/zamalang/Conversion/HLFHEToMidLFHE/Patterns.h +++ b/compiler/include/zamalang/Conversion/HLFHEToMidLFHE/Patterns.h @@ -63,6 +63,8 @@ createApplyLookupTableGLWEOpFromHLFHE(mlir::PatternRewriter rewriter, mlir::NamedAttribute(mlir::Identifier::get("baseLogKS", context), unset), mlir::NamedAttribute(mlir::Identifier::get("levelBS", context), unset), mlir::NamedAttribute(mlir::Identifier::get("baseLogBS", context), unset), + mlir::NamedAttribute(mlir::Identifier::get("outputSizeKS", context), + unset), }; auto eint = result.getType().cast(); diff --git a/compiler/include/zamalang/Conversion/MidLFHEToLowLFHE/Patterns.h b/compiler/include/zamalang/Conversion/MidLFHEToLowLFHE/Patterns.h index 9e58b4efe..cad3336c6 100644 --- a/compiler/include/zamalang/Conversion/MidLFHEToLowLFHE/Patterns.h +++ b/compiler/include/zamalang/Conversion/MidLFHEToLowLFHE/Patterns.h @@ -174,7 +174,7 @@ mlir::Value createPBS(mlir::PatternRewriter rewriter, mlir::Location loc, mlir::IntegerAttr polynomialSize, mlir::IntegerAttr levelKS, mlir::IntegerAttr baseLogKS, mlir::IntegerAttr levelBS, mlir::IntegerAttr baseLogBS, - mlir::OpResult result) { + mlir::IntegerAttr outputSizeKS, mlir::OpResult result) { // fill the the table in the GLWE accumulator mlir::Value accumulator = rewriter @@ -189,9 +189,9 @@ mlir::Value createPBS(mlir::PatternRewriter rewriter, mlir::Location loc, mlir::SmallVector ksAttrs{ mlir::NamedAttribute( mlir::Identifier::get("inputLweSize", rewriter.getContext()), k), - // TODO: get the actual output size mlir::NamedAttribute( - mlir::Identifier::get("outputLweSize", rewriter.getContext()), k), + mlir::Identifier::get("outputLweSize", rewriter.getContext()), + outputSizeKS), mlir::NamedAttribute( mlir::Identifier::get("level", rewriter.getContext()), levelKS), mlir::NamedAttribute( diff --git a/compiler/include/zamalang/Conversion/MidLFHEToLowLFHE/Patterns.td b/compiler/include/zamalang/Conversion/MidLFHEToLowLFHE/Patterns.td index 7ed5a2700..e57b209a3 100644 --- a/compiler/include/zamalang/Conversion/MidLFHEToLowLFHE/Patterns.td +++ b/compiler/include/zamalang/Conversion/MidLFHEToLowLFHE/Patterns.td @@ -35,10 +35,10 @@ def SubIntGLWEPattern : Pat< (SubIntGLWEOp:$result $arg0, $arg1), (createSubIntLweOp $arg0, $arg1, $result)>; -def createPBS : NativeCodeCall<"mlir::zamalang::createPBS($_builder, $_loc, $0, $1, $2, $3, $4, $5, $6, $7, $8)">; +def createPBS : NativeCodeCall<"mlir::zamalang::createPBS($_builder, $_loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9)">; def ApplyLookupTableGLWEPattern : Pat< - (ApplyLookupTable:$result $ct, $table, $k, $polynomialSize, $levelKS, $baseLogKS, $levelBS, $baseLogBS), - (createPBS $ct, $table, $k, $polynomialSize, $levelKS, $baseLogKS, $levelBS, $baseLogBS, $result)>; + (ApplyLookupTable:$result $ct, $table, $k, $polynomialSize, $levelKS, $baseLogKS, $levelBS, $baseLogBS, $outputSizeKS), + (createPBS $ct, $table, $k, $polynomialSize, $levelKS, $baseLogKS, $levelBS, $baseLogBS, $outputSizeKS, $result)>; #endif diff --git a/compiler/include/zamalang/Dialect/MidLFHE/IR/MidLFHEOps.td b/compiler/include/zamalang/Dialect/MidLFHE/IR/MidLFHEOps.td index faccf0b4a..76b951d31 100644 --- a/compiler/include/zamalang/Dialect/MidLFHE/IR/MidLFHEOps.td +++ b/compiler/include/zamalang/Dialect/MidLFHE/IR/MidLFHEOps.td @@ -67,7 +67,8 @@ def ApplyLookupTable : MidLFHE_Op<"apply_lookup_table"> { TensorOf<[AnyInteger]>:$l_cst, I32Attr:$k, I32Attr:$polynomialSize, I32Attr:$levelKS, I32Attr:$baseLogKS, - I32Attr:$levelBS, I32Attr:$baseLogBS); + I32Attr:$levelBS, I32Attr:$baseLogBS, + I32Attr:$outputSizeKS); let results = (outs GLWECipherTextType); let verifier = [{ diff --git a/compiler/lib/Conversion/LowLFHEToConcreteCAPI/LowLFHEToConcreteCAPI.cpp b/compiler/lib/Conversion/LowLFHEToConcreteCAPI/LowLFHEToConcreteCAPI.cpp index 5fb104fe5..3895a2461 100644 --- a/compiler/lib/Conversion/LowLFHEToConcreteCAPI/LowLFHEToConcreteCAPI.cpp +++ b/compiler/lib/Conversion/LowLFHEToConcreteCAPI/LowLFHEToConcreteCAPI.cpp @@ -462,6 +462,8 @@ struct LowLFHEBootstrapLweOpPattern auto errOp = rewriter.create(op.getLoc(), rewriter.getIndexAttr(0)); // allocate the result lwe ciphertext + // TODO: use right value for output lwe size + // LweSize output_lwe_size = { (glwe_size._0 -1) * poly_size._0 + 1} auto lweSizeOp = rewriter.create( op.getLoc(), mlir::IntegerAttr::get( mlir::IntegerType::get(rewriter.getContext(), 32), diff --git a/compiler/lib/Conversion/MidLFHEGlobalParametrization/MidLFHEGlobalParametrization.cpp b/compiler/lib/Conversion/MidLFHEGlobalParametrization/MidLFHEGlobalParametrization.cpp index dd67b0032..ed5c1c1db 100644 --- a/compiler/lib/Conversion/MidLFHEGlobalParametrization/MidLFHEGlobalParametrization.cpp +++ b/compiler/lib/Conversion/MidLFHEGlobalParametrization/MidLFHEGlobalParametrization.cpp @@ -114,6 +114,8 @@ struct MidLFHEApplyLookupTableParametrizationPattern rewriter.getI32IntegerAttr(v0Parameter.brLevel)), mlir::NamedAttribute(rewriter.getIdentifier("baseLogBS"), rewriter.getI32IntegerAttr(v0Parameter.brLogBase)), + mlir::NamedAttribute(rewriter.getIdentifier("outputSizeKS"), + rewriter.getI32IntegerAttr(v0Parameter.nSmall)), }; rewriter.replaceOpWithNewOp( diff --git a/compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate.mlir b/compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate.mlir index fb648bc69..74c4d531c 100644 --- a/compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate.mlir +++ b/compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate.mlir @@ -2,7 +2,7 @@ // CHECK-LABEL: func @apply_lookup_table(%arg0: !MidLFHE.glwe<{_,_,_}{2}>, %arg1: tensor<4xi2>) -> !MidLFHE.glwe<{_,_,_}{2}> func @apply_lookup_table(%arg0: !HLFHE.eint<2>, %arg1: tensor<4xi2>) -> !HLFHE.eint<2> { - // CHECK-NEXT: %[[V1:.*]] = "MidLFHE.apply_lookup_table"(%arg0, %arg1) {baseLogBS = -1 : i32, baseLogKS = -1 : i32, k = -1 : i32, levelBS = -1 : i32, levelKS = -1 : i32, polynomialSize = -1 : i32} : (!MidLFHE.glwe<{_,_,_}{2}>, tensor<4xi2>) -> !MidLFHE.glwe<{_,_,_}{2}> + // CHECK-NEXT: %[[V1:.*]] = "MidLFHE.apply_lookup_table"(%arg0, %arg1) {baseLogBS = -1 : i32, baseLogKS = -1 : i32, k = -1 : i32, levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = -1 : i32, polynomialSize = -1 : i32} : (!MidLFHE.glwe<{_,_,_}{2}>, tensor<4xi2>) -> !MidLFHE.glwe<{_,_,_}{2}> // CHECK-NEXT: return %[[V1]] : !MidLFHE.glwe<{_,_,_}{2}> %1 = "HLFHE.apply_lookup_table"(%arg0, %arg1): (!HLFHE.eint<2>, tensor<4xi2>) -> (!HLFHE.eint<2>) diff --git a/compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate_cst.mlir b/compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate_cst.mlir index 3790ea57b..15046f824 100644 --- a/compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate_cst.mlir +++ b/compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate_cst.mlir @@ -2,10 +2,10 @@ // CHECK-LABEL: func @apply_lookup_table_cst(%arg0: !MidLFHE.glwe<{_,_,_}{7}>) -> !MidLFHE.glwe<{_,_,_}{7}> func @apply_lookup_table_cst(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - // CHECK-NEXT: %[[TABLE:.*]] = constant dense<"0x00000000000000000000000000008000000000000000000100000000000080010000000000000002000000000000800200000000000000030000000000008003000000000000000400000000000080040000000000000005000000000000800500000000000000060000000000008006000000000000000700000000000080070000000000000008000000000000800800000000000000090000000000008009000000000000000A000000000000800A000000000000000B000000000000800B000000000000000C000000000000800C000000000000000D000000000000800D000000000000000E000000000000800E000000000000000F000000000000800F00000000000000100000000000008010000000000000001100000000000080110000000000000012000000000000801200000000000000130000000000008013000000000000001400000000000080140000000000000015000000000000801500000000000000160000000000008016000000000000001700000000000080170000000000000018000000000000801800000000000000190000000000008019000000000000001A000000000000801A000000000000001B000000000000801B000000000000001C000000000000801C000000000000001D000000000000801D000000000000001E000000000000801E000000000000001F000000000000801F00000000000000200000000000008020000000000000002100000000000080210000000000000022000000000000802200000000000000230000000000008023000000000000002400000000000080240000000000000025000000000000802500000000000000260000000000008026000000000000002700000000000080270000000000000028000000000000802800000000000000290000000000008029000000000000002A000000000000802A000000000000002B000000000000802B000000000000002C000000000000802C000000000000002D000000000000802D000000000000002E000000000000802E000000000000002F000000000000802F00000000000000300000000000008030000000000000003100000000000080310000000000000032000000000000803200000000000000330000000000008033000000000000003400000000000080340000000000000035000000000000803500000000000000360000000000008036000000000000003700000000000080370000000000000038000000000000803800000000000000390000000000008039000000000000003A000000000000803A000000000000003B000000000000803B000000000000003C000000000000803C000000000000003D000000000000803D000000000000003E000000000000803E000000000000003F000000000000803F"> : tensor<128xi64> - // CHECK-NEXT: %[[V0:.*]] = "MidLFHE.apply_lookup_table"(%arg0, %[[TABLE]]) {baseLogBS = -1 : i32, baseLogKS = -1 : i32, k = -1 : i32, levelBS = -1 : i32, levelKS = -1 : i32, polynomialSize = -1 : i32} : (!MidLFHE.glwe<{_,_,_}{7}>, tensor<128xi64>) -> !MidLFHE.glwe<{_,_,_}{7}> + // CHECK-NEXT: %[[TABLE:.*]] = constant dense<"0x0000000000000000000000000000000100000000000000020000000000000003000000000000000400000000000000050000000000000006000000000000000700000000000000080000000000000009000000000000000A000000000000000B000000000000000C000000000000000D000000000000000E000000000000000F0000000000000010000000000000001100000000000000120000000000000013000000000000001400000000000000150000000000000016000000000000001700000000000000180000000000000019000000000000001A000000000000001B000000000000001C000000000000001D000000000000001E000000000000001F0000000000000020000000000000002100000000000000220000000000000023000000000000002400000000000000250000000000000026000000000000002700000000000000280000000000000029000000000000002A000000000000002B000000000000002C000000000000002D000000000000002E000000000000002F0000000000000030000000000000003100000000000000320000000000000033000000000000003400000000000000350000000000000036000000000000003700000000000000380000000000000039000000000000003A000000000000003B000000000000003C000000000000003D000000000000003E000000000000003F0000000000000040000000000000004100000000000000420000000000000043000000000000004400000000000000450000000000000046000000000000004700000000000000480000000000000049000000000000004A000000000000004B000000000000004C000000000000004D000000000000004E000000000000004F0000000000000050000000000000005100000000000000520000000000000053000000000000005400000000000000550000000000000056000000000000005700000000000000580000000000000059000000000000005A000000000000005B000000000000005C000000000000005D000000000000005E000000000000005F0000000000000060000000000000006100000000000000620000000000000063000000000000006400000000000000650000000000000066000000000000006700000000000000680000000000000069000000000000006A000000000000006B000000000000006C000000000000006D000000000000006E000000000000006F0000000000000070000000000000007100000000000000720000000000000073000000000000007400000000000000750000000000000076000000000000007700000000000000780000000000000079000000000000007A000000000000007B000000000000007C000000000000007D000000000000007E000000000000007F"> : tensor<128xi64> + // CHECK-NEXT: %[[V0:.*]] = "MidLFHE.apply_lookup_table"(%arg0, %[[TABLE]]) {baseLogBS = -1 : i32, baseLogKS = -1 : i32, k = -1 : i32, levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = -1 : i32, polynomialSize = -1 : i32} : (!MidLFHE.glwe<{_,_,_}{7}>, tensor<128xi64>) -> !MidLFHE.glwe<{_,_,_}{7}> // CHECK-NEXT: return %[[V0]] : !MidLFHE.glwe<{_,_,_}{7}> - %tlu = std.constant dense<[0, 36028797018963968, 72057594037927936, 108086391056891904, 144115188075855872, 180143985094819840, 216172782113783808, 252201579132747776, 288230376151711744, 324259173170675712, 360287970189639680, 396316767208603648, 432345564227567616, 468374361246531584, 504403158265495552, 540431955284459520, 576460752303423488, 612489549322387456, 648518346341351424, 684547143360315392, 720575940379279360, 756604737398243328, 792633534417207296, 828662331436171264, 864691128455135232, 900719925474099200, 936748722493063168, 972777519512027136, 1008806316530991104, 1044835113549955072, 1080863910568919040, 1116892707587883008, 1152921504606846976, 1188950301625810944, 1224979098644774912, 1261007895663738880, 1297036692682702848, 1333065489701666816, 1369094286720630784, 1405123083739594752, 1441151880758558720, 1477180677777522688, 1513209474796486656, 1549238271815450624, 1585267068834414592, 1621295865853378560, 1657324662872342528, 1693353459891306496, 1729382256910270464, 1765411053929234432, 1801439850948198400, 1837468647967162368, 1873497444986126336, 1909526242005090304, 1945555039024054272, 1981583836043018240, 2017612633061982208, 2053641430080946176, 2089670227099910144, 2125699024118874112, 2161727821137838080, 2197756618156802048, 2233785415175766016, 2269814212194729984, 2305843009213693952, 2341871806232657920, 2377900603251621888, 2413929400270585856, 2449958197289549824, 2485986994308513792, 2522015791327477760, 2558044588346441728, 2594073385365405696, 2630102182384369664, 2666130979403333632, 2702159776422297600, 2738188573441261568, 2774217370460225536, 2810246167479189504, 2846274964498153472, 2882303761517117440, 2918332558536081408, 2954361355555045376, 2990390152574009344, 3026418949592973312, 3062447746611937280, 3098476543630901248, 3134505340649865216, 3170534137668829184, 3206562934687793152, 3242591731706757120, 3278620528725721088, 3314649325744685056, 3350678122763649024, 3386706919782612992, 3422735716801576960, 3458764513820540928, 3494793310839504896, 3530822107858468864, 3566850904877432832, 3602879701896396800, 3638908498915360768, 3674937295934324736, 3710966092953288704, 3746994889972252672, 3783023686991216640, 3819052484010180608, 3855081281029144576, 3891110078048108544, 3927138875067072512, 3963167672086036480, 3999196469105000448, 4035225266123964416, 4071254063142928384, 4107282860161892352, 4143311657180856320, 4179340454199820288, 4215369251218784256, 4251398048237748224, 4287426845256712192, 4323455642275676160, 4359484439294640128, 4395513236313604096, 4431542033332568064, 4467570830351532032, 4503599627370496000, 4539628424389459968, 4575657221408423936]> : tensor<128xi64> + %tlu = std.constant dense<[0, 72057594037927936, 144115188075855872, 216172782113783808, 288230376151711744, 360287970189639680, 432345564227567616, 504403158265495552, 576460752303423488, 648518346341351424, 720575940379279360, 792633534417207296, 864691128455135232, 936748722493063168, 1008806316530991104, 1080863910568919040, 1152921504606846976, 1224979098644774912, 1297036692682702848, 1369094286720630784, 1441151880758558720, 1513209474796486656, 1585267068834414592, 1657324662872342528, 1729382256910270464, 1801439850948198400, 1873497444986126336, 1945555039024054272, 2017612633061982208, 2089670227099910144, 2161727821137838080, 2233785415175766016, 2305843009213693952, 2377900603251621888, 2449958197289549824, 2522015791327477760, 2594073385365405696, 2666130979403333632, 2738188573441261568, 2810246167479189504, 2882303761517117440, 2954361355555045376, 3026418949592973312, 3098476543630901248, 3170534137668829184, 3242591731706757120, 3314649325744685056, 3386706919782612992, 3458764513820540928, 3530822107858468864, 3602879701896396800, 3674937295934324736, 3746994889972252672, 3819052484010180608, 3891110078048108544, 3963167672086036480, 4035225266123964416, 4107282860161892352, 4179340454199820288, 4251398048237748224, 4323455642275676160, 4395513236313604096, 4467570830351532032, 4539628424389459968, 4611686018427387904, 4683743612465315840, 4755801206503243776, 4827858800541171712, 4899916394579099648, 4971973988617027584, 5044031582654955520, 5116089176692883456, 5188146770730811392, 5260204364768739328, 5332261958806667264, 5404319552844595200, 5476377146882523136, 5548434740920451072, 5620492334958379008, 5692549928996306944, 5764607523034234880, 5836665117072162816, 5908722711110090752, 5980780305148018688, 6052837899185946624, 6124895493223874560, 6196953087261802496, 6269010681299730432, 6341068275337658368, 6413125869375586304, 6485183463413514240, 6557241057451442176, 6629298651489370112, 6701356245527298048, 6773413839565225984, 6845471433603153920, 6917529027641081856, 6989586621679009792, 7061644215716937728, 7133701809754865664, 7205759403792793600, 7277816997830721536, 7349874591868649472, 7421932185906577408, 7493989779944505344, 7566047373982433280, 7638104968020361216, 7710162562058289152, 7782220156096217088, 7854277750134145024, 7926335344172072960, 7998392938210000896, 8070450532247928832, 8142508126285856768, 8214565720323784704, 8286623314361712640, 8358680908399640576, 8430738502437568512, 8502796096475496448, 8574853690513424384, 8646911284551352320, 8718968878589280256, 8791026472627208192, 8863084066665136128, 8935141660703064064, 9007199254740992000, 9079256848778919936, 9151314442816847872]> : tensor<128xi64> %1 = "HLFHE.apply_lookup_table"(%arg0, %tlu): (!HLFHE.eint<7>, tensor<128xi64>) -> (!HLFHE.eint<7>) return %1: !HLFHE.eint<7> } \ No newline at end of file diff --git a/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table.mlir b/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table.mlir index ab757025f..d68a4f876 100644 --- a/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table.mlir +++ b/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table.mlir @@ -3,9 +3,9 @@ // CHECK-LABEL: func @apply_lookup_table(%arg0: !LowLFHE.lwe_ciphertext<1024,4>, %arg1: tensor<16xi4>) -> !LowLFHE.lwe_ciphertext<1024,4> func @apply_lookup_table(%arg0: !MidLFHE.glwe<{1024,1,64}{4}>, %arg1: tensor<16xi4>) -> !MidLFHE.glwe<{1024,1,64}{4}> { // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.glwe_from_table"(%arg1) {k = 1 : i32, polynomialSize = 1024 : i32} : (tensor<16xi4>) -> !LowLFHE.glwe_ciphertext - // CHECK-NEXT: %[[V2:.*]] = "LowLFHE.keyswitch_lwe"(%arg0) {baseLog = 2 : i32, inputLweSize = 1 : i32, level = 3 : i32, outputLweSize = 1 : i32} : (!LowLFHE.lwe_ciphertext<1024,4>) -> !LowLFHE.lwe_ciphertext<1024,4> + // CHECK-NEXT: %[[V2:.*]] = "LowLFHE.keyswitch_lwe"(%arg0) {baseLog = 2 : i32, inputLweSize = 1 : i32, level = 3 : i32, outputLweSize = 600 : i32} : (!LowLFHE.lwe_ciphertext<1024,4>) -> !LowLFHE.lwe_ciphertext<1024,4> // CHECK-NEXT: %[[V3:.*]] = "LowLFHE.bootstrap_lwe"(%[[V2]], %[[V1]]) {baseLog = 4 : i32, k = 1 : i32, level = 5 : i32, polynomialSize = 1024 : i32} : (!LowLFHE.lwe_ciphertext<1024,4>, !LowLFHE.glwe_ciphertext) -> !LowLFHE.lwe_ciphertext<1024,4> // CHECK-NEXT: return %[[V3]] : !LowLFHE.lwe_ciphertext<1024,4> - %1 = "MidLFHE.apply_lookup_table"(%arg0, %arg1){k=1:i32, polynomialSize=1024:i32, levelKS=3:i32, baseLogKS=2:i32, levelBS=5:i32, baseLogBS=4:i32}: (!MidLFHE.glwe<{1024,1,64}{4}>, tensor<16xi4>) -> (!MidLFHE.glwe<{1024,1,64}{4}>) + %1 = "MidLFHE.apply_lookup_table"(%arg0, %arg1){k=1:i32, polynomialSize=1024:i32, levelKS=3:i32, baseLogKS=2:i32, levelBS=5:i32, baseLogBS=4:i32, outputSizeKS=600:i32}: (!MidLFHE.glwe<{1024,1,64}{4}>, tensor<16xi4>) -> (!MidLFHE.glwe<{1024,1,64}{4}>) return %1: !MidLFHE.glwe<{1024,1,64}{4}> } \ No newline at end of file diff --git a/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table_cst.mlir b/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table_cst.mlir index 943d9fe1f..3e4bde0c3 100644 --- a/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table_cst.mlir +++ b/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table_cst.mlir @@ -4,10 +4,10 @@ func @apply_lookup_table_cst(%arg0: !MidLFHE.glwe<{2048,1,64}{4}>) -> !MidLFHE.glwe<{2048,1,64}{4}> { // CHECK-NEXT: %[[TABLE:.*]] = constant dense<[0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1]> : tensor<16xi4> // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.glwe_from_table"(%[[TABLE]]) {k = 1 : i32, polynomialSize = 2048 : i32} : (tensor<16xi4>) -> !LowLFHE.glwe_ciphertext - // CHECK-NEXT: %[[V2:.*]] = "LowLFHE.keyswitch_lwe"(%arg0) {baseLog = 2 : i32, inputLweSize = 1 : i32, level = 3 : i32, outputLweSize = 1 : i32} : (!LowLFHE.lwe_ciphertext<2048,4>) -> !LowLFHE.lwe_ciphertext<2048,4> + // CHECK-NEXT: %[[V2:.*]] = "LowLFHE.keyswitch_lwe"(%arg0) {baseLog = 2 : i32, inputLweSize = 1 : i32, level = 3 : i32, outputLweSize = 600 : i32} : (!LowLFHE.lwe_ciphertext<2048,4>) -> !LowLFHE.lwe_ciphertext<2048,4> // CHECK-NEXT: %[[V3:.*]] = "LowLFHE.bootstrap_lwe"(%[[V2]], %[[V1]]) {baseLog = 4 : i32, k = 1 : i32, level = 5 : i32, polynomialSize = 2048 : i32} : (!LowLFHE.lwe_ciphertext<2048,4>, !LowLFHE.glwe_ciphertext) -> !LowLFHE.lwe_ciphertext<2048,4> // CHECK-NEXT: return %[[V3]] : !LowLFHE.lwe_ciphertext<2048,4> %tlu = std.constant dense<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]> : tensor<16xi4> - %1 = "MidLFHE.apply_lookup_table"(%arg0, %tlu){k=1:i32, polynomialSize=2048:i32, levelKS=3:i32, baseLogKS=2:i32, levelBS=5:i32, baseLogBS=4:i32}: (!MidLFHE.glwe<{2048,1,64}{4}>, tensor<16xi4>) -> (!MidLFHE.glwe<{2048,1,64}{4}>) + %1 = "MidLFHE.apply_lookup_table"(%arg0, %tlu){k=1:i32, polynomialSize=2048:i32, levelKS=3:i32, baseLogKS=2:i32, levelBS=5:i32, baseLogBS=4:i32, outputSizeKS=600:i32}: (!MidLFHE.glwe<{2048,1,64}{4}>, tensor<16xi4>) -> (!MidLFHE.glwe<{2048,1,64}{4}>) return %1: !MidLFHE.glwe<{2048,1,64}{4}> } \ No newline at end of file diff --git a/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.invalid.mlir b/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.invalid.mlir index f43ec7e69..04f52dafc 100644 --- a/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.invalid.mlir +++ b/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.invalid.mlir @@ -3,7 +3,7 @@ // Bad dimension of the lookup table func @apply_lookup_table(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: tensor<4xi2>) -> !MidLFHE.glwe<{512,10,64}{2}> { // expected-error @+1 {{'MidLFHE.apply_lookup_table' op should have as `l_cst` argument a shape of one dimension equals to 2^p, where p is the width of the `ct` argument}} - %1 = "MidLFHE.apply_lookup_table"(%arg0, %arg1) {k = 1 : i32, polynomialSize = 1024 : i32, levelKS = 2 : i32, baseLogKS = -82 : i32, levelBS = 3 : i32, baseLogBS = -83 : i32}: (!MidLFHE.glwe<{1024,12,64}{7}>, tensor<4xi2>) -> (!MidLFHE.glwe<{512,10,64}{2}>) + %1 = "MidLFHE.apply_lookup_table"(%arg0, %arg1) {k = 1 : i32, polynomialSize = 1024 : i32, levelKS = 2 : i32, baseLogKS = -82 : i32, levelBS = 3 : i32, baseLogBS = -83 : i32, outputSizeKS = 600 : i32}: (!MidLFHE.glwe<{1024,12,64}{7}>, tensor<4xi2>) -> (!MidLFHE.glwe<{512,10,64}{2}>) return %1: !MidLFHE.glwe<{512,10,64}{2}> } diff --git a/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.mlir b/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.mlir index 65c93cb2e..07de47e6e 100644 --- a/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.mlir +++ b/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.mlir @@ -2,9 +2,9 @@ // CHECK-LABEL: func @apply_lookup_table(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: tensor<128xi2>) -> !MidLFHE.glwe<{512,10,64}{2}> func @apply_lookup_table(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: tensor<128xi2>) -> !MidLFHE.glwe<{512,10,64}{2}> { - // CHECK-NEXT: %[[V1:.*]] = "MidLFHE.apply_lookup_table"(%arg0, %arg1) {baseLogBS = -83 : i32, baseLogKS = -82 : i32, k = 1 : i32, levelBS = 3 : i32, levelKS = 2 : i32, polynomialSize = 1024 : i32} : (!MidLFHE.glwe<{1024,12,64}{7}>, tensor<128xi2>) -> !MidLFHE.glwe<{512,10,64}{2}> + // CHECK-NEXT: %[[V1:.*]] = "MidLFHE.apply_lookup_table"(%arg0, %arg1) {baseLogBS = -83 : i32, baseLogKS = -82 : i32, k = 1 : i32, levelBS = 3 : i32, levelKS = 2 : i32, outputSizeKS = 600 : i32, polynomialSize = 1024 : i32} : (!MidLFHE.glwe<{1024,12,64}{7}>, tensor<128xi2>) -> !MidLFHE.glwe<{512,10,64}{2}> // CHECK-NEXT: return %[[V1]] : !MidLFHE.glwe<{512,10,64}{2}> - %1 = "MidLFHE.apply_lookup_table"(%arg0, %arg1) {k = 1 : i32, polynomialSize = 1024 : i32, levelKS = 2 : i32, baseLogKS = -82 : i32, levelBS = 3 : i32, baseLogBS = -83 : i32} : (!MidLFHE.glwe<{1024,12,64}{7}>, tensor<128xi2>) -> (!MidLFHE.glwe<{512,10,64}{2}>) + %1 = "MidLFHE.apply_lookup_table"(%arg0, %arg1) {k = 1 : i32, polynomialSize = 1024 : i32, levelKS = 2 : i32, baseLogKS = -82 : i32, levelBS = 3 : i32, baseLogBS = -83 : i32, outputSizeKS = 600 : i32} : (!MidLFHE.glwe<{1024,12,64}{7}>, tensor<128xi2>) -> (!MidLFHE.glwe<{512,10,64}{2}>) return %1: !MidLFHE.glwe<{512,10,64}{2}> } \ No newline at end of file diff --git a/compiler/tests/RunJit/lowlfhe_negate_lwe_ciphertext.mlir b/compiler/tests/RunJit/lowlfhe_negate_lwe_ciphertext.mlir index aa397deae..e465c8189 100644 --- a/compiler/tests/RunJit/lowlfhe_negate_lwe_ciphertext.mlir +++ b/compiler/tests/RunJit/lowlfhe_negate_lwe_ciphertext.mlir @@ -1,4 +1,4 @@ -// RUN: zamacompiler %s --run-jit --jit-args -32 2>&1| FileCheck %s +// RUN: zamacompiler %s --run-jit --jit-args 224 2>&1| FileCheck %s // CHECK-LABEL: 32 func @main(%arg0: !LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> {