enhance(bench): Add benchmark generator for leveled operators

This commit is contained in:
Quentin Bourgerie
2022-11-04 15:46:06 +01:00
parent dfe2e5e076
commit 84041557ab
4 changed files with 80 additions and 1 deletions

1
compiler/.gitignore vendored
View File

@@ -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

View File

@@ -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

View File

@@ -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();

View File

@@ -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()