mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 12:15:09 -05:00
feat(compiler): add MidLFHE.neg_glwe op
This commit is contained in:
@@ -50,6 +50,15 @@ def SubIntGLWEOp : MidLFHE_Op<"sub_int_glwe"> {
|
||||
}];
|
||||
}
|
||||
|
||||
def NegGLWEOp : MidLFHE_Op<"neg_glwe"> {
|
||||
let arguments = (ins GLWECipherTextType:$a);
|
||||
let results = (outs GLWECipherTextType);
|
||||
|
||||
let verifier = [{
|
||||
return ::mlir::zamalang::MidLFHE::verifyUnaryGLWEOperator<NegGLWEOp>(*this);
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
def MulGLWEIntOp : MidLFHE_Op<"mul_glwe_int"> {
|
||||
let arguments = (ins GLWECipherTextType:$a, AnyInteger:$b);
|
||||
|
||||
@@ -105,6 +105,36 @@ mlir::LogicalResult verifyBinaryGLWEOperator(Operator &op) {
|
||||
return mlir::success();
|
||||
}
|
||||
|
||||
// verifyUnaryGLWEOperator verify parameters of operators that has the following
|
||||
// signature (!MidLFHE.glwe<{dim,poly,bits}{p}>) ->
|
||||
// (!MidLFHE.glwe<{dim,poly,bits}{p}>))
|
||||
template <class Operator>
|
||||
mlir::LogicalResult verifyUnaryGLWEOperator(Operator &op) {
|
||||
auto a = ((mlir::Type)(op.a().getType())).cast<GLWECipherTextType>();
|
||||
auto result =
|
||||
((mlir::Type)(op.getResult().getType())).cast<GLWECipherTextType>();
|
||||
|
||||
// verify consistency of a and result GLWE parameter
|
||||
if (a.getDimension() != result.getDimension()) {
|
||||
emitOpErrorForIncompatibleGLWEParameter(op, "dimension");
|
||||
return mlir::failure();
|
||||
}
|
||||
if (a.getPolynomialSize() != result.getPolynomialSize()) {
|
||||
emitOpErrorForIncompatibleGLWEParameter(op, "polynomialSize");
|
||||
return mlir::failure();
|
||||
}
|
||||
if (a.getBits() != result.getBits()) {
|
||||
emitOpErrorForIncompatibleGLWEParameter(op, "bits");
|
||||
return mlir::failure();
|
||||
}
|
||||
if (a.getP() != result.getP()) {
|
||||
emitOpErrorForIncompatibleGLWEParameter(op, "p");
|
||||
return mlir::failure();
|
||||
}
|
||||
|
||||
return mlir::success();
|
||||
}
|
||||
|
||||
/// verifyApplyLookupTable verify the GLWE parameters follow the rules:
|
||||
/// - The l_cst argument must be a memref of one dimension of size 2^p
|
||||
/// - The lookup table contains integer values of the same width of the output
|
||||
|
||||
36
compiler/tests/Dialect/MidLFHE/op_neg_glwe.invalid.mlir
Normal file
36
compiler/tests/Dialect/MidLFHE/op_neg_glwe.invalid.mlir
Normal file
@@ -0,0 +1,36 @@
|
||||
// RUN: zamacompiler --split-input-file --verify-diagnostics --action=roundtrip %s
|
||||
|
||||
// GLWE p parameter
|
||||
func @neg_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{6}> {
|
||||
// expected-error @+1 {{'MidLFHE.neg_glwe' op should have the same GLWE 'p' parameter}}
|
||||
%1 = "MidLFHE.neg_glwe"(%arg0): (!MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,12,64}{6}>)
|
||||
return %1: !MidLFHE.glwe<{1024,12,64}{6}>
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
// GLWE dimension parameter
|
||||
func @neg_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{512,12,64}{7}> {
|
||||
// expected-error @+1 {{'MidLFHE.neg_glwe' op should have the same GLWE 'dimension' parameter}}
|
||||
%1 = "MidLFHE.neg_glwe"(%arg0): (!MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{512,12,64}{7}>)
|
||||
return %1: !MidLFHE.glwe<{512,12,64}{7}>
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
// GLWE polynomialSize parameter
|
||||
func @neg_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,11,64}{7}> {
|
||||
// expected-error @+1 {{'MidLFHE.neg_glwe' op should have the same GLWE 'polynomialSize' parameter}}
|
||||
%1 = "MidLFHE.neg_glwe"(%arg0): (!MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,11,64}{7}>)
|
||||
return %1: !MidLFHE.glwe<{1024,11,64}{7}>
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
// integer width doesn't match GLWE parameter
|
||||
func @neg_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,11,64}{7}> {
|
||||
// expected-error @+1 {{'MidLFHE.neg_glwe' op should have the same GLWE 'polynomialSize' parameter}}
|
||||
%1 = "MidLFHE.neg_glwe"(%arg0): (!MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,11,64}{7}>)
|
||||
return %1: !MidLFHE.glwe<{1024,11,64}{7}>
|
||||
}
|
||||
|
||||
10
compiler/tests/Dialect/MidLFHE/op_neg_glwe.mlir
Normal file
10
compiler/tests/Dialect/MidLFHE/op_neg_glwe.mlir
Normal file
@@ -0,0 +1,10 @@
|
||||
// RUN: zamacompiler --action=roundtrip %s 2>&1| FileCheck %s
|
||||
|
||||
// CHECK-LABEL: func @neg_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}>
|
||||
func @neg_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> {
|
||||
// CHECK-NEXT: %[[V1:.*]] = "MidLFHE.neg_glwe"(%arg0) : (!MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}>
|
||||
// CHECK-NEXT: return %[[V1]] : !MidLFHE.glwe<{1024,12,64}{7}>
|
||||
|
||||
%1 = "MidLFHE.neg_glwe"(%arg0): (!MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,12,64}{7}>)
|
||||
return %1: !MidLFHE.glwe<{1024,12,64}{7}>
|
||||
}
|
||||
Reference in New Issue
Block a user