Skip to content

Commit

Permalink
Merge pull request #1190 from ZenithalHourlyRate:migrate-new-lwe-type
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 706834214
  • Loading branch information
copybara-github committed Dec 16, 2024
2 parents c9b1202 + 0caca2f commit 8c68164
Show file tree
Hide file tree
Showing 58 changed files with 1,323 additions and 737 deletions.
51 changes: 25 additions & 26 deletions lib/Dialect/BGV/IR/BGVOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,30 @@ class BGV_CiphertextPlaintextOp<string mnemonic, list<Trait> traits =
[Pure, AllTypesMatch<["ciphertextInput", "output"]>,
TypesMatchWith<"type of 'plaintextInput' matches encoding type of 'ciphertextInput'",
"ciphertextInput", "plaintextInput",
"lwe::RLWEPlaintextType::get($_ctxt, "
"::llvm::cast<lwe::RLWECiphertextType>($_self).getEncoding(),"
"::llvm::cast<lwe::RLWECiphertextType>($_self).getRlweParams().getRing(),"
"::llvm::cast<lwe::RLWECiphertextType>($_self).getUnderlyingType())">]> :
"lwe::NewLWEPlaintextType::get($_ctxt, "
"::llvm::cast<lwe::NewLWECiphertextType>($_self).getApplicationData(),"
"::llvm::cast<lwe::NewLWECiphertextType>($_self).getPlaintextSpace())">]> :
BGV_Op<mnemonic, traits> {
let arguments = (ins
RLWECiphertext:$ciphertextInput,
RLWEPlaintext:$plaintextInput
NewLWECiphertext:$ciphertextInput,
NewLWEPlaintext:$plaintextInput
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);
}

def BGV_AddOp : BGV_Op<"add", [Pure, Commutative, SameOperandsAndResultType]> {
let summary = "Addition operation between ciphertexts.";

let arguments = (ins
RLWECiphertext:$lhs,
RLWECiphertext:$rhs
NewLWECiphertext:$lhs,
NewLWECiphertext:$rhs
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let assemblyFormat = "operands attr-dict `:` qualified(type($output))" ;
Expand All @@ -61,12 +60,12 @@ def BGV_SubOp : BGV_Op<"sub", [Pure, SameOperandsAndResultType]> {
let summary = "Subtraction operation between ciphertexts.";

let arguments = (ins
RLWECiphertext:$lhs,
RLWECiphertext:$rhs
NewLWECiphertext:$lhs,
NewLWECiphertext:$rhs
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let assemblyFormat = "operands attr-dict `:` qualified(type($output))" ;
Expand All @@ -80,12 +79,12 @@ def BGV_MulOp : BGV_Op<"mul", [Pure, Commutative, SameOperandsAndResultRings, Sa
let summary = "Multiplication operation between ciphertexts.";

let arguments = (ins
RLWECiphertext:$lhs,
RLWECiphertext:$rhs
NewLWECiphertext:$lhs,
NewLWECiphertext:$rhs
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let hasVerifier = 1;
Expand All @@ -99,12 +98,12 @@ def BGV_RotateOp : BGV_Op<"rotate", [Pure, AllTypesMatch<["input", "output"]>]>
let summary = "Rotate the coefficients of the ciphertext using a Galois automorphism.";

let arguments = (ins
RLWECiphertext:$input,
NewLWECiphertext:$input,
Builtin_IntegerAttr:$offset
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let hasVerifier = 1;
Expand All @@ -128,12 +127,12 @@ def BGV_ExtractOp : BGV_Op<"extract", [Pure, SameOperandsAndResultRings]> {
}];

let arguments = (ins
RLWECiphertext:$input,
NewLWECiphertext:$input,
AnySignlessIntegerOrIndex:$offset
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let hasVerifier = 1;
Expand All @@ -143,11 +142,11 @@ def BGV_NegateOp : BGV_Op<"negate", [Pure, Involution, SameOperandsAndResultType
let summary = "Negate the coefficients of the ciphertext.";

let arguments = (ins
RLWECiphertext:$input
NewLWECiphertext:$input
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let assemblyFormat = "operands attr-dict `:` qualified(type($output))" ;
Expand All @@ -167,13 +166,13 @@ def BGV_RelinearizeOp : BGV_Op<"relinearize", [SameOperandsAndResultRings, Infer
}];

let arguments = (ins
RLWECiphertext:$input,
NewLWECiphertext:$input,
DenseI32ArrayAttr:$from_basis,
DenseI32ArrayAttr:$to_basis
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let hasVerifier = 1;
Expand All @@ -184,12 +183,12 @@ def BGV_ModulusSwitchOp : BGV_Op<"modulus_switch"> {
let summary = "Lower the modulus level of the ciphertext.";

let arguments = (ins
RLWECiphertext:$input,
NewLWECiphertext:$input,
Polynomial_RingAttr:$to_ring
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let hasVerifier = 1;
Expand Down
51 changes: 25 additions & 26 deletions lib/Dialect/CKKS/IR/CKKSOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,30 @@ class CKKS_CiphertextPlaintextOp<string mnemonic, list<Trait> traits =
[Pure, AllTypesMatch<["ciphertextInput", "output"]>,
TypesMatchWith<"type of 'plaintextInput' matches encoding type of 'ciphertextInput'",
"ciphertextInput", "plaintextInput",
"lwe::RLWEPlaintextType::get($_ctxt, "
"::llvm::cast<lwe::RLWECiphertextType>($_self).getEncoding(),"
"::llvm::cast<lwe::RLWECiphertextType>($_self).getRlweParams().getRing(),"
"::llvm::cast<lwe::RLWECiphertextType>($_self).getUnderlyingType())">]> :
"lwe::NewLWEPlaintextType::get($_ctxt, "
"::llvm::cast<lwe::NewLWECiphertextType>($_self).getApplicationData(),"
"::llvm::cast<lwe::NewLWECiphertextType>($_self).getPlaintextSpace())">]> :
CKKS_Op<mnemonic, traits> {
let arguments = (ins
RLWECiphertext:$ciphertextInput,
RLWEPlaintext:$plaintextInput
NewLWECiphertext:$ciphertextInput,
NewLWEPlaintext:$plaintextInput
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);
}

def CKKS_AddOp : CKKS_Op<"add", [Pure, Commutative, SameOperandsAndResultType]> {
let summary = "Addition operation between ciphertexts.";

let arguments = (ins
RLWECiphertext:$lhs,
RLWECiphertext:$rhs
NewLWECiphertext:$lhs,
NewLWECiphertext:$rhs
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let assemblyFormat = "operands attr-dict `:` qualified(type($output))" ;
Expand All @@ -61,12 +60,12 @@ def CKKS_SubOp : CKKS_Op<"sub", [SameOperandsAndResultType]> {
let summary = "Subtraction operation between ciphertexts.";

let arguments = (ins
RLWECiphertext:$lhs,
RLWECiphertext:$rhs
NewLWECiphertext:$lhs,
NewLWECiphertext:$rhs
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let assemblyFormat = "operands attr-dict `:` qualified(type($output))" ;
Expand All @@ -80,12 +79,12 @@ def CKKS_MulOp : CKKS_Op<"mul", [Pure, Commutative, SameOperandsAndResultRings,
let summary = "Multiplication operation between ciphertexts.";

let arguments = (ins
RLWECiphertext:$lhs,
RLWECiphertext:$rhs
NewLWECiphertext:$lhs,
NewLWECiphertext:$rhs
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let hasVerifier = 1;
Expand All @@ -99,12 +98,12 @@ def CKKS_RotateOp : CKKS_Op<"rotate", [Pure, AllTypesMatch<["input", "output"]>]
let summary = "Rotate the coefficients of the ciphertext using a Galois automorphism.";

let arguments = (ins
RLWECiphertext:$input,
NewLWECiphertext:$input,
Builtin_IntegerAttr:$offset
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let hasVerifier = 1;
Expand All @@ -128,12 +127,12 @@ def CKKS_ExtractOp : CKKS_Op<"extract", [SameOperandsAndResultRings]> {
}];

let arguments = (ins
RLWECiphertext:$input,
NewLWECiphertext:$input,
AnySignlessIntegerOrIndex:$offset
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let hasVerifier = 1;
Expand All @@ -143,11 +142,11 @@ def CKKS_NegateOp : CKKS_Op<"negate", [Pure, SameOperandsAndResultType, Involuti
let summary = "Negate the coefficients of the ciphertext.";

let arguments = (ins
RLWECiphertext:$input
NewLWECiphertext:$input
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let assemblyFormat = "operands attr-dict `:` qualified(type($output))" ;
Expand All @@ -167,13 +166,13 @@ def CKKS_RelinearizeOp : CKKS_Op<"relinearize", [Pure, SameOperandsAndResultRing
}];

let arguments = (ins
RLWECiphertext:$input,
NewLWECiphertext:$input,
DenseI32ArrayAttr:$from_basis,
DenseI32ArrayAttr:$to_basis
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let hasVerifier = 1;
Expand All @@ -184,12 +183,12 @@ def CKKS_RescaleOp : CKKS_Op<"rescale", [Pure]> {
let summary = "Rescales the ciphertext, which is the CKKS version of modulus switching in BGV/BFV.";

let arguments = (ins
RLWECiphertext:$input,
NewLWECiphertext:$input,
Polynomial_RingAttr:$to_ring
);

let results = (outs
RLWECiphertext:$output
NewLWECiphertext:$output
);

let hasVerifier = 1;
Expand Down
Loading

0 comments on commit 8c68164

Please sign in to comment.