diff --git a/compiler/.gitignore b/compiler/.gitignore index 918a67995..1d6894b1c 100644 --- a/compiler/.gitignore +++ b/compiler/.gitignore @@ -10,3 +10,4 @@ concrete-core-ffi* # Test-generated artifacts 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 diff --git a/compiler/Makefile b/compiler/Makefile index 3ee64bb03..0bd7cc764 100644 --- a/compiler/Makefile +++ b/compiler/Makefile @@ -241,10 +241,13 @@ run-end-to-end-gpu-tests: build-end-to-end-gpu-tests # benchmark +generate-benchmarks: + python ./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 + build-benchmarks: build-initialized cmake --build $(BUILD_DIR) --target end_to_end_benchmark -run-benchmarks: build-benchmarks +run-benchmarks: build-benchmarks generate-benchmarks $(BUILD_DIR)/bin/end_to_end_benchmark --benchmark_out=benchmarks_results.json --benchmark_out_format=json --benchmark_repetitions=10 --benchmark_report_aggregates_only=true build-mlbench: build-initialized 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 6db099920..ed8ac14e9 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 @@ -157,6 +157,10 @@ auto _ = { "FHELinalg", "tests/end_to_end_fixture/end_to_end_fhelinalg.yaml"), registerEndToEndTestFromFile( "FHELinalg", "tests/end_to_end_fixture/end_to_end_programs.yaml", - 0x8000000)}; + 0x8000000), + registerEndToEndTestFromFile( + "FHETLU", + "tests/end_to_end_fixture/end_to_end_linalg_apply_lookup_table.yaml"), +}; BENCHMARK_MAIN(); diff --git a/compiler/tests/end_to_end_fixture/end_to_end_linalg_apply_lookup_table_gen.py b/compiler/tests/end_to_end_fixture/end_to_end_linalg_apply_lookup_table_gen.py new file mode 100644 index 000000000..d46488a77 --- /dev/null +++ b/compiler/tests/end_to_end_fixture/end_to_end_linalg_apply_lookup_table_gen.py @@ -0,0 +1,43 @@ +from platform import mac_ver +import numpy as np + +MIN_PRECISON = 1 +MAX_PRECISION = 16 +N_CT = [1, 10, 100, 1000, 10000] + + +def main(): + print("# /!\ DO NOT EDIT MANUALLY THIS FILE MANUALLY") + print("# /!\ THIS FILE HAS BEEN GENERATED THANKS THE end_to_end_levelled_gen.py scripts") + np.random.seed(0) + for n_ct in N_CT: + for p in range(MIN_PRECISON, MAX_PRECISION+1): + if p != 1: + print("---") + max_value = (2 ** p) - 1 + random_lut = np.random.randint(max_value+1, size=2**p) + # identity_apply_lookup_table + print( + "description: apply_lookup_table_{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(" %tlu = arith.constant dense<[{0}]> : tensor<{1}xi64>".format( + ','.join(map(str, random_lut)), 2**p)) + print( + " %1 = \"FHELinalg.apply_lookup_table\"(%arg0, %tlu): (tensor<{2}x!FHE.eint<{0}>>, tensor<{1}xi64>) -> (tensor<{2}x!FHE.eint<{0}>>)".format(p, 2**p, n_ct)) + print(" return %1: tensor<{1}x!FHE.eint<{0}>>".format(p, n_ct)) + print(" }") + random_input = np.random.randint(max_value+1, size=n_ct) + print("tests:") + print(" - inputs:") + print( + " - tensor: [{0}]".format(','.join(map(str, random_input)))) + print(" shape: [{0}]".format(n_ct)) + outputs = np.vectorize(lambda i: random_lut[i])(random_input) + print(" outputs:") + print(" - tensor: [{0}]".format(','.join(map(str, outputs)))) + print(" shape: [{0}]".format(n_ct)) + + +main()