mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 12:15:09 -05:00
test(compiler): Fix end to end test we loss the 7 bits
This commit is contained in:
@@ -11,9 +11,9 @@
|
||||
TEST(CompileAndRunHLFHE, add_eint) {
|
||||
mlir::zamalang::CompilerEngine engine;
|
||||
auto mlirStr = R"XXX(
|
||||
func @main(%arg0: !HLFHE.eint<7>, %arg1: !HLFHE.eint<7>) -> !HLFHE.eint<7> {
|
||||
%1 = "HLFHE.add_eint"(%arg0, %arg1): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>)
|
||||
return %1: !HLFHE.eint<7>
|
||||
func @main(%arg0: !HLFHE.eint<6>, %arg1: !HLFHE.eint<6>) -> !HLFHE.eint<6> {
|
||||
%1 = "HLFHE.add_eint"(%arg0, %arg1): (!HLFHE.eint<6>, !HLFHE.eint<6>) -> (!HLFHE.eint<6>)
|
||||
return %1: !HLFHE.eint<6>
|
||||
}
|
||||
)XXX";
|
||||
ASSERT_FALSE(engine.compile(mlirStr));
|
||||
@@ -351,17 +351,17 @@ TEST(CompileAndRunTensorEncrypted, linalg_generic) {
|
||||
auto mlirStr = R"XXX(
|
||||
#map0 = affine_map<(d0) -> (d0)>
|
||||
#map1 = affine_map<(d0) -> (0)>
|
||||
func @main(%arg0: tensor<2x!HLFHE.eint<7>>, %arg1: tensor<2xi8>, %acc: !HLFHE.eint<7>) -> !HLFHE.eint<7> {
|
||||
%tacc = tensor.from_elements %acc : tensor<1x!HLFHE.eint<7>>
|
||||
%2 = linalg.generic {indexing_maps = [#map0, #map0, #map1], iterator_types = ["reduction"]} ins(%arg0, %arg1 : tensor<2x!HLFHE.eint<7>>, tensor<2xi8>) outs(%tacc : tensor<1x!HLFHE.eint<7>>) {
|
||||
^bb0(%arg2: !HLFHE.eint<7>, %arg3: i8, %arg4: !HLFHE.eint<7>): // no predecessors
|
||||
%4 = "HLFHE.mul_eint_int"(%arg2, %arg3) : (!HLFHE.eint<7>, i8) -> !HLFHE.eint<7>
|
||||
%5 = "HLFHE.add_eint"(%4, %arg4) : (!HLFHE.eint<7>, !HLFHE.eint<7>) -> !HLFHE.eint<7>
|
||||
linalg.yield %5 : !HLFHE.eint<7>
|
||||
} -> tensor<1x!HLFHE.eint<7>>
|
||||
func @main(%arg0: tensor<2x!HLFHE.eint<6>>, %arg1: tensor<2xi7>, %acc: !HLFHE.eint<6>) -> !HLFHE.eint<6> {
|
||||
%tacc = tensor.from_elements %acc : tensor<1x!HLFHE.eint<6>>
|
||||
%2 = linalg.generic {indexing_maps = [#map0, #map0, #map1], iterator_types = ["reduction"]} ins(%arg0, %arg1 : tensor<2x!HLFHE.eint<6>>, tensor<2xi7>) outs(%tacc : tensor<1x!HLFHE.eint<6>>) {
|
||||
^bb0(%arg2: !HLFHE.eint<6>, %arg3: i7, %arg4: !HLFHE.eint<6>): // no predecessors
|
||||
%4 = "HLFHE.mul_eint_int"(%arg2, %arg3) : (!HLFHE.eint<6>, i7) -> !HLFHE.eint<6>
|
||||
%5 = "HLFHE.add_eint"(%4, %arg4) : (!HLFHE.eint<6>, !HLFHE.eint<6>) -> !HLFHE.eint<6>
|
||||
linalg.yield %5 : !HLFHE.eint<6>
|
||||
} -> tensor<1x!HLFHE.eint<6>>
|
||||
%c0 = constant 0 : index
|
||||
%ret = tensor.extract %2[%c0] : tensor<1x!HLFHE.eint<7>>
|
||||
return %ret : !HLFHE.eint<7>
|
||||
%ret = tensor.extract %2[%c0] : tensor<1x!HLFHE.eint<6>>
|
||||
return %ret : !HLFHE.eint<6>
|
||||
}
|
||||
)XXX";
|
||||
ASSERT_LLVM_ERROR(engine.compile(mlirStr));
|
||||
@@ -386,12 +386,12 @@ func @main(%arg0: tensor<2x!HLFHE.eint<7>>, %arg1: tensor<2xi8>, %acc: !HLFHE.ei
|
||||
TEST(CompileAndRunTensorEncrypted, dot_eint_int_7) {
|
||||
mlir::zamalang::CompilerEngine engine;
|
||||
auto mlirStr = R"XXX(
|
||||
func @main(%arg0: tensor<4x!HLFHE.eint<7>>,
|
||||
%arg1: tensor<4xi8>) -> !HLFHE.eint<7>
|
||||
func @main(%arg0: tensor<4x!HLFHE.eint<6>>,
|
||||
%arg1: tensor<4xi7>) -> !HLFHE.eint<6>
|
||||
{
|
||||
%ret = "HLFHE.dot_eint_int"(%arg0, %arg1) :
|
||||
(tensor<4x!HLFHE.eint<7>>, tensor<4xi8>) -> !HLFHE.eint<7>
|
||||
return %ret : !HLFHE.eint<7>
|
||||
(tensor<4x!HLFHE.eint<6>>, tensor<4xi7>) -> !HLFHE.eint<6>
|
||||
return %ret : !HLFHE.eint<6>
|
||||
}
|
||||
)XXX";
|
||||
ASSERT_LLVM_ERROR(engine.compile(mlirStr));
|
||||
@@ -415,48 +415,53 @@ func @main(%arg0: tensor<4x!HLFHE.eint<7>>,
|
||||
TEST(CompileAndRunTLU, identity_func) {
|
||||
mlir::zamalang::CompilerEngine engine;
|
||||
auto mlirStr = R"XXX(
|
||||
func @main(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> {
|
||||
%tlu = std.constant dense<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127]> : tensor<128xi64>
|
||||
%1 = "HLFHE.apply_lookup_table"(%arg0, %tlu): (!HLFHE.eint<7>, tensor<128xi64>) -> (!HLFHE.eint<7>)
|
||||
return %1: !HLFHE.eint<7>
|
||||
func @main(%arg0: !HLFHE.eint<6>) -> !HLFHE.eint<6> {
|
||||
%tlu = std.constant dense<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]> : tensor<64xi64>
|
||||
%1 = "HLFHE.apply_lookup_table"(%arg0, %tlu): (!HLFHE.eint<6>, tensor<64xi64>) -> (!HLFHE.eint<6>)
|
||||
return %1: !HLFHE.eint<6>
|
||||
}
|
||||
)XXX";
|
||||
ASSERT_FALSE(engine.compile(mlirStr));
|
||||
uint64_t expected = 5;
|
||||
auto maybeResult = engine.run({expected});
|
||||
ASSERT_TRUE((bool)maybeResult);
|
||||
uint64_t result = maybeResult.get();
|
||||
ASSERT_EQ(result, expected);
|
||||
for (auto i = 0; i < 100; i++) {
|
||||
auto maybeResult = engine.run({expected});
|
||||
ASSERT_TRUE((bool)maybeResult);
|
||||
uint64_t result = maybeResult.get();
|
||||
ASSERT_EQ(result, expected);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CompileAndRunTLU, random_func) {
|
||||
mlir::zamalang::CompilerEngine engine;
|
||||
auto mlirStr = R"XXX(
|
||||
func @main(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> {
|
||||
%tlu = std.constant dense<[16, 91, 16, 83, 80, 74, 21, 96, 1, 63, 49, 122, 76, 89, 74, 55, 109, 110, 103, 54, 105, 14, 66, 47, 52, 89, 7, 10, 73, 44, 119, 92, 25, 104, 123, 100, 108, 86, 29, 121, 118, 52, 107, 48, 34, 37, 13, 122, 107, 48, 74, 59, 96, 36, 50, 55, 120, 72, 27, 45, 12, 5, 96, 12, 24, 90, 112, 121, 68, 125, 72, 36, 0, 13, 66, 64, 18, 3, 55, 102, 116, 100, 116, 59, 94, 12, 12, 41, 3, 120, 89, 69, 71, 125, 105, 113, 4, 11, 72, 38, 88, 54, 80, 84, 64, 23, 16, 13, 36, 50, 76, 55, 115, 115, 96, 37, 60, 96, 44, 31, 111, 78, 0, 5, 23, 41, 127, 6]> : tensor<128xi64>
|
||||
%1 = "HLFHE.apply_lookup_table"(%arg0, %tlu): (!HLFHE.eint<7>, tensor<128xi64>) -> (!HLFHE.eint<7>)
|
||||
return %1: !HLFHE.eint<7>
|
||||
func @main(%arg0: !HLFHE.eint<6>) -> !HLFHE.eint<6> {
|
||||
%tlu = std.constant dense<[27, 7,37,62,57,16,25,33,49,21,30,19,10,50,14,55,46,35,18,61, 9,20,39,22,29,32, 3, 8,51,52,11,64,40,42, 6,36,15,13,58,41,23,26,54,56,45,44, 5,34,59,47,63, 1,17,12,38, 2,43,28,48,60,31,24, 4,53]> : tensor<64xi64>
|
||||
%1 = "HLFHE.apply_lookup_table"(%arg0, %tlu): (!HLFHE.eint<6>, tensor<64xi64>) -> (!HLFHE.eint<6>)
|
||||
return %1: !HLFHE.eint<6>
|
||||
}
|
||||
)XXX";
|
||||
ASSERT_FALSE(engine.compile(mlirStr));
|
||||
// first value
|
||||
auto maybeResult = engine.run({5});
|
||||
ASSERT_TRUE((bool)maybeResult);
|
||||
uint64_t result = maybeResult.get();
|
||||
ASSERT_EQ(result, 74);
|
||||
// second value
|
||||
maybeResult = engine.run({126});
|
||||
ASSERT_TRUE((bool)maybeResult);
|
||||
result = maybeResult.get();
|
||||
ASSERT_EQ(result, 127);
|
||||
// edge value low
|
||||
maybeResult = engine.run({0});
|
||||
ASSERT_TRUE((bool)maybeResult);
|
||||
result = maybeResult.get();
|
||||
ASSERT_EQ(result, 16);
|
||||
// edge value high
|
||||
maybeResult = engine.run({127});
|
||||
ASSERT_TRUE((bool)maybeResult);
|
||||
result = maybeResult.get();
|
||||
ASSERT_EQ(result, 6);
|
||||
|
||||
for (auto i = 0; i < 100; i++) {
|
||||
// first value
|
||||
auto maybeResult = engine.run({5});
|
||||
ASSERT_TRUE((bool)maybeResult);
|
||||
uint64_t result = maybeResult.get();
|
||||
ASSERT_EQ(result, 16);
|
||||
// second value
|
||||
maybeResult = engine.run({12});
|
||||
ASSERT_TRUE((bool)maybeResult);
|
||||
result = maybeResult.get();
|
||||
ASSERT_EQ(result, 10);
|
||||
// edge value low
|
||||
maybeResult = engine.run({0});
|
||||
ASSERT_TRUE((bool)maybeResult);
|
||||
result = maybeResult.get();
|
||||
ASSERT_EQ(result, 27);
|
||||
// edge value high
|
||||
maybeResult = engine.run({63});
|
||||
ASSERT_TRUE((bool)maybeResult);
|
||||
result = maybeResult.get();
|
||||
ASSERT_EQ(result, 53);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user