Skip to content

Commit

Permalink
port two polynomial examples from HECO, fix lowering to bgv test
Browse files Browse the repository at this point in the history
  • Loading branch information
j2kun committed Mar 29, 2024
1 parent 457aa1f commit 00142d4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
20 changes: 20 additions & 0 deletions tests/heir_simd_vectorizer/linear_polynomial_64.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: heir-opt --secretize=entry-function=linear_polynomial --wrap-generic --canonicalize --cse \
// RUN: --heir-simd-vectorizer %s | FileCheck %s

// CHECK-LABEL: @linear_polynomial
// CHECK: secret.generic
// CHECK-NOT: tensor_ext.rotate
func.func @linear_polynomial(%a: tensor<64xi16>, %b: tensor<64xi16>, %x: tensor<64xi16>, %y: tensor<64xi16>) -> tensor<64xi16> {
%0 = affine.for %i = 0 to 64 iter_args(%iter = %y) -> (tensor<64xi16>) {
%ai = tensor.extract %a[%i] : tensor<64xi16>
%bi = tensor.extract %b[%i] : tensor<64xi16>
%xi = tensor.extract %x[%i] : tensor<64xi16>
%yi = tensor.extract %y[%i] : tensor<64xi16>
%axi = arith.muli %ai, %xi : i16
%t1 = arith.subi %yi, %axi : i16
%t2 = arith.subi %t1, %bi : i16
%out = tensor.insert %t2 into %iter[%i] : tensor<64xi16>
affine.yield %out : tensor<64xi16>
}
return %0 : tensor<64xi16>
}
23 changes: 23 additions & 0 deletions tests/heir_simd_vectorizer/quadratic_polynomial.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: heir-opt --secretize=entry-function=quadratic_polynomial --wrap-generic --canonicalize --cse \
// RUN: --heir-simd-vectorizer %s | FileCheck %s

// CHECK-LABEL: @quadratic_polynomial
// CHECK: secret.generic
// CHECK-NOT: tensor_ext.rotate
func.func @quadratic_polynomial(%a: tensor<64xi16>, %b: tensor<64xi16>, %c: tensor<64xi16>, %x: tensor<64xi16>, %y: tensor<64xi16>) -> tensor<64xi16> {
%0 = affine.for %i = 0 to 64 iter_args(%iter = %y) -> (tensor<64xi16>) {
%ai = tensor.extract %a[%i] : tensor<64xi16>
%bi = tensor.extract %b[%i] : tensor<64xi16>
%ci = tensor.extract %c[%i] : tensor<64xi16>
%xi = tensor.extract %x[%i] : tensor<64xi16>
%yi = tensor.extract %y[%i] : tensor<64xi16>
%axi = arith.muli %ai, %xi : i16
%t1 = arith.addi %axi, %bi : i16
%t2 = arith.muli %xi, %t1 : i16
%t3 = arith.addi %t2, %ci : i16
%t4 = arith.subi %yi, %t3 : i16
%out = tensor.insert %t4 into %iter[%i] : tensor<64xi16>
affine.yield %out : tensor<64xi16>
}
return %0 : tensor<64xi16>
}
4 changes: 1 addition & 3 deletions tests/secret_to_bgv/hamming_distance_1024.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
// CHECK: bgv.sub
// CHECK-NEXT: bgv.mul
// CHECK-NEXT: bgv.relinearize

// TODO(#521): After rotate-and-reduce works, only check for 10 bg.rotate
// CHECK-COUNT-1023: bgv.rotate
// CHECK-COUNT-10: bgv.rotate
// CHECK: bgv.extract
// CHECK-NEXT: return

Expand Down

0 comments on commit 00142d4

Please sign in to comment.