From d0ae2563faec5a891deb98c77353f139a70e7484 Mon Sep 17 00:00:00 2001 From: youben11 Date: Mon, 6 Feb 2023 10:50:51 +0100 Subject: [PATCH] test: add chunked eint e2e tests --- compiler/Makefile | 5 +++- .../tests/end_to_end_tests/CMakeLists.txt | 2 ++ .../end_to_end_jit_chunked_int.cc | 21 ++++++++++++++ .../end_to_end_tests/end_to_end_jit_test.h | 28 +++++++++++++++---- 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 compiler/tests/end_to_end_tests/end_to_end_jit_chunked_int.cc diff --git a/compiler/Makefile b/compiler/Makefile index c9d59ce12..749b9cad9 100644 --- a/compiler/Makefile +++ b/compiler/Makefile @@ -238,6 +238,9 @@ run-rust-tests: rust-bindings ## end-to-end-tests +build-end-to-end-jit-chunked-int: build-initialized + cmake --build $(BUILD_DIR) --target end_to_end_jit_chunked_int + build-end-to-end-jit-test: build-initialized cmake --build $(BUILD_DIR) --target end_to_end_jit_test @@ -253,7 +256,7 @@ build-end-to-end-jit-fhelinalg: build-initialized build-end-to-end-jit-lambda: build-initialized cmake --build $(BUILD_DIR) --target end_to_end_jit_lambda -build-end-to-end-tests: build-end-to-end-jit-test build-end-to-end-test build-end-to-end-jit-encrypted-tensor build-end-to-end-jit-fhelinalg build-end-to-end-jit-lambda +build-end-to-end-tests: build-end-to-end-jit-chunked-int build-end-to-end-jit-test build-end-to-end-test build-end-to-end-jit-encrypted-tensor build-end-to-end-jit-fhelinalg build-end-to-end-jit-lambda ### end-to-end-tests CPU diff --git a/compiler/tests/end_to_end_tests/CMakeLists.txt b/compiler/tests/end_to_end_tests/CMakeLists.txt index f178e224d..27277068c 100644 --- a/compiler/tests/end_to_end_tests/CMakeLists.txt +++ b/compiler/tests/end_to_end_tests/CMakeLists.txt @@ -20,6 +20,8 @@ if(CONCRETELANG_DATAFLOW_EXECUTION_ENABLED) add_compile_options(-DCONCRETELANG_DATAFLOW_TESTING_ENABLED) endif() +add_concretecompiler_unittest(end_to_end_jit_chunked_int end_to_end_jit_chunked_int.cc globals.cc) + add_concretecompiler_unittest(end_to_end_jit_test end_to_end_jit_test.cc globals.cc) add_concretecompiler_unittest(end_to_end_jit_encrypted_tensor end_to_end_jit_encrypted_tensor.cc globals.cc) diff --git a/compiler/tests/end_to_end_tests/end_to_end_jit_chunked_int.cc b/compiler/tests/end_to_end_tests/end_to_end_jit_chunked_int.cc new file mode 100644 index 000000000..006ca0772 --- /dev/null +++ b/compiler/tests/end_to_end_tests/end_to_end_jit_chunked_int.cc @@ -0,0 +1,21 @@ +#include + +#include "end_to_end_jit_test.h" +#include "tests_tools/GtestEnvironment.h" + +TEST(Lambda_chunked_int, chunked_int_add_eint) { + checkedJit(lambda, R"XXX( + func.func @main(%arg0: !FHE.eint<64>, %arg1: !FHE.eint<64>) -> !FHE.eint<64> { + %1 = "FHE.add_eint"(%arg0, %arg1): (!FHE.eint<64>, !FHE.eint<64>) -> (!FHE.eint<64>) + return %1: !FHE.eint<64> + } + )XXX", + "main", DEFAULT_useDefaultFHEConstraints, + DEFAULT_dataflowParallelize, DEFAULT_loopParallelize, + DEFAULT_batchConcreteOps, DEFAULT_global_p_error, true, 4, 2); + ASSERT_EXPECTED_VALUE(lambda(1_u64, 2_u64), (uint64_t)3); + ASSERT_EXPECTED_VALUE(lambda(72057594037927936_u64, 10000_u64), + (uint64_t)72057594037937936); + ASSERT_EXPECTED_VALUE(lambda(2057594037927936_u64, 1111_u64), + (uint64_t)2057594037929047); +} diff --git a/compiler/tests/end_to_end_tests/end_to_end_jit_test.h b/compiler/tests/end_to_end_tests/end_to_end_jit_test.h index b30dd910f..a63eb17db 100644 --- a/compiler/tests/end_to_end_tests/end_to_end_jit_test.h +++ b/compiler/tests/end_to_end_tests/end_to_end_jit_test.h @@ -12,20 +12,38 @@ #include "globals.h" #include "tests_tools/assert.h" +llvm::StringRef DEFAULT_func = "main"; +bool DEFAULT_useDefaultFHEConstraints = false; +bool DEFAULT_dataflowParallelize = false; +bool DEFAULT_loopParallelize = false; +bool DEFAULT_batchConcreteOps = false; +double DEFAULT_global_p_error = TEST_ERROR_RATE; +bool DEFAULT_chunkedIntegers = false; +unsigned int DEFAULT_chunkSize = 4; +unsigned int DEFAULT_chunkWidth = 2; + // Jit-compiles the function specified by `func` from `src` and // returns the corresponding lambda. Any compilation errors are caught // and reult in abnormal termination. inline llvm::Expected< mlir::concretelang::ClientServer> -internalCheckedJit(llvm::StringRef src, llvm::StringRef func = "main", - bool useDefaultFHEConstraints = false, - bool dataflowParallelize = false, - bool loopParallelize = false, bool batchConcreteOps = false, - double global_p_error = TEST_ERROR_RATE) { +internalCheckedJit( + llvm::StringRef src, llvm::StringRef func = DEFAULT_func, + bool useDefaultFHEConstraints = DEFAULT_useDefaultFHEConstraints, + bool dataflowParallelize = DEFAULT_dataflowParallelize, + bool loopParallelize = DEFAULT_loopParallelize, + bool batchConcreteOps = DEFAULT_batchConcreteOps, + double global_p_error = DEFAULT_global_p_error, + bool chunkedIntegers = DEFAULT_chunkedIntegers, + unsigned int chunkSize = DEFAULT_chunkSize, + unsigned int chunkWidth = DEFAULT_chunkWidth) { auto options = mlir::concretelang::CompilationOptions(std::string(func.data())); options.optimizerConfig.global_p_error = global_p_error; + options.chunkIntegers = chunkedIntegers; + options.chunkSize = chunkSize; + options.chunkWidth = chunkWidth; if (useDefaultFHEConstraints) { options.v0FHEConstraints = defaultV0Constraints; options.optimizerConfig.strategy_v0 = true;