From 84041557abcaec1986dd909d55401c58f95f2d2b Mon Sep 17 00:00:00 2001 From: Quentin Bourgerie Date: Fri, 4 Nov 2022 15:46:06 +0100 Subject: [PATCH] enhance(bench): Add benchmark generator for leveled operators --- compiler/.gitignore | 1 + compiler/Makefile | 1 + .../end_to_end_benchmark.cpp | 5 +- .../end_to_end_linalg_leveled_gen.py | 74 +++++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 compiler/tests/end_to_end_fixture/end_to_end_linalg_leveled_gen.py diff --git a/compiler/.gitignore b/compiler/.gitignore index 1d6894b1c..ac561f67f 100644 --- a/compiler/.gitignore +++ b/compiler/.gitignore @@ -11,3 +11,4 @@ concrete-core-ffi* concrete-compiler_compilation_artifacts/ py_test_lib_compile_and_run_custom_perror/ tests/end_to_end_fixture/end_to_end_linalg_apply_lookup_table.yaml +tests/end_to_end_fixture/end_to_end_linalg_leveled.yaml diff --git a/compiler/Makefile b/compiler/Makefile index bb9e6f248..673e3992a 100644 --- a/compiler/Makefile +++ b/compiler/Makefile @@ -254,6 +254,7 @@ run-end-to-end-gpu-tests: build-end-to-end-gpu-tests generate-benchmarks: $(Python3_EXECUTABLE) ./tests/end_to_end_fixture/end_to_end_linalg_apply_lookup_table_gen.py > tests/end_to_end_fixture/end_to_end_linalg_apply_lookup_table.yaml + $(Python3_EXECUTABLE) ./tests/end_to_end_fixture/end_to_end_linalg_leveled_gen.py > tests/end_to_end_fixture/end_to_end_linalg_leveled.yaml build-benchmarks: build-initialized cmake --build $(BUILD_DIR) --target end_to_end_benchmark diff --git a/compiler/tests/end_to_end_benchmarks/end_to_end_benchmark.cpp b/compiler/tests/end_to_end_benchmarks/end_to_end_benchmark.cpp index d0dcd8933..6479fcc43 100644 --- a/compiler/tests/end_to_end_benchmarks/end_to_end_benchmark.cpp +++ b/compiler/tests/end_to_end_benchmarks/end_to_end_benchmark.cpp @@ -155,8 +155,11 @@ auto _ = { registerEndToEndTestFromFile( "FHELinalg", "tests/end_to_end_fixture/end_to_end_fhelinalg.yaml"), registerEndToEndTestFromFile( - "FHETLU", + "FHELinalgTLU", "tests/end_to_end_fixture/end_to_end_linalg_apply_lookup_table.yaml"), + registerEndToEndTestFromFile( + "FHELinalgLeveled", + "tests/end_to_end_fixture/end_to_end_linalg_leveled.yaml"), }; BENCHMARK_MAIN(); diff --git a/compiler/tests/end_to_end_fixture/end_to_end_linalg_leveled_gen.py b/compiler/tests/end_to_end_fixture/end_to_end_linalg_leveled_gen.py new file mode 100644 index 000000000..b22fcd664 --- /dev/null +++ b/compiler/tests/end_to_end_fixture/end_to_end_linalg_leveled_gen.py @@ -0,0 +1,74 @@ +import numpy as np + +PRECISIONS_TO_BENCH = [1, 2, 5, 8, 9, 12, 16, 24, 32, 40, 48, 56] +N_CT = [100, 1000, 100000] + + +def main(): + print("# /!\ DO NOT EDIT MANUALLY THIS FILE MANUALLY") + print("# /!\ THIS FILE HAS BEEN GENERATED") + for p in PRECISIONS_TO_BENCH: + for n_ct in N_CT: + max_value = (2 ** p) - 1 + integer_bitwidth = p + 1 + random_cst = np.random.randint(max_value+1, size=n_ct) + random_input = np.random.randint(max_value+1, size=n_ct) + # add_eint_int_cst + print( + "description: add_eint_int_cst_{0}bits_{1}ct".format(p, n_ct)) + print("program: |") + print( + " func.func @main(%arg0: tensor<{1}x!FHE.eint<{0}>>) -> tensor<{1}x!FHE.eint<{0}>> {{".format(p, n_ct)) + print(" %0 = arith.constant dense<[{0}]> : tensor<{1}xi{2}>".format( + ','.join(map(str, random_cst)), n_ct, integer_bitwidth)) + print( + " %1 = \"FHELinalg.add_eint_int\"(%arg0, %0): (tensor<{1}x!FHE.eint<{0}>>, tensor<{1}xi{2}>) -> (tensor<{1}x!FHE.eint<{0}>>)".format(p, n_ct, integer_bitwidth)) + print(" return %1: tensor<{1}x!FHE.eint<{0}>>".format(p, n_ct)) + print(" }") + print("tests:") + print(" - inputs:") + print( + " - tensor: [{0}]".format(','.join(map(str, random_input)))) + print(" shape: [{0}]".format(n_ct)) + print("---") + # add_eint + print( + "description: add_eint_{0}bits_{1}ct".format(p, n_ct)) + print("program: |") + print( + " func.func @main(%arg0: tensor<{1}x!FHE.eint<{0}>>, %arg1: tensor<{1}x!FHE.eint<{0}>>) -> tensor<{1}x!FHE.eint<{0}>> {{".format(p, n_ct)) + print( + " %1 = \"FHELinalg.add_eint\"(%arg0, %arg1): (tensor<{1}x!FHE.eint<{0}>>, tensor<{1}x!FHE.eint<{0}>>) -> (tensor<{1}x!FHE.eint<{0}>>)".format(p, n_ct, integer_bitwidth)) + print(" return %1: tensor<{1}x!FHE.eint<{0}>>".format(p, n_ct)) + print(" }") + print("tests:") + print(" - inputs:") + print( + " - tensor: [{0}]".format(','.join(map(str, random_input)))) + print(" shape: [{0}]".format(n_ct)) + print( + " - tensor: [{0}]".format(','.join(map(str, random_input)))) + print(" shape: [{0}]".format(n_ct)) + print("---") + # mul_eint_int + print( + "description: mul_eint_int_{0}bits_{1}ct".format(p, n_ct)) + print("program: |") + print( + " func.func @main(%arg0: tensor<{1}x!FHE.eint<{0}>>) -> tensor<{1}x!FHE.eint<{0}>> {{".format(p, n_ct)) + print(" %0 = arith.constant dense<[2]> : tensor<1xi{0}>".format( + integer_bitwidth)) + print( + " %1 = \"FHELinalg.mul_eint_int\"(%arg0, %0): (tensor<{1}x!FHE.eint<{0}>>, tensor<1xi{2}>) -> (tensor<{1}x!FHE.eint<{0}>>)".format(p, n_ct, integer_bitwidth)) + print(" return %1: tensor<{1}x!FHE.eint<{0}>>".format( + p, n_ct, integer_bitwidth)) + print(" }") + print("tests:") + print(" - inputs:") + print( + " - tensor: [{0}]".format(','.join(map(str, random_input)))) + print(" shape: [{0}]".format(n_ct)) + print("---") + + +main()