mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 03:55:04 -05:00
enhance(bench): Add benchmark generator for leveled operators
This commit is contained in:
1
compiler/.gitignore
vendored
1
compiler/.gitignore
vendored
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user