-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1081 from WoutLegiest:not_packed
PiperOrigin-RevId: 696131357
- Loading branch information
Showing
9 changed files
with
105 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ defvar OR_GATE = 2; | |
defvar NOR_GATE = 3; | ||
defvar XOR_GATE = 4; | ||
defvar XNOR_GATE = 5; | ||
defvar NOT_GATE = 6; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/Dialect/TfheRustBool/Emitters/emit_tfhe_rust_bool_packed.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// RUN: heir-translate %s --emit-tfhe-rust-bool-packed | FileCheck %s | ||
|
||
!bsks = !tfhe_rust_bool.server_key | ||
!eb = !tfhe_rust_bool.eb | ||
|
||
module{ | ||
// CHECK-LABEL: pub fn test_and( | ||
// CHECK-NEXT: [[bsks:v[0-9]+]]: &ServerKey, | ||
// CHECK-NEXT: [[input1:v[0-9]+]]: &Vec<Ciphertext>, | ||
// CHECK-NEXT: [[input2:v[0-9]+]]: &Vec<Ciphertext>, | ||
// CHECK-NEXT: ) -> Vec<Ciphertext> { | ||
// CHECK-NEXT: let [[input1]]_ref = [[input1]].clone(); | ||
// CHECK-NEXT: let [[input1]]_ref: Vec<&Ciphertext> = [[input1]].iter().collect(); | ||
// CHECK-NEXT: let [[input2]]_ref = [[input2]].clone(); | ||
// CHECK-NEXT: let [[input2]]_ref: Vec<&Ciphertext> = [[input2]].iter().collect(); | ||
// CHECK-NEXT: let [[v0:.*]] = [[bsks]].packed_gates( | ||
// CHECK-NEXT: &vec![Gate::AND, Gate::AND, Gate::AND, Gate::AND, ], | ||
// CHECK-NEXT: &[[input1]]_ref, &[[input2]]_ref); | ||
// CHECK-NEXT: [[v0]] | ||
// CHECK-NEXT: } | ||
func.func @test_and(%bsks : !bsks, %input1 : tensor<4x!eb>, %input2 : tensor<4x!eb>) -> tensor<4x!eb> { | ||
%out = tfhe_rust_bool.and %bsks, %input1, %input2 : (!bsks, tensor<4x!eb>, tensor<4x!eb>) -> tensor<4x!eb> | ||
return %out : tensor<4x!eb> | ||
} | ||
|
||
// CHECK-LABEL: pub fn test_not( | ||
// CHECK-NEXT: [[bsks:v[0-9]+]]: &ServerKey, | ||
// CHECK-NEXT: [[input1:v[0-9]+]]: &Vec<Ciphertext>, | ||
// CHECK-NEXT: ) -> Vec<Ciphertext> { | ||
// CHECK-NEXT: let [[input1]]_ref = [[input1]].clone(); | ||
// CHECK-NEXT: let [[input1]]_ref: Vec<&Ciphertext> = [[input1]].iter().collect(); | ||
// CHECK-NEXT: let [[v0:.*]] = [[bsks]].packed_not( | ||
// CHECK-NEXT: &[[input1]]_ref); | ||
// CHECK-NEXT: [[v0]] | ||
// CHECK-NEXT: } | ||
func.func @test_not(%bsks : !bsks, %input1 : tensor<4x!eb>) -> tensor<4x!eb>{ | ||
%out = tfhe_rust_bool.not %bsks, %input1 : (!bsks, tensor<4x!eb>) -> tensor<4x!eb> | ||
return %out : tensor<4x!eb> | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
tests/Examples/tfhe_rust_bool/fpga/test_fully_connected.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
// RUN: heir-opt --tosa-to-boolean-fpga-tfhe="abc-fast=true entry-function=fn_under_test" %s | heir-translate --emit-tfhe-rust-bool-packed > %S/src/fn_under_test.rs | ||
// RUN: cargo run --release --manifest-path %S/Cargo.toml --bin main_fully_connected -- 2 | FileCheck %s | ||
|
||
// This takes takes the input x and outputs 2 \cdot x + 3. | ||
// This takes takes the input x and outputs a FC layer operation. | ||
// CHECK: 00000111 | ||
module attributes {tf_saved_model.semantics} { | ||
func.func @fn_under_test(%11: tensor<1x1xi8>) -> tensor<1x1xi32> { | ||
%0 = "tosa.const"() {value = dense<3> : tensor<1xi32>} : () -> tensor<1xi32> | ||
%1 = "tosa.const"() {value = dense<[[2]]> : tensor<1x1xi8>} : () -> tensor<1x1xi8> | ||
%2 = "tosa.fully_connected"(%11, %1, %0) {quantization_info = #tosa.conv_quant<input_zp = 0, weight_zp = 0>} : (tensor<1x1xi8>, tensor<1x1xi8>, tensor<1xi32>) -> tensor<1x1xi32> | ||
return %2 : tensor<1x1xi32> | ||
func.func @fn_under_test(%11: tensor<1x3xi8>) -> tensor<1x3xi32> { | ||
%0 = "tosa.const"() {value = dense<[3, 1, 4]> : tensor<3xi32>} : () -> tensor<3xi32> | ||
%1 = "tosa.const"() {value = dense<[[2, 7, 1], [8,2,8], [1,8,2]]> : tensor<3x3xi8>} : () -> tensor<3x3xi8> | ||
%2 = "tosa.fully_connected"(%11, %1, %0) {quantization_info = #tosa.conv_quant<input_zp = 0, weight_zp = 0>} : (tensor<1x3xi8>, tensor<3x3xi8>, tensor<3xi32>) -> tensor<1x3xi32> | ||
return %2 : tensor<1x3xi32> | ||
} | ||
} |