Skip to content

Commit

Permalink
Add a verifier for bgv.rotate and corresponding test (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maokami authored and jaeho committed Nov 29, 2023
1 parent 649b4f6 commit 1657451
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/Dialect/BGV/IR/BGVOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def BGV_Rotate : BGV_Op<"rotate", [SameOperandsAndResultRings]> {
let results = (outs
Ciphertext:$output
);

let hasVerifier = 1;
}

def BGV_Negate : BGV_Op<"negate", [SameOperandsAndResultType]> {
Expand Down
11 changes: 11 additions & 0 deletions lib/Dialect/BGV/IR/BGVDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ LogicalResult MulOp::verify() {
}
return success();
}
LogicalResult Rotate::verify() {
auto x = this->getX().getType();
if (x.getDim() != 2) {
return this->emitOpError() << "x.dim == 2 does not hold";
}
auto out = this->getOutput().getType();
if (out.getDim() != 2) {
return this->emitOpError() << "output.dim == 2 does not hold";
}
return success();
}

LogicalResult Relinearize::verify() {
auto x = this->getX().getType();
Expand Down
13 changes: 13 additions & 0 deletions tests/bgv/verifier.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: heir-opt --verify-diagnostics --split-input-file %s

#my_poly = #polynomial.polynomial<1 + x**1024>
#ring1 = #polynomial.ring<cmod=463187969, ideal=#my_poly>
#ring2 = #polynomial.ring<cmod=33538049, ideal=#my_poly>
#rings = #bgv.rings<#ring1, #ring2>

func.func @test_input_dimension_error(%input: !bgv.ciphertext<rings=#rings, dim=3>) {
// expected-error@+1 {{x.dim == 2 does not hold}}
%out = bgv.rotate (%input) {offset = 4} : (!bgv.ciphertext<rings=#rings, dim=3>) -> !bgv.ciphertext<rings=#rings>

return
}

0 comments on commit 1657451

Please sign in to comment.