From 9e007c988fb82c941e7ea5ea9227b9992d598ad9 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bossuat Date: Wed, 19 Nov 2025 15:34:31 +0100 Subject: [PATCH] Backend refactor (#120) * remove spqlios, split cpu_ref and cpu_avx into different crates * remove spqlios submodule * update crate naming & add avx tests --- .gitmodules | 3 - Cargo.lock | 33 +- Cargo.toml | 8 +- poulpy-backend/benches/fft.rs | 227 ----- poulpy-backend/benches/vec_znx.rs | 43 - poulpy-backend/benches/vmp.rs | 33 - poulpy-backend/build.rs | 7 - poulpy-backend/builds/cpu_spqlios.rs | 12 - poulpy-backend/src/cpu_fft64_avx/tests.rs | 128 --- poulpy-backend/src/cpu_spqlios/ffi/cnv.rs | 7 - poulpy-backend/src/cpu_spqlios/ffi/mod.rs | 19 - poulpy-backend/src/cpu_spqlios/ffi/module.rs | 17 - poulpy-backend/src/cpu_spqlios/ffi/reim.rs | 172 ---- poulpy-backend/src/cpu_spqlios/ffi/svp.rs | 38 - poulpy-backend/src/cpu_spqlios/ffi/vec_znx.rs | 119 --- .../src/cpu_spqlios/ffi/vec_znx_big.rs | 151 --- .../src/cpu_spqlios/ffi/vec_znx_dft.rs | 56 -- poulpy-backend/src/cpu_spqlios/ffi/vmp.rs | 102 -- poulpy-backend/src/cpu_spqlios/ffi/zn64.rs | 13 - poulpy-backend/src/cpu_spqlios/ffi/znx.rs | 7 - poulpy-backend/src/cpu_spqlios/fft64/mod.rs | 10 - .../src/cpu_spqlios/fft64/module.rs | 34 - .../src/cpu_spqlios/fft64/scratch.rs | 81 -- .../src/cpu_spqlios/fft64/svp_ppol.rs | 104 -- .../src/cpu_spqlios/fft64/vec_znx.rs | 908 ------------------ .../src/cpu_spqlios/fft64/vec_znx_big.rs | 621 ------------ .../src/cpu_spqlios/fft64/vec_znx_dft.rs | 435 --------- .../src/cpu_spqlios/fft64/vmp_pmat.rs | 281 ------ poulpy-backend/src/cpu_spqlios/fft64/znx.rs | 189 ---- poulpy-backend/src/cpu_spqlios/mod.rs | 10 - poulpy-backend/src/cpu_spqlios/ntt120/mod.rs | 7 - .../src/cpu_spqlios/ntt120/module.rs | 33 - .../src/cpu_spqlios/ntt120/svp_ppol.rs | 24 - .../src/cpu_spqlios/ntt120/vec_znx_big.rs | 9 - .../src/cpu_spqlios/ntt120/vec_znx_dft.rs | 18 - .../src/cpu_spqlios/ntt120/vmp_pmat.rs | 1 - .../src/cpu_spqlios/spqlios-arithmetic | 1 - poulpy-backend/src/cpu_spqlios/tests.rs | 117 --- poulpy-backend/src/lib.rs | 11 - poulpy-core/Cargo.toml | 4 +- .../benches/external_product_glwe_fft64.rs | 18 +- poulpy-core/benches/keyswitch_glwe_fft64.rs | 14 +- poulpy-core/examples/encryption.rs | 8 +- poulpy-core/src/tests/mod.rs | 252 ++--- poulpy-cpu-avx/Cargo.toml | 33 + poulpy-cpu-avx/README.md | 18 + poulpy-cpu-avx/benches/fft.rs | 80 ++ poulpy-cpu-avx/benches/vec_znx.rs | 26 + poulpy-cpu-avx/benches/vmp.rs | 11 + .../examples/rlwe_encrypt.rs | 12 +- .../mod.rs => poulpy-cpu-avx/src/lib.rs | 0 .../src}/module.rs | 2 +- .../src}/reim/conversion.rs | 0 .../src}/reim/fft16_avx2_fma.s | 0 .../src}/reim/fft_avx2_fma.rs | 2 +- .../src}/reim/fft_vec_avx2_fma.rs | 0 .../src}/reim/ifft16_avx2_fma.s | 0 .../src}/reim/ifft_avx2_fma.rs | 2 +- .../src}/reim/mod.rs | 2 +- .../src}/reim4/arithmetic_avx.rs | 0 .../src}/reim4/mod.rs | 0 .../src}/scratch.rs | 2 +- .../src}/svp.rs | 2 +- poulpy-cpu-avx/src/tests.rs | 125 +++ .../src}/vec_znx.rs | 2 +- .../src}/vec_znx_big.rs | 2 +- .../src}/vec_znx_dft.rs | 2 +- .../src}/vmp.rs | 2 +- .../src}/znx_avx/add.rs | 0 .../src}/znx_avx/automorphism.rs | 0 .../src}/znx_avx/mod.rs | 0 .../src}/znx_avx/mul.rs | 2 +- .../src}/znx_avx/neg.rs | 0 .../src}/znx_avx/normalization.rs | 0 .../src}/znx_avx/sub.rs | 0 .../src}/znx_avx/switch_ring.rs | 0 {poulpy-backend => poulpy-cpu-ref}/Cargo.toml | 9 +- {poulpy-backend => poulpy-cpu-ref}/README.md | 0 poulpy-cpu-ref/benches/fft.rs | 64 ++ poulpy-cpu-ref/benches/vec_znx.rs | 28 + poulpy-cpu-ref/benches/vmp.rs | 11 + .../mod.rs => poulpy-cpu-ref/src/lib.rs | 0 poulpy-cpu-ref/src/main.rs | 3 + .../src}/module.rs | 2 +- .../src}/reim.rs | 0 .../src}/scratch.rs | 2 +- .../src}/svp.rs | 2 +- .../src}/tests.rs | 0 .../src}/vec_znx.rs | 2 +- .../src}/vec_znx_big.rs | 2 +- .../src}/vec_znx_dft.rs | 2 +- .../src}/vmp.rs | 2 +- .../src}/znx.rs | 2 +- poulpy-hal/Cargo.toml | 1 + poulpy-hal/src/test_suite/vmp.rs | 42 +- poulpy-schemes/Cargo.toml | 3 +- .../benches/circuit_bootstrapping.rs | 10 +- .../examples/circuit_bootstrapping.rs | 6 +- .../bdd_arithmetic/bdd_1w_to_1w.rs | 2 +- .../bdd_arithmetic/bdd_2w_to_1w.rs | 2 +- .../bdd_arithmetic/blind_retrieval.rs | 2 +- .../bdd_arithmetic/blind_rotation.rs | 2 +- .../bdd_arithmetic/blind_selection.rs | 2 +- .../bdd_arithmetic/ciphertexts/fhe_uint.rs | 2 +- .../ciphertexts/fhe_uint_prepared.rs | 8 +- .../ciphertexts/fhe_uint_prepared_debug.rs | 4 +- .../bdd_arithmetic/ciphertexts/mod.rs | 0 .../bdd_arithmetic/circuits/mod.rs | 0 .../circuits/u32/add_codegen.rs | 2 +- .../circuits/u32/and_codegen.rs | 2 +- .../circuits/u32/identity_codgen.rs | 2 +- .../bdd_arithmetic/circuits/u32/mod.rs | 0 .../bdd_arithmetic/circuits/u32/or_codegen.rs | 2 +- .../circuits/u32/sll_codegen.rs | 2 +- .../circuits/u32/slt_codegen.rs | 2 +- .../circuits/u32/sltu_codegen.rs | 2 +- .../circuits/u32/sra_codegen.rs | 2 +- .../circuits/u32/srl_codegen.rs | 2 +- .../circuits/u32/sub_codegen.rs | 2 +- .../circuits/u32/xor_codegen.rs | 2 +- .../{tfhe => bin_fhe}/bdd_arithmetic/eval.rs | 2 +- .../{tfhe => bin_fhe}/bdd_arithmetic/key.rs | 40 +- .../{tfhe => bin_fhe}/bdd_arithmetic/mod.rs | 0 .../bin_fhe/bdd_arithmetic/tests/fft64_avx.rs | 113 +++ .../bin_fhe/bdd_arithmetic/tests/fft64_ref.rs | 113 +++ .../src/bin_fhe/bdd_arithmetic/tests/mod.rs | 9 + .../bdd_arithmetic/tests/test_suite/add.rs | 2 +- .../bdd_arithmetic/tests/test_suite/and.rs | 2 +- .../tests/test_suite/fheuint.rs | 2 +- .../tests/test_suite/ggsw_blind_rotations.rs | 2 +- .../tests/test_suite/glwe_blind_rotation.rs | 2 +- .../tests/test_suite/glwe_blind_selection.rs | 2 +- .../bdd_arithmetic/tests/test_suite/mod.rs | 2 +- .../bdd_arithmetic/tests/test_suite/or.rs | 2 +- .../tests/test_suite/prepare.rs | 2 +- .../bdd_arithmetic/tests/test_suite/sll.rs | 2 +- .../bdd_arithmetic/tests/test_suite/slt.rs | 2 +- .../bdd_arithmetic/tests/test_suite/sltu.rs | 2 +- .../bdd_arithmetic/tests/test_suite/sra.rs | 2 +- .../bdd_arithmetic/tests/test_suite/srl.rs | 2 +- .../bdd_arithmetic/tests/test_suite/sub.rs | 2 +- .../bdd_arithmetic/tests/test_suite/swap.rs | 2 +- .../bdd_arithmetic/tests/test_suite/xor.rs | 2 +- .../algorithms/cggi/algorithm.rs | 2 +- .../blind_rotation/algorithms/cggi/key.rs | 2 +- .../algorithms/cggi/key_compressed.rs | 2 +- .../algorithms/cggi/key_prepared.rs | 2 +- .../blind_rotation/algorithms/cggi/mod.rs | 2 +- .../blind_rotation/algorithms/mod.rs | 4 +- .../blind_rotation/encryption/key.rs | 2 +- .../encryption/key_compressed.rs | 2 +- .../blind_rotation/encryption/mod.rs | 0 .../blind_rotation/layouts/key.rs | 2 +- .../blind_rotation/layouts/key_compressed.rs | 2 +- .../blind_rotation/layouts/key_prepared.rs | 2 +- .../blind_rotation/layouts/mod.rs | 0 .../{tfhe => bin_fhe}/blind_rotation/lut.rs | 0 .../{tfhe => bin_fhe}/blind_rotation/mod.rs | 0 .../bin_fhe/blind_rotation/tests/fft64_avx.rs | 40 + .../blind_rotation/tests/fft64_ref.rs} | 4 +- .../src/bin_fhe/blind_rotation/tests/mod.rs | 10 + .../test_suite}/generic_blind_rotation.rs | 2 +- .../tests/test_suite}/generic_lut.rs | 2 +- .../test_suite}/generic_serialization.rs | 2 +- .../blind_rotation/tests/test_suite/mod.rs | 3 + .../{tfhe => bin_fhe}/blind_rotation/utils.rs | 0 .../circuit_bootstrapping/circuit.rs | 2 +- .../circuit_bootstrapping/key.rs | 2 +- .../circuit_bootstrapping/key_compressed.rs | 2 +- .../circuit_bootstrapping/key_prepared.rs | 2 +- .../circuit_bootstrapping/mod.rs | 0 .../tests/circuit_bootstrapping.rs | 2 +- .../circuit_bootstrapping/tests/fft64_avx.rs | 21 + .../circuit_bootstrapping/tests/fft64_ref.rs} | 8 +- .../circuit_bootstrapping/tests/mod.rs | 9 + poulpy-schemes/src/{tfhe => bin_fhe}/mod.rs | 0 poulpy-schemes/src/lib.rs | 2 +- .../tfhe/bdd_arithmetic/tests/fft64_ref.rs | 122 --- .../src/tfhe/bdd_arithmetic/tests/mod.rs | 4 - .../tests/implementation/mod.rs | 1 - .../src/tfhe/blind_rotation/tests/mod.rs | 7 - .../tfhe/circuit_bootstrapping/tests/mod.rs | 3 - 182 files changed, 1053 insertions(+), 4483 deletions(-) delete mode 100644 .gitmodules delete mode 100644 poulpy-backend/benches/fft.rs delete mode 100644 poulpy-backend/benches/vec_znx.rs delete mode 100644 poulpy-backend/benches/vmp.rs delete mode 100644 poulpy-backend/build.rs delete mode 100644 poulpy-backend/builds/cpu_spqlios.rs delete mode 100644 poulpy-backend/src/cpu_fft64_avx/tests.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ffi/cnv.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ffi/mod.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ffi/module.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ffi/reim.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ffi/svp.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ffi/vec_znx.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ffi/vec_znx_big.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ffi/vec_znx_dft.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ffi/vmp.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ffi/zn64.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ffi/znx.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/fft64/mod.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/fft64/module.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/fft64/scratch.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/fft64/svp_ppol.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/fft64/vec_znx.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/fft64/vec_znx_big.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/fft64/vec_znx_dft.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/fft64/vmp_pmat.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/fft64/znx.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/mod.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ntt120/mod.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ntt120/module.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ntt120/svp_ppol.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ntt120/vec_znx_big.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ntt120/vec_znx_dft.rs delete mode 100644 poulpy-backend/src/cpu_spqlios/ntt120/vmp_pmat.rs delete mode 160000 poulpy-backend/src/cpu_spqlios/spqlios-arithmetic delete mode 100644 poulpy-backend/src/cpu_spqlios/tests.rs delete mode 100644 poulpy-backend/src/lib.rs create mode 100644 poulpy-cpu-avx/Cargo.toml create mode 100644 poulpy-cpu-avx/README.md create mode 100644 poulpy-cpu-avx/benches/fft.rs create mode 100644 poulpy-cpu-avx/benches/vec_znx.rs create mode 100644 poulpy-cpu-avx/benches/vmp.rs rename {poulpy-backend => poulpy-cpu-avx}/examples/rlwe_encrypt.rs (91%) rename poulpy-backend/src/cpu_fft64_avx/mod.rs => poulpy-cpu-avx/src/lib.rs (100%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/module.rs (99%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/reim/conversion.rs (100%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/reim/fft16_avx2_fma.s (100%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/reim/fft_avx2_fma.rs (99%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/reim/fft_vec_avx2_fma.rs (100%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/reim/ifft16_avx2_fma.s (100%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/reim/ifft_avx2_fma.rs (99%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/reim/mod.rs (95%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/reim4/arithmetic_avx.rs (100%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/reim4/mod.rs (100%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/scratch.rs (98%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/svp.rs (96%) create mode 100644 poulpy-cpu-avx/src/tests.rs rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/vec_znx.rs (99%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/vec_znx_big.rs (99%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/vec_znx_dft.rs (98%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/vmp.rs (98%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/znx_avx/add.rs (100%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/znx_avx/automorphism.rs (100%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/znx_avx/mod.rs (100%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/znx_avx/mul.rs (99%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/znx_avx/neg.rs (100%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/znx_avx/normalization.rs (100%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/znx_avx/sub.rs (100%) rename {poulpy-backend/src/cpu_fft64_avx => poulpy-cpu-avx/src}/znx_avx/switch_ring.rs (100%) rename {poulpy-backend => poulpy-cpu-ref}/Cargo.toml (77%) rename {poulpy-backend => poulpy-cpu-ref}/README.md (100%) create mode 100644 poulpy-cpu-ref/benches/fft.rs create mode 100644 poulpy-cpu-ref/benches/vec_znx.rs create mode 100644 poulpy-cpu-ref/benches/vmp.rs rename poulpy-backend/src/cpu_fft64_ref/mod.rs => poulpy-cpu-ref/src/lib.rs (100%) create mode 100644 poulpy-cpu-ref/src/main.rs rename {poulpy-backend/src/cpu_fft64_ref => poulpy-cpu-ref/src}/module.rs (97%) rename {poulpy-backend/src/cpu_fft64_ref => poulpy-cpu-ref/src}/reim.rs (100%) rename {poulpy-backend/src/cpu_fft64_ref => poulpy-cpu-ref/src}/scratch.rs (98%) rename {poulpy-backend/src/cpu_fft64_ref => poulpy-cpu-ref/src}/svp.rs (96%) rename {poulpy-backend/src/cpu_fft64_ref => poulpy-cpu-ref/src}/tests.rs (100%) rename {poulpy-backend/src/cpu_fft64_ref => poulpy-cpu-ref/src}/vec_znx.rs (99%) rename {poulpy-backend/src/cpu_fft64_ref => poulpy-cpu-ref/src}/vec_znx_big.rs (99%) rename {poulpy-backend/src/cpu_fft64_ref => poulpy-cpu-ref/src}/vec_znx_dft.rs (98%) rename {poulpy-backend/src/cpu_fft64_ref => poulpy-cpu-ref/src}/vmp.rs (98%) rename {poulpy-backend/src/cpu_fft64_ref => poulpy-cpu-ref/src}/znx.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/bdd_1w_to_1w.rs (97%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/bdd_2w_to_1w.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/blind_retrieval.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/blind_rotation.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/blind_selection.rs (97%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/ciphertexts/fhe_uint.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs (98%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/ciphertexts/fhe_uint_prepared_debug.rs (97%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/ciphertexts/mod.rs (100%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/circuits/mod.rs (100%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/circuits/u32/add_codegen.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/circuits/u32/and_codegen.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/circuits/u32/identity_codgen.rs (98%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/circuits/u32/mod.rs (100%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/circuits/u32/or_codegen.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/circuits/u32/sll_codegen.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/circuits/u32/slt_codegen.rs (98%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/circuits/u32/sltu_codegen.rs (98%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/circuits/u32/sra_codegen.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/circuits/u32/srl_codegen.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/circuits/u32/sub_codegen.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/circuits/u32/xor_codegen.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/eval.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/key.rs (92%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/mod.rs (100%) create mode 100644 poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/fft64_avx.rs create mode 100644 poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/fft64_ref.rs create mode 100644 poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/mod.rs rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/add.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/and.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/fheuint.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/ggsw_blind_rotations.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/glwe_blind_rotation.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/glwe_blind_selection.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/mod.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/or.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/prepare.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/sll.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/slt.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/sltu.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/sra.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/srl.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/sub.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/swap.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/bdd_arithmetic/tests/test_suite/xor.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/algorithms/cggi/algorithm.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/algorithms/cggi/key.rs (98%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/algorithms/cggi/key_compressed.rs (98%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/algorithms/cggi/key_prepared.rs (98%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/algorithms/cggi/mod.rs (71%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/algorithms/mod.rs (95%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/encryption/key.rs (95%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/encryption/key_compressed.rs (91%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/encryption/mod.rs (100%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/layouts/key.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/layouts/key_compressed.rs (98%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/layouts/key_prepared.rs (97%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/layouts/mod.rs (100%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/lut.rs (100%) rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/mod.rs (100%) create mode 100644 poulpy-schemes/src/bin_fhe/blind_rotation/tests/fft64_avx.rs rename poulpy-schemes/src/{tfhe/blind_rotation/tests/implementation/fft64.rs => bin_fhe/blind_rotation/tests/fft64_ref.rs} (94%) create mode 100644 poulpy-schemes/src/bin_fhe/blind_rotation/tests/mod.rs rename poulpy-schemes/src/{tfhe/blind_rotation/tests => bin_fhe/blind_rotation/tests/test_suite}/generic_blind_rotation.rs (99%) rename poulpy-schemes/src/{tfhe/blind_rotation/tests => bin_fhe/blind_rotation/tests/test_suite}/generic_lut.rs (96%) rename poulpy-schemes/src/{tfhe/blind_rotation/tests => bin_fhe/blind_rotation/tests/test_suite}/generic_serialization.rs (89%) create mode 100644 poulpy-schemes/src/bin_fhe/blind_rotation/tests/test_suite/mod.rs rename poulpy-schemes/src/{tfhe => bin_fhe}/blind_rotation/utils.rs (100%) rename poulpy-schemes/src/{tfhe => bin_fhe}/circuit_bootstrapping/circuit.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/circuit_bootstrapping/key.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/circuit_bootstrapping/key_compressed.rs (83%) rename poulpy-schemes/src/{tfhe => bin_fhe}/circuit_bootstrapping/key_prepared.rs (99%) rename poulpy-schemes/src/{tfhe => bin_fhe}/circuit_bootstrapping/mod.rs (100%) rename poulpy-schemes/src/{tfhe => bin_fhe}/circuit_bootstrapping/tests/circuit_bootstrapping.rs (99%) create mode 100644 poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/fft64_avx.rs rename poulpy-schemes/src/{tfhe/circuit_bootstrapping/tests/fft64.rs => bin_fhe/circuit_bootstrapping/tests/fft64_ref.rs} (81%) create mode 100644 poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/mod.rs rename poulpy-schemes/src/{tfhe => bin_fhe}/mod.rs (100%) delete mode 100644 poulpy-schemes/src/tfhe/bdd_arithmetic/tests/fft64_ref.rs delete mode 100644 poulpy-schemes/src/tfhe/bdd_arithmetic/tests/mod.rs delete mode 100644 poulpy-schemes/src/tfhe/blind_rotation/tests/implementation/mod.rs delete mode 100644 poulpy-schemes/src/tfhe/blind_rotation/tests/mod.rs delete mode 100644 poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/mod.rs diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e3b469f..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "poulpy-backend/src/cpu_spqlios/spqlios-arithmetic"] - path = poulpy-backend/src/cpu_spqlios/spqlios-arithmetic - url = https://github.com/phantomzone-org/spqlios-arithmetic diff --git a/Cargo.lock b/Cargo.lock index ebc0f43..ce45514 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -358,14 +358,31 @@ dependencies = [ ] [[package]] -name = "poulpy-backend" +name = "poulpy-core" version = "0.3.2" dependencies = [ + "bytemuck", "byteorder", - "cmake", "criterion", "itertools 0.14.0", "once_cell", + "paste", + "poulpy-cpu-avx", + "poulpy-cpu-ref", + "poulpy-hal", + "rug", +] + +[[package]] +name = "poulpy-cpu-avx" +version = "0.3.2" +dependencies = [ + "byteorder", + "criterion", + "itertools 0.14.0", + "once_cell", + "paste", + "poulpy-cpu-ref", "poulpy-hal", "rand", "rand_chacha", @@ -375,16 +392,18 @@ dependencies = [ ] [[package]] -name = "poulpy-core" +name = "poulpy-cpu-ref" version = "0.3.2" dependencies = [ - "bytemuck", "byteorder", "criterion", "itertools 0.14.0", "once_cell", - "poulpy-backend", "poulpy-hal", + "rand", + "rand_chacha", + "rand_core", + "rand_distr", "rug", ] @@ -398,6 +417,7 @@ dependencies = [ "criterion", "itertools 0.14.0", "once_cell", + "paste", "rand", "rand_chacha", "rand_core", @@ -413,8 +433,9 @@ dependencies = [ "criterion", "itertools 0.14.0", "paste", - "poulpy-backend", "poulpy-core", + "poulpy-cpu-avx", + "poulpy-cpu-ref", "poulpy-hal", "rand", ] diff --git a/Cargo.toml b/Cargo.toml index 964e654..4df0906 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,12 @@ [workspace] -members = ["poulpy-hal", "poulpy-core", "poulpy-backend", "poulpy-schemes"] +members = ["poulpy-hal", "poulpy-core", "poulpy-cpu-avx", "poulpy-schemes", "poulpy-cpu-ref"] resolver = "3" [workspace.dependencies] poulpy-hal = {path = "poulpy-hal"} poulpy-core = {path = "poulpy-core"} -poulpy-backend = {path = "poulpy-backend"} +poulpy-cpu-avx = {path = "poulpy-cpu-avx"} +poulpy-cpu-ref = {path = "poulpy-cpu-ref"} poulpy-schemes = {path = "poulpy-schemes"} rug = "1.28.0" rand = "0.9.2" @@ -17,4 +18,5 @@ criterion = "0.7.0" byteorder = "1.5.0" zstd = "0.13.3" once_cell = "1.21.3" -bytemuck = "1.24.0" \ No newline at end of file +bytemuck = "1.24.0" +paste = "1.0.15" \ No newline at end of file diff --git a/poulpy-backend/benches/fft.rs b/poulpy-backend/benches/fft.rs deleted file mode 100644 index 88665b3..0000000 --- a/poulpy-backend/benches/fft.rs +++ /dev/null @@ -1,227 +0,0 @@ -use std::{ffi::c_void, hint::black_box}; - -use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main}; -use poulpy_backend::cpu_spqlios::reim; -use poulpy_hal::reference::fft64::reim::{ReimDFTExecute, ReimFFTRef, ReimFFTTable, ReimIFFTRef, ReimIFFTTable}; - -pub fn bench_fft_ref(c: &mut Criterion) { - let group_name: String = "fft_ref".to_string(); - - let mut group = c.benchmark_group(group_name); - - fn runner(m: usize) -> impl FnMut() { - let mut values: Vec = vec![0f64; m << 1]; - let scale: f64 = 1.0f64 / (2 * m) as f64; - values - .iter_mut() - .enumerate() - .for_each(|(i, x)| *x = (i + 1) as f64 * scale); - let table: ReimFFTTable = ReimFFTTable::::new(m); - move || { - ReimFFTRef::reim_dft_execute(&table, &mut values); - black_box(()); - } - } - - for log_m in [9, 10, 11, 12, 13, 14, 15] { - let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m)); - let mut runner = runner(1 << log_m); - group.bench_with_input(id, &(), |b, _| b.iter(&mut runner)); - } - - group.finish(); -} - -pub fn bench_fft_spqlios(c: &mut Criterion) { - let group_name: String = "fft_spqlios".to_string(); - - let mut group = c.benchmark_group(group_name); - - fn runner(m: usize) -> impl FnMut() { - let mut values: Vec = vec![0f64; m << 1]; - - let scale = 1.0f64 / (2 * m) as f64; - values - .iter_mut() - .enumerate() - .for_each(|(i, x)| *x = (i + 1) as f64 * scale); - - unsafe { - reim::reim_fft_simple(m as u32, values.as_mut_ptr() as *mut c_void); - } - - move || { - unsafe { - reim::reim_fft_simple(m as u32, values.as_mut_ptr() as *mut c_void); - } - black_box(()); - } - } - - for log_m in [9, 10, 11, 12, 13, 14, 15] { - let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m)); - let mut runner = runner(1 << log_m); - group.bench_with_input(id, &(), |b, _| b.iter(&mut runner)); - } - - group.finish(); -} - -pub fn bench_ifft_ref(c: &mut Criterion) { - let group_name: String = "ifft_ref".to_string(); - - let mut group = c.benchmark_group(group_name); - - fn runner(m: usize) -> impl FnMut() { - let mut values: Vec = vec![0f64; m << 1]; - let scale: f64 = 1.0f64 / (2 * m) as f64; - values - .iter_mut() - .enumerate() - .for_each(|(i, x)| *x = (i + 1) as f64 * scale); - let table: ReimIFFTTable = ReimIFFTTable::::new(m); - move || { - ReimIFFTRef::reim_dft_execute(&table, &mut values); - black_box(()); - } - } - - for log_m in [9, 10, 11, 12, 13, 14, 15] { - let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m)); - let mut runner = runner(1 << log_m); - group.bench_with_input(id, &(), |b, _| b.iter(&mut runner)); - } - - group.finish(); -} - -pub fn bench_ifft_spqlios(c: &mut Criterion) { - let group_name: String = "ifft_spqlios".to_string(); - - let mut group = c.benchmark_group(group_name); - - fn runner(m: usize) -> impl FnMut() { - let mut values: Vec = vec![0f64; m << 1]; - - let scale = 1.0f64 / (2 * m) as f64; - values - .iter_mut() - .enumerate() - .for_each(|(i, x)| *x = (i + 1) as f64 * scale); - - unsafe { - reim::reim_ifft_simple(m as u32, values.as_mut_ptr() as *mut c_void); - } - - move || { - unsafe { - reim::reim_ifft_simple(m as u32, values.as_mut_ptr() as *mut c_void); - } - black_box(()); - } - } - - for log_m in [9, 10, 11, 12, 13, 14, 15] { - let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m)); - let mut runner = runner(1 << log_m); - group.bench_with_input(id, &(), |b, _| b.iter(&mut runner)); - } - - group.finish(); -} - -#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] -mod x86 { - use super::*; - - #[allow(dead_code)] - pub fn bench_ifft_avx2_fma(c: &mut Criterion) { - let group_name: String = "ifft_avx2_fma".to_string(); - - let mut group = c.benchmark_group(group_name); - - if std::is_x86_feature_detected!("avx2") { - fn runner(m: usize) -> impl FnMut() { - let mut values: Vec = vec![0f64; m << 1]; - - let scale = 1.0f64 / (2 * m) as f64; - values - .iter_mut() - .enumerate() - .for_each(|(i, x)| *x = (i + 1) as f64 * scale); - - let table: ReimIFFTTable = ReimIFFTTable::::new(m); - move || { - use poulpy_backend::cpu_fft64_avx::ReimIFFTAvx; - - ReimIFFTAvx::reim_dft_execute(&table, &mut values); - black_box(()); - } - } - - for log_m in [9, 10, 11, 12, 13, 14, 15] { - let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m)); - - let mut runner = runner(1 << log_m); - group.bench_with_input(id, &(), |b, _| b.iter(&mut runner)); - } - } else { - eprintln!("skipping: CPU lacks avx2"); - return; - } - - group.finish(); - } - - #[allow(dead_code)] - pub fn bench_fft_avx2_fma(c: &mut Criterion) { - let group_name: String = "fft_avx2_fma".to_string(); - - let mut group = c.benchmark_group(group_name); - - if std::is_x86_feature_detected!("avx2") { - fn runner(m: usize) -> impl FnMut() { - let mut values: Vec = vec![0f64; m << 1]; - - let scale = 1.0f64 / (2 * m) as f64; - values - .iter_mut() - .enumerate() - .for_each(|(i, x)| *x = (i + 1) as f64 * scale); - - let table: ReimFFTTable = ReimFFTTable::::new(m); - move || { - use poulpy_backend::cpu_fft64_avx::ReimFFTAvx; - - ReimFFTAvx::reim_dft_execute(&table, &mut values); - black_box(()); - } - } - - for log_m in [9, 10, 11, 12, 13, 14, 15] { - let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m)); - - let mut runner = runner(1 << log_m); - group.bench_with_input(id, &(), |b, _| b.iter(&mut runner)); - } - } else { - eprintln!("skipping: CPU lacks avx2"); - return; - } - - group.finish(); - } - - criterion_group!(benches_x86, bench_fft_avx2_fma, bench_ifft_avx2_fma,); - criterion_main!(benches_x86); -} - -criterion_group!( - benches, - bench_fft_ref, - bench_fft_spqlios, - bench_ifft_ref, - bench_ifft_spqlios -); - -criterion_main!(benches); diff --git a/poulpy-backend/benches/vec_znx.rs b/poulpy-backend/benches/vec_znx.rs deleted file mode 100644 index 8dafd16..0000000 --- a/poulpy-backend/benches/vec_znx.rs +++ /dev/null @@ -1,43 +0,0 @@ -// poulpy-backend/benches/vec_znx_add.rs -use criterion::{Criterion, criterion_group, criterion_main}; -use poulpy_backend::{cpu_fft64_ref, cpu_spqlios}; -use poulpy_hal::reference::vec_znx::{bench_vec_znx_add, bench_vec_znx_automorphism, bench_vec_znx_normalize_inplace}; - -#[allow(dead_code)] -fn bench_vec_znx_add_cpu_spqlios_fft64(c: &mut Criterion) { - bench_vec_znx_add::(c, "cpu_spqlios::fft64"); -} - -#[allow(dead_code)] -fn bench_vec_znx_add_cpu_ref_fft64(c: &mut Criterion) { - bench_vec_znx_add::(c, "cpu_spqlios::fft64"); -} - -#[allow(dead_code)] -fn bench_vec_znx_normalize_inplace_cpu_ref_fft64(c: &mut Criterion) { - bench_vec_znx_normalize_inplace::(c, "cpu_ref::fft64"); -} - -#[allow(dead_code)] -fn bench_vec_znx_normalize_inplace_cpu_spqlios_fft64(c: &mut Criterion) { - bench_vec_znx_normalize_inplace::(c, "cpu_spqlios::fft64"); -} - -fn bench_vec_znx_automorphism_cpu_ref_fft64(c: &mut Criterion) { - bench_vec_znx_automorphism::(c, "cpu_ref::fft64"); -} - -fn bench_vec_znx_automorphism_cpu_spqlios_fft64(c: &mut Criterion) { - bench_vec_znx_automorphism::(c, "cpu_spqlios::fft64"); -} - -criterion_group!( - benches, - // bench_vec_znx_add_cpu_spqlios_fft64, - // bench_vec_znx_add_cpu_ref_fft64, - // bench_vec_znx_normalize_inplace_cpu_ref_fft64, - // bench_vec_znx_normalize_inplace_cpu_spqlios_fft64, - bench_vec_znx_automorphism_cpu_ref_fft64, - bench_vec_znx_automorphism_cpu_spqlios_fft64, -); -criterion_main!(benches); diff --git a/poulpy-backend/benches/vmp.rs b/poulpy-backend/benches/vmp.rs deleted file mode 100644 index ae2dfb4..0000000 --- a/poulpy-backend/benches/vmp.rs +++ /dev/null @@ -1,33 +0,0 @@ -// poulpy-backend/benches/vec_znx_add.rs -use criterion::{Criterion, criterion_group, criterion_main}; -use poulpy_backend::{FFT64Ref, FFT64Spqlios}; -use poulpy_hal::bench_suite::vmp::bench_vmp_apply_dft_to_dft; - -fn bench_vmp_apply_dft_to_dft_cpu_spqlios_fft64(c: &mut Criterion) { - bench_vmp_apply_dft_to_dft::(c, "cpu_spqlios::fft64"); -} - -fn bench_vmp_apply_dft_to_dft_cpu_ref_fft64(c: &mut Criterion) { - bench_vmp_apply_dft_to_dft::(c, "cpu_ref::fft64"); -} - -#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] -mod x86 { - use super::*; - use poulpy_backend::FFT64Avx; - - #[allow(dead_code)] - fn bench_vmp_apply_dft_to_dft_cpu_avx_fft64(c: &mut Criterion) { - bench_vmp_apply_dft_to_dft::(c, "cpu_avx::fft64"); - } - - criterion_group!(benches_x86, bench_vmp_apply_dft_to_dft_cpu_avx_fft64,); - criterion_main!(benches_x86); -} - -criterion_group!( - benches, - bench_vmp_apply_dft_to_dft_cpu_spqlios_fft64, - bench_vmp_apply_dft_to_dft_cpu_ref_fft64, -); -criterion_main!(benches); diff --git a/poulpy-backend/build.rs b/poulpy-backend/build.rs deleted file mode 100644 index e6d82be..0000000 --- a/poulpy-backend/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod builds { - pub mod cpu_spqlios; -} - -fn main() { - builds::cpu_spqlios::build() -} diff --git a/poulpy-backend/builds/cpu_spqlios.rs b/poulpy-backend/builds/cpu_spqlios.rs deleted file mode 100644 index 8abb07a..0000000 --- a/poulpy-backend/builds/cpu_spqlios.rs +++ /dev/null @@ -1,12 +0,0 @@ -use std::path::PathBuf; - -pub fn build() { - let dst: PathBuf = cmake::Config::new("src/cpu_spqlios/spqlios-arithmetic") - .define("ENABLE_TESTING", "FALSE") - .build(); - - let lib_dir: PathBuf = dst.join("lib"); - - println!("cargo:rustc-link-search=native={}", lib_dir.display()); - println!("cargo:rustc-link-lib=static=spqlios"); -} diff --git a/poulpy-backend/src/cpu_fft64_avx/tests.rs b/poulpy-backend/src/cpu_fft64_avx/tests.rs deleted file mode 100644 index 9abddf0..0000000 --- a/poulpy-backend/src/cpu_fft64_avx/tests.rs +++ /dev/null @@ -1,128 +0,0 @@ -use poulpy_hal::{ - api::ModuleNew, backend_test_suite, cross_backend_test_suite, layouts::Module, - test_suite::convolution::test_bivariate_tensoring, -}; - -use crate::FFT64Avx; - -cross_backend_test_suite! { - mod vec_znx, - backend_ref = crate::cpu_fft64_ref::FFT64Ref, - backend_test = crate::cpu_fft64_avx::FFT64Avx, - size = 1 << 5, - base2k = 12, - tests = { - test_vec_znx_add => poulpy_hal::test_suite::vec_znx::test_vec_znx_add, - test_vec_znx_add_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_inplace, - test_vec_znx_add_scalar => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_scalar, - test_vec_znx_add_scalar_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_scalar_inplace, - test_vec_znx_sub => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub, - test_vec_znx_sub_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_inplace, - test_vec_znx_sub_negate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_negate_inplace, - test_vec_znx_sub_scalar => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_scalar, - test_vec_znx_sub_scalar_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_scalar_inplace, - test_vec_znx_rsh => poulpy_hal::test_suite::vec_znx::test_vec_znx_rsh, - test_vec_znx_rsh_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_rsh_inplace, - test_vec_znx_lsh => poulpy_hal::test_suite::vec_znx::test_vec_znx_lsh, - test_vec_znx_lsh_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_lsh_inplace, - test_vec_znx_negate => poulpy_hal::test_suite::vec_znx::test_vec_znx_negate, - test_vec_znx_negate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_negate_inplace, - test_vec_znx_rotate => poulpy_hal::test_suite::vec_znx::test_vec_znx_rotate, - test_vec_znx_rotate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_rotate_inplace, - test_vec_znx_automorphism => poulpy_hal::test_suite::vec_znx::test_vec_znx_automorphism, - test_vec_znx_automorphism_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_automorphism_inplace, - test_vec_znx_mul_xp_minus_one => poulpy_hal::test_suite::vec_znx::test_vec_znx_mul_xp_minus_one, - test_vec_znx_mul_xp_minus_one_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_mul_xp_minus_one_inplace, - test_vec_znx_normalize => poulpy_hal::test_suite::vec_znx::test_vec_znx_normalize, - test_vec_znx_normalize_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_normalize_inplace, - test_vec_znx_switch_ring => poulpy_hal::test_suite::vec_znx::test_vec_znx_switch_ring, - test_vec_znx_split_ring => poulpy_hal::test_suite::vec_znx::test_vec_znx_split_ring, - test_vec_znx_copy => poulpy_hal::test_suite::vec_znx::test_vec_znx_copy, - } -} - -cross_backend_test_suite! { - mod svp, - backend_ref = crate::cpu_fft64_ref::FFT64Ref, - backend_test = crate::cpu_fft64_avx::FFT64Avx, - size = 1 << 5, - base2k = 12, - tests = { - test_svp_apply_dft_to_dft => poulpy_hal::test_suite::svp::test_svp_apply_dft_to_dft, - test_svp_apply_dft_to_dft_inplace => poulpy_hal::test_suite::svp::test_svp_apply_dft_to_dft_inplace, - } -} - -cross_backend_test_suite! { - mod vec_znx_big, - backend_ref = crate::cpu_fft64_ref::FFT64Ref, - backend_test = crate::cpu_fft64_avx::FFT64Avx, - size = 1 << 5, - base2k = 12, - tests = { - test_vec_znx_big_add => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add, - test_vec_znx_big_add_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_inplace, - test_vec_znx_big_add_small => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_small, - test_vec_znx_big_add_small_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_small_inplace, - test_vec_znx_big_sub => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub, - test_vec_znx_big_sub_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_inplace, - test_vec_znx_big_automorphism => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_automorphism, - test_vec_znx_big_automorphism_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_automorphism_inplace, - test_vec_znx_big_negate => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_negate, - test_vec_znx_big_negate_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_negate_inplace, - test_vec_znx_big_normalize => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_normalize, - test_vec_znx_big_sub_negate_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_negate_inplace, - test_vec_znx_big_sub_small_a => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_a, - test_vec_znx_big_sub_small_a_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_a_inplace, - test_vec_znx_big_sub_small_b => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_b, - test_vec_znx_big_sub_small_b_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_b_inplace, - } -} - -cross_backend_test_suite! { - mod vec_znx_dft, - backend_ref = crate::cpu_fft64_ref::FFT64Ref, - backend_test = crate::cpu_fft64_avx::FFT64Avx, - size = 1 << 5, - base2k = 12, - tests = { - test_vec_znx_dft_add => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_add, - test_vec_znx_dft_add_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_add_inplace, - test_vec_znx_dft_sub => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub, - test_vec_znx_dft_sub_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub_inplace, - test_vec_znx_dft_sub_negate_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub_negate_inplace, - test_vec_znx_idft_apply => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply, - test_vec_znx_idft_apply_consume => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply_consume, - test_vec_znx_idft_apply_tmpa => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply_tmpa, - } -} - -cross_backend_test_suite! { - mod vmp, - backend_ref = crate::cpu_fft64_ref::FFT64Ref, - backend_test = crate::cpu_fft64_avx::FFT64Avx, - size = 1 << 5, - base2k = 12, - tests = { - test_vmp_apply_dft_to_dft => poulpy_hal::test_suite::vmp::test_vmp_apply_dft_to_dft, - test_vmp_apply_dft_to_dft_add => poulpy_hal::test_suite::vmp::test_vmp_apply_dft_to_dft_add, - } -} - -backend_test_suite! { - mod sampling, - backend = crate::cpu_fft64_avx::FFT64Avx, - size = 1 << 12, - tests = { - test_vec_znx_fill_uniform => poulpy_hal::test_suite::vec_znx::test_vec_znx_fill_uniform, - test_vec_znx_fill_normal => poulpy_hal::test_suite::vec_znx::test_vec_znx_fill_normal, - test_vec_znx_add_normal => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_normal, - test_vec_znx_big_sub_small_b_inplace => poulpy_hal::reference::fft64::vec_znx_big::test_vec_znx_big_add_normal, - } -} - -#[test] -fn test_convolution_fft64_avx() { - let module: Module = Module::::new(64); - test_bivariate_tensoring(&module); -} diff --git a/poulpy-backend/src/cpu_spqlios/ffi/cnv.rs b/poulpy-backend/src/cpu_spqlios/ffi/cnv.rs deleted file mode 100644 index 07b4f7f..0000000 --- a/poulpy-backend/src/cpu_spqlios/ffi/cnv.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub type CNV_PVEC_L = cnv_pvec_l_t; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct cnv_pvec_r_t { - _unused: [u8; 0], -} -pub type CNV_PVEC_R = cnv_pvec_r_t; diff --git a/poulpy-backend/src/cpu_spqlios/ffi/mod.rs b/poulpy-backend/src/cpu_spqlios/ffi/mod.rs deleted file mode 100644 index df792fb..0000000 --- a/poulpy-backend/src/cpu_spqlios/ffi/mod.rs +++ /dev/null @@ -1,19 +0,0 @@ -#[allow(non_camel_case_types)] -pub mod module; -#[allow(non_camel_case_types)] -pub mod reim; -#[allow(non_camel_case_types)] -pub mod svp; -#[allow(non_camel_case_types)] -pub mod vec_znx; -#[allow(dead_code)] -#[allow(non_camel_case_types)] -pub mod vec_znx_big; -#[allow(non_camel_case_types)] -pub mod vec_znx_dft; -#[allow(non_camel_case_types)] -pub mod vmp; -#[allow(non_camel_case_types)] -pub mod zn64; -#[allow(non_camel_case_types)] -pub mod znx; diff --git a/poulpy-backend/src/cpu_spqlios/ffi/module.rs b/poulpy-backend/src/cpu_spqlios/ffi/module.rs deleted file mode 100644 index 9e67c30..0000000 --- a/poulpy-backend/src/cpu_spqlios/ffi/module.rs +++ /dev/null @@ -1,17 +0,0 @@ -#[repr(C)] -pub struct module_info_t { - _unused: [u8; 0], -} - -pub type module_type_t = ::std::os::raw::c_uint; -pub use self::module_type_t as MODULE_TYPE; - -#[allow(clippy::upper_case_acronyms)] -pub type MODULE = module_info_t; - -unsafe extern "C" { - pub unsafe fn new_module_info(N: u64, mode: MODULE_TYPE) -> *mut MODULE; -} -unsafe extern "C" { - pub unsafe fn delete_module_info(module_info: *mut MODULE); -} diff --git a/poulpy-backend/src/cpu_spqlios/ffi/reim.rs b/poulpy-backend/src/cpu_spqlios/ffi/reim.rs deleted file mode 100644 index eb2fae7..0000000 --- a/poulpy-backend/src/cpu_spqlios/ffi/reim.rs +++ /dev/null @@ -1,172 +0,0 @@ -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct reim_fft_precomp { - _unused: [u8; 0], -} -pub type REIM_FFT_PRECOMP = reim_fft_precomp; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct reim_ifft_precomp { - _unused: [u8; 0], -} -pub type REIM_IFFT_PRECOMP = reim_ifft_precomp; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct reim_mul_precomp { - _unused: [u8; 0], -} -pub type REIM_FFTVEC_MUL_PRECOMP = reim_mul_precomp; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct reim_addmul_precomp { - _unused: [u8; 0], -} -pub type REIM_FFTVEC_ADDMUL_PRECOMP = reim_addmul_precomp; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct reim_from_znx32_precomp { - _unused: [u8; 0], -} -pub type REIM_FROM_ZNX32_PRECOMP = reim_from_znx32_precomp; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct reim_from_znx64_precomp { - _unused: [u8; 0], -} -pub type REIM_FROM_ZNX64_PRECOMP = reim_from_znx64_precomp; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct reim_from_tnx32_precomp { - _unused: [u8; 0], -} -pub type REIM_FROM_TNX32_PRECOMP = reim_from_tnx32_precomp; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct reim_to_tnx32_precomp { - _unused: [u8; 0], -} -pub type REIM_TO_TNX32_PRECOMP = reim_to_tnx32_precomp; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct reim_to_tnx_precomp { - _unused: [u8; 0], -} -pub type REIM_TO_TNX_PRECOMP = reim_to_tnx_precomp; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct reim_to_znx64_precomp { - _unused: [u8; 0], -} -pub type REIM_TO_ZNX64_PRECOMP = reim_to_znx64_precomp; -unsafe extern "C" { - pub unsafe fn new_reim_fft_precomp(m: u32, num_buffers: u32) -> *mut REIM_FFT_PRECOMP; -} -unsafe extern "C" { - pub unsafe fn reim_fft_precomp_get_buffer(tables: *const REIM_FFT_PRECOMP, buffer_index: u32) -> *mut f64; -} -unsafe extern "C" { - pub unsafe fn new_reim_fft_buffer(m: u32) -> *mut f64; -} -unsafe extern "C" { - pub unsafe fn delete_reim_fft_buffer(buffer: *mut f64); -} -unsafe extern "C" { - pub unsafe fn reim_fft(tables: *const REIM_FFT_PRECOMP, data: *mut f64); -} -unsafe extern "C" { - pub unsafe fn new_reim_ifft_precomp(m: u32, num_buffers: u32) -> *mut REIM_IFFT_PRECOMP; -} -unsafe extern "C" { - pub unsafe fn reim_ifft_precomp_get_buffer(tables: *const REIM_IFFT_PRECOMP, buffer_index: u32) -> *mut f64; -} -unsafe extern "C" { - pub unsafe fn reim_ifft(tables: *const REIM_IFFT_PRECOMP, data: *mut f64); -} -unsafe extern "C" { - pub unsafe fn new_reim_fftvec_mul_precomp(m: u32) -> *mut REIM_FFTVEC_MUL_PRECOMP; -} -unsafe extern "C" { - pub unsafe fn reim_fftvec_mul(tables: *const REIM_FFTVEC_MUL_PRECOMP, r: *mut f64, a: *const f64, b: *const f64); -} -unsafe extern "C" { - pub unsafe fn new_reim_fftvec_addmul_precomp(m: u32) -> *mut REIM_FFTVEC_ADDMUL_PRECOMP; -} -unsafe extern "C" { - pub unsafe fn reim_fftvec_addmul(tables: *const REIM_FFTVEC_ADDMUL_PRECOMP, r: *mut f64, a: *const f64, b: *const f64); -} -unsafe extern "C" { - pub unsafe fn new_reim_from_znx32_precomp(m: u32, log2bound: u32) -> *mut REIM_FROM_ZNX32_PRECOMP; -} -unsafe extern "C" { - pub unsafe fn reim_from_znx32(tables: *const REIM_FROM_ZNX32_PRECOMP, r: *mut ::std::os::raw::c_void, a: *const i32); -} -unsafe extern "C" { - pub unsafe fn reim_from_znx64(tables: *const REIM_FROM_ZNX64_PRECOMP, r: *mut ::std::os::raw::c_void, a: *const i64); -} -unsafe extern "C" { - pub unsafe fn new_reim_from_znx64_precomp(m: u32, maxbnd: u32) -> *mut REIM_FROM_ZNX64_PRECOMP; -} -unsafe extern "C" { - pub unsafe fn reim_from_znx64_simple(m: u32, log2bound: u32, r: *mut ::std::os::raw::c_void, a: *const i64); -} -unsafe extern "C" { - pub unsafe fn new_reim_from_tnx32_precomp(m: u32) -> *mut REIM_FROM_TNX32_PRECOMP; -} -unsafe extern "C" { - pub unsafe fn reim_from_tnx32(tables: *const REIM_FROM_TNX32_PRECOMP, r: *mut ::std::os::raw::c_void, a: *const i32); -} -unsafe extern "C" { - pub unsafe fn new_reim_to_tnx32_precomp(m: u32, divisor: f64, log2overhead: u32) -> *mut REIM_TO_TNX32_PRECOMP; -} -unsafe extern "C" { - pub unsafe fn reim_to_tnx32(tables: *const REIM_TO_TNX32_PRECOMP, r: *mut i32, a: *const ::std::os::raw::c_void); -} -unsafe extern "C" { - pub unsafe fn new_reim_to_tnx_precomp(m: u32, divisor: f64, log2overhead: u32) -> *mut REIM_TO_TNX_PRECOMP; -} -unsafe extern "C" { - pub unsafe fn reim_to_tnx(tables: *const REIM_TO_TNX_PRECOMP, r: *mut f64, a: *const f64); -} -unsafe extern "C" { - pub unsafe fn reim_to_tnx_simple(m: u32, divisor: f64, log2overhead: u32, r: *mut f64, a: *const f64); -} -unsafe extern "C" { - pub unsafe fn new_reim_to_znx64_precomp(m: u32, divisor: f64, log2bound: u32) -> *mut REIM_TO_ZNX64_PRECOMP; -} -unsafe extern "C" { - pub unsafe fn reim_to_znx64(precomp: *const REIM_TO_ZNX64_PRECOMP, r: *mut i64, a: *const ::std::os::raw::c_void); -} -unsafe extern "C" { - pub unsafe fn reim_to_znx64_simple(m: u32, divisor: f64, log2bound: u32, r: *mut i64, a: *const ::std::os::raw::c_void); -} -unsafe extern "C" { - pub unsafe fn reim_fft_simple(m: u32, data: *mut ::std::os::raw::c_void); -} -unsafe extern "C" { - pub unsafe fn reim_ifft_simple(m: u32, data: *mut ::std::os::raw::c_void); -} -unsafe extern "C" { - pub unsafe fn reim_fftvec_mul_simple( - m: u32, - r: *mut ::std::os::raw::c_void, - a: *const ::std::os::raw::c_void, - b: *const ::std::os::raw::c_void, - ); -} -unsafe extern "C" { - pub unsafe fn reim_fftvec_addmul_simple( - m: u32, - r: *mut ::std::os::raw::c_void, - a: *const ::std::os::raw::c_void, - b: *const ::std::os::raw::c_void, - ); -} -unsafe extern "C" { - pub unsafe fn reim_from_znx32_simple(m: u32, log2bound: u32, r: *mut ::std::os::raw::c_void, x: *const i32); -} -unsafe extern "C" { - pub unsafe fn reim_from_tnx32_simple(m: u32, r: *mut ::std::os::raw::c_void, x: *const i32); -} -unsafe extern "C" { - pub unsafe fn reim_to_tnx32_simple(m: u32, divisor: f64, log2overhead: u32, r: *mut i32, x: *const ::std::os::raw::c_void); -} diff --git a/poulpy-backend/src/cpu_spqlios/ffi/svp.rs b/poulpy-backend/src/cpu_spqlios/ffi/svp.rs deleted file mode 100644 index 1b72fb3..0000000 --- a/poulpy-backend/src/cpu_spqlios/ffi/svp.rs +++ /dev/null @@ -1,38 +0,0 @@ -use crate::cpu_spqlios::ffi::{module::MODULE, vec_znx_dft::VEC_ZNX_DFT}; - -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct svp_ppol_t { - _unused: [u8; 0], -} -pub type SVP_PPOL = svp_ppol_t; - -unsafe extern "C" { - pub unsafe fn svp_prepare(module: *const MODULE, ppol: *mut SVP_PPOL, pol: *const i64); -} - -#[allow(dead_code)] -unsafe extern "C" { - pub unsafe fn svp_apply_dft( - module: *const MODULE, - res: *const VEC_ZNX_DFT, - res_size: u64, - ppol: *const SVP_PPOL, - a: *const i64, - a_size: u64, - a_sl: u64, - ); -} - -unsafe extern "C" { - pub unsafe fn svp_apply_dft_to_dft( - module: *const MODULE, - res: *const VEC_ZNX_DFT, - res_size: u64, - res_cols: u64, - ppol: *const SVP_PPOL, - a: *const VEC_ZNX_DFT, - a_size: u64, - a_cols: u64, - ); -} diff --git a/poulpy-backend/src/cpu_spqlios/ffi/vec_znx.rs b/poulpy-backend/src/cpu_spqlios/ffi/vec_znx.rs deleted file mode 100644 index 6ede6f1..0000000 --- a/poulpy-backend/src/cpu_spqlios/ffi/vec_znx.rs +++ /dev/null @@ -1,119 +0,0 @@ -use crate::cpu_spqlios::ffi::module::MODULE; - -unsafe extern "C" { - pub unsafe fn vec_znx_add( - module: *const MODULE, - res: *mut i64, - res_size: u64, - res_sl: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - b: *const i64, - b_size: u64, - b_sl: u64, - ); -} - -unsafe extern "C" { - pub unsafe fn vec_znx_automorphism( - module: *const MODULE, - p: i64, - res: *mut i64, - res_size: u64, - res_sl: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - ); -} - -unsafe extern "C" { - pub unsafe fn vec_znx_mul_xp_minus_one( - module: *const MODULE, - p: i64, - res: *mut i64, - res_size: u64, - res_sl: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - ); -} - -unsafe extern "C" { - pub unsafe fn vec_znx_negate( - module: *const MODULE, - res: *mut i64, - res_size: u64, - res_sl: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - ); -} - -#[allow(dead_code)] -unsafe extern "C" { - pub unsafe fn vec_znx_rotate( - module: *const MODULE, - p: i64, - res: *mut i64, - res_size: u64, - res_sl: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - ); -} - -unsafe extern "C" { - pub unsafe fn vec_znx_sub( - module: *const MODULE, - res: *mut i64, - res_size: u64, - res_sl: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - b: *const i64, - b_size: u64, - b_sl: u64, - ); -} - -#[allow(dead_code)] -unsafe extern "C" { - pub unsafe fn vec_znx_zero(module: *const MODULE, res: *mut i64, res_size: u64, res_sl: u64); -} - -#[allow(dead_code)] -unsafe extern "C" { - pub unsafe fn vec_znx_copy( - module: *const MODULE, - res: *mut i64, - res_size: u64, - res_sl: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - ); -} - -unsafe extern "C" { - pub unsafe fn vec_znx_normalize_base2k( - module: *const MODULE, - base2k: u64, - res: *mut i64, - res_size: u64, - res_sl: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - tmp_space: *mut u8, - ); -} - -unsafe extern "C" { - pub unsafe fn vec_znx_normalize_base2k_tmp_bytes(module: *const MODULE) -> u64; -} diff --git a/poulpy-backend/src/cpu_spqlios/ffi/vec_znx_big.rs b/poulpy-backend/src/cpu_spqlios/ffi/vec_znx_big.rs deleted file mode 100644 index e62153f..0000000 --- a/poulpy-backend/src/cpu_spqlios/ffi/vec_znx_big.rs +++ /dev/null @@ -1,151 +0,0 @@ -use crate::cpu_spqlios::ffi::module::MODULE; - -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct vec_znx_big_t { - _unused: [u8; 0], -} -pub type VEC_ZNX_BIG = vec_znx_big_t; - -unsafe extern "C" { - pub unsafe fn vec_znx_big_add( - module: *const MODULE, - res: *mut VEC_ZNX_BIG, - res_size: u64, - a: *const VEC_ZNX_BIG, - a_size: u64, - b: *const VEC_ZNX_BIG, - b_size: u64, - ); -} -unsafe extern "C" { - pub unsafe fn vec_znx_big_add_small( - module: *const MODULE, - res: *mut VEC_ZNX_BIG, - res_size: u64, - a: *const VEC_ZNX_BIG, - a_size: u64, - b: *const i64, - b_size: u64, - b_sl: u64, - ); -} -unsafe extern "C" { - pub unsafe fn vec_znx_big_add_small2( - module: *const MODULE, - res: *mut VEC_ZNX_BIG, - res_size: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - b: *const i64, - b_size: u64, - b_sl: u64, - ); -} -unsafe extern "C" { - pub unsafe fn vec_znx_big_sub( - module: *const MODULE, - res: *mut VEC_ZNX_BIG, - res_size: u64, - a: *const VEC_ZNX_BIG, - a_size: u64, - b: *const VEC_ZNX_BIG, - b_size: u64, - ); -} -unsafe extern "C" { - pub unsafe fn vec_znx_big_sub_small_b( - module: *const MODULE, - res: *mut VEC_ZNX_BIG, - res_size: u64, - a: *const VEC_ZNX_BIG, - a_size: u64, - b: *const i64, - b_size: u64, - b_sl: u64, - ); -} -unsafe extern "C" { - pub unsafe fn vec_znx_big_sub_small_a( - module: *const MODULE, - res: *mut VEC_ZNX_BIG, - res_size: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - b: *const VEC_ZNX_BIG, - b_size: u64, - ); -} -unsafe extern "C" { - pub unsafe fn vec_znx_big_sub_small2( - module: *const MODULE, - res: *mut VEC_ZNX_BIG, - res_size: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - b: *const i64, - b_size: u64, - b_sl: u64, - ); -} - -unsafe extern "C" { - pub unsafe fn vec_znx_big_normalize_base2k_tmp_bytes(module: *const MODULE) -> u64; -} - -unsafe extern "C" { - pub unsafe fn vec_znx_big_normalize_base2k( - module: *const MODULE, - log2_base2k: u64, - res: *mut i64, - res_size: u64, - res_sl: u64, - a: *const VEC_ZNX_BIG, - a_size: u64, - tmp_space: *mut u8, - ); -} - -unsafe extern "C" { - pub unsafe fn vec_znx_big_range_normalize_base2k( - module: *const MODULE, - log2_base2k: u64, - res: *mut i64, - res_size: u64, - res_sl: u64, - a: *const VEC_ZNX_BIG, - a_range_begin: u64, - a_range_xend: u64, - a_range_step: u64, - tmp_space: *mut u8, - ); -} - -unsafe extern "C" { - pub unsafe fn vec_znx_big_range_normalize_base2k_tmp_bytes(module: *const MODULE) -> u64; -} - -unsafe extern "C" { - pub unsafe fn vec_znx_big_automorphism( - module: *const MODULE, - p: i64, - res: *mut VEC_ZNX_BIG, - res_size: u64, - a: *const VEC_ZNX_BIG, - a_size: u64, - ); -} - -unsafe extern "C" { - pub unsafe fn vec_znx_big_rotate( - module: *const MODULE, - p: i64, - res: *mut VEC_ZNX_BIG, - res_size: u64, - a: *const VEC_ZNX_BIG, - a_size: u64, - ); -} diff --git a/poulpy-backend/src/cpu_spqlios/ffi/vec_znx_dft.rs b/poulpy-backend/src/cpu_spqlios/ffi/vec_znx_dft.rs deleted file mode 100644 index e786775..0000000 --- a/poulpy-backend/src/cpu_spqlios/ffi/vec_znx_dft.rs +++ /dev/null @@ -1,56 +0,0 @@ -use crate::cpu_spqlios::ffi::{module::MODULE, vec_znx_big::VEC_ZNX_BIG}; - -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct vec_znx_dft_t { - _unused: [u8; 0], -} -pub type VEC_ZNX_DFT = vec_znx_dft_t; - -unsafe extern "C" { - pub unsafe fn vec_dft_add( - module: *const MODULE, - res: *mut VEC_ZNX_DFT, - res_size: u64, - a: *const VEC_ZNX_DFT, - a_size: u64, - b: *const VEC_ZNX_DFT, - b_size: u64, - ); -} -unsafe extern "C" { - pub unsafe fn vec_dft_sub( - module: *const MODULE, - res: *mut VEC_ZNX_DFT, - res_size: u64, - a: *const VEC_ZNX_DFT, - a_size: u64, - b: *const VEC_ZNX_DFT, - b_size: u64, - ); -} -unsafe extern "C" { - pub unsafe fn vec_znx_dft(module: *const MODULE, res: *mut VEC_ZNX_DFT, res_size: u64, a: *const i64, a_size: u64, a_sl: u64); -} -unsafe extern "C" { - pub unsafe fn vec_znx_idft( - module: *const MODULE, - res: *mut VEC_ZNX_BIG, - res_size: u64, - a_dft: *const VEC_ZNX_DFT, - a_size: u64, - tmp: *mut u8, - ); -} -unsafe extern "C" { - pub unsafe fn vec_znx_idft_tmp_bytes(module: *const MODULE) -> u64; -} -unsafe extern "C" { - pub unsafe fn vec_znx_idft_tmp_a( - module: *const MODULE, - res: *mut VEC_ZNX_BIG, - res_size: u64, - a_dft: *mut VEC_ZNX_DFT, - a_size: u64, - ); -} diff --git a/poulpy-backend/src/cpu_spqlios/ffi/vmp.rs b/poulpy-backend/src/cpu_spqlios/ffi/vmp.rs deleted file mode 100644 index 6cf8635..0000000 --- a/poulpy-backend/src/cpu_spqlios/ffi/vmp.rs +++ /dev/null @@ -1,102 +0,0 @@ -use crate::cpu_spqlios::ffi::{module::MODULE, vec_znx_dft::VEC_ZNX_DFT}; - -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct vmp_pmat_t { - _unused: [u8; 0], -} - -// [rows][cols] = [#Decomposition][#Limbs] -pub type VMP_PMAT = vmp_pmat_t; - -#[allow(dead_code)] -unsafe extern "C" { - pub unsafe fn vmp_apply_dft( - module: *const MODULE, - res: *mut VEC_ZNX_DFT, - res_size: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - pmat: *const VMP_PMAT, - nrows: u64, - ncols: u64, - tmp_space: *mut u8, - ); -} - -#[allow(dead_code)] -unsafe extern "C" { - pub unsafe fn vmp_apply_dft_add( - module: *const MODULE, - res: *mut VEC_ZNX_DFT, - res_size: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - pmat: *const VMP_PMAT, - nrows: u64, - ncols: u64, - pmat_scale: u64, - tmp_space: *mut u8, - ); -} - -#[allow(dead_code)] -unsafe extern "C" { - pub unsafe fn vmp_apply_dft_tmp_bytes(module: *const MODULE, res_size: u64, a_size: u64, nrows: u64, ncols: u64) -> u64; -} - -unsafe extern "C" { - pub unsafe fn vmp_apply_dft_to_dft( - module: *const MODULE, - res: *mut VEC_ZNX_DFT, - res_size: u64, - a_dft: *const VEC_ZNX_DFT, - a_size: u64, - pmat: *const VMP_PMAT, - nrows: u64, - ncols: u64, - tmp_space: *mut u8, - ); -} - -unsafe extern "C" { - pub unsafe fn vmp_apply_dft_to_dft_add( - module: *const MODULE, - res: *mut VEC_ZNX_DFT, - res_size: u64, - a_dft: *const VEC_ZNX_DFT, - a_size: u64, - pmat: *const VMP_PMAT, - nrows: u64, - ncols: u64, - pmat_scale: u64, - tmp_space: *mut u8, - ); -} - -unsafe extern "C" { - pub unsafe fn vmp_apply_dft_to_dft_tmp_bytes( - module: *const MODULE, - res_size: u64, - a_size: u64, - nrows: u64, - ncols: u64, - ) -> u64; -} - -unsafe extern "C" { - pub unsafe fn vmp_prepare_contiguous( - module: *const MODULE, - pmat: *mut VMP_PMAT, - mat: *const i64, - nrows: u64, - ncols: u64, - tmp_space: *mut u8, - ); -} - -unsafe extern "C" { - pub unsafe fn vmp_prepare_tmp_bytes(module: *const MODULE, nrows: u64, ncols: u64) -> u64; -} diff --git a/poulpy-backend/src/cpu_spqlios/ffi/zn64.rs b/poulpy-backend/src/cpu_spqlios/ffi/zn64.rs deleted file mode 100644 index 9228332..0000000 --- a/poulpy-backend/src/cpu_spqlios/ffi/zn64.rs +++ /dev/null @@ -1,13 +0,0 @@ -unsafe extern "C" { - pub unsafe fn zn64_normalize_base2k_ref( - n: u64, - base2k: u64, - res: *mut i64, - res_size: u64, - res_sl: u64, - a: *const i64, - a_size: u64, - a_sl: u64, - tmp_space: *mut u8, - ); -} diff --git a/poulpy-backend/src/cpu_spqlios/ffi/znx.rs b/poulpy-backend/src/cpu_spqlios/ffi/znx.rs deleted file mode 100644 index e669c35..0000000 --- a/poulpy-backend/src/cpu_spqlios/ffi/znx.rs +++ /dev/null @@ -1,7 +0,0 @@ -unsafe extern "C" { - pub unsafe fn znx_rotate_i64(nn: u64, p: i64, res: *mut i64, in_: *const i64); -} - -unsafe extern "C" { - pub unsafe fn znx_rotate_inplace_i64(nn: u64, p: i64, res: *mut i64); -} diff --git a/poulpy-backend/src/cpu_spqlios/fft64/mod.rs b/poulpy-backend/src/cpu_spqlios/fft64/mod.rs deleted file mode 100644 index 4a1f4e3..0000000 --- a/poulpy-backend/src/cpu_spqlios/fft64/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -mod module; -mod scratch; -mod svp_ppol; -mod vec_znx; -mod vec_znx_big; -mod vec_znx_dft; -mod vmp_pmat; -mod znx; - -pub struct FFT64Spqlios; diff --git a/poulpy-backend/src/cpu_spqlios/fft64/module.rs b/poulpy-backend/src/cpu_spqlios/fft64/module.rs deleted file mode 100644 index 1425cec..0000000 --- a/poulpy-backend/src/cpu_spqlios/fft64/module.rs +++ /dev/null @@ -1,34 +0,0 @@ -use std::ptr::NonNull; - -use poulpy_hal::{ - layouts::{Backend, Module}, - oep::ModuleNewImpl, -}; - -use crate::cpu_spqlios::{ - FFT64Spqlios, - ffi::module::{MODULE, delete_module_info, new_module_info}, -}; - -impl Backend for FFT64Spqlios { - type ScalarPrep = f64; - type ScalarBig = i64; - type Handle = MODULE; - unsafe fn destroy(handle: NonNull) { - unsafe { delete_module_info(handle.as_ptr()) } - } - - fn layout_big_word_count() -> usize { - 1 - } - - fn layout_prep_word_count() -> usize { - 1 - } -} - -unsafe impl ModuleNewImpl for FFT64Spqlios { - fn new_impl(n: u64) -> Module { - unsafe { Module::from_raw_parts(new_module_info(n, 0), n) } - } -} diff --git a/poulpy-backend/src/cpu_spqlios/fft64/scratch.rs b/poulpy-backend/src/cpu_spqlios/fft64/scratch.rs deleted file mode 100644 index d32b9f4..0000000 --- a/poulpy-backend/src/cpu_spqlios/fft64/scratch.rs +++ /dev/null @@ -1,81 +0,0 @@ -use std::marker::PhantomData; - -use poulpy_hal::{ - DEFAULTALIGN, alloc_aligned, - api::ScratchFromBytes, - layouts::{Backend, Scratch, ScratchOwned}, - oep::{ScratchAvailableImpl, ScratchFromBytesImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeSliceImpl}, -}; - -use crate::cpu_spqlios::FFT64Spqlios; - -unsafe impl ScratchOwnedAllocImpl for FFT64Spqlios { - fn scratch_owned_alloc_impl(size: usize) -> ScratchOwned { - let data: Vec = alloc_aligned(size); - ScratchOwned { - data, - _phantom: PhantomData, - } - } -} - -unsafe impl ScratchOwnedBorrowImpl for FFT64Spqlios -where - B: ScratchFromBytesImpl, -{ - fn scratch_owned_borrow_impl(scratch: &mut ScratchOwned) -> &mut Scratch { - Scratch::from_bytes(&mut scratch.data) - } -} - -unsafe impl ScratchFromBytesImpl for FFT64Spqlios { - fn scratch_from_bytes_impl(data: &mut [u8]) -> &mut Scratch { - unsafe { &mut *(data as *mut [u8] as *mut Scratch) } - } -} - -unsafe impl ScratchAvailableImpl for FFT64Spqlios { - fn scratch_available_impl(scratch: &Scratch) -> usize { - let ptr: *const u8 = scratch.data.as_ptr(); - let self_len: usize = scratch.data.len(); - let aligned_offset: usize = ptr.align_offset(DEFAULTALIGN); - self_len.saturating_sub(aligned_offset) - } -} - -unsafe impl TakeSliceImpl for FFT64Spqlios -where - B: ScratchFromBytesImpl, -{ - fn take_slice_impl(scratch: &mut Scratch, len: usize) -> (&mut [T], &mut Scratch) { - let (take_slice, rem_slice) = take_slice_aligned(&mut scratch.data, len * std::mem::size_of::()); - - unsafe { - ( - &mut *(std::ptr::slice_from_raw_parts_mut(take_slice.as_mut_ptr() as *mut T, len)), - Scratch::from_bytes(rem_slice), - ) - } - } -} - -fn take_slice_aligned(data: &mut [u8], take_len: usize) -> (&mut [u8], &mut [u8]) { - let ptr: *mut u8 = data.as_mut_ptr(); - let self_len: usize = data.len(); - - let aligned_offset: usize = ptr.align_offset(DEFAULTALIGN); - let aligned_len: usize = self_len.saturating_sub(aligned_offset); - - if let Some(rem_len) = aligned_len.checked_sub(take_len) { - unsafe { - let rem_ptr: *mut u8 = ptr.add(aligned_offset).add(take_len); - let rem_slice: &mut [u8] = &mut *std::ptr::slice_from_raw_parts_mut(rem_ptr, rem_len); - - let take_slice: &mut [u8] = &mut *std::ptr::slice_from_raw_parts_mut(ptr.add(aligned_offset), take_len); - - (take_slice, rem_slice) - } - } else { - panic!("Attempted to take {take_len} from scratch with {aligned_len} aligned bytes left"); - } -} diff --git a/poulpy-backend/src/cpu_spqlios/fft64/svp_ppol.rs b/poulpy-backend/src/cpu_spqlios/fft64/svp_ppol.rs deleted file mode 100644 index f46b795..0000000 --- a/poulpy-backend/src/cpu_spqlios/fft64/svp_ppol.rs +++ /dev/null @@ -1,104 +0,0 @@ -use poulpy_hal::{ - layouts::{ - Backend, Module, ScalarZnxToRef, SvpPPol, SvpPPolOwned, SvpPPolToMut, SvpPPolToRef, VecZnxDft, VecZnxDftToMut, - VecZnxDftToRef, ZnxInfos, ZnxView, ZnxViewMut, - }, - oep::{ - SvpApplyDftToDftImpl, SvpApplyDftToDftInplaceImpl, SvpPPolAllocBytesImpl, SvpPPolAllocImpl, SvpPPolFromBytesImpl, - SvpPrepareImpl, - }, -}; - -use crate::cpu_spqlios::{ - FFT64Spqlios, - ffi::{svp, vec_znx_dft::vec_znx_dft_t}, -}; - -unsafe impl SvpPPolFromBytesImpl for FFT64Spqlios { - fn svp_ppol_from_bytes_impl(n: usize, cols: usize, bytes: Vec) -> SvpPPolOwned { - SvpPPolOwned::from_bytes(n, cols, bytes) - } -} - -unsafe impl SvpPPolAllocImpl for FFT64Spqlios { - fn svp_ppol_alloc_impl(n: usize, cols: usize) -> SvpPPolOwned { - SvpPPolOwned::alloc(n, cols) - } -} - -unsafe impl SvpPPolAllocBytesImpl for FFT64Spqlios { - fn svp_ppol_bytes_of_impl(n: usize, cols: usize) -> usize { - FFT64Spqlios::layout_prep_word_count() * n * cols * size_of::() - } -} - -unsafe impl SvpPrepareImpl for FFT64Spqlios { - fn svp_prepare_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: SvpPPolToMut, - A: ScalarZnxToRef, - { - unsafe { - svp::svp_prepare( - module.ptr(), - res.to_mut().at_mut_ptr(res_col, 0) as *mut svp::svp_ppol_t, - a.to_ref().at_ptr(a_col, 0), - ) - } - } -} - -unsafe impl SvpApplyDftToDftImpl for FFT64Spqlios { - fn svp_apply_dft_to_dft_impl( - module: &Module, - res: &mut R, - res_col: usize, - a: &A, - a_col: usize, - b: &B, - b_col: usize, - ) where - R: VecZnxDftToMut, - A: SvpPPolToRef, - B: VecZnxDftToRef, - { - let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut(); - let a: SvpPPol<&[u8], Self> = a.to_ref(); - let b: VecZnxDft<&[u8], Self> = b.to_ref(); - unsafe { - svp::svp_apply_dft_to_dft( - module.ptr(), - res.at_mut_ptr(res_col, 0) as *mut vec_znx_dft_t, - res.size() as u64, - res.cols() as u64, - a.at_ptr(a_col, 0) as *const svp::svp_ppol_t, - b.at_ptr(b_col, 0) as *const vec_znx_dft_t, - b.size() as u64, - b.cols() as u64, - ) - } - } -} - -unsafe impl SvpApplyDftToDftInplaceImpl for FFT64Spqlios { - fn svp_apply_dft_to_dft_inplace_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxDftToMut, - A: SvpPPolToRef, - { - let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut(); - let a: SvpPPol<&[u8], Self> = a.to_ref(); - unsafe { - svp::svp_apply_dft_to_dft( - module.ptr(), - res.at_mut_ptr(res_col, 0) as *mut vec_znx_dft_t, - res.size() as u64, - res.cols() as u64, - a.at_ptr(a_col, 0) as *const svp::svp_ppol_t, - res.at_ptr(res_col, 0) as *const vec_znx_dft_t, - res.size() as u64, - res.cols() as u64, - ) - } - } -} diff --git a/poulpy-backend/src/cpu_spqlios/fft64/vec_znx.rs b/poulpy-backend/src/cpu_spqlios/fft64/vec_znx.rs deleted file mode 100644 index e33dd1a..0000000 --- a/poulpy-backend/src/cpu_spqlios/fft64/vec_znx.rs +++ /dev/null @@ -1,908 +0,0 @@ -use poulpy_hal::{ - api::{ - TakeSlice, VecZnxLshTmpBytes, VecZnxMergeRingsTmpBytes, VecZnxNormalizeTmpBytes, VecZnxRshTmpBytes, - VecZnxSplitRingTmpBytes, - }, - layouts::{ - Module, ScalarZnx, ScalarZnxToRef, Scratch, VecZnx, VecZnxToMut, VecZnxToRef, ZnxInfos, ZnxSliceSize, ZnxView, ZnxViewMut, - }, - oep::{ - TakeSliceImpl, VecZnxAddImpl, VecZnxAddInplaceImpl, VecZnxAddNormalImpl, VecZnxAddScalarImpl, VecZnxAddScalarInplaceImpl, - VecZnxAutomorphismImpl, VecZnxAutomorphismInplaceImpl, VecZnxAutomorphismInplaceTmpBytesImpl, VecZnxCopyImpl, - VecZnxFillNormalImpl, VecZnxFillUniformImpl, VecZnxLshImpl, VecZnxLshInplaceImpl, VecZnxLshTmpBytesImpl, - VecZnxMergeRingsImpl, VecZnxMergeRingsTmpBytesImpl, VecZnxMulXpMinusOneImpl, VecZnxMulXpMinusOneInplaceImpl, - VecZnxMulXpMinusOneInplaceTmpBytesImpl, VecZnxNegateImpl, VecZnxNegateInplaceImpl, VecZnxNormalizeImpl, - VecZnxNormalizeInplaceImpl, VecZnxNormalizeTmpBytesImpl, VecZnxRotateImpl, VecZnxRotateInplaceImpl, - VecZnxRotateInplaceTmpBytesImpl, VecZnxRshImpl, VecZnxRshInplaceImpl, VecZnxRshTmpBytesImpl, VecZnxSplitRingImpl, - VecZnxSplitRingTmpBytesImpl, VecZnxSubImpl, VecZnxSubInplaceImpl, VecZnxSubNegateInplaceImpl, VecZnxSubScalarImpl, - VecZnxSubScalarInplaceImpl, VecZnxSwitchRingImpl, VecZnxZeroImpl, - }, - reference::{ - vec_znx::{ - vec_znx_add_normal_ref, vec_znx_automorphism_inplace_tmp_bytes, vec_znx_copy, vec_znx_fill_normal_ref, - vec_znx_fill_uniform_ref, vec_znx_lsh, vec_znx_lsh_inplace, vec_znx_lsh_tmp_bytes, vec_znx_merge_rings, - vec_znx_merge_rings_tmp_bytes, vec_znx_mul_xp_minus_one_inplace_tmp_bytes, vec_znx_normalize_tmp_bytes, - vec_znx_rotate_inplace_tmp_bytes, vec_znx_rsh, vec_znx_rsh_inplace, vec_znx_rsh_tmp_bytes, vec_znx_split_ring, - vec_znx_split_ring_tmp_bytes, vec_znx_switch_ring, vec_znx_zero, - }, - znx::{znx_copy_ref, znx_zero_ref}, - }, - source::Source, -}; - -use crate::cpu_spqlios::{ - FFT64Spqlios, - ffi::{module::module_info_t, vec_znx, znx}, -}; - -unsafe impl VecZnxZeroImpl for FFT64Spqlios { - fn vec_znx_zero_impl(_module: &Module, res: &mut R, res_col: usize) - where - R: VecZnxToMut, - { - vec_znx_zero::<_, FFT64Spqlios>(res, res_col); - } -} - -unsafe impl VecZnxNormalizeTmpBytesImpl for FFT64Spqlios { - fn vec_znx_normalize_tmp_bytes_impl(module: &Module) -> usize { - vec_znx_normalize_tmp_bytes(module.n()) - } -} - -unsafe impl VecZnxNormalizeImpl for FFT64Spqlios -where - Self: TakeSliceImpl + VecZnxNormalizeTmpBytesImpl, -{ - fn vec_znx_normalize_impl( - module: &Module, - res_basek: usize, - res: &mut R, - res_col: usize, - _a_basek: usize, - a: &A, - a_col: usize, - scratch: &mut Scratch, - ) where - R: VecZnxToMut, - A: VecZnxToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(res.n(), a.n()); - assert_eq!( - res_basek, _a_basek, - "res_basek != a_basek -> base2k conversion is not supported" - ) - } - - let (tmp_bytes, _) = scratch.take_slice(module.vec_znx_normalize_tmp_bytes()); - - unsafe { - vec_znx::vec_znx_normalize_base2k( - module.ptr() as *const module_info_t, - res_basek as u64, - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - tmp_bytes.as_mut_ptr(), - ); - } - } -} - -unsafe impl VecZnxNormalizeInplaceImpl for FFT64Spqlios -where - Self: TakeSliceImpl + VecZnxNormalizeTmpBytesImpl, -{ - fn vec_znx_normalize_inplace_impl( - module: &Module, - base2k: usize, - a: &mut A, - a_col: usize, - scratch: &mut Scratch, - ) where - A: VecZnxToMut, - { - let mut a: VecZnx<&mut [u8]> = a.to_mut(); - - let (tmp_bytes, _) = scratch.take_slice(module.vec_znx_normalize_tmp_bytes()); - - unsafe { - vec_znx::vec_znx_normalize_base2k( - module.ptr() as *const module_info_t, - base2k as u64, - a.at_mut_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - tmp_bytes.as_mut_ptr(), - ); - } - } -} - -unsafe impl VecZnxAddImpl for FFT64Spqlios { - fn vec_znx_add_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) - where - R: VecZnxToMut, - A: VecZnxToRef, - C: VecZnxToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let b: VecZnx<&[u8]> = b.to_ref(); - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - assert_eq!(b.n(), res.n()); - assert_ne!(a.as_ptr(), b.as_ptr()); - } - unsafe { - vec_znx::vec_znx_add( - module.ptr() as *const module_info_t, - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - b.at_ptr(b_col, 0), - b.size() as u64, - b.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxAddInplaceImpl for FFT64Spqlios { - fn vec_znx_add_inplace_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxToMut, - A: VecZnxToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_add( - module.ptr() as *const module_info_t, - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - res.at_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxAddScalarInplaceImpl for FFT64Spqlios { - fn vec_znx_add_scalar_inplace_impl( - module: &Module, - res: &mut R, - res_col: usize, - res_limb: usize, - a: &A, - a_col: usize, - ) where - R: VecZnxToMut, - A: ScalarZnxToRef, - { - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - let a: ScalarZnx<&[u8]> = a.to_ref(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - - unsafe { - vec_znx::vec_znx_add( - module.ptr() as *const module_info_t, - res.at_mut_ptr(res_col, res_limb), - 1_u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - res.at_ptr(res_col, res_limb), - 1_u64, - res.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxAddScalarImpl for FFT64Spqlios { - fn vec_znx_add_scalar_impl( - module: &Module, - res: &mut R, - res_col: usize, - a: &A, - a_col: usize, - b: &B, - b_col: usize, - b_limb: usize, - ) where - R: VecZnxToMut, - A: ScalarZnxToRef, - B: VecZnxToRef, - { - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - let a: ScalarZnx<&[u8]> = a.to_ref(); - let b: VecZnx<&[u8]> = b.to_ref(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - - let min_size: usize = b.size().min(res.size()); - - unsafe { - vec_znx::vec_znx_add( - module.ptr() as *const module_info_t, - res.at_mut_ptr(res_col, b_limb), - 1_u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - b.at_ptr(b_col, b_limb), - 1_u64, - b.sl() as u64, - ); - - for j in 0..min_size { - if j != b_limb { - znx_copy_ref(res.at_mut(res_col, j), b.at(b_col, j)); - } - } - - for j in min_size..res.size() { - znx_zero_ref(res.at_mut(res_col, j)); - } - } - } -} - -unsafe impl VecZnxSubImpl for FFT64Spqlios { - fn vec_znx_sub_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) - where - R: VecZnxToMut, - A: VecZnxToRef, - C: VecZnxToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let b: VecZnx<&[u8]> = b.to_ref(); - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - assert_eq!(b.n(), res.n()); - assert_ne!(a.as_ptr(), b.as_ptr()); - } - unsafe { - vec_znx::vec_znx_sub( - module.ptr() as *const module_info_t, - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - b.at_ptr(b_col, 0), - b.size() as u64, - b.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxSubInplaceImpl for FFT64Spqlios { - fn vec_znx_sub_inplace_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxToMut, - A: VecZnxToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_sub( - module.ptr() as *const module_info_t, - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - res.at_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxSubNegateInplaceImpl for FFT64Spqlios { - fn vec_znx_sub_negate_inplace_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxToMut, - A: VecZnxToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_sub( - module.ptr() as *const module_info_t, - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - res.at_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxSubScalarImpl for FFT64Spqlios { - fn vec_znx_sub_scalar_impl( - module: &Module, - res: &mut R, - res_col: usize, - a: &A, - a_col: usize, - b: &B, - b_col: usize, - b_limb: usize, - ) where - R: VecZnxToMut, - A: ScalarZnxToRef, - B: VecZnxToRef, - { - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - let a: ScalarZnx<&[u8]> = a.to_ref(); - let b: VecZnx<&[u8]> = b.to_ref(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - - let min_size: usize = b.size().min(res.size()); - - unsafe { - vec_znx::vec_znx_sub( - module.ptr() as *const module_info_t, - res.at_mut_ptr(res_col, b_limb), - 1_u64, - res.sl() as u64, - b.at_ptr(b_col, b_limb), - 1_u64, - b.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ); - - for j in 0..min_size { - if j != b_limb { - res.at_mut(res_col, j).copy_from_slice(b.at(b_col, j)) - } - } - - for j in min_size..res.size() { - znx_zero_ref(res.at_mut(res_col, j)); - } - } - } -} - -unsafe impl VecZnxSubScalarInplaceImpl for FFT64Spqlios { - fn vec_znx_sub_scalar_inplace_impl( - module: &Module, - res: &mut R, - res_col: usize, - res_limb: usize, - a: &A, - a_col: usize, - ) where - R: VecZnxToMut, - A: ScalarZnxToRef, - { - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - let a: ScalarZnx<&[u8]> = a.to_ref(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - - unsafe { - vec_znx::vec_znx_sub( - module.ptr() as *const module_info_t, - res.at_mut_ptr(res_col, res_limb), - 1_u64, - res.sl() as u64, - res.at_ptr(res_col, res_limb), - 1_u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxNegateImpl for FFT64Spqlios { - fn vec_znx_negate_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxToMut, - A: VecZnxToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_negate( - module.ptr() as *const module_info_t, - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxNegateInplaceImpl for FFT64Spqlios { - fn vec_znx_negate_inplace_impl(module: &Module, a: &mut A, a_col: usize) - where - A: VecZnxToMut, - { - let mut a: VecZnx<&mut [u8]> = a.to_mut(); - unsafe { - vec_znx::vec_znx_negate( - module.ptr() as *const module_info_t, - a.at_mut_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxLshTmpBytesImpl for FFT64Spqlios { - fn vec_znx_lsh_tmp_bytes_impl(module: &Module) -> usize { - vec_znx_lsh_tmp_bytes(module.n()) - } -} - -unsafe impl VecZnxRshTmpBytesImpl for FFT64Spqlios { - fn vec_znx_rsh_tmp_bytes_impl(module: &Module) -> usize { - vec_znx_rsh_tmp_bytes(module.n()) - } -} - -unsafe impl VecZnxLshImpl for FFT64Spqlios -where - Module: VecZnxNormalizeTmpBytes, - Scratch: TakeSlice, -{ - fn vec_znx_lsh_impl( - module: &Module, - base2k: usize, - k: usize, - res: &mut R, - res_col: usize, - a: &A, - a_col: usize, - scratch: &mut Scratch, - ) where - R: VecZnxToMut, - A: VecZnxToRef, - { - let (carry, _) = scratch.take_slice(module.vec_znx_lsh_tmp_bytes() / size_of::()); - vec_znx_lsh::<_, _, FFT64Spqlios>(base2k, k, res, res_col, a, a_col, carry) - } -} - -unsafe impl VecZnxLshInplaceImpl for FFT64Spqlios -where - Module: VecZnxNormalizeTmpBytes, - Scratch: TakeSlice, -{ - fn vec_znx_lsh_inplace_impl( - module: &Module, - base2k: usize, - k: usize, - a: &mut A, - a_col: usize, - scratch: &mut Scratch, - ) where - A: VecZnxToMut, - { - let (carry, _) = scratch.take_slice(module.vec_znx_lsh_tmp_bytes() / size_of::()); - vec_znx_lsh_inplace::<_, FFT64Spqlios>(base2k, k, a, a_col, carry) - } -} - -unsafe impl VecZnxRshImpl for FFT64Spqlios -where - Module: VecZnxNormalizeTmpBytes, - Scratch: TakeSlice, -{ - fn vec_znx_rsh_impl( - module: &Module, - base2k: usize, - k: usize, - res: &mut R, - res_col: usize, - a: &A, - a_col: usize, - scratch: &mut Scratch, - ) where - R: VecZnxToMut, - A: VecZnxToRef, - { - let (carry, _) = scratch.take_slice(module.vec_znx_rsh_tmp_bytes() / size_of::()); - vec_znx_rsh::<_, _, FFT64Spqlios>(base2k, k, res, res_col, a, a_col, carry) - } -} - -unsafe impl VecZnxRshInplaceImpl for FFT64Spqlios -where - Module: VecZnxNormalizeTmpBytes, - Scratch: TakeSlice, -{ - fn vec_znx_rsh_inplace_impl( - module: &Module, - base2k: usize, - k: usize, - a: &mut A, - a_col: usize, - scratch: &mut Scratch, - ) where - A: VecZnxToMut, - { - let (carry, _) = scratch.take_slice(module.vec_znx_rsh_tmp_bytes() / size_of::()); - vec_znx_rsh_inplace::<_, FFT64Spqlios>(base2k, k, a, a_col, carry) - } -} - -unsafe impl VecZnxRotateImpl for FFT64Spqlios { - fn vec_znx_rotate_impl(_module: &Module, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxToMut, - A: VecZnxToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - #[cfg(debug_assertions)] - { - assert_eq!(res.n(), a.n()); - } - unsafe { - let min_size = res.size().min(a.size()); - (0..min_size).for_each(|j| { - znx::znx_rotate_i64( - a.n() as u64, - k, - res.at_mut_ptr(res_col, j), - a.at_ptr(a_col, j), - ); - }); - - (min_size..res.size()).for_each(|j| { - znx_zero_ref(res.at_mut(res_col, j)); - }) - } - } -} - -unsafe impl VecZnxRotateInplaceTmpBytesImpl for FFT64Spqlios -where - Scratch: TakeSlice, -{ - fn vec_znx_rotate_inplace_tmp_bytes_impl(module: &Module) -> usize { - vec_znx_rotate_inplace_tmp_bytes(module.n()) - } -} - -unsafe impl VecZnxRotateInplaceImpl for FFT64Spqlios -where - Scratch: TakeSlice, -{ - fn vec_znx_rotate_inplace_impl(_module: &Module, k: i64, a: &mut A, a_col: usize, _scratch: &mut Scratch) - where - A: VecZnxToMut, - { - let mut a: VecZnx<&mut [u8]> = a.to_mut(); - unsafe { - (0..a.size()).for_each(|j| { - znx::znx_rotate_inplace_i64(a.n() as u64, k, a.at_mut_ptr(a_col, j)); - }); - } - } -} - -unsafe impl VecZnxAutomorphismImpl for FFT64Spqlios { - fn vec_znx_automorphism_impl(module: &Module, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxToMut, - A: VecZnxToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_automorphism( - module.ptr() as *const module_info_t, - k, - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxAutomorphismInplaceTmpBytesImpl for FFT64Spqlios { - fn vec_znx_automorphism_inplace_tmp_bytes_impl(module: &Module) -> usize { - vec_znx_automorphism_inplace_tmp_bytes(module.n()) - } -} - -unsafe impl VecZnxAutomorphismInplaceImpl for FFT64Spqlios { - fn vec_znx_automorphism_inplace_impl(module: &Module, k: i64, a: &mut A, a_col: usize, _scratch: &mut Scratch) - where - A: VecZnxToMut, - { - let mut a: VecZnx<&mut [u8]> = a.to_mut(); - #[cfg(debug_assertions)] - { - assert!(k & 1 != 0, "invalid galois element: must be odd but is {k}"); - } - unsafe { - vec_znx::vec_znx_automorphism( - module.ptr() as *const module_info_t, - k, - a.at_mut_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxMulXpMinusOneImpl for FFT64Spqlios { - fn vec_znx_mul_xp_minus_one_impl(module: &Module, p: i64, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxToMut, - A: VecZnxToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - assert_eq!(res.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_mul_xp_minus_one( - module.ptr() as *const module_info_t, - p, - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxMulXpMinusOneInplaceTmpBytesImpl for FFT64Spqlios { - fn vec_znx_mul_xp_minus_one_inplace_tmp_bytes_impl(module: &Module) -> usize { - vec_znx_mul_xp_minus_one_inplace_tmp_bytes(module.n()) - } -} - -unsafe impl VecZnxMulXpMinusOneInplaceImpl for FFT64Spqlios { - fn vec_znx_mul_xp_minus_one_inplace_impl( - module: &Module, - p: i64, - res: &mut R, - res_col: usize, - _scratch: &mut Scratch, - ) where - R: VecZnxToMut, - { - let mut res: VecZnx<&mut [u8]> = res.to_mut(); - #[cfg(debug_assertions)] - { - assert_eq!(res.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_mul_xp_minus_one( - module.ptr() as *const module_info_t, - p, - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - res.at_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxSplitRingTmpBytesImpl for FFT64Spqlios { - fn vec_znx_split_ring_tmp_bytes_impl(module: &Module) -> usize { - vec_znx_split_ring_tmp_bytes(module.n()) - } -} - -unsafe impl VecZnxSplitRingImpl for FFT64Spqlios -where - Module: VecZnxSplitRingTmpBytes, - Scratch: TakeSlice, -{ - fn vec_znx_split_ring_impl( - module: &Module, - res: &mut [R], - res_col: usize, - a: &A, - a_col: usize, - scratch: &mut Scratch, - ) where - R: VecZnxToMut, - A: VecZnxToRef, - { - let (tmp, _) = scratch.take_slice(module.vec_znx_split_ring_tmp_bytes() / size_of::()); - vec_znx_split_ring::<_, _, FFT64Spqlios>(res, res_col, a, a_col, tmp); - } -} - -unsafe impl VecZnxMergeRingsTmpBytesImpl for FFT64Spqlios { - fn vec_znx_merge_rings_tmp_bytes_impl(module: &Module) -> usize { - vec_znx_merge_rings_tmp_bytes(module.n()) - } -} - -unsafe impl VecZnxMergeRingsImpl for FFT64Spqlios -where - Module: VecZnxMergeRingsTmpBytes, -{ - fn vec_znx_merge_rings_impl( - module: &Module, - res: &mut R, - res_col: usize, - a: &[A], - a_col: usize, - scratch: &mut Scratch, - ) where - R: VecZnxToMut, - A: VecZnxToRef, - { - let (tmp, _) = scratch.take_slice(module.vec_znx_merge_rings_tmp_bytes() / size_of::()); - vec_znx_merge_rings::<_, _, FFT64Spqlios>(res, res_col, a, a_col, tmp); - } -} - -unsafe impl VecZnxSwitchRingImpl for FFT64Spqlios -where - Self: VecZnxCopyImpl, -{ - fn vec_znx_switch_ring_impl(_module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxToMut, - A: VecZnxToRef, - { - vec_znx_switch_ring::<_, _, FFT64Spqlios>(res, res_col, a, a_col); - } -} - -unsafe impl VecZnxCopyImpl for FFT64Spqlios { - fn vec_znx_copy_impl(_module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxToMut, - A: VecZnxToRef, - { - vec_znx_copy::<_, _, FFT64Spqlios>(res, res_col, a, a_col) - } -} - -unsafe impl VecZnxFillUniformImpl for FFT64Spqlios { - fn vec_znx_fill_uniform_impl(_module: &Module, base2k: usize, res: &mut R, res_col: usize, source: &mut Source) - where - R: VecZnxToMut, - { - vec_znx_fill_uniform_ref(base2k, res, res_col, source) - } -} - -unsafe impl VecZnxFillNormalImpl for FFT64Spqlios { - fn vec_znx_fill_normal_impl( - _module: &Module, - base2k: usize, - res: &mut R, - res_col: usize, - k: usize, - source: &mut Source, - sigma: f64, - bound: f64, - ) where - R: VecZnxToMut, - { - vec_znx_fill_normal_ref(base2k, res, res_col, k, sigma, bound, source); - } -} - -unsafe impl VecZnxAddNormalImpl for FFT64Spqlios { - fn vec_znx_add_normal_impl( - _module: &Module, - base2k: usize, - res: &mut R, - res_col: usize, - k: usize, - source: &mut Source, - sigma: f64, - bound: f64, - ) where - R: VecZnxToMut, - { - vec_znx_add_normal_ref(base2k, res, res_col, k, sigma, bound, source); - } -} diff --git a/poulpy-backend/src/cpu_spqlios/fft64/vec_znx_big.rs b/poulpy-backend/src/cpu_spqlios/fft64/vec_znx_big.rs deleted file mode 100644 index 5021f6b..0000000 --- a/poulpy-backend/src/cpu_spqlios/fft64/vec_znx_big.rs +++ /dev/null @@ -1,621 +0,0 @@ -use crate::cpu_spqlios::{FFT64Spqlios, ffi::vec_znx}; -use poulpy_hal::{ - api::{TakeSlice, VecZnxBigNormalizeTmpBytes}, - layouts::{ - Backend, Module, Scratch, VecZnx, VecZnxBig, VecZnxBigOwned, VecZnxBigToMut, VecZnxBigToRef, VecZnxToMut, VecZnxToRef, - ZnxInfos, ZnxSliceSize, ZnxView, ZnxViewMut, - }, - oep::{ - TakeSliceImpl, VecZnxBigAddImpl, VecZnxBigAddInplaceImpl, VecZnxBigAddNormalImpl, VecZnxBigAddSmallImpl, - VecZnxBigAddSmallInplaceImpl, VecZnxBigAllocBytesImpl, VecZnxBigAllocImpl, VecZnxBigAutomorphismImpl, - VecZnxBigAutomorphismInplaceImpl, VecZnxBigAutomorphismInplaceTmpBytesImpl, VecZnxBigFromBytesImpl, - VecZnxBigFromSmallImpl, VecZnxBigNegateImpl, VecZnxBigNegateInplaceImpl, VecZnxBigNormalizeImpl, - VecZnxBigNormalizeTmpBytesImpl, VecZnxBigSubImpl, VecZnxBigSubInplaceImpl, VecZnxBigSubNegateInplaceImpl, - VecZnxBigSubSmallAImpl, VecZnxBigSubSmallBImpl, VecZnxBigSubSmallInplaceImpl, VecZnxBigSubSmallNegateInplaceImpl, - }, - reference::{ - fft64::vec_znx_big::vec_znx_big_normalize, - vec_znx::{vec_znx_add_normal_ref, vec_znx_normalize_tmp_bytes}, - znx::{znx_copy_ref, znx_zero_ref}, - }, - source::Source, -}; - -unsafe impl VecZnxBigAllocBytesImpl for FFT64Spqlios { - fn vec_znx_big_bytes_of_impl(n: usize, cols: usize, size: usize) -> usize { - Self::layout_big_word_count() * n * cols * size * size_of::() - } -} - -unsafe impl VecZnxBigAllocImpl for FFT64Spqlios { - fn vec_znx_big_alloc_impl(n: usize, cols: usize, size: usize) -> VecZnxBigOwned { - VecZnxBig::alloc(n, cols, size) - } -} - -unsafe impl VecZnxBigFromBytesImpl for FFT64Spqlios { - fn vec_znx_big_from_bytes_impl(n: usize, cols: usize, size: usize, bytes: Vec) -> VecZnxBigOwned { - VecZnxBig::from_bytes(n, cols, size, bytes) - } -} - -unsafe impl VecZnxBigFromSmallImpl for FFT64Spqlios { - fn vec_znx_big_from_small_impl(res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxBigToMut, - A: VecZnxToRef, - { - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - let a: VecZnx<&[u8]> = a.to_ref(); - - #[cfg(debug_assertions)] - { - assert_eq!(res.n(), a.n()); - } - - let res_size: usize = res.size(); - let a_size: usize = a.size(); - - let min_size: usize = res_size.min(a_size); - - for j in 0..min_size { - znx_copy_ref(res.at_mut(res_col, j), a.at(a_col, j)); - } - - for j in min_size..res_size { - znx_zero_ref(res.at_mut(res_col, j)); - } - } -} - -unsafe impl VecZnxBigAddNormalImpl for FFT64Spqlios { - fn add_normal_impl>( - _module: &Module, - base2k: usize, - res: &mut R, - res_col: usize, - k: usize, - source: &mut Source, - sigma: f64, - bound: f64, - ) { - let res: VecZnxBig<&mut [u8], FFT64Spqlios> = res.to_mut(); - - let mut res_znx: VecZnx<&mut [u8]> = VecZnx { - data: res.data, - n: res.n, - cols: res.cols, - size: res.size, - max_size: res.max_size, - }; - - vec_znx_add_normal_ref(base2k, &mut res_znx, res_col, k, sigma, bound, source); - } -} - -unsafe impl VecZnxBigAddImpl for FFT64Spqlios { - /// Adds `a` to `b` and stores the result on `c`. - fn vec_znx_big_add_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &B, b_col: usize) - where - R: VecZnxBigToMut, - A: VecZnxBigToRef, - B: VecZnxBigToRef, - { - let a: VecZnxBig<&[u8], Self> = a.to_ref(); - let b: VecZnxBig<&[u8], Self> = b.to_ref(); - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - assert_eq!(b.n(), res.n()); - assert_ne!(a.as_ptr(), b.as_ptr()); - } - unsafe { - vec_znx::vec_znx_add( - module.ptr(), - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - b.at_ptr(b_col, 0), - b.size() as u64, - b.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigAddInplaceImpl for FFT64Spqlios { - /// Adds `a` to `b` and stores the result on `b`. - fn vec_znx_big_add_inplace_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxBigToMut, - A: VecZnxBigToRef, - { - let a: VecZnxBig<&[u8], Self> = a.to_ref(); - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_add( - module.ptr(), - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - res.at_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigAddSmallImpl for FFT64Spqlios { - /// Adds `a` to `b` and stores the result on `c`. - fn vec_znx_big_add_small_impl( - module: &Module, - res: &mut R, - res_col: usize, - a: &A, - a_col: usize, - b: &B, - b_col: usize, - ) where - R: VecZnxBigToMut, - A: VecZnxBigToRef, - B: VecZnxToRef, - { - let a: VecZnxBig<&[u8], Self> = a.to_ref(); - let b: VecZnx<&[u8]> = b.to_ref(); - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - assert_eq!(b.n(), res.n()); - assert_ne!(a.as_ptr(), b.as_ptr()); - } - unsafe { - vec_znx::vec_znx_add( - module.ptr(), - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - b.at_ptr(b_col, 0), - b.size() as u64, - b.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigAddSmallInplaceImpl for FFT64Spqlios { - /// Adds `a` to `b` and stores the result on `b`. - fn vec_znx_big_add_small_inplace_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxBigToMut, - A: VecZnxToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_add( - module.ptr(), - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - res.at_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigSubImpl for FFT64Spqlios { - /// Subtracts `a` to `b` and stores the result on `c`. - fn vec_znx_big_sub_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &B, b_col: usize) - where - R: VecZnxBigToMut, - A: VecZnxBigToRef, - B: VecZnxBigToRef, - { - let a: VecZnxBig<&[u8], Self> = a.to_ref(); - let b: VecZnxBig<&[u8], Self> = b.to_ref(); - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - assert_eq!(b.n(), res.n()); - assert_ne!(a.as_ptr(), b.as_ptr()); - } - unsafe { - vec_znx::vec_znx_sub( - module.ptr(), - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - b.at_ptr(b_col, 0), - b.size() as u64, - b.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigSubInplaceImpl for FFT64Spqlios { - /// Subtracts `a` from `b` and stores the result on `b`. - fn vec_znx_big_sub_inplace_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxBigToMut, - A: VecZnxBigToRef, - { - let a: VecZnxBig<&[u8], Self> = a.to_ref(); - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_sub( - module.ptr(), - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - res.at_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigSubNegateInplaceImpl for FFT64Spqlios { - /// Subtracts `b` from `a` and stores the result on `b`. - fn vec_znx_big_sub_negate_inplace_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxBigToMut, - A: VecZnxBigToRef, - { - let a: VecZnxBig<&[u8], Self> = a.to_ref(); - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_sub( - module.ptr(), - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - res.at_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigSubSmallAImpl for FFT64Spqlios { - /// Subtracts `b` from `a` and stores the result on `c`. - fn vec_znx_big_sub_small_a_impl( - module: &Module, - res: &mut R, - res_col: usize, - a: &A, - a_col: usize, - b: &B, - b_col: usize, - ) where - R: VecZnxBigToMut, - A: VecZnxToRef, - B: VecZnxBigToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let b: VecZnxBig<&[u8], Self> = b.to_ref(); - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - assert_eq!(b.n(), res.n()); - assert_ne!(a.as_ptr(), b.as_ptr()); - } - unsafe { - vec_znx::vec_znx_sub( - module.ptr(), - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - b.at_ptr(b_col, 0), - b.size() as u64, - b.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigSubSmallInplaceImpl for FFT64Spqlios { - /// Subtracts `a` from `res` and stores the result on `res`. - fn vec_znx_big_sub_small_inplace_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxBigToMut, - A: VecZnxToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_sub( - module.ptr(), - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - res.at_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigSubSmallBImpl for FFT64Spqlios { - /// Subtracts `b` from `a` and stores the result on `c`. - fn vec_znx_big_sub_small_b_impl( - module: &Module, - res: &mut R, - res_col: usize, - a: &A, - a_col: usize, - b: &B, - b_col: usize, - ) where - R: VecZnxBigToMut, - A: VecZnxBigToRef, - B: VecZnxToRef, - { - let a: VecZnxBig<&[u8], Self> = a.to_ref(); - let b: VecZnx<&[u8]> = b.to_ref(); - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - assert_eq!(b.n(), res.n()); - assert_ne!(a.as_ptr(), b.as_ptr()); - } - unsafe { - vec_znx::vec_znx_sub( - module.ptr(), - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - b.at_ptr(b_col, 0), - b.size() as u64, - b.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigSubSmallNegateInplaceImpl for FFT64Spqlios { - /// Subtracts `res` from `a` and stores the result on `res`. - fn vec_znx_big_sub_small_negate_inplace_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxBigToMut, - A: VecZnxToRef, - { - let a: VecZnx<&[u8]> = a.to_ref(); - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_sub( - module.ptr(), - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - res.at_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigNegateImpl for FFT64Spqlios { - fn vec_znx_big_negate_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxBigToMut, - A: VecZnxBigToRef, - { - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - let a: VecZnxBig<&[u8], Self> = a.to_ref(); - unsafe { - vec_znx::vec_znx_negate( - module.ptr(), - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigNegateInplaceImpl for FFT64Spqlios { - fn vec_znx_big_negate_inplace_impl(module: &Module, a: &mut A, a_col: usize) - where - A: VecZnxBigToMut, - { - let mut a: VecZnxBig<&mut [u8], Self> = a.to_mut(); - unsafe { - vec_znx::vec_znx_negate( - module.ptr(), - a.at_mut_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigNormalizeTmpBytesImpl for FFT64Spqlios { - fn vec_znx_big_normalize_tmp_bytes_impl(module: &Module) -> usize { - vec_znx_normalize_tmp_bytes(module.n()) - } -} - -unsafe impl VecZnxBigNormalizeImpl for FFT64Spqlios -where - Self: TakeSliceImpl, -{ - fn vec_znx_big_normalize_impl( - module: &Module, - res_basek: usize, - res: &mut R, - res_col: usize, - a_basek: usize, - a: &A, - a_col: usize, - scratch: &mut Scratch, - ) where - R: VecZnxToMut, - A: VecZnxBigToRef, - { - let (carry, _) = scratch.take_slice(module.vec_znx_big_normalize_tmp_bytes() / size_of::()); - // unsafe { - // vec_znx::vec_znx_normalize_base2k( - // module.ptr(), - // base2k as u64, - // res.at_mut_ptr(res_col, 0), - // res.size() as u64, - // res.sl() as u64, - // a.at_ptr(a_col, 0), - // a.size() as u64, - // a.sl() as u64, - // tmp_bytes.as_mut_ptr(), - // ); - // } - vec_znx_big_normalize(res_basek, res, res_col, a_basek, a, a_col, carry); - } -} - -unsafe impl VecZnxBigAutomorphismImpl for FFT64Spqlios { - /// Applies the automorphism X^i -> X^ik on `a` and stores the result on `b`. - fn vec_znx_big_automorphism_impl(module: &Module, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxBigToMut, - A: VecZnxBigToRef, - { - let a: VecZnxBig<&[u8], Self> = a.to_ref(); - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - } - unsafe { - vec_znx::vec_znx_automorphism( - module.ptr(), - k, - res.at_mut_ptr(res_col, 0), - res.size() as u64, - res.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} - -unsafe impl VecZnxBigAutomorphismInplaceTmpBytesImpl for FFT64Spqlios { - fn vec_znx_big_automorphism_inplace_tmp_bytes_impl(_module: &Module) -> usize { - 0 - } -} - -unsafe impl VecZnxBigAutomorphismInplaceImpl for FFT64Spqlios { - /// Applies the automorphism X^i -> X^ik on `a` and stores the result on `a`. - fn vec_znx_big_automorphism_inplace_impl( - module: &Module, - k: i64, - a: &mut A, - a_col: usize, - _scratch: &mut Scratch, - ) where - A: VecZnxBigToMut, - { - let mut a: VecZnxBig<&mut [u8], Self> = a.to_mut(); - unsafe { - vec_znx::vec_znx_automorphism( - module.ptr(), - k, - a.at_mut_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - a.at_ptr(a_col, 0), - a.size() as u64, - a.sl() as u64, - ) - } - } -} diff --git a/poulpy-backend/src/cpu_spqlios/fft64/vec_znx_dft.rs b/poulpy-backend/src/cpu_spqlios/fft64/vec_znx_dft.rs deleted file mode 100644 index cdffb41..0000000 --- a/poulpy-backend/src/cpu_spqlios/fft64/vec_znx_dft.rs +++ /dev/null @@ -1,435 +0,0 @@ -use poulpy_hal::{ - api::{TakeSlice, VecZnxIdftApplyTmpBytes}, - layouts::{ - Backend, Data, Module, Scratch, VecZnx, VecZnxBig, VecZnxBigToMut, VecZnxDft, VecZnxDftOwned, VecZnxDftToMut, - VecZnxDftToRef, VecZnxToRef, ZnxInfos, ZnxSliceSize, ZnxView, ZnxViewMut, - }, - oep::{ - VecZnxDftAddImpl, VecZnxDftAddInplaceImpl, VecZnxDftAllocBytesImpl, VecZnxDftAllocImpl, VecZnxDftApplyImpl, - VecZnxDftCopyImpl, VecZnxDftFromBytesImpl, VecZnxDftSubImpl, VecZnxDftSubInplaceImpl, VecZnxDftSubNegateInplaceImpl, - VecZnxDftZeroImpl, VecZnxIdftApplyConsumeImpl, VecZnxIdftApplyImpl, VecZnxIdftApplyTmpAImpl, VecZnxIdftApplyTmpBytesImpl, - }, - reference::{ - fft64::{ - reim::{ReimCopy, ReimZero, reim_copy_ref, reim_negate_inplace_ref, reim_negate_ref, reim_zero_ref}, - vec_znx_dft::{vec_znx_dft_copy, vec_znx_dft_zero}, - }, - znx::znx_zero_ref, - }, -}; - -use crate::cpu_spqlios::{ - FFT64Spqlios, - ffi::{vec_znx_big, vec_znx_dft}, -}; - -unsafe impl VecZnxDftFromBytesImpl for FFT64Spqlios { - fn vec_znx_dft_from_bytes_impl(n: usize, cols: usize, size: usize, bytes: Vec) -> VecZnxDftOwned { - VecZnxDft::, Self>::from_bytes(n, cols, size, bytes) - } -} - -unsafe impl VecZnxDftAllocBytesImpl for FFT64Spqlios { - fn vec_znx_dft_bytes_of_impl(n: usize, cols: usize, size: usize) -> usize { - Self::layout_prep_word_count() * n * cols * size * size_of::<::ScalarPrep>() - } -} - -unsafe impl VecZnxDftAllocImpl for FFT64Spqlios { - fn vec_znx_dft_alloc_impl(n: usize, cols: usize, size: usize) -> VecZnxDftOwned { - VecZnxDftOwned::alloc(n, cols, size) - } -} - -unsafe impl VecZnxIdftApplyTmpBytesImpl for FFT64Spqlios { - fn vec_znx_idft_apply_tmp_bytes_impl(module: &Module) -> usize { - unsafe { vec_znx_dft::vec_znx_idft_tmp_bytes(module.ptr()) as usize } - } -} - -unsafe impl VecZnxIdftApplyImpl for FFT64Spqlios { - fn vec_znx_idft_apply_impl( - module: &Module, - res: &mut R, - res_col: usize, - a: &A, - a_col: usize, - scratch: &mut Scratch, - ) where - R: VecZnxBigToMut, - A: VecZnxDftToRef, - { - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - let a: VecZnxDft<&[u8], Self> = a.to_ref(); - - #[cfg(debug_assertions)] - { - assert_eq!(res.n(), a.n()) - } - - let (tmp_bytes, _) = scratch.take_slice(module.vec_znx_idft_apply_tmp_bytes()); - - let min_size: usize = res.size().min(a.size()); - - unsafe { - (0..min_size).for_each(|j| { - vec_znx_dft::vec_znx_idft( - module.ptr(), - res.at_mut_ptr(res_col, j) as *mut vec_znx_big::vec_znx_big_t, - 1_u64, - a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1_u64, - tmp_bytes.as_mut_ptr(), - ) - }); - (min_size..res.size()).for_each(|j| znx_zero_ref(res.at_mut(res_col, j))); - } - } -} - -unsafe impl VecZnxIdftApplyTmpAImpl for FFT64Spqlios { - fn vec_znx_idft_apply_tmpa_impl(module: &Module, res: &mut R, res_col: usize, a: &mut A, a_col: usize) - where - R: VecZnxBigToMut, - A: VecZnxDftToMut, - { - let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut(); - let mut a_mut: VecZnxDft<&mut [u8], Self> = a.to_mut(); - - let min_size: usize = res.size().min(a_mut.size()); - - unsafe { - (0..min_size).for_each(|j| { - vec_znx_dft::vec_znx_idft_tmp_a( - module.ptr(), - res.at_mut_ptr(res_col, j) as *mut vec_znx_big::vec_znx_big_t, - 1_u64, - a_mut.at_mut_ptr(a_col, j) as *mut vec_znx_dft::vec_znx_dft_t, - 1_u64, - ) - }); - (min_size..res.size()).for_each(|j| znx_zero_ref(res.at_mut(res_col, j))) - } - } -} - -unsafe impl VecZnxIdftApplyConsumeImpl for FFT64Spqlios { - fn vec_znx_idft_apply_consume_impl(module: &Module, mut a: VecZnxDft) -> VecZnxBig - where - VecZnxDft: VecZnxDftToMut, - { - let mut a_mut: VecZnxDft<&mut [u8], Self> = a.to_mut(); - - unsafe { - // Rev col and rows because ZnxDft.sl() >= ZnxBig.sl() - (0..a_mut.size()).for_each(|j| { - (0..a_mut.cols()).for_each(|i| { - vec_znx_dft::vec_znx_idft_tmp_a( - module.ptr(), - a_mut.at_mut_ptr(i, j) as *mut vec_znx_big::vec_znx_big_t, - 1_u64, - a_mut.at_mut_ptr(i, j) as *mut vec_znx_dft::vec_znx_dft_t, - 1_u64, - ) - }); - }); - } - - a.into_big() - } -} - -unsafe impl VecZnxDftApplyImpl for FFT64Spqlios { - fn vec_znx_dft_apply_impl( - module: &Module, - step: usize, - offset: usize, - res: &mut R, - res_col: usize, - a: &A, - a_col: usize, - ) where - R: VecZnxDftToMut, - A: VecZnxToRef, - { - let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut(); - let a: VecZnx<&[u8]> = a.to_ref(); - let steps: usize = a.size().div_ceil(step); - let min_steps: usize = res.size().min(steps); - unsafe { - (0..min_steps).for_each(|j| { - let limb: usize = offset + j * step; - if limb < a.size() { - vec_znx_dft::vec_znx_dft( - module.ptr(), - res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t, - 1_u64, - a.at_ptr(a_col, limb), - 1_u64, - a.sl() as u64, - ) - } - }); - (min_steps..res.size()).for_each(|j| reim_zero_ref(res.at_mut(res_col, j))); - } - } -} - -unsafe impl VecZnxDftAddImpl for FFT64Spqlios { - fn vec_znx_dft_add_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &D, b_col: usize) - where - R: VecZnxDftToMut, - A: VecZnxDftToRef, - D: VecZnxDftToRef, - { - let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut(); - let a: VecZnxDft<&[u8], Self> = a.to_ref(); - let b: VecZnxDft<&[u8], Self> = b.to_ref(); - - let res_size: usize = res.size(); - let a_size: usize = a.size(); - let b_size: usize = b.size(); - - unsafe { - if a_size <= b_size { - let sum_size: usize = a_size.min(res_size); - let cpy_size: usize = b_size.min(res_size); - - (0..sum_size).for_each(|j| { - vec_znx_dft::vec_dft_add( - module.ptr(), - res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t, - 1, - a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - b.at_ptr(b_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - ); - }); - - for j in sum_size..cpy_size { - reim_copy_ref(res.at_mut(res_col, j), b.at(b_col, j)); - } - - for j in cpy_size..res_size { - reim_zero_ref(res.at_mut(res_col, j)); - } - } else { - let sum_size: usize = b_size.min(res_size); - let cpy_size: usize = a_size.min(res_size); - - (0..sum_size).for_each(|j| { - vec_znx_dft::vec_dft_add( - module.ptr(), - res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t, - 1, - a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - b.at_ptr(b_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - ); - }); - - for j in sum_size..cpy_size { - reim_copy_ref(res.at_mut(res_col, j), a.at(b_col, j)); - } - - for j in cpy_size..res_size { - reim_zero_ref(res.at_mut(res_col, j)); - } - } - } - } -} - -unsafe impl VecZnxDftAddInplaceImpl for FFT64Spqlios { - fn vec_znx_dft_add_inplace_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxDftToMut, - A: VecZnxDftToRef, - { - let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut(); - let a: VecZnxDft<&[u8], Self> = a.to_ref(); - - let min_size: usize = res.size().min(a.size()); - - unsafe { - (0..min_size).for_each(|j| { - vec_znx_dft::vec_dft_add( - module.ptr(), - res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t, - 1, - res.at_ptr(res_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - ); - }); - } - } -} - -unsafe impl VecZnxDftSubImpl for FFT64Spqlios { - fn vec_znx_dft_sub_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &D, b_col: usize) - where - R: VecZnxDftToMut, - A: VecZnxDftToRef, - D: VecZnxDftToRef, - { - let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut(); - let a: VecZnxDft<&[u8], Self> = a.to_ref(); - let b: VecZnxDft<&[u8], Self> = b.to_ref(); - - unsafe { - let res_size: usize = res.size(); - let a_size: usize = a.size(); - let b_size: usize = b.size(); - - if a_size <= b_size { - let sum_size: usize = a_size.min(res_size); - let cpy_size: usize = b_size.min(res_size); - - (0..sum_size).for_each(|j| { - vec_znx_dft::vec_dft_sub( - module.ptr(), - res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t, - 1, - a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - b.at_ptr(b_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - ); - }); - - for j in sum_size..cpy_size { - reim_negate_ref(res.at_mut(res_col, j), b.at(b_col, j)); - } - - for j in cpy_size..res_size { - reim_zero_ref(res.at_mut(res_col, j)); - } - } else { - let sum_size: usize = b_size.min(res_size); - let cpy_size: usize = a_size.min(res_size); - - (0..sum_size).for_each(|j| { - vec_znx_dft::vec_dft_sub( - module.ptr(), - res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t, - 1, - a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - b.at_ptr(b_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - ); - }); - - for j in sum_size..cpy_size { - reim_copy_ref(res.at_mut(res_col, j), a.at(a_col, j)); - } - - for j in cpy_size..res_size { - reim_zero_ref(res.at_mut(res_col, j)); - } - } - } - } -} - -unsafe impl VecZnxDftSubInplaceImpl for FFT64Spqlios { - fn vec_znx_dft_sub_inplace_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxDftToMut, - A: VecZnxDftToRef, - { - let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut(); - let a: VecZnxDft<&[u8], Self> = a.to_ref(); - - let min_size: usize = res.size().min(a.size()); - - unsafe { - (0..min_size).for_each(|j| { - vec_znx_dft::vec_dft_sub( - module.ptr(), - res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t, - 1, - res.at_ptr(res_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - ); - }); - } - } -} - -unsafe impl VecZnxDftSubNegateInplaceImpl for FFT64Spqlios { - fn vec_znx_dft_sub_negate_inplace_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) - where - R: VecZnxDftToMut, - A: VecZnxDftToRef, - { - let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut(); - let a: VecZnxDft<&[u8], Self> = a.to_ref(); - - let min_size: usize = res.size().min(a.size()); - - unsafe { - (0..min_size).for_each(|j| { - vec_znx_dft::vec_dft_sub( - module.ptr(), - res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t, - 1, - a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - res.at_ptr(res_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1, - ); - }); - - for j in min_size..res.size() { - reim_negate_inplace_ref(res.at_mut(res_col, j)); - } - } - } -} - -unsafe impl VecZnxDftCopyImpl for FFT64Spqlios { - fn vec_znx_dft_copy_impl( - _module: &Module, - step: usize, - offset: usize, - res: &mut R, - res_col: usize, - a: &A, - a_col: usize, - ) where - R: VecZnxDftToMut, - A: VecZnxDftToRef, - { - vec_znx_dft_copy(step, offset, res, res_col, a, a_col); - } -} - -impl ReimCopy for FFT64Spqlios { - #[inline(always)] - fn reim_copy(res: &mut [f64], a: &[f64]) { - reim_copy_ref(res, a); - } -} - -impl ReimZero for FFT64Spqlios { - #[inline(always)] - fn reim_zero(res: &mut [f64]) { - reim_zero_ref(res); - } -} - -unsafe impl VecZnxDftZeroImpl for FFT64Spqlios { - fn vec_znx_dft_zero_impl(_module: &Module, res: &mut R, res_col: usize) - where - R: VecZnxDftToMut, - { - vec_znx_dft_zero(res, res_col); - } -} diff --git a/poulpy-backend/src/cpu_spqlios/fft64/vmp_pmat.rs b/poulpy-backend/src/cpu_spqlios/fft64/vmp_pmat.rs deleted file mode 100644 index bd60680..0000000 --- a/poulpy-backend/src/cpu_spqlios/fft64/vmp_pmat.rs +++ /dev/null @@ -1,281 +0,0 @@ -use poulpy_hal::{ - api::{TakeSlice, VmpApplyDftToDftTmpBytes, VmpPrepareTmpBytes}, - layouts::{ - Backend, MatZnx, MatZnxToRef, Module, Scratch, VecZnxDft, VecZnxDftToMut, VecZnxDftToRef, VmpPMat, VmpPMatOwned, - VmpPMatToMut, VmpPMatToRef, ZnxInfos, ZnxView, ZnxViewMut, - }, - oep::{ - VmpApplyDftToDftAddImpl, VmpApplyDftToDftAddTmpBytesImpl, VmpApplyDftToDftImpl, VmpApplyDftToDftTmpBytesImpl, - VmpPMatAllocBytesImpl, VmpPMatAllocImpl, VmpPMatFromBytesImpl, VmpPrepareImpl, VmpPrepareTmpBytesImpl, VmpZeroImpl, - }, - reference::fft64::vmp::vmp_zero, -}; - -use crate::cpu_spqlios::{ - FFT64Spqlios, - ffi::{vec_znx_dft::vec_znx_dft_t, vmp}, -}; - -unsafe impl VmpPMatAllocBytesImpl for FFT64Spqlios { - fn vmp_pmat_bytes_of_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize { - Self::layout_prep_word_count() * n * rows * cols_in * cols_out * size * size_of::() - } -} - -unsafe impl VmpPMatFromBytesImpl for FFT64Spqlios { - fn vmp_pmat_from_bytes_impl( - n: usize, - rows: usize, - cols_in: usize, - cols_out: usize, - size: usize, - bytes: Vec, - ) -> VmpPMatOwned { - VmpPMatOwned::from_bytes(n, rows, cols_in, cols_out, size, bytes) - } -} - -unsafe impl VmpPMatAllocImpl for FFT64Spqlios { - fn vmp_pmat_alloc_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> VmpPMatOwned { - VmpPMatOwned::alloc(n, rows, cols_in, cols_out, size) - } -} - -unsafe impl VmpPrepareTmpBytesImpl for FFT64Spqlios { - fn vmp_prepare_tmp_bytes_impl(module: &Module, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize { - unsafe { - vmp::vmp_prepare_tmp_bytes( - module.ptr(), - (rows * cols_in) as u64, - (cols_out * size) as u64, - ) as usize - } - } -} - -unsafe impl VmpPrepareImpl for FFT64Spqlios { - fn vmp_prepare_impl(module: &Module, res: &mut R, a: &A, scratch: &mut Scratch) - where - R: VmpPMatToMut, - A: MatZnxToRef, - { - let mut res: VmpPMat<&mut [u8], Self> = res.to_mut(); - let a: MatZnx<&[u8]> = a.to_ref(); - - #[cfg(debug_assertions)] - { - assert_eq!(a.n(), res.n()); - assert_eq!( - res.cols_in(), - a.cols_in(), - "res.cols_in: {} != a.cols_in: {}", - res.cols_in(), - a.cols_in() - ); - assert_eq!( - res.rows(), - a.rows(), - "res.rows: {} != a.rows: {}", - res.rows(), - a.rows() - ); - assert_eq!( - res.cols_out(), - a.cols_out(), - "res.cols_out: {} != a.cols_out: {}", - res.cols_out(), - a.cols_out() - ); - assert_eq!( - res.size(), - a.size(), - "res.size: {} != a.size: {}", - res.size(), - a.size() - ); - } - - let (tmp_bytes, _) = scratch.take_slice(module.vmp_prepare_tmp_bytes(a.rows(), a.cols_in(), a.cols_out(), a.size())); - - unsafe { - vmp::vmp_prepare_contiguous( - module.ptr(), - res.as_mut_ptr() as *mut vmp::vmp_pmat_t, - a.as_ptr(), - (a.rows() * a.cols_in()) as u64, - (a.size() * a.cols_out()) as u64, - tmp_bytes.as_mut_ptr(), - ); - } - } -} - -unsafe impl VmpApplyDftToDftTmpBytesImpl for FFT64Spqlios { - fn vmp_apply_dft_to_dft_tmp_bytes_impl( - module: &Module, - res_size: usize, - a_size: usize, - b_rows: usize, - b_cols_in: usize, - b_cols_out: usize, - b_size: usize, - ) -> usize { - unsafe { - vmp::vmp_apply_dft_to_dft_tmp_bytes( - module.ptr(), - (res_size * b_cols_out) as u64, - (a_size * b_cols_in) as u64, - (b_rows * b_cols_in) as u64, - (b_size * b_cols_out) as u64, - ) as usize - } - } -} - -unsafe impl VmpApplyDftToDftImpl for FFT64Spqlios { - fn vmp_apply_dft_to_dft_impl(module: &Module, res: &mut R, a: &A, b: &C, scratch: &mut Scratch) - where - R: VecZnxDftToMut, - A: VecZnxDftToRef, - C: VmpPMatToRef, - { - let mut res: VecZnxDft<&mut [u8], _> = res.to_mut(); - let a: VecZnxDft<&[u8], _> = a.to_ref(); - let b: VmpPMat<&[u8], _> = b.to_ref(); - - #[cfg(debug_assertions)] - { - assert_eq!(b.n(), res.n()); - assert_eq!(a.n(), res.n()); - assert_eq!( - res.cols(), - b.cols_out(), - "res.cols(): {} != b.cols_out: {}", - res.cols(), - b.cols_out() - ); - assert_eq!( - a.cols(), - b.cols_in(), - "a.cols(): {} != b.cols_in: {}", - a.cols(), - b.cols_in() - ); - } - - let (tmp_bytes, _) = scratch.take_slice(module.vmp_apply_dft_to_dft_tmp_bytes( - res.size(), - a.size(), - b.rows(), - b.cols_in(), - b.cols_out(), - b.size(), - )); - unsafe { - vmp::vmp_apply_dft_to_dft( - module.ptr(), - res.as_mut_ptr() as *mut vec_znx_dft_t, - (res.size() * res.cols()) as u64, - a.as_ptr() as *const vec_znx_dft_t, - (a.size() * a.cols()) as u64, - b.as_ptr() as *const vmp::vmp_pmat_t, - (b.rows() * b.cols_in()) as u64, - (b.size() * b.cols_out()) as u64, - tmp_bytes.as_mut_ptr(), - ) - } - } -} - -unsafe impl VmpApplyDftToDftAddTmpBytesImpl for FFT64Spqlios { - fn vmp_apply_dft_to_dft_add_tmp_bytes_impl( - module: &Module, - res_size: usize, - a_size: usize, - b_rows: usize, - b_cols_in: usize, - b_cols_out: usize, - b_size: usize, - ) -> usize { - unsafe { - vmp::vmp_apply_dft_to_dft_tmp_bytes( - module.ptr(), - (res_size * b_cols_out) as u64, - (a_size * b_cols_in) as u64, - (b_rows * b_cols_in) as u64, - (b_size * b_cols_out) as u64, - ) as usize - } - } -} - -unsafe impl VmpApplyDftToDftAddImpl for FFT64Spqlios { - fn vmp_apply_dft_to_dft_add_impl( - module: &Module, - res: &mut R, - a: &A, - b: &C, - scale: usize, - scratch: &mut Scratch, - ) where - R: VecZnxDftToMut, - A: VecZnxDftToRef, - C: VmpPMatToRef, - { - let mut res: VecZnxDft<&mut [u8], _> = res.to_mut(); - let a: VecZnxDft<&[u8], _> = a.to_ref(); - let b: VmpPMat<&[u8], _> = b.to_ref(); - - #[cfg(debug_assertions)] - { - assert_eq!(b.n(), res.n()); - assert_eq!(a.n(), res.n()); - assert_eq!( - res.cols(), - b.cols_out(), - "res.cols(): {} != b.cols_out: {}", - res.cols(), - b.cols_out() - ); - assert_eq!( - a.cols(), - b.cols_in(), - "a.cols(): {} != b.cols_in: {}", - a.cols(), - b.cols_in() - ); - } - - let (tmp_bytes, _) = scratch.take_slice(module.vmp_apply_dft_to_dft_tmp_bytes( - res.size(), - a.size(), - b.rows(), - b.cols_in(), - b.cols_out(), - b.size(), - )); - unsafe { - vmp::vmp_apply_dft_to_dft_add( - module.ptr(), - res.as_mut_ptr() as *mut vec_znx_dft_t, - (res.size() * res.cols()) as u64, - a.as_ptr() as *const vec_znx_dft_t, - (a.size() * a.cols()) as u64, - b.as_ptr() as *const vmp::vmp_pmat_t, - (b.rows() * b.cols_in()) as u64, - (b.size() * b.cols_out()) as u64, - (scale * b.cols_out()) as u64, - tmp_bytes.as_mut_ptr(), - ) - } - } -} - -unsafe impl VmpZeroImpl for FFT64Spqlios { - fn vmp_zero_impl(_module: &Module, res: &mut R) - where - R: VmpPMatToMut, - { - vmp_zero(res); - } -} diff --git a/poulpy-backend/src/cpu_spqlios/fft64/znx.rs b/poulpy-backend/src/cpu_spqlios/fft64/znx.rs deleted file mode 100644 index c15c8ff..0000000 --- a/poulpy-backend/src/cpu_spqlios/fft64/znx.rs +++ /dev/null @@ -1,189 +0,0 @@ -use poulpy_hal::reference::znx::{ - ZnxAdd, ZnxAddInplace, ZnxAutomorphism, ZnxCopy, ZnxExtractDigitAddMul, ZnxMulAddPowerOfTwo, ZnxMulPowerOfTwo, - ZnxMulPowerOfTwoInplace, ZnxNegate, ZnxNegateInplace, ZnxNormalizeDigit, ZnxNormalizeFinalStep, ZnxNormalizeFinalStepInplace, - ZnxNormalizeFirstStep, ZnxNormalizeFirstStepCarryOnly, ZnxNormalizeFirstStepInplace, ZnxNormalizeMiddleStep, - ZnxNormalizeMiddleStepCarryOnly, ZnxNormalizeMiddleStepInplace, ZnxRotate, ZnxSub, ZnxSubInplace, ZnxSubNegateInplace, - ZnxSwitchRing, ZnxZero, znx_add_inplace_ref, znx_add_ref, znx_automorphism_ref, znx_copy_ref, znx_extract_digit_addmul_ref, - znx_mul_add_power_of_two_ref, znx_mul_power_of_two_inplace_ref, znx_mul_power_of_two_ref, znx_negate_inplace_ref, - znx_negate_ref, znx_normalize_digit_ref, znx_normalize_final_step_inplace_ref, znx_normalize_final_step_ref, - znx_normalize_first_step_carry_only_ref, znx_normalize_first_step_inplace_ref, znx_normalize_first_step_ref, - znx_normalize_middle_step_carry_only_ref, znx_normalize_middle_step_inplace_ref, znx_normalize_middle_step_ref, znx_rotate, - znx_sub_inplace_ref, znx_sub_negate_inplace_ref, znx_sub_ref, znx_switch_ring_ref, znx_zero_ref, -}; - -use crate::FFT64Spqlios; - -impl ZnxAdd for FFT64Spqlios { - #[inline(always)] - fn znx_add(res: &mut [i64], a: &[i64], b: &[i64]) { - znx_add_ref(res, a, b); - } -} - -impl ZnxAddInplace for FFT64Spqlios { - #[inline(always)] - fn znx_add_inplace(res: &mut [i64], a: &[i64]) { - znx_add_inplace_ref(res, a); - } -} - -impl ZnxSub for FFT64Spqlios { - #[inline(always)] - fn znx_sub(res: &mut [i64], a: &[i64], b: &[i64]) { - znx_sub_ref(res, a, b); - } -} - -impl ZnxSubInplace for FFT64Spqlios { - #[inline(always)] - fn znx_sub_inplace(res: &mut [i64], a: &[i64]) { - znx_sub_inplace_ref(res, a); - } -} - -impl ZnxSubNegateInplace for FFT64Spqlios { - #[inline(always)] - fn znx_sub_negate_inplace(res: &mut [i64], a: &[i64]) { - znx_sub_negate_inplace_ref(res, a); - } -} - -impl ZnxMulAddPowerOfTwo for FFT64Spqlios { - #[inline(always)] - fn znx_muladd_power_of_two(k: i64, res: &mut [i64], a: &[i64]) { - znx_mul_add_power_of_two_ref(k, res, a); - } -} - -impl ZnxMulPowerOfTwo for FFT64Spqlios { - #[inline(always)] - fn znx_mul_power_of_two(k: i64, res: &mut [i64], a: &[i64]) { - znx_mul_power_of_two_ref(k, res, a); - } -} - -impl ZnxMulPowerOfTwoInplace for FFT64Spqlios { - #[inline(always)] - fn znx_mul_power_of_two_inplace(k: i64, res: &mut [i64]) { - znx_mul_power_of_two_inplace_ref(k, res); - } -} - -impl ZnxAutomorphism for FFT64Spqlios { - #[inline(always)] - fn znx_automorphism(p: i64, res: &mut [i64], a: &[i64]) { - znx_automorphism_ref(p, res, a); - } -} - -impl ZnxCopy for FFT64Spqlios { - #[inline(always)] - fn znx_copy(res: &mut [i64], a: &[i64]) { - znx_copy_ref(res, a); - } -} - -impl ZnxNegate for FFT64Spqlios { - #[inline(always)] - fn znx_negate(res: &mut [i64], src: &[i64]) { - znx_negate_ref(res, src); - } -} - -impl ZnxNegateInplace for FFT64Spqlios { - #[inline(always)] - fn znx_negate_inplace(res: &mut [i64]) { - znx_negate_inplace_ref(res); - } -} - -impl ZnxRotate for FFT64Spqlios { - #[inline(always)] - fn znx_rotate(p: i64, res: &mut [i64], src: &[i64]) { - znx_rotate::(p, res, src); - } -} - -impl ZnxZero for FFT64Spqlios { - #[inline(always)] - fn znx_zero(res: &mut [i64]) { - znx_zero_ref(res); - } -} - -impl ZnxSwitchRing for FFT64Spqlios { - #[inline(always)] - fn znx_switch_ring(res: &mut [i64], a: &[i64]) { - znx_switch_ring_ref(res, a); - } -} - -impl ZnxNormalizeFinalStep for FFT64Spqlios { - #[inline(always)] - fn znx_normalize_final_step(base2k: usize, lsh: usize, x: &mut [i64], a: &[i64], carry: &mut [i64]) { - znx_normalize_final_step_ref(base2k, lsh, x, a, carry); - } -} - -impl ZnxNormalizeFinalStepInplace for FFT64Spqlios { - #[inline(always)] - fn znx_normalize_final_step_inplace(base2k: usize, lsh: usize, x: &mut [i64], carry: &mut [i64]) { - znx_normalize_final_step_inplace_ref(base2k, lsh, x, carry); - } -} - -impl ZnxNormalizeFirstStep for FFT64Spqlios { - #[inline(always)] - fn znx_normalize_first_step(base2k: usize, lsh: usize, x: &mut [i64], a: &[i64], carry: &mut [i64]) { - znx_normalize_first_step_ref(base2k, lsh, x, a, carry); - } -} - -impl ZnxNormalizeFirstStepCarryOnly for FFT64Spqlios { - #[inline(always)] - fn znx_normalize_first_step_carry_only(base2k: usize, lsh: usize, x: &[i64], carry: &mut [i64]) { - znx_normalize_first_step_carry_only_ref(base2k, lsh, x, carry); - } -} - -impl ZnxNormalizeFirstStepInplace for FFT64Spqlios { - #[inline(always)] - fn znx_normalize_first_step_inplace(base2k: usize, lsh: usize, x: &mut [i64], carry: &mut [i64]) { - znx_normalize_first_step_inplace_ref(base2k, lsh, x, carry); - } -} - -impl ZnxNormalizeMiddleStep for FFT64Spqlios { - #[inline(always)] - fn znx_normalize_middle_step(base2k: usize, lsh: usize, x: &mut [i64], a: &[i64], carry: &mut [i64]) { - znx_normalize_middle_step_ref(base2k, lsh, x, a, carry); - } -} - -impl ZnxNormalizeMiddleStepCarryOnly for FFT64Spqlios { - #[inline(always)] - fn znx_normalize_middle_step_carry_only(base2k: usize, lsh: usize, x: &[i64], carry: &mut [i64]) { - znx_normalize_middle_step_carry_only_ref(base2k, lsh, x, carry); - } -} - -impl ZnxNormalizeMiddleStepInplace for FFT64Spqlios { - #[inline(always)] - fn znx_normalize_middle_step_inplace(base2k: usize, lsh: usize, x: &mut [i64], carry: &mut [i64]) { - znx_normalize_middle_step_inplace_ref(base2k, lsh, x, carry); - } -} - -impl ZnxExtractDigitAddMul for FFT64Spqlios { - #[inline(always)] - fn znx_extract_digit_addmul(base2k: usize, lsh: usize, res: &mut [i64], src: &mut [i64]) { - znx_extract_digit_addmul_ref(base2k, lsh, res, src); - } -} - -impl ZnxNormalizeDigit for FFT64Spqlios { - #[inline(always)] - fn znx_normalize_digit(base2k: usize, res: &mut [i64], src: &mut [i64]) { - znx_normalize_digit_ref(base2k, res, src); - } -} diff --git a/poulpy-backend/src/cpu_spqlios/mod.rs b/poulpy-backend/src/cpu_spqlios/mod.rs deleted file mode 100644 index 6a34dec..0000000 --- a/poulpy-backend/src/cpu_spqlios/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -mod ffi; -mod fft64; -mod ntt120; - -#[cfg(test)] -mod tests; - -pub use ffi::*; -pub use fft64::*; -pub use ntt120::*; diff --git a/poulpy-backend/src/cpu_spqlios/ntt120/mod.rs b/poulpy-backend/src/cpu_spqlios/ntt120/mod.rs deleted file mode 100644 index cd4cb13..0000000 --- a/poulpy-backend/src/cpu_spqlios/ntt120/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod module; -mod svp_ppol; -mod vec_znx_big; -mod vec_znx_dft; -mod vmp_pmat; - -pub use module::NTT120; diff --git a/poulpy-backend/src/cpu_spqlios/ntt120/module.rs b/poulpy-backend/src/cpu_spqlios/ntt120/module.rs deleted file mode 100644 index 65aa143..0000000 --- a/poulpy-backend/src/cpu_spqlios/ntt120/module.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::ptr::NonNull; - -use poulpy_hal::{ - layouts::{Backend, Module}, - oep::ModuleNewImpl, -}; - -use crate::cpu_spqlios::ffi::module::{MODULE, delete_module_info, new_module_info}; - -pub struct NTT120; - -impl Backend for NTT120 { - type ScalarPrep = i64; - type ScalarBig = i128; - type Handle = MODULE; - unsafe fn destroy(handle: NonNull) { - unsafe { delete_module_info(handle.as_ptr()) } - } - - fn layout_big_word_count() -> usize { - 4 - } - - fn layout_prep_word_count() -> usize { - 1 - } -} - -unsafe impl ModuleNewImpl for NTT120 { - fn new_impl(n: u64) -> Module { - unsafe { Module::from_raw_parts(new_module_info(n, 1), n) } - } -} diff --git a/poulpy-backend/src/cpu_spqlios/ntt120/svp_ppol.rs b/poulpy-backend/src/cpu_spqlios/ntt120/svp_ppol.rs deleted file mode 100644 index 8c7fdcc..0000000 --- a/poulpy-backend/src/cpu_spqlios/ntt120/svp_ppol.rs +++ /dev/null @@ -1,24 +0,0 @@ -use poulpy_hal::{ - layouts::{Backend, SvpPPolOwned}, - oep::{SvpPPolAllocBytesImpl, SvpPPolAllocImpl, SvpPPolFromBytesImpl}, -}; - -use crate::cpu_spqlios::NTT120; - -unsafe impl SvpPPolFromBytesImpl for NTT120 { - fn svp_ppol_from_bytes_impl(n: usize, cols: usize, bytes: Vec) -> SvpPPolOwned { - SvpPPolOwned::from_bytes(n, cols, bytes) - } -} - -unsafe impl SvpPPolAllocImpl for NTT120 { - fn svp_ppol_alloc_impl(n: usize, cols: usize) -> SvpPPolOwned { - SvpPPolOwned::alloc(n, cols) - } -} - -unsafe impl SvpPPolAllocBytesImpl for NTT120 { - fn svp_ppol_bytes_of_impl(n: usize, cols: usize) -> usize { - NTT120::layout_prep_word_count() * n * cols * size_of::() - } -} diff --git a/poulpy-backend/src/cpu_spqlios/ntt120/vec_znx_big.rs b/poulpy-backend/src/cpu_spqlios/ntt120/vec_znx_big.rs deleted file mode 100644 index 58ddf78..0000000 --- a/poulpy-backend/src/cpu_spqlios/ntt120/vec_znx_big.rs +++ /dev/null @@ -1,9 +0,0 @@ -use poulpy_hal::{layouts::Backend, oep::VecZnxBigAllocBytesImpl}; - -use crate::cpu_spqlios::NTT120; - -unsafe impl VecZnxBigAllocBytesImpl for NTT120 { - fn vec_znx_big_bytes_of_impl(n: usize, cols: usize, size: usize) -> usize { - NTT120::layout_big_word_count() * n * cols * size * size_of::() - } -} diff --git a/poulpy-backend/src/cpu_spqlios/ntt120/vec_znx_dft.rs b/poulpy-backend/src/cpu_spqlios/ntt120/vec_znx_dft.rs deleted file mode 100644 index 9e1666b..0000000 --- a/poulpy-backend/src/cpu_spqlios/ntt120/vec_znx_dft.rs +++ /dev/null @@ -1,18 +0,0 @@ -use poulpy_hal::{ - layouts::{Backend, VecZnxDftOwned}, - oep::{VecZnxDftAllocBytesImpl, VecZnxDftAllocImpl}, -}; - -use crate::cpu_spqlios::NTT120; - -unsafe impl VecZnxDftAllocBytesImpl for NTT120 { - fn vec_znx_dft_bytes_of_impl(n: usize, cols: usize, size: usize) -> usize { - NTT120::layout_prep_word_count() * n * cols * size * size_of::() - } -} - -unsafe impl VecZnxDftAllocImpl for NTT120 { - fn vec_znx_dft_alloc_impl(n: usize, cols: usize, size: usize) -> VecZnxDftOwned { - VecZnxDftOwned::alloc(n, cols, size) - } -} diff --git a/poulpy-backend/src/cpu_spqlios/ntt120/vmp_pmat.rs b/poulpy-backend/src/cpu_spqlios/ntt120/vmp_pmat.rs deleted file mode 100644 index 8b13789..0000000 --- a/poulpy-backend/src/cpu_spqlios/ntt120/vmp_pmat.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/poulpy-backend/src/cpu_spqlios/spqlios-arithmetic b/poulpy-backend/src/cpu_spqlios/spqlios-arithmetic deleted file mode 160000 index e8aed63..0000000 --- a/poulpy-backend/src/cpu_spqlios/spqlios-arithmetic +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e8aed6384cfb5441fe6bfa26323ffb0b57179656 diff --git a/poulpy-backend/src/cpu_spqlios/tests.rs b/poulpy-backend/src/cpu_spqlios/tests.rs deleted file mode 100644 index bb1f8a0..0000000 --- a/poulpy-backend/src/cpu_spqlios/tests.rs +++ /dev/null @@ -1,117 +0,0 @@ -use poulpy_hal::{backend_test_suite, cross_backend_test_suite}; - -cross_backend_test_suite! { - mod vec_znx, - backend_ref = crate::cpu_fft64_ref::FFT64Ref, - backend_test = crate::cpu_spqlios::FFT64Spqlios, - size = 1 << 5, - base2k = 12, - tests = { - test_vec_znx_add => poulpy_hal::test_suite::vec_znx::test_vec_znx_add, - test_vec_znx_add_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_inplace, - test_vec_znx_add_scalar => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_scalar, - test_vec_znx_add_scalar_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_scalar_inplace, - test_vec_znx_sub => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub, - test_vec_znx_sub_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_inplace, - test_vec_znx_sub_negate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_negate_inplace, - test_vec_znx_sub_scalar => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_scalar, - test_vec_znx_sub_scalar_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_scalar_inplace, - test_vec_znx_rsh => poulpy_hal::test_suite::vec_znx::test_vec_znx_rsh, - test_vec_znx_rsh_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_rsh_inplace, - test_vec_znx_lsh => poulpy_hal::test_suite::vec_znx::test_vec_znx_lsh, - test_vec_znx_lsh_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_lsh_inplace, - test_vec_znx_negate => poulpy_hal::test_suite::vec_znx::test_vec_znx_negate, - test_vec_znx_negate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_negate_inplace, - test_vec_znx_rotate => poulpy_hal::test_suite::vec_znx::test_vec_znx_rotate, - test_vec_znx_rotate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_rotate_inplace, - test_vec_znx_automorphism => poulpy_hal::test_suite::vec_znx::test_vec_znx_automorphism, - test_vec_znx_automorphism_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_automorphism_inplace, - test_vec_znx_mul_xp_minus_one => poulpy_hal::test_suite::vec_znx::test_vec_znx_mul_xp_minus_one, - test_vec_znx_mul_xp_minus_one_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_mul_xp_minus_one_inplace, - test_vec_znx_normalize => poulpy_hal::test_suite::vec_znx::test_vec_znx_normalize, - test_vec_znx_normalize_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_normalize_inplace, - test_vec_znx_switch_ring => poulpy_hal::test_suite::vec_znx::test_vec_znx_switch_ring, - test_vec_znx_split_ring => poulpy_hal::test_suite::vec_znx::test_vec_znx_split_ring, - test_vec_znx_copy => poulpy_hal::test_suite::vec_znx::test_vec_znx_copy, - } -} - -cross_backend_test_suite! { - mod svp, - backend_ref = crate::cpu_fft64_ref::FFT64Ref, - backend_test = crate::cpu_spqlios::FFT64Spqlios, - size = 1 << 5, - base2k = 12, - tests = { - test_svp_apply_dft_to_dft => poulpy_hal::test_suite::svp::test_svp_apply_dft_to_dft, - test_svp_apply_dft_to_dft_inplace => poulpy_hal::test_suite::svp::test_svp_apply_dft_to_dft_inplace, - } -} - -cross_backend_test_suite! { - mod vec_znx_big, - backend_ref = crate::cpu_fft64_ref::FFT64Ref, - backend_test = crate::cpu_spqlios::FFT64Spqlios, - size = 1 << 5, - base2k = 12, - tests = { - test_vec_znx_big_add => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add, - test_vec_znx_big_add_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_inplace, - test_vec_znx_big_add_small => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_small, - test_vec_znx_big_add_small_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_small_inplace, - test_vec_znx_big_sub => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub, - test_vec_znx_big_sub_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_inplace, - test_vec_znx_big_automorphism => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_automorphism, - test_vec_znx_big_automorphism_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_automorphism_inplace, - test_vec_znx_big_negate => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_negate, - test_vec_znx_big_negate_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_negate_inplace, - test_vec_znx_big_normalize => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_normalize, - test_vec_znx_big_sub_negate_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_negate_inplace, - test_vec_znx_big_sub_small_a => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_a, - test_vec_znx_big_sub_small_a_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_a_inplace, - test_vec_znx_big_sub_small_b => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_b, - test_vec_znx_big_sub_small_b_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_b_inplace, - } -} - -cross_backend_test_suite! { - mod vec_znx_dft, - backend_ref = crate::cpu_fft64_ref::FFT64Ref, - backend_test = crate::cpu_spqlios::FFT64Spqlios, - size = 1 << 5, - base2k = 12, - tests = { - test_vec_znx_dft_add => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_add, - test_vec_znx_dft_add_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_add_inplace, - test_vec_znx_dft_sub => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub, - test_vec_znx_dft_sub_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub_inplace, - test_vec_znx_dft_sub_negate_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub_negate_inplace, - test_vec_znx_idft_apply => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply, - test_vec_znx_idft_apply_consume => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply_consume, - test_vec_znx_idft_apply_tmpa => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply_tmpa, - } -} - -cross_backend_test_suite! { - mod vmp, - backend_ref = crate::cpu_fft64_ref::FFT64Ref, - backend_test = crate::cpu_spqlios::FFT64Spqlios, - size = 1 << 5, - base2k = 12, - tests = { - test_vmp_apply_dft_to_dft => poulpy_hal::test_suite::vmp::test_vmp_apply_dft_to_dft, - test_vmp_apply_dft_to_dft_add => poulpy_hal::test_suite::vmp::test_vmp_apply_dft_to_dft_add, - } -} - -backend_test_suite! { - mod sampling, - backend = crate::cpu_spqlios::FFT64Spqlios, - size = 1 << 12, - tests = { - test_vec_znx_fill_uniform => poulpy_hal::test_suite::vec_znx::test_vec_znx_fill_uniform, - test_vec_znx_fill_normal => poulpy_hal::test_suite::vec_znx::test_vec_znx_fill_normal, - test_vec_znx_add_normal => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_normal, - test_vec_znx_big_sub_small_b_inplace => poulpy_hal::reference::fft64::vec_znx_big::test_vec_znx_big_add_normal, - } -} diff --git a/poulpy-backend/src/lib.rs b/poulpy-backend/src/lib.rs deleted file mode 100644 index f8ff115..0000000 --- a/poulpy-backend/src/lib.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] -pub mod cpu_fft64_avx; - -pub mod cpu_fft64_ref; -pub mod cpu_spqlios; - -#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] -pub use cpu_fft64_avx::FFT64Avx; - -pub use cpu_fft64_ref::FFT64Ref; -pub use cpu_spqlios::FFT64Spqlios; diff --git a/poulpy-core/Cargo.toml b/poulpy-core/Cargo.toml index d0336ee..8a5e471 100644 --- a/poulpy-core/Cargo.toml +++ b/poulpy-core/Cargo.toml @@ -12,11 +12,13 @@ documentation = "https://docs.rs/poulpy" rug = {workspace = true} criterion = {workspace = true} poulpy-hal = {workspace = true} -poulpy-backend = {workspace = true} +poulpy-cpu-avx = {workspace = true} +poulpy-cpu-ref = {workspace = true} itertools = {workspace = true} byteorder = {workspace = true} bytemuck = {workspace = true} once_cell = {workspace = true} +paste = {workspace = true} [[bench]] name = "external_product_glwe_fft64" diff --git a/poulpy-core/benches/external_product_glwe_fft64.rs b/poulpy-core/benches/external_product_glwe_fft64.rs index 900eda1..3bbd4f4 100644 --- a/poulpy-core/benches/external_product_glwe_fft64.rs +++ b/poulpy-core/benches/external_product_glwe_fft64.rs @@ -6,7 +6,7 @@ use std::hint::black_box; use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main}; -use poulpy_backend::cpu_spqlios::FFT64Spqlios; +use poulpy_cpu_ref::FFT64Ref; use poulpy_hal::{ api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow}, layouts::{Module, ScalarZnx, ScratchOwned}, @@ -26,7 +26,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) { } fn runner(p: Params) -> impl FnMut() { - let module: Module = Module::::new(1 << p.log_n); + let module: Module = Module::::new(1 << p.log_n); let n: Degree = Degree(module.n() as u32); let base2k: Base2K = p.base2k; @@ -66,7 +66,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) { let mut ct_glwe_out: GLWE> = GLWE::alloc_from_infos(&glwe_out_layout); let pt_rgsw: ScalarZnx> = ScalarZnx::alloc(n.into(), 1); - let mut scratch: ScratchOwned = ScratchOwned::alloc( + let mut scratch: ScratchOwned = ScratchOwned::alloc( GGSW::encrypt_sk_tmp_bytes(&module, &ggsw_layout) | GLWE::encrypt_sk_tmp_bytes(&module, &glwe_in_layout) | GLWE::external_product_tmp_bytes(&module, &glwe_out_layout, &glwe_in_layout, &ggsw_layout), @@ -79,7 +79,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) { let mut sk: GLWESecret> = GLWESecret::alloc_from_infos(&glwe_in_layout); sk.fill_ternary_prob(0.5, &mut source_xs); - let mut sk_dft: GLWESecretPrepared, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank); + let mut sk_dft: GLWESecretPrepared, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank); sk_dft.prepare(&module, &sk); ct_ggsw.encrypt_sk( @@ -99,7 +99,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) { scratch.borrow(), ); - let mut ggsw_prepared: GGSWPrepared, FFT64Spqlios> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw); + let mut ggsw_prepared: GGSWPrepared, FFT64Ref> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw); ggsw_prepared.prepare(&module, &ct_ggsw, scratch.borrow()); move || { @@ -138,7 +138,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) { } fn runner(p: Params) -> impl FnMut() { - let module: Module = Module::::new(1 << p.log_n); + let module: Module = Module::::new(1 << p.log_n); let n: Degree = Degree(module.n() as u32); let base2k: Base2K = p.base2k; @@ -169,7 +169,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) { let mut ct_glwe: GLWE> = GLWE::alloc_from_infos(&glwe_layout); let pt_rgsw: ScalarZnx> = ScalarZnx::alloc(n.into(), 1); - let mut scratch: ScratchOwned = ScratchOwned::alloc( + let mut scratch: ScratchOwned = ScratchOwned::alloc( GGSW::encrypt_sk_tmp_bytes(&module, &ggsw_layout) | GLWE::encrypt_sk_tmp_bytes(&module, &glwe_layout) | GLWE::external_product_tmp_bytes(&module, &glwe_layout, &glwe_layout, &ggsw_layout), @@ -182,7 +182,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) { let mut sk: GLWESecret> = GLWESecret::alloc_from_infos(&glwe_layout); sk.fill_ternary_prob(0.5, &mut source_xs); - let mut sk_dft: GLWESecretPrepared, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank); + let mut sk_dft: GLWESecretPrepared, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank); sk_dft.prepare(&module, &sk); ct_ggsw.encrypt_sk( @@ -202,7 +202,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) { scratch.borrow(), ); - let mut ggsw_prepared: GGSWPrepared, FFT64Spqlios> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw); + let mut ggsw_prepared: GGSWPrepared, FFT64Ref> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw); ggsw_prepared.prepare(&module, &ct_ggsw, scratch.borrow()); move || { let scratch_borrow = scratch.borrow(); diff --git a/poulpy-core/benches/keyswitch_glwe_fft64.rs b/poulpy-core/benches/keyswitch_glwe_fft64.rs index e0ca001..61399c0 100644 --- a/poulpy-core/benches/keyswitch_glwe_fft64.rs +++ b/poulpy-core/benches/keyswitch_glwe_fft64.rs @@ -6,7 +6,7 @@ use poulpy_core::layouts::{ use std::{hint::black_box, time::Duration}; use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main}; -use poulpy_backend::cpu_spqlios::FFT64Spqlios; +use poulpy_cpu_ref::FFT64Ref; use poulpy_hal::{ api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow}, layouts::{Module, ScratchOwned}, @@ -27,7 +27,7 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) { } fn runner(p: Params) -> impl FnMut() { - let module: Module = Module::::new(1 << p.log_n); + let module: Module = Module::::new(1 << p.log_n); let n: Degree = Degree(module.n() as u32); let base2k: Base2K = p.base2k; @@ -66,7 +66,7 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) { let mut ct_in: GLWE> = GLWE::alloc_from_infos(&glwe_in_layout); let mut ct_out: GLWE> = GLWE::alloc_from_infos(&glwe_out_layout); - let mut scratch: ScratchOwned = ScratchOwned::alloc( + let mut scratch: ScratchOwned = ScratchOwned::alloc( GLWESwitchingKey::encrypt_sk_tmp_bytes(&module, &gglwe_atk_layout) | GLWE::encrypt_sk_tmp_bytes(&module, &glwe_in_layout) | GLWE::keyswitch_tmp_bytes( @@ -84,7 +84,7 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) { let mut sk_in: GLWESecret> = GLWESecret::alloc_from_infos(&glwe_in_layout); sk_in.fill_ternary_prob(0.5, &mut source_xs); - let mut sk_in_dft: GLWESecretPrepared, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank); + let mut sk_in_dft: GLWESecretPrepared, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank); sk_in_dft.prepare(&module, &sk_in); ksk.encrypt_sk( @@ -150,7 +150,7 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) { } fn runner(p: Params) -> impl FnMut() { - let module: Module = Module::::new(1 << p.log_n); + let module: Module = Module::::new(1 << p.log_n); let n: Degree = Degree(module.n() as u32); let base2k: Base2K = p.base2k; @@ -181,7 +181,7 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) { let mut ksk: GLWESwitchingKey> = GLWESwitchingKey::alloc_from_infos(&gglwe_layout); let mut ct: GLWE> = GLWE::alloc_from_infos(&glwe_layout); - let mut scratch: ScratchOwned = ScratchOwned::alloc( + let mut scratch: ScratchOwned = ScratchOwned::alloc( GLWESwitchingKey::encrypt_sk_tmp_bytes(&module, &gglwe_layout) | GLWE::encrypt_sk_tmp_bytes(&module, &glwe_layout) | GLWE::keyswitch_tmp_bytes(&module, &glwe_layout, &glwe_layout, &gglwe_layout), @@ -194,7 +194,7 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) { let mut sk_in: GLWESecret> = GLWESecret::alloc_from_infos(&glwe_layout); sk_in.fill_ternary_prob(0.5, &mut source_xs); - let mut sk_in_dft: GLWESecretPrepared, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank); + let mut sk_in_dft: GLWESecretPrepared, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank); sk_in_dft.prepare(&module, &sk_in); let mut sk_out: GLWESecret> = GLWESecret::alloc_from_infos(&glwe_layout); diff --git a/poulpy-core/examples/encryption.rs b/poulpy-core/examples/encryption.rs index e933fde..0aa3c67 100644 --- a/poulpy-core/examples/encryption.rs +++ b/poulpy-core/examples/encryption.rs @@ -1,4 +1,3 @@ -use poulpy_backend::cpu_spqlios::FFT64Spqlios; use poulpy_core::{ GLWESub, SIGMA, layouts::{ @@ -6,6 +5,7 @@ use poulpy_core::{ prepared::GLWESecretPrepared, }, }; +use poulpy_cpu_ref::FFT64Ref; use poulpy_hal::{ api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxFillUniform}, layouts::{Module, ScratchOwned}, @@ -31,7 +31,7 @@ fn main() { let rank: Rank = Rank(1); // Instantiate Module (DFT Tables) - let module: Module = Module::::new(n.0 as u64); + let module: Module = Module::::new(n.0 as u64); let glwe_ct_infos: GLWELayout = GLWELayout { n, @@ -53,7 +53,7 @@ fn main() { let mut source_xa: Source = Source::new([2u8; 32]); // Scratch space - let mut scratch: ScratchOwned = ScratchOwned::alloc( + let mut scratch: ScratchOwned = ScratchOwned::alloc( GLWE::encrypt_sk_tmp_bytes(&module, &glwe_ct_infos) | GLWE::decrypt_tmp_bytes(&module, &glwe_ct_infos), ); @@ -62,7 +62,7 @@ fn main() { sk.fill_ternary_prob(0.5, &mut source_xs); // Backend-prepared secret - let mut sk_prepared: GLWESecretPrepared, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank); + let mut sk_prepared: GLWESecretPrepared, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank); sk_prepared.prepare(&module, &sk); // Uniform plaintext diff --git a/poulpy-core/src/tests/mod.rs b/poulpy-core/src/tests/mod.rs index 7708c2a..3881fa4 100644 --- a/poulpy-core/src/tests/mod.rs +++ b/poulpy-core/src/tests/mod.rs @@ -3,131 +3,133 @@ pub mod test_suite; #[cfg(test)] mod serialization; -#[allow(unused_imports)] -use poulpy_hal::backend_test_suite; - #[cfg(test)] -backend_test_suite!( - mod cpu_ref, - backend = poulpy_backend::cpu_fft64_ref::FFT64Ref, - size = 1<<8, - tests = { - //GLWE Encryption - glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk, - glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk, - glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk, - glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk, -// GLWE Base2k Conversion -glwe_base2k_conv => crate::tests::test_suite::test_glwe_base2k_conversion, -// GLWE Keyswitch -glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, -glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, -// GLWE Automorphism -glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism, -glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace, -// GLWE External Product -glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product, -glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace, -// GLWE Trace -glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace, -glwe_packing => crate::tests::test_suite::test_glwe_packing, -glwe_packer => crate::tests::test_suite::test_glwe_packer, -// GGLWE Encryption -gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, -gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, -gglwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_compressed_encrypt_sk, -gglwe_automorphism_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphism_key_encrypt_sk, -gglwe_automorphism_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphism_key_compressed_encrypt_sk, -gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, -gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, -gglwe_to_ggsw_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_to_ggsw_key_encrypt_sk, -// GGLWE Keyswitching -gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch, -gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace, -// GGLWE External Product -gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product, -gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace, -// GGLWE Automorphism -gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism, -gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace, -// GGSW Encryption -ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, -ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, -// GGSW Keyswitching -ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch, -ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace, -// GGSW External Product -ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product, -ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace, -// GGSW Automorphism -ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism, -ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace, -// LWE -lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, -glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, -lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe, -} - ); +mod poulpy_core { + use poulpy_hal::backend_test_suite; -#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] -#[cfg(test)] -backend_test_suite!( - mod cpu_avx, - backend = poulpy_backend::cpu_fft64_avx::FFT64Avx, - size = 1<<8, - tests = { - //GLWE Encryption - glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk, - glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk, - glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk, - glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk, - // GLWE Base2k Conversion -glwe_base2k_conv => crate::tests::test_suite::test_glwe_base2k_conversion, -// GLWE Keyswitch -glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, -glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, -// GLWE Automorphism -glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism, -glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace, -// GLWE External Product -glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product, -glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace, -// GLWE Trace -glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace, -glwe_packing => crate::tests::test_suite::test_glwe_packing, -glwe_packer => crate::tests::test_suite::test_glwe_packer, -// GGLWE Encryption -gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, -gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, -gglwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_compressed_encrypt_sk, -gglwe_automorphism_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphism_key_encrypt_sk, -gglwe_automorphism_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphism_key_compressed_encrypt_sk, -gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, -gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, -// GGLWE Keyswitching -gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch, -gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace, -// GGLWE External Product -gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product, -gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace, -// GGLWE Automorphism -gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism, -gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace, -// GGSW Encryption -ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, -ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, -// GGSW Keyswitching -ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch, -ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace, -// GGSW External Product -ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product, -ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace, -// GGSW Automorphism -ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism, -ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace, -// LWE -lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, -glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, -lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe, + #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] + backend_test_suite!( + mod cpu_avx, + backend = poulpy_cpu_avx::FFT64Avx, + size = 1<<8, + tests = { + //GLWE Encryption + glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk, + glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk, + glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk, + glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk, + // GLWE Base2k Conversion + glwe_base2k_conv => crate::tests::test_suite::test_glwe_base2k_conversion, + // GLWE Keyswitch + glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, + glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, + // GLWE Automorphism + glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism, + glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace, + // GLWE External Product + glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product, + glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace, + // GLWE Trace + glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace, + glwe_packing => crate::tests::test_suite::test_glwe_packing, + glwe_packer => crate::tests::test_suite::test_glwe_packer, + // GGLWE Encryption + gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, + gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, + gglwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_compressed_encrypt_sk, + gglwe_automorphism_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphism_key_encrypt_sk, + gglwe_automorphism_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphism_key_compressed_encrypt_sk, + gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, + gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, + gglwe_to_ggsw_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_to_ggsw_key_encrypt_sk, + // GGLWE Keyswitching + gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch, + gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace, + // GGLWE External Product + gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product, + gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace, + // GGLWE Automorphism + gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism, + gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace, + // GGSW Encryption + ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, + ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, + // GGSW Keyswitching + ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch, + ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace, + // GGSW External Product + ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product, + ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace, + // GGSW Automorphism + ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism, + ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace, + // LWE + lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, + glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, + lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe, + } + ); + + #[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))] + backend_test_suite!( + mod cpu_ref, + backend = poulpy_cpu_ref::FFT64Ref, + size = 1<<8, + tests = { + //GLWE Encryption + glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk, + glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk, + glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk, + glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk, + // GLWE Base2k Conversion + glwe_base2k_conv => crate::tests::test_suite::test_glwe_base2k_conversion, + // GLWE Keyswitch + glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, + glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, + // GLWE Automorphism + glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism, + glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace, + // GLWE External Product + glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product, + glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace, + // GLWE Trace + glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace, + glwe_packing => crate::tests::test_suite::test_glwe_packing, + glwe_packer => crate::tests::test_suite::test_glwe_packer, + // GGLWE Encryption + gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, + gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, + gglwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_compressed_encrypt_sk, + gglwe_automorphism_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphism_key_encrypt_sk, + gglwe_automorphism_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphism_key_compressed_encrypt_sk, + gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, + gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, + gglwe_to_ggsw_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_to_ggsw_key_encrypt_sk, + // GGLWE Keyswitching + gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch, + gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace, + // GGLWE External Product + gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product, + gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace, + // GGLWE Automorphism + gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism, + gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace, + // GGSW Encryption + ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, + ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, + // GGSW Keyswitching + ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch, + ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace, + // GGSW External Product + ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product, + ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace, + // GGSW Automorphism + ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism, + ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace, + // LWE + lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, + glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, + lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe, + } + ); } - ); diff --git a/poulpy-cpu-avx/Cargo.toml b/poulpy-cpu-avx/Cargo.toml new file mode 100644 index 0000000..8becb6a --- /dev/null +++ b/poulpy-cpu-avx/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "poulpy-cpu-avx" +version = "0.3.2" +edition = "2024" +license = "Apache-2.0" +readme = "README.md" +description = "A crate providing concrete AVX accelerated CPU implementations of poulpy-hal through its open extension points" +repository = "https://github.com/phantomzone-org/poulpy" +homepage = "https://github.com/phantomzone-org/poulpy" +documentation = "https://docs.rs/poulpy" + +[dependencies] +poulpy-hal = {workspace = true} +poulpy-cpu-ref = {workspace = true} +rug = {workspace = true} +criterion = {workspace = true} +itertools = {workspace = true} +rand = {workspace = true} +rand_distr = {workspace = true} +rand_core = {workspace = true} +byteorder = {workspace = true} +once_cell = {workspace = true} +rand_chacha = {workspace = true} +paste = {workspace = true} + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] + + +[[bench]] +name = "vmp" +harness = false \ No newline at end of file diff --git a/poulpy-cpu-avx/README.md b/poulpy-cpu-avx/README.md new file mode 100644 index 0000000..2cb4d6a --- /dev/null +++ b/poulpy-cpu-avx/README.md @@ -0,0 +1,18 @@ +# 🐙 Poulpy-Backend + +**Poulpy-Backend-CPU-AVX** is a Rust crate that provides concrete implementations of **`poulpy-hal`**. This crate is used to instantiate projects implemented with **`poulpy-hal`**, **`poulpy-core`** and/or **`poulpy-schemes`**. + +## Example + +```rust +use poulpy_backend_cpu_avx::FFT64Avx; +use poulpy_hal::{api::ModuleNew, layouts::Module}; + +let log_n: usize = 10; +let module = Module = Module::new(1< impl FnMut() { + let mut values: Vec = vec![0f64; m << 1]; + + let scale = 1.0f64 / (2 * m) as f64; + values + .iter_mut() + .enumerate() + .for_each(|(i, x)| *x = (i + 1) as f64 * scale); + + let table: ReimIFFTTable = ReimIFFTTable::::new(m); + move || { + ReimIFFTAvx::reim_dft_execute(&table, &mut values); + black_box(()); + } + } + + for log_m in [9, 10, 11, 12, 13, 14, 15] { + let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m)); + + let mut runner = runner(1 << log_m); + group.bench_with_input(id, &(), |b, _| b.iter(&mut runner)); + } + } else { + eprintln!("skipping: CPU lacks avx2"); + return; + } + + group.finish(); +} + +pub fn bench_fft_avx2_fma(c: &mut Criterion) { + let group_name: String = "fft_avx2_fma".to_string(); + + let mut group = c.benchmark_group(group_name); + + if std::is_x86_feature_detected!("avx2") { + fn runner(m: usize) -> impl FnMut() { + let mut values: Vec = vec![0f64; m << 1]; + + let scale = 1.0f64 / (2 * m) as f64; + values + .iter_mut() + .enumerate() + .for_each(|(i, x)| *x = (i + 1) as f64 * scale); + + let table: ReimFFTTable = ReimFFTTable::::new(m); + move || { + ReimFFTAvx::reim_dft_execute(&table, &mut values); + black_box(()); + } + } + + for log_m in [9, 10, 11, 12, 13, 14, 15] { + let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m)); + + let mut runner = runner(1 << log_m); + group.bench_with_input(id, &(), |b, _| b.iter(&mut runner)); + } + } else { + eprintln!("skipping: CPU lacks avx2"); + return; + } + + group.finish(); +} + +criterion_group!(benches_x86, bench_fft_avx2_fma, bench_ifft_avx2_fma,); +criterion_main!(benches_x86); diff --git a/poulpy-cpu-avx/benches/vec_znx.rs b/poulpy-cpu-avx/benches/vec_znx.rs new file mode 100644 index 0000000..fde4ac5 --- /dev/null +++ b/poulpy-cpu-avx/benches/vec_znx.rs @@ -0,0 +1,26 @@ +// poulpy-backend/benches/vec_znx_add.rs +use criterion::{Criterion, criterion_group, criterion_main}; +use poulpy_cpu_avx::FFT64Avx; +use poulpy_hal::reference::vec_znx::{bench_vec_znx_add, bench_vec_znx_automorphism, bench_vec_znx_normalize_inplace}; + +#[allow(dead_code)] +fn bench_vec_znx_add_cpu_avx_fft64(c: &mut Criterion) { + bench_vec_znx_add::(c, "FFT64Avx"); +} + +#[allow(dead_code)] +fn bench_vec_znx_normalize_inplace_cpu_avx_fft64(c: &mut Criterion) { + bench_vec_znx_normalize_inplace::(c, "FFT64Avx"); +} + +fn bench_vec_znx_automorphism_cpu_avx_fft64(c: &mut Criterion) { + bench_vec_znx_automorphism::(c, "FFT64Avx"); +} + +criterion_group!( + benches, + bench_vec_znx_add_cpu_avx_fft64, + bench_vec_znx_normalize_inplace_cpu_avx_fft64, + bench_vec_znx_automorphism_cpu_avx_fft64, +); +criterion_main!(benches); diff --git a/poulpy-cpu-avx/benches/vmp.rs b/poulpy-cpu-avx/benches/vmp.rs new file mode 100644 index 0000000..195fa36 --- /dev/null +++ b/poulpy-cpu-avx/benches/vmp.rs @@ -0,0 +1,11 @@ +// poulpy-backend/benches/vec_znx_add.rs +use criterion::{Criterion, criterion_group, criterion_main}; +use poulpy_cpu_avx::FFT64Avx; +use poulpy_hal::bench_suite::vmp::bench_vmp_apply_dft_to_dft; + +fn bench_vmp_apply_dft_to_dft_cpu_avx_fft64(c: &mut Criterion) { + bench_vmp_apply_dft_to_dft::(c, "FFT64Avx"); +} + +criterion_group!(benches_x86, bench_vmp_apply_dft_to_dft_cpu_avx_fft64,); +criterion_main!(benches_x86); diff --git a/poulpy-backend/examples/rlwe_encrypt.rs b/poulpy-cpu-avx/examples/rlwe_encrypt.rs similarity index 91% rename from poulpy-backend/examples/rlwe_encrypt.rs rename to poulpy-cpu-avx/examples/rlwe_encrypt.rs index 64061e2..b312757 100644 --- a/poulpy-backend/examples/rlwe_encrypt.rs +++ b/poulpy-cpu-avx/examples/rlwe_encrypt.rs @@ -1,5 +1,5 @@ use itertools::izip; -use poulpy_backend::cpu_fft64_ref::FFT64Ref; +use poulpy_cpu_avx::FFT64Avx; use poulpy_hal::{ api::{ ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPrepare, VecZnxAddNormal, @@ -16,9 +16,9 @@ fn main() { let ct_size: usize = 3; let msg_size: usize = 2; let log_scale: usize = msg_size * base2k - 5; - let module: Module = Module::::new(n as u64); + let module: Module = Module::::new(n as u64); - let mut scratch: ScratchOwned = ScratchOwned::::alloc(module.vec_znx_big_normalize_tmp_bytes()); + let mut scratch: ScratchOwned = ScratchOwned::::alloc(module.vec_znx_big_normalize_tmp_bytes()); let seed: [u8; 32] = [0; 32]; let mut source: Source = Source::new(seed); @@ -28,7 +28,7 @@ fn main() { s.fill_ternary_prob(0, 0.5, &mut source); // Buffer to store s in the DFT domain - let mut s_dft: SvpPPol, FFT64Ref> = module.svp_ppol_alloc(s.cols()); + let mut s_dft: SvpPPol, FFT64Avx> = module.svp_ppol_alloc(s.cols()); // s_dft <- DFT(s) module.svp_prepare(&mut s_dft, 0, &s, 0); @@ -43,7 +43,7 @@ fn main() { // Fill the second column with random values: ct = (0, a) module.vec_znx_fill_uniform(base2k, &mut ct, 1, &mut source); - let mut buf_dft: VecZnxDft, FFT64Ref> = module.vec_znx_dft_alloc(1, ct_size); + let mut buf_dft: VecZnxDft, FFT64Avx> = module.vec_znx_dft_alloc(1, ct_size); module.vec_znx_dft_apply(1, 0, &mut buf_dft, 0, &ct, 1); @@ -58,7 +58,7 @@ fn main() { // Alias scratch space (VecZnxDft is always at least as big as VecZnxBig) // BIG(ct[1] * s) <- IDFT(DFT(ct[1] * s)) (not normalized) - let mut buf_big: VecZnxBig, FFT64Ref> = module.vec_znx_big_alloc(1, ct_size); + let mut buf_big: VecZnxBig, FFT64Avx> = module.vec_znx_big_alloc(1, ct_size); module.vec_znx_idft_apply_tmpa(&mut buf_big, 0, &mut buf_dft, 0); // Creates a plaintext: VecZnx with 1 column diff --git a/poulpy-backend/src/cpu_fft64_avx/mod.rs b/poulpy-cpu-avx/src/lib.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/mod.rs rename to poulpy-cpu-avx/src/lib.rs diff --git a/poulpy-backend/src/cpu_fft64_avx/module.rs b/poulpy-cpu-avx/src/module.rs similarity index 99% rename from poulpy-backend/src/cpu_fft64_avx/module.rs rename to poulpy-cpu-avx/src/module.rs index 750bab1..9495257 100644 --- a/poulpy-backend/src/cpu_fft64_avx/module.rs +++ b/poulpy-cpu-avx/src/module.rs @@ -24,7 +24,7 @@ use poulpy_hal::{ }, }; -use crate::cpu_fft64_avx::{ +use crate::{ FFT64Avx, reim::{ ReimFFTAvx, ReimIFFTAvx, reim_add_avx2_fma, reim_add_inplace_avx2_fma, reim_addmul_avx2_fma, reim_from_znx_i64_bnd50_fma, diff --git a/poulpy-backend/src/cpu_fft64_avx/reim/conversion.rs b/poulpy-cpu-avx/src/reim/conversion.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/reim/conversion.rs rename to poulpy-cpu-avx/src/reim/conversion.rs diff --git a/poulpy-backend/src/cpu_fft64_avx/reim/fft16_avx2_fma.s b/poulpy-cpu-avx/src/reim/fft16_avx2_fma.s similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/reim/fft16_avx2_fma.s rename to poulpy-cpu-avx/src/reim/fft16_avx2_fma.s diff --git a/poulpy-backend/src/cpu_fft64_avx/reim/fft_avx2_fma.rs b/poulpy-cpu-avx/src/reim/fft_avx2_fma.rs similarity index 99% rename from poulpy-backend/src/cpu_fft64_avx/reim/fft_avx2_fma.rs rename to poulpy-cpu-avx/src/reim/fft_avx2_fma.rs index de5d991..ce2446f 100644 --- a/poulpy-backend/src/cpu_fft64_avx/reim/fft_avx2_fma.rs +++ b/poulpy-cpu-avx/src/reim/fft_avx2_fma.rs @@ -3,7 +3,7 @@ use std::arch::x86_64::{ _mm256_permute2f128_pd, _mm256_set_m128d, _mm256_storeu_pd, _mm256_sub_pd, _mm256_unpackhi_pd, _mm256_unpacklo_pd, }; -use crate::cpu_fft64_avx::reim::{as_arr, as_arr_mut}; +use crate::reim::{as_arr, as_arr_mut}; #[target_feature(enable = "avx2,fma")] pub(crate) fn fft_avx2_fma(m: usize, omg: &[f64], data: &mut [f64]) { diff --git a/poulpy-backend/src/cpu_fft64_avx/reim/fft_vec_avx2_fma.rs b/poulpy-cpu-avx/src/reim/fft_vec_avx2_fma.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/reim/fft_vec_avx2_fma.rs rename to poulpy-cpu-avx/src/reim/fft_vec_avx2_fma.rs diff --git a/poulpy-backend/src/cpu_fft64_avx/reim/ifft16_avx2_fma.s b/poulpy-cpu-avx/src/reim/ifft16_avx2_fma.s similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/reim/ifft16_avx2_fma.s rename to poulpy-cpu-avx/src/reim/ifft16_avx2_fma.s diff --git a/poulpy-backend/src/cpu_fft64_avx/reim/ifft_avx2_fma.rs b/poulpy-cpu-avx/src/reim/ifft_avx2_fma.rs similarity index 99% rename from poulpy-backend/src/cpu_fft64_avx/reim/ifft_avx2_fma.rs rename to poulpy-cpu-avx/src/reim/ifft_avx2_fma.rs index 953d439..776396c 100644 --- a/poulpy-backend/src/cpu_fft64_avx/reim/ifft_avx2_fma.rs +++ b/poulpy-cpu-avx/src/reim/ifft_avx2_fma.rs @@ -3,7 +3,7 @@ use std::arch::x86_64::{ _mm256_permute2f128_pd, _mm256_set_m128d, _mm256_storeu_pd, _mm256_sub_pd, _mm256_unpackhi_pd, _mm256_unpacklo_pd, }; -use crate::cpu_fft64_avx::reim::{as_arr, as_arr_mut}; +use crate::reim::{as_arr, as_arr_mut}; #[target_feature(enable = "avx2,fma")] pub(crate) fn ifft_avx2_fma(m: usize, omg: &[f64], data: &mut [f64]) { diff --git a/poulpy-backend/src/cpu_fft64_avx/reim/mod.rs b/poulpy-cpu-avx/src/reim/mod.rs similarity index 95% rename from poulpy-backend/src/cpu_fft64_avx/reim/mod.rs rename to poulpy-cpu-avx/src/reim/mod.rs index cb57bd3..ae2d67a 100644 --- a/poulpy-backend/src/cpu_fft64_avx/reim/mod.rs +++ b/poulpy-cpu-avx/src/reim/mod.rs @@ -30,7 +30,7 @@ pub(crate) use fft_vec_avx2_fma::*; use poulpy_hal::reference::fft64::reim::{ReimDFTExecute, ReimFFTTable, ReimIFFTTable}; use rand_distr::num_traits::{Float, FloatConst}; -use crate::cpu_fft64_avx::reim::{fft_avx2_fma::fft_avx2_fma, ifft_avx2_fma::ifft_avx2_fma}; +use crate::reim::{fft_avx2_fma::fft_avx2_fma, ifft_avx2_fma::ifft_avx2_fma}; global_asm!( include_str!("fft16_avx2_fma.s"), diff --git a/poulpy-backend/src/cpu_fft64_avx/reim4/arithmetic_avx.rs b/poulpy-cpu-avx/src/reim4/arithmetic_avx.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/reim4/arithmetic_avx.rs rename to poulpy-cpu-avx/src/reim4/arithmetic_avx.rs diff --git a/poulpy-backend/src/cpu_fft64_avx/reim4/mod.rs b/poulpy-cpu-avx/src/reim4/mod.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/reim4/mod.rs rename to poulpy-cpu-avx/src/reim4/mod.rs diff --git a/poulpy-backend/src/cpu_fft64_avx/scratch.rs b/poulpy-cpu-avx/src/scratch.rs similarity index 98% rename from poulpy-backend/src/cpu_fft64_avx/scratch.rs rename to poulpy-cpu-avx/src/scratch.rs index f6595f9..95a8f31 100644 --- a/poulpy-backend/src/cpu_fft64_avx/scratch.rs +++ b/poulpy-cpu-avx/src/scratch.rs @@ -7,7 +7,7 @@ use poulpy_hal::{ oep::{ScratchAvailableImpl, ScratchFromBytesImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeSliceImpl}, }; -use crate::cpu_fft64_avx::FFT64Avx; +use crate::FFT64Avx; unsafe impl ScratchOwnedAllocImpl for FFT64Avx { fn scratch_owned_alloc_impl(size: usize) -> ScratchOwned { diff --git a/poulpy-backend/src/cpu_fft64_avx/svp.rs b/poulpy-cpu-avx/src/svp.rs similarity index 96% rename from poulpy-backend/src/cpu_fft64_avx/svp.rs rename to poulpy-cpu-avx/src/svp.rs index 1c2c999..4571e51 100644 --- a/poulpy-backend/src/cpu_fft64_avx/svp.rs +++ b/poulpy-cpu-avx/src/svp.rs @@ -7,7 +7,7 @@ use poulpy_hal::{ reference::fft64::svp::{svp_apply_dft_to_dft, svp_apply_dft_to_dft_inplace, svp_prepare}, }; -use crate::cpu_fft64_avx::{FFT64Avx, module::FFT64ModuleHandle}; +use crate::{FFT64Avx, module::FFT64ModuleHandle}; unsafe impl SvpPPolFromBytesImpl for FFT64Avx { fn svp_ppol_from_bytes_impl(n: usize, cols: usize, bytes: Vec) -> SvpPPolOwned { diff --git a/poulpy-cpu-avx/src/tests.rs b/poulpy-cpu-avx/src/tests.rs new file mode 100644 index 0000000..99cefa6 --- /dev/null +++ b/poulpy-cpu-avx/src/tests.rs @@ -0,0 +1,125 @@ +use poulpy_hal::{api::ModuleNew, layouts::Module, test_suite::convolution::test_bivariate_tensoring}; + +use crate::FFT64Avx; + +#[cfg(test)] +mod poulpy_cpu_avx { + use poulpy_hal::{backend_test_suite, cross_backend_test_suite}; + + cross_backend_test_suite! { + mod vec_znx, + backend_ref = poulpy_cpu_ref::FFT64Ref, + backend_test = crate::FFT64Avx, + size = 1<<8, + base2k = 12, + tests = { + test_vec_znx_add => poulpy_hal::test_suite::vec_znx::test_vec_znx_add, + test_vec_znx_add_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_inplace, + test_vec_znx_add_scalar => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_scalar, + test_vec_znx_add_scalar_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_scalar_inplace, + test_vec_znx_sub => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub, + test_vec_znx_sub_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_inplace, + test_vec_znx_sub_negate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_negate_inplace, + test_vec_znx_sub_scalar => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_scalar, + test_vec_znx_sub_scalar_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_scalar_inplace, + test_vec_znx_rsh => poulpy_hal::test_suite::vec_znx::test_vec_znx_rsh, + test_vec_znx_rsh_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_rsh_inplace, + test_vec_znx_lsh => poulpy_hal::test_suite::vec_znx::test_vec_znx_lsh, + test_vec_znx_lsh_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_lsh_inplace, + test_vec_znx_negate => poulpy_hal::test_suite::vec_znx::test_vec_znx_negate, + test_vec_znx_negate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_negate_inplace, + test_vec_znx_rotate => poulpy_hal::test_suite::vec_znx::test_vec_znx_rotate, + test_vec_znx_rotate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_rotate_inplace, + test_vec_znx_automorphism => poulpy_hal::test_suite::vec_znx::test_vec_znx_automorphism, + test_vec_znx_automorphism_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_automorphism_inplace, + test_vec_znx_mul_xp_minus_one => poulpy_hal::test_suite::vec_znx::test_vec_znx_mul_xp_minus_one, + test_vec_znx_mul_xp_minus_one_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_mul_xp_minus_one_inplace, + test_vec_znx_normalize => poulpy_hal::test_suite::vec_znx::test_vec_znx_normalize, + test_vec_znx_normalize_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_normalize_inplace, + test_vec_znx_switch_ring => poulpy_hal::test_suite::vec_znx::test_vec_znx_switch_ring, + test_vec_znx_split_ring => poulpy_hal::test_suite::vec_znx::test_vec_znx_split_ring, + test_vec_znx_copy => poulpy_hal::test_suite::vec_znx::test_vec_znx_copy, + } + } + cross_backend_test_suite! { + mod svp, + backend_ref = poulpy_cpu_ref::FFT64Ref, + backend_test = crate::FFT64Avx, + size = 1<<8, + base2k = 12, + tests = { + test_svp_apply_dft_to_dft => poulpy_hal::test_suite::svp::test_svp_apply_dft_to_dft, + test_svp_apply_dft_to_dft_inplace => poulpy_hal::test_suite::svp::test_svp_apply_dft_to_dft_inplace, + } + } + cross_backend_test_suite! { + mod vec_znx_big, + backend_ref = poulpy_cpu_ref::FFT64Ref, + backend_test = crate::FFT64Avx, + size = 1<<8, + base2k = 12, + tests = { + test_vec_znx_big_add => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add, + test_vec_znx_big_add_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_inplace, + test_vec_znx_big_add_small => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_small, + test_vec_znx_big_add_small_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_small_inplace, + test_vec_znx_big_sub => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub, + test_vec_znx_big_sub_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_inplace, + test_vec_znx_big_automorphism => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_automorphism, + test_vec_znx_big_automorphism_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_automorphism_inplace, + test_vec_znx_big_negate => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_negate, + test_vec_znx_big_negate_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_negate_inplace, + test_vec_znx_big_normalize => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_normalize, + test_vec_znx_big_sub_negate_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_negate_inplace, + test_vec_znx_big_sub_small_a => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_a, + test_vec_znx_big_sub_small_a_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_a_inplace, + test_vec_znx_big_sub_small_b => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_b, + test_vec_znx_big_sub_small_b_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_b_inplace, + } + } + cross_backend_test_suite! { + mod vec_znx_dft, + backend_ref = poulpy_cpu_ref::FFT64Ref, + backend_test = crate::FFT64Avx, + size = 1<<8, + base2k = 12, + tests = { + test_vec_znx_dft_add => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_add, + test_vec_znx_dft_add_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_add_inplace, + test_vec_znx_dft_sub => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub, + test_vec_znx_dft_sub_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub_inplace, + test_vec_znx_dft_sub_negate_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub_negate_inplace, + test_vec_znx_idft_apply => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply, + test_vec_znx_idft_apply_consume => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply_consume, + test_vec_znx_idft_apply_tmpa => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply_tmpa, + } + } + cross_backend_test_suite! { + mod vmp, + backend_ref = poulpy_cpu_ref::FFT64Ref, + backend_test = crate::FFT64Avx, + size = 1<<8, + base2k = 12, + tests = { + test_vmp_apply_dft_to_dft => poulpy_hal::test_suite::vmp::test_vmp_apply_dft_to_dft, + test_vmp_apply_dft_to_dft_add => poulpy_hal::test_suite::vmp::test_vmp_apply_dft_to_dft_add, + } + } + + backend_test_suite! { + mod sampling, + backend = crate::FFT64Avx, + size = 1<<12, + tests = { + test_vec_znx_fill_uniform => poulpy_hal::test_suite::vec_znx::test_vec_znx_fill_uniform, + test_vec_znx_fill_normal => poulpy_hal::test_suite::vec_znx::test_vec_znx_fill_normal, + test_vec_znx_add_normal => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_normal, + } + } +} + +#[test] +fn test_convolution_fft64_avx() { + let module: Module = Module::::new(64); + test_bivariate_tensoring(&module); +} diff --git a/poulpy-backend/src/cpu_fft64_avx/vec_znx.rs b/poulpy-cpu-avx/src/vec_znx.rs similarity index 99% rename from poulpy-backend/src/cpu_fft64_avx/vec_znx.rs rename to poulpy-cpu-avx/src/vec_znx.rs index 941ce19..e42b595 100644 --- a/poulpy-backend/src/cpu_fft64_avx/vec_znx.rs +++ b/poulpy-cpu-avx/src/vec_znx.rs @@ -30,7 +30,7 @@ use poulpy_hal::{ source::Source, }; -use crate::cpu_fft64_avx::FFT64Avx; +use crate::FFT64Avx; unsafe impl VecZnxZeroImpl for FFT64Avx { fn vec_znx_zero_impl(_module: &Module, res: &mut R, res_col: usize) diff --git a/poulpy-backend/src/cpu_fft64_avx/vec_znx_big.rs b/poulpy-cpu-avx/src/vec_znx_big.rs similarity index 99% rename from poulpy-backend/src/cpu_fft64_avx/vec_znx_big.rs rename to poulpy-cpu-avx/src/vec_znx_big.rs index 08ec98a..e1e4580 100644 --- a/poulpy-backend/src/cpu_fft64_avx/vec_znx_big.rs +++ b/poulpy-cpu-avx/src/vec_znx_big.rs @@ -1,4 +1,4 @@ -use crate::cpu_fft64_avx::FFT64Avx; +use crate::FFT64Avx; use poulpy_hal::{ api::{TakeSlice, VecZnxBigAutomorphismInplaceTmpBytes, VecZnxBigNormalizeTmpBytes}, layouts::{ diff --git a/poulpy-backend/src/cpu_fft64_avx/vec_znx_dft.rs b/poulpy-cpu-avx/src/vec_znx_dft.rs similarity index 98% rename from poulpy-backend/src/cpu_fft64_avx/vec_znx_dft.rs rename to poulpy-cpu-avx/src/vec_znx_dft.rs index 1e1954e..3fcbed6 100644 --- a/poulpy-backend/src/cpu_fft64_avx/vec_znx_dft.rs +++ b/poulpy-cpu-avx/src/vec_znx_dft.rs @@ -16,7 +16,7 @@ use poulpy_hal::{ }, }; -use crate::cpu_fft64_avx::{FFT64Avx, module::FFT64ModuleHandle}; +use crate::{FFT64Avx, module::FFT64ModuleHandle}; unsafe impl VecZnxDftFromBytesImpl for FFT64Avx { fn vec_znx_dft_from_bytes_impl(n: usize, cols: usize, size: usize, bytes: Vec) -> VecZnxDftOwned { diff --git a/poulpy-backend/src/cpu_fft64_avx/vmp.rs b/poulpy-cpu-avx/src/vmp.rs similarity index 98% rename from poulpy-backend/src/cpu_fft64_avx/vmp.rs rename to poulpy-cpu-avx/src/vmp.rs index b98ef1d..78b52ae 100644 --- a/poulpy-backend/src/cpu_fft64_avx/vmp.rs +++ b/poulpy-cpu-avx/src/vmp.rs @@ -14,7 +14,7 @@ use poulpy_hal::{ }, }; -use crate::cpu_fft64_avx::{FFT64Avx, module::FFT64ModuleHandle}; +use crate::{FFT64Avx, module::FFT64ModuleHandle}; unsafe impl VmpPMatAllocBytesImpl for FFT64Avx { fn vmp_pmat_bytes_of_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize { diff --git a/poulpy-backend/src/cpu_fft64_avx/znx_avx/add.rs b/poulpy-cpu-avx/src/znx_avx/add.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/znx_avx/add.rs rename to poulpy-cpu-avx/src/znx_avx/add.rs diff --git a/poulpy-backend/src/cpu_fft64_avx/znx_avx/automorphism.rs b/poulpy-cpu-avx/src/znx_avx/automorphism.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/znx_avx/automorphism.rs rename to poulpy-cpu-avx/src/znx_avx/automorphism.rs diff --git a/poulpy-backend/src/cpu_fft64_avx/znx_avx/mod.rs b/poulpy-cpu-avx/src/znx_avx/mod.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/znx_avx/mod.rs rename to poulpy-cpu-avx/src/znx_avx/mod.rs diff --git a/poulpy-backend/src/cpu_fft64_avx/znx_avx/mul.rs b/poulpy-cpu-avx/src/znx_avx/mul.rs similarity index 99% rename from poulpy-backend/src/cpu_fft64_avx/znx_avx/mul.rs rename to poulpy-cpu-avx/src/znx_avx/mul.rs index 44dfdb6..ef8c304 100644 --- a/poulpy-backend/src/cpu_fft64_avx/znx_avx/mul.rs +++ b/poulpy-cpu-avx/src/znx_avx/mul.rs @@ -232,7 +232,7 @@ pub unsafe fn znx_mul_add_power_of_two_avx(k: i64, res: &mut [i64], a: &[i64]) { } if k == 0 { - use crate::cpu_fft64_avx::znx_avx::znx_add_inplace_avx; + use crate::znx_avx::znx_add_inplace_avx; znx_add_inplace_avx(res, a); return; diff --git a/poulpy-backend/src/cpu_fft64_avx/znx_avx/neg.rs b/poulpy-cpu-avx/src/znx_avx/neg.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/znx_avx/neg.rs rename to poulpy-cpu-avx/src/znx_avx/neg.rs diff --git a/poulpy-backend/src/cpu_fft64_avx/znx_avx/normalization.rs b/poulpy-cpu-avx/src/znx_avx/normalization.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/znx_avx/normalization.rs rename to poulpy-cpu-avx/src/znx_avx/normalization.rs diff --git a/poulpy-backend/src/cpu_fft64_avx/znx_avx/sub.rs b/poulpy-cpu-avx/src/znx_avx/sub.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/znx_avx/sub.rs rename to poulpy-cpu-avx/src/znx_avx/sub.rs diff --git a/poulpy-backend/src/cpu_fft64_avx/znx_avx/switch_ring.rs b/poulpy-cpu-avx/src/znx_avx/switch_ring.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_avx/znx_avx/switch_ring.rs rename to poulpy-cpu-avx/src/znx_avx/switch_ring.rs diff --git a/poulpy-backend/Cargo.toml b/poulpy-cpu-ref/Cargo.toml similarity index 77% rename from poulpy-backend/Cargo.toml rename to poulpy-cpu-ref/Cargo.toml index 0acc0b6..39c7284 100644 --- a/poulpy-backend/Cargo.toml +++ b/poulpy-cpu-ref/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "poulpy-backend" +name = "poulpy-cpu-ref" version = "0.3.2" edition = "2024" license = "Apache-2.0" readme = "README.md" -description = "A crate providing concrete implementations of poulpy-hal through its open extension points" +description = "The providing concrete implementations of poulpy-hal through its open extension points and reference cpu code" repository = "https://github.com/phantomzone-org/poulpy" homepage = "https://github.com/phantomzone-org/poulpy" documentation = "https://docs.rs/poulpy" @@ -19,10 +19,7 @@ rand_distr = {workspace = true} rand_core = {workspace = true} byteorder = {workspace = true} once_cell = {workspace = true} -rand_chacha = "0.9.0" - -[build-dependencies] -cmake = "0.1.54" +rand_chacha = {workspace = true} [package.metadata.docs.rs] all-features = true diff --git a/poulpy-backend/README.md b/poulpy-cpu-ref/README.md similarity index 100% rename from poulpy-backend/README.md rename to poulpy-cpu-ref/README.md diff --git a/poulpy-cpu-ref/benches/fft.rs b/poulpy-cpu-ref/benches/fft.rs new file mode 100644 index 0000000..47be0f3 --- /dev/null +++ b/poulpy-cpu-ref/benches/fft.rs @@ -0,0 +1,64 @@ +use std::hint::black_box; + +use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main}; +use poulpy_hal::reference::fft64::reim::{ReimDFTExecute, ReimFFTRef, ReimFFTTable, ReimIFFTRef, ReimIFFTTable}; + +pub fn bench_fft_ref(c: &mut Criterion) { + let group_name: String = "fft_ref".to_string(); + + let mut group = c.benchmark_group(group_name); + + fn runner(m: usize) -> impl FnMut() { + let mut values: Vec = vec![0f64; m << 1]; + let scale: f64 = 1.0f64 / (2 * m) as f64; + values + .iter_mut() + .enumerate() + .for_each(|(i, x)| *x = (i + 1) as f64 * scale); + let table: ReimFFTTable = ReimFFTTable::::new(m); + move || { + ReimFFTRef::reim_dft_execute(&table, &mut values); + black_box(()); + } + } + + for log_m in [9, 10, 11, 12, 13, 14, 15] { + let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m)); + let mut runner = runner(1 << log_m); + group.bench_with_input(id, &(), |b, _| b.iter(&mut runner)); + } + + group.finish(); +} + +pub fn bench_ifft_ref(c: &mut Criterion) { + let group_name: String = "ifft_ref".to_string(); + + let mut group = c.benchmark_group(group_name); + + fn runner(m: usize) -> impl FnMut() { + let mut values: Vec = vec![0f64; m << 1]; + let scale: f64 = 1.0f64 / (2 * m) as f64; + values + .iter_mut() + .enumerate() + .for_each(|(i, x)| *x = (i + 1) as f64 * scale); + let table: ReimIFFTTable = ReimIFFTTable::::new(m); + move || { + ReimIFFTRef::reim_dft_execute(&table, &mut values); + black_box(()); + } + } + + for log_m in [9, 10, 11, 12, 13, 14, 15] { + let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m)); + let mut runner = runner(1 << log_m); + group.bench_with_input(id, &(), |b, _| b.iter(&mut runner)); + } + + group.finish(); +} + +criterion_group!(benches, bench_fft_ref, bench_ifft_ref,); + +criterion_main!(benches); diff --git a/poulpy-cpu-ref/benches/vec_znx.rs b/poulpy-cpu-ref/benches/vec_znx.rs new file mode 100644 index 0000000..9c98649 --- /dev/null +++ b/poulpy-cpu-ref/benches/vec_znx.rs @@ -0,0 +1,28 @@ +// poulpy-backend/benches/vec_znx_add.rs +use criterion::{Criterion, criterion_group, criterion_main}; +use poulpy_cpu_ref::FFT64Ref; +use poulpy_hal::reference::vec_znx::{bench_vec_znx_add, bench_vec_znx_automorphism, bench_vec_znx_normalize_inplace}; + +#[allow(dead_code)] +fn bench_vec_znx_add_cpu_ref_fft64(c: &mut Criterion) { + bench_vec_znx_add::(c, "cpu_spqlios::fft64"); +} + +#[allow(dead_code)] +fn bench_vec_znx_normalize_inplace_cpu_ref_fft64(c: &mut Criterion) { + bench_vec_znx_normalize_inplace::(c, "cpu_ref::fft64"); +} + +fn bench_vec_znx_automorphism_cpu_ref_fft64(c: &mut Criterion) { + bench_vec_znx_automorphism::(c, "cpu_ref::fft64"); +} + +criterion_group!( + benches, + // bench_vec_znx_add_cpu_spqlios_fft64, + // bench_vec_znx_add_cpu_ref_fft64, + // bench_vec_znx_normalize_inplace_cpu_ref_fft64, + // bench_vec_znx_normalize_inplace_cpu_spqlios_fft64, + bench_vec_znx_automorphism_cpu_ref_fft64, +); +criterion_main!(benches); diff --git a/poulpy-cpu-ref/benches/vmp.rs b/poulpy-cpu-ref/benches/vmp.rs new file mode 100644 index 0000000..1bf73b0 --- /dev/null +++ b/poulpy-cpu-ref/benches/vmp.rs @@ -0,0 +1,11 @@ +// poulpy-backend/benches/vec_znx_add.rs +use criterion::{Criterion, criterion_group, criterion_main}; +use poulpy_cpu_ref::FFT64Ref; +use poulpy_hal::bench_suite::vmp::bench_vmp_apply_dft_to_dft; + +fn bench_vmp_apply_dft_to_dft_cpu_ref_fft64(c: &mut Criterion) { + bench_vmp_apply_dft_to_dft::(c, "cpu_ref::fft64"); +} + +criterion_group!(benches, bench_vmp_apply_dft_to_dft_cpu_ref_fft64,); +criterion_main!(benches); diff --git a/poulpy-backend/src/cpu_fft64_ref/mod.rs b/poulpy-cpu-ref/src/lib.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_ref/mod.rs rename to poulpy-cpu-ref/src/lib.rs diff --git a/poulpy-cpu-ref/src/main.rs b/poulpy-cpu-ref/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/poulpy-cpu-ref/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/poulpy-backend/src/cpu_fft64_ref/module.rs b/poulpy-cpu-ref/src/module.rs similarity index 97% rename from poulpy-backend/src/cpu_fft64_ref/module.rs rename to poulpy-cpu-ref/src/module.rs index d9815e2..9bdf715 100644 --- a/poulpy-backend/src/cpu_fft64_ref/module.rs +++ b/poulpy-cpu-ref/src/module.rs @@ -6,7 +6,7 @@ use poulpy_hal::{ reference::fft64::reim::{ReimFFTTable, ReimIFFTTable}, }; -use crate::cpu_fft64_ref::FFT64Ref; +use crate::FFT64Ref; #[repr(C)] pub struct FFT64RefHandle { diff --git a/poulpy-backend/src/cpu_fft64_ref/reim.rs b/poulpy-cpu-ref/src/reim.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_ref/reim.rs rename to poulpy-cpu-ref/src/reim.rs diff --git a/poulpy-backend/src/cpu_fft64_ref/scratch.rs b/poulpy-cpu-ref/src/scratch.rs similarity index 98% rename from poulpy-backend/src/cpu_fft64_ref/scratch.rs rename to poulpy-cpu-ref/src/scratch.rs index 1593370..6f5c558 100644 --- a/poulpy-backend/src/cpu_fft64_ref/scratch.rs +++ b/poulpy-cpu-ref/src/scratch.rs @@ -7,7 +7,7 @@ use poulpy_hal::{ oep::{ScratchAvailableImpl, ScratchFromBytesImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeSliceImpl}, }; -use crate::cpu_fft64_ref::FFT64Ref; +use crate::FFT64Ref; unsafe impl ScratchOwnedAllocImpl for FFT64Ref { fn scratch_owned_alloc_impl(size: usize) -> ScratchOwned { diff --git a/poulpy-backend/src/cpu_fft64_ref/svp.rs b/poulpy-cpu-ref/src/svp.rs similarity index 96% rename from poulpy-backend/src/cpu_fft64_ref/svp.rs rename to poulpy-cpu-ref/src/svp.rs index 37ca14a..723cedd 100644 --- a/poulpy-backend/src/cpu_fft64_ref/svp.rs +++ b/poulpy-cpu-ref/src/svp.rs @@ -7,7 +7,7 @@ use poulpy_hal::{ reference::fft64::svp::{svp_apply_dft_to_dft, svp_apply_dft_to_dft_inplace, svp_prepare}, }; -use crate::cpu_fft64_ref::{FFT64Ref, module::FFT64ModuleHandle}; +use crate::{FFT64Ref, module::FFT64ModuleHandle}; unsafe impl SvpPPolFromBytesImpl for FFT64Ref { fn svp_ppol_from_bytes_impl(n: usize, cols: usize, bytes: Vec) -> SvpPPolOwned { diff --git a/poulpy-backend/src/cpu_fft64_ref/tests.rs b/poulpy-cpu-ref/src/tests.rs similarity index 100% rename from poulpy-backend/src/cpu_fft64_ref/tests.rs rename to poulpy-cpu-ref/src/tests.rs diff --git a/poulpy-backend/src/cpu_fft64_ref/vec_znx.rs b/poulpy-cpu-ref/src/vec_znx.rs similarity index 99% rename from poulpy-backend/src/cpu_fft64_ref/vec_znx.rs rename to poulpy-cpu-ref/src/vec_znx.rs index a2a2086..927a85e 100644 --- a/poulpy-backend/src/cpu_fft64_ref/vec_znx.rs +++ b/poulpy-cpu-ref/src/vec_znx.rs @@ -30,7 +30,7 @@ use poulpy_hal::{ source::Source, }; -use crate::cpu_fft64_ref::FFT64Ref; +use crate::FFT64Ref; unsafe impl VecZnxZeroImpl for FFT64Ref { fn vec_znx_zero_impl(_module: &Module, res: &mut R, res_col: usize) diff --git a/poulpy-backend/src/cpu_fft64_ref/vec_znx_big.rs b/poulpy-cpu-ref/src/vec_znx_big.rs similarity index 99% rename from poulpy-backend/src/cpu_fft64_ref/vec_znx_big.rs rename to poulpy-cpu-ref/src/vec_znx_big.rs index 348c9b6..6f8c3f2 100644 --- a/poulpy-backend/src/cpu_fft64_ref/vec_znx_big.rs +++ b/poulpy-cpu-ref/src/vec_znx_big.rs @@ -1,4 +1,4 @@ -use crate::cpu_fft64_ref::FFT64Ref; +use crate::FFT64Ref; use poulpy_hal::{ api::{TakeSlice, VecZnxBigAutomorphismInplaceTmpBytes, VecZnxBigNormalizeTmpBytes}, layouts::{ diff --git a/poulpy-backend/src/cpu_fft64_ref/vec_znx_dft.rs b/poulpy-cpu-ref/src/vec_znx_dft.rs similarity index 98% rename from poulpy-backend/src/cpu_fft64_ref/vec_znx_dft.rs rename to poulpy-cpu-ref/src/vec_znx_dft.rs index b6ee4dd..3635bbd 100644 --- a/poulpy-backend/src/cpu_fft64_ref/vec_znx_dft.rs +++ b/poulpy-cpu-ref/src/vec_znx_dft.rs @@ -16,7 +16,7 @@ use poulpy_hal::{ }, }; -use crate::cpu_fft64_ref::{FFT64Ref, module::FFT64ModuleHandle}; +use crate::{FFT64Ref, module::FFT64ModuleHandle}; unsafe impl VecZnxDftFromBytesImpl for FFT64Ref { fn vec_znx_dft_from_bytes_impl(n: usize, cols: usize, size: usize, bytes: Vec) -> VecZnxDftOwned { diff --git a/poulpy-backend/src/cpu_fft64_ref/vmp.rs b/poulpy-cpu-ref/src/vmp.rs similarity index 98% rename from poulpy-backend/src/cpu_fft64_ref/vmp.rs rename to poulpy-cpu-ref/src/vmp.rs index 3cee4c7..f0aeba2 100644 --- a/poulpy-backend/src/cpu_fft64_ref/vmp.rs +++ b/poulpy-cpu-ref/src/vmp.rs @@ -14,7 +14,7 @@ use poulpy_hal::{ }, }; -use crate::cpu_fft64_ref::{FFT64Ref, module::FFT64ModuleHandle}; +use crate::{FFT64Ref, module::FFT64ModuleHandle}; unsafe impl VmpPMatAllocBytesImpl for FFT64Ref { fn vmp_pmat_bytes_of_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize { diff --git a/poulpy-backend/src/cpu_fft64_ref/znx.rs b/poulpy-cpu-ref/src/znx.rs similarity index 99% rename from poulpy-backend/src/cpu_fft64_ref/znx.rs rename to poulpy-cpu-ref/src/znx.rs index 84d0e83..e584506 100644 --- a/poulpy-backend/src/cpu_fft64_ref/znx.rs +++ b/poulpy-cpu-ref/src/znx.rs @@ -11,7 +11,7 @@ use poulpy_hal::reference::znx::{ znx_sub_inplace_ref, znx_sub_negate_inplace_ref, znx_sub_ref, znx_switch_ring_ref, znx_zero_ref, }; -use crate::cpu_fft64_ref::FFT64Ref; +use crate::FFT64Ref; impl ZnxAdd for FFT64Ref { #[inline(always)] diff --git a/poulpy-hal/Cargo.toml b/poulpy-hal/Cargo.toml index 5d9a1ca..45abcdb 100644 --- a/poulpy-hal/Cargo.toml +++ b/poulpy-hal/Cargo.toml @@ -20,6 +20,7 @@ byteorder = {workspace = true} once_cell = {workspace = true} rand_chacha = "0.9.0" bytemuck = {workspace = true} +paste = "1.0.15" [build-dependencies] diff --git a/poulpy-hal/src/test_suite/vmp.rs b/poulpy-hal/src/test_suite/vmp.rs index 4cf0880..2a7f720 100644 --- a/poulpy-hal/src/test_suite/vmp.rs +++ b/poulpy-hal/src/test_suite/vmp.rs @@ -1,8 +1,8 @@ use crate::{ api::{ - ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxBigNormalize, VecZnxDftAlloc, VecZnxDftApply, - VecZnxIdftApplyConsume, VmpApplyDft, VmpApplyDftTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, - VmpApplyDftToDftAddTmpBytes, VmpApplyDftToDftTmpBytes, VmpPMatAlloc, VmpPrepare, + ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftAlloc, + VecZnxDftApply, VecZnxIdftApplyConsume, VmpApplyDft, VmpApplyDftTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, + VmpApplyDftToDftAddTmpBytes, VmpApplyDftToDftTmpBytes, VmpPMatAlloc, VmpPrepare, VmpPrepareTmpBytes, }, layouts::{DataViewMut, DigestU64, FillUniform, MatZnx, Module, ScratchOwned, VecZnx, VecZnxBig}, source::Source, @@ -129,7 +129,9 @@ where + VmpPrepare
+ VecZnxIdftApplyConsume
+ VecZnxBigNormalize
- + VecZnxDftApply
, + + VecZnxDftApply
+ + VmpPrepareTmpBytes + + VecZnxBigNormalizeTmpBytes, ScratchOwned
: ScratchOwnedAlloc
+ ScratchOwnedBorrow
, Module: ModuleNew + VmpApplyDftToDftTmpBytes @@ -139,7 +141,9 @@ where + VmpPrepare + VecZnxIdftApplyConsume + VecZnxBigNormalize - + VecZnxDftApply, + + VecZnxDftApply + + VmpPrepareTmpBytes + + VecZnxBigNormalizeTmpBytes, ScratchOwned: ScratchOwnedAlloc + ScratchOwnedBorrow, { assert_eq!(module_ref.n(), module_test.n()); @@ -151,10 +155,16 @@ where let mut source: Source = Source::new([0u8; 32]); let mut scratch_ref: ScratchOwned
= ScratchOwned::alloc( - module_ref.vmp_apply_dft_to_dft_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size), + module_ref + .vmp_apply_dft_to_dft_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size) + .max(module_ref.vmp_prepare_tmp_bytes(max_size, max_cols, max_cols, max_size)) + .max(module_ref.vec_znx_big_normalize_tmp_bytes()), ); let mut scratch_test: ScratchOwned = ScratchOwned::alloc( - module_test.vmp_apply_dft_to_dft_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size), + module_test + .vmp_apply_dft_to_dft_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size) + .max(module_test.vmp_prepare_tmp_bytes(max_size, max_cols, max_cols, max_size)) + .max(module_test.vec_znx_big_normalize_tmp_bytes()), ); for cols_in in 1..max_cols + 1 { @@ -258,7 +268,9 @@ where + VmpPrepare
+ VecZnxIdftApplyConsume
+ VecZnxBigNormalize
- + VecZnxDftApply
, + + VecZnxDftApply
+ + VmpPrepareTmpBytes + + VecZnxBigNormalizeTmpBytes, ScratchOwned
: ScratchOwnedAlloc
+ ScratchOwnedBorrow
, Module: ModuleNew + VmpApplyDftToDftAddTmpBytes @@ -268,7 +280,9 @@ where + VmpPrepare + VecZnxIdftApplyConsume + VecZnxBigNormalize - + VecZnxDftApply, + + VecZnxDftApply + + VmpPrepareTmpBytes + + VecZnxBigNormalizeTmpBytes, ScratchOwned: ScratchOwnedAlloc + ScratchOwnedBorrow, { assert_eq!(module_ref.n(), module_test.n()); @@ -280,10 +294,16 @@ where let mut source: Source = Source::new([0u8; 32]); let mut scratch_ref: ScratchOwned
= ScratchOwned::alloc( - module_ref.vmp_apply_dft_to_dft_add_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size), + module_ref + .vmp_apply_dft_to_dft_add_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size) + .max(module_ref.vmp_prepare_tmp_bytes(max_size, max_cols, max_cols, max_size)) + .max(module_ref.vec_znx_big_normalize_tmp_bytes()), ); let mut scratch_test: ScratchOwned = ScratchOwned::alloc( - module_test.vmp_apply_dft_to_dft_add_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size), + module_test + .vmp_apply_dft_to_dft_add_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size) + .max(module_test.vmp_prepare_tmp_bytes(max_size, max_cols, max_cols, max_size)) + .max(module_test.vec_znx_big_normalize_tmp_bytes()), ); for cols_in in 1..max_cols + 1 { diff --git a/poulpy-schemes/Cargo.toml b/poulpy-schemes/Cargo.toml index bf1ec39..2b7da12 100644 --- a/poulpy-schemes/Cargo.toml +++ b/poulpy-schemes/Cargo.toml @@ -10,7 +10,8 @@ homepage = "https://github.com/phantomzone-org/poulpy" documentation = "https://docs.rs/poulpy" [dependencies] -poulpy-backend = {workspace = true} +poulpy-cpu-avx = {workspace = true} +poulpy-cpu-ref = {workspace = true} poulpy-hal = {workspace = true} poulpy-core = {workspace = true} criterion = {workspace = true} diff --git a/poulpy-schemes/benches/circuit_bootstrapping.rs b/poulpy-schemes/benches/circuit_bootstrapping.rs index f283a32..2a6cc0e 100644 --- a/poulpy-schemes/benches/circuit_bootstrapping.rs +++ b/poulpy-schemes/benches/circuit_bootstrapping.rs @@ -1,7 +1,6 @@ use std::hint::black_box; use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main}; -use poulpy_backend::{FFT64Avx, FFT64Ref, FFT64Spqlios}; use poulpy_core::{ GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWEExternalProduct, LWEEncryptSk, ScratchTakeCore, layouts::{ @@ -9,12 +8,14 @@ use poulpy_core::{ GLWESecretPreparedFactory, LWE, LWELayout, LWESecret, }, }; +use poulpy_cpu_avx::FFT64Avx; +use poulpy_cpu_ref::FFT64Ref; use poulpy_hal::{ api::{ModuleN, ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxRotateInplace}, layouts::{Backend, Module, Scratch, ScratchOwned}, source::Source, }; -use poulpy_schemes::tfhe::{ +use poulpy_schemes::bin_fhe::{ blind_rotation::{ BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory, BlindRotationKeyInfos, BlindRotationKeyLayout, CGGI, }, @@ -187,15 +188,10 @@ fn bench_circuit_bootstrapping_cpu_avx_fft64(c: &mut Criterion) { benc_circuit_bootstrapping::(c, "fft64_avx"); } -fn bench_circuit_bootstrapping_cpu_spqlios_fft64(c: &mut Criterion) { - benc_circuit_bootstrapping::(c, "fft64_spqlios"); -} - criterion_group!( benches, bench_circuit_bootstrapping_cpu_ref_fft64, bench_circuit_bootstrapping_cpu_avx_fft64, - bench_circuit_bootstrapping_cpu_spqlios_fft64, ); criterion_main!(benches); diff --git a/poulpy-schemes/examples/circuit_bootstrapping.rs b/poulpy-schemes/examples/circuit_bootstrapping.rs index 8ececbe..67e1cae 100644 --- a/poulpy-schemes/examples/circuit_bootstrapping.rs +++ b/poulpy-schemes/examples/circuit_bootstrapping.rs @@ -9,10 +9,10 @@ use poulpy_core::{ use std::time::Instant; #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] -use poulpy_backend::FFT64Avx as BackendImpl; +use poulpy_cpu_avx::FFT64Avx as BackendImpl; #[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))] -use poulpy_backend::FFT64Ref as BackendImpl; +use poulpy_cpu_ref::FFT64Ref as BackendImpl; use poulpy_hal::{ api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxNormalizeInplace}, @@ -20,7 +20,7 @@ use poulpy_hal::{ source::Source, }; -use poulpy_schemes::tfhe::{ +use poulpy_schemes::bin_fhe::{ blind_rotation::{BlindRotationKeyLayout, CGGI}, circuit_bootstrapping::{CircuitBootstrappingKey, CircuitBootstrappingKeyLayout, CircuitBootstrappingKeyPrepared}, }; diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_1w_to_1w.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/bdd_1w_to_1w.rs similarity index 97% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_1w_to_1w.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/bdd_1w_to_1w.rs index 7fc4ded..6e649c7 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_1w_to_1w.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/bdd_1w_to_1w.rs @@ -7,7 +7,7 @@ use poulpy_hal::{ layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; -use crate::tfhe::bdd_arithmetic::{ExecuteBDDCircuit, FheUint, FheUintPrepared, GetBitCircuitInfo, UnsignedInteger, circuits}; +use crate::bin_fhe::bdd_arithmetic::{ExecuteBDDCircuit, FheUint, FheUintPrepared, GetBitCircuitInfo, UnsignedInteger, circuits}; impl ExecuteBDDCircuit1WTo1W for Module where Self: Sized + ExecuteBDDCircuit + GLWEPacking + GLWECopy {} diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_2w_to_1w.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/bdd_2w_to_1w.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_2w_to_1w.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/bdd_2w_to_1w.rs index 45b2fb3..b3c34a6 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_2w_to_1w.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/bdd_2w_to_1w.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; -use crate::tfhe::bdd_arithmetic::{ +use crate::bin_fhe::bdd_arithmetic::{ BitSize, ExecuteBDDCircuit, FheUint, FheUintPrepared, GetBitCircuitInfo, GetGGSWBit, UnsignedInteger, circuits, }; diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/blind_retrieval.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/blind_retrieval.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/blind_retrieval.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/blind_retrieval.rs index f993975..bcbd640 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/blind_retrieval.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/blind_retrieval.rs @@ -5,7 +5,7 @@ use poulpy_core::{ }; use poulpy_hal::layouts::{Backend, Module, Scratch}; -use crate::tfhe::bdd_arithmetic::{Cmux, Cswap, GetGGSWBit}; +use crate::bin_fhe::bdd_arithmetic::{Cmux, Cswap, GetGGSWBit}; pub struct GLWEBlindRetriever { accumulators: Vec, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/blind_rotation.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/blind_rotation.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/blind_rotation.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/blind_rotation.rs index fe1ae39..7e11149 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/blind_rotation.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/blind_rotation.rs @@ -7,7 +7,7 @@ use poulpy_hal::{ layouts::{Backend, Module, ScalarZnx, ScalarZnxToRef, Scratch, ZnxZero}, }; -use crate::tfhe::bdd_arithmetic::{Cmux, GetGGSWBit, UnsignedInteger}; +use crate::bin_fhe::bdd_arithmetic::{Cmux, GetGGSWBit, UnsignedInteger}; impl GGSWBlindRotation for Module where diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/blind_selection.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/blind_selection.rs similarity index 97% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/blind_selection.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/blind_selection.rs index 3684ff8..2351446 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/blind_selection.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/blind_selection.rs @@ -6,7 +6,7 @@ use poulpy_core::{ }; use poulpy_hal::layouts::{Backend, Module, Scratch, ZnxZero}; -use crate::tfhe::bdd_arithmetic::{Cmux, GetGGSWBit, UnsignedInteger}; +use crate::bin_fhe::bdd_arithmetic::{Cmux, GetGGSWBit, UnsignedInteger}; impl GLWEBlinSelection for Module where Self: GLWECopy + Cmux + GLWEDecrypt {} diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/ciphertexts/fhe_uint.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/ciphertexts/fhe_uint.rs index 7853673..9f8aed8 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/ciphertexts/fhe_uint.rs @@ -14,7 +14,7 @@ use poulpy_hal::{ }; use std::{collections::HashMap, marker::PhantomData}; -use crate::tfhe::bdd_arithmetic::{Cmux, FheUintPrepared, FromBits, GetGGSWBit, ToBits, UnsignedInteger}; +use crate::bin_fhe::bdd_arithmetic::{Cmux, FheUintPrepared, FromBits, GetGGSWBit, ToBits, UnsignedInteger}; /// An FHE ciphertext encrypting the bits of an [UnsignedInteger]. pub struct FheUint { diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs similarity index 98% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs index 8cad75b..7342223 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs @@ -20,12 +20,12 @@ use poulpy_hal::{ source::Source, }; -use crate::tfhe::bdd_arithmetic::{ +use crate::bin_fhe::bdd_arithmetic::{ BDDKey, BDDKeyHelper, BDDKeyInfos, BDDKeyPrepared, BDDKeyPreparedFactory, BitSize, FheUint, ToBits, }; -use crate::tfhe::bdd_arithmetic::{Cmux, FromBits, ScratchTakeBDD, UnsignedInteger}; -use crate::tfhe::blind_rotation::BlindRotationAlgo; -use crate::tfhe::circuit_bootstrapping::{CircuitBootstrappingKeyInfos, CirtuitBootstrappingExecute}; +use crate::bin_fhe::bdd_arithmetic::{Cmux, FromBits, ScratchTakeBDD, UnsignedInteger}; +use crate::bin_fhe::blind_rotation::BlindRotationAlgo; +use crate::bin_fhe::circuit_bootstrapping::{CircuitBootstrappingKeyInfos, CirtuitBootstrappingExecute}; /// A prepared FHE ciphertext encrypting the bits of an [UnsignedInteger]. pub struct FheUintPrepared { diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared_debug.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared_debug.rs similarity index 97% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared_debug.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared_debug.rs index 46e3254..7b4066b 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared_debug.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared_debug.rs @@ -1,7 +1,7 @@ use std::marker::PhantomData; -use crate::tfhe::bdd_arithmetic::{BDDKeyPrepared, FheUint, FheUintPrepareDebug, ToBits}; -use crate::tfhe::{ +use crate::bin_fhe::bdd_arithmetic::{BDDKeyPrepared, FheUint, FheUintPrepareDebug, ToBits}; +use crate::bin_fhe::{ bdd_arithmetic::UnsignedInteger, blind_rotation::BlindRotationAlgo, circuit_bootstrapping::CirtuitBootstrappingExecute, }; use poulpy_core::GGSWNoise; diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/mod.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/ciphertexts/mod.rs similarity index 100% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/mod.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/ciphertexts/mod.rs diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/mod.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/mod.rs similarity index 100% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/mod.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/mod.rs diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/add_codegen.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/add_codegen.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/add_codegen.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/add_codegen.rs index 056e482..0ad70f3 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/add_codegen.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/add_codegen.rs @@ -1,4 +1,4 @@ -use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; +use crate::bin_fhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; pub(crate) enum AnyBitCircuit { B0(BitCircuit<4>), B1(BitCircuit<8>), diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/and_codegen.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/and_codegen.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/and_codegen.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/and_codegen.rs index d23ef67..d38c827 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/and_codegen.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/and_codegen.rs @@ -1,4 +1,4 @@ -use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; +use crate::bin_fhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; pub(crate) enum AnyBitCircuit { B0(BitCircuit<4>), B1(BitCircuit<4>), diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/identity_codgen.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/identity_codgen.rs similarity index 98% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/identity_codgen.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/identity_codgen.rs index caae248..c91534f 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/identity_codgen.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/identity_codgen.rs @@ -1,4 +1,4 @@ -use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; +use crate::bin_fhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; pub(crate) enum AnyBitCircuit { B0(BitCircuit<2>), B1(BitCircuit<2>), diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/mod.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/mod.rs similarity index 100% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/mod.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/mod.rs diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/or_codegen.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/or_codegen.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/or_codegen.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/or_codegen.rs index a41c701..5dac043 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/or_codegen.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/or_codegen.rs @@ -1,4 +1,4 @@ -use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; +use crate::bin_fhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; pub(crate) enum AnyBitCircuit { B0(BitCircuit<4>), B1(BitCircuit<4>), diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/sll_codegen.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/sll_codegen.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/sll_codegen.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/sll_codegen.rs index ec2be77..ddd82c9 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/sll_codegen.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/sll_codegen.rs @@ -1,4 +1,4 @@ -use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; +use crate::bin_fhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; pub(crate) enum AnyBitCircuit { B0(BitCircuit<12>), B1(BitCircuit<18>), diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/slt_codegen.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/slt_codegen.rs similarity index 98% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/slt_codegen.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/slt_codegen.rs index de2a69d..b5c269b 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/slt_codegen.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/slt_codegen.rs @@ -1,4 +1,4 @@ -use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; +use crate::bin_fhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; pub(crate) enum AnyBitCircuit { B0(BitCircuit<256>), } diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/sltu_codegen.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/sltu_codegen.rs similarity index 98% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/sltu_codegen.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/sltu_codegen.rs index 77cd451..31a433f 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/sltu_codegen.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/sltu_codegen.rs @@ -1,4 +1,4 @@ -use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; +use crate::bin_fhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; pub(crate) enum AnyBitCircuit { B0(BitCircuit<256>), } diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/sra_codegen.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/sra_codegen.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/sra_codegen.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/sra_codegen.rs index 1e7f886..0ce8186 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/sra_codegen.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/sra_codegen.rs @@ -1,4 +1,4 @@ -use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; +use crate::bin_fhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; pub(crate) enum AnyBitCircuit { B0(BitCircuit<192>), B1(BitCircuit<186>), diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/srl_codegen.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/srl_codegen.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/srl_codegen.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/srl_codegen.rs index e85c03d..ff6ba9c 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/srl_codegen.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/srl_codegen.rs @@ -1,4 +1,4 @@ -use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; +use crate::bin_fhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; pub(crate) enum AnyBitCircuit { B0(BitCircuit<192>), B1(BitCircuit<192>), diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/sub_codegen.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/sub_codegen.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/sub_codegen.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/sub_codegen.rs index 5bcca74..e0454e0 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/sub_codegen.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/sub_codegen.rs @@ -1,4 +1,4 @@ -use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; +use crate::bin_fhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; pub(crate) enum AnyBitCircuit { B0(BitCircuit<4>), B1(BitCircuit<8>), diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/xor_codegen.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/xor_codegen.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/xor_codegen.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/xor_codegen.rs index ecc9b62..46b2cf2 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/xor_codegen.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/circuits/u32/xor_codegen.rs @@ -1,4 +1,4 @@ -use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; +use crate::bin_fhe::bdd_arithmetic::{BitCircuit, BitCircuitFamily, BitCircuitInfo, Circuit, Node}; pub(crate) enum AnyBitCircuit { B0(BitCircuit<4>), B1(BitCircuit<4>), diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/eval.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/eval.rs index b92b783..66e1c02 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/eval.rs @@ -16,7 +16,7 @@ use poulpy_hal::{ layouts::{Backend, DataMut, Module, Scratch, VecZnxBig, ZnxInfos, ZnxZero}, }; -use crate::tfhe::bdd_arithmetic::GetGGSWBit; +use crate::bin_fhe::bdd_arithmetic::GetGGSWBit; pub trait BitCircuitInfo: Sync { fn info(&self) -> (&[Node], usize); diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/key.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/key.rs similarity index 92% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/key.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/key.rs index b036317..66061f9 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/key.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/key.rs @@ -1,6 +1,6 @@ -use crate::tfhe::bdd_arithmetic::FheUintPreparedDebug; -use crate::tfhe::circuit_bootstrapping::CircuitBootstrappingKeyInfos; -use crate::tfhe::{ +use crate::bin_fhe::bdd_arithmetic::FheUintPreparedDebug; +use crate::bin_fhe::circuit_bootstrapping::CircuitBootstrappingKeyInfos; +use crate::bin_fhe::{ bdd_arithmetic::{FheUint, UnsignedInteger}, blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory}, circuit_bootstrapping::{ @@ -71,15 +71,12 @@ where where A: BDDKeyInfos, { - let ks_glwe: Option>> = if let Some(ks_infos) = &infos.ks_glwe_infos() { - Some(GLWESwitchingKey::alloc_from_infos(ks_infos)) - } else { - None - }; - Self { cbt: CircuitBootstrappingKey::alloc_from_infos(&infos.cbt_infos()), - ks_glwe: ks_glwe, + ks_glwe: infos + .ks_glwe_infos() + .as_ref() + .map(GLWESwitchingKey::alloc_from_infos), ks_lwe: GLWEToLWEKey::alloc_from_infos(&infos.ks_lwe_infos()), } } @@ -185,19 +182,15 @@ impl BDDKeyInfos for BDDKeyPrep } } fn ks_glwe_infos(&self) -> Option { - if let Some(ks_glwe) = &self.ks_glwe { - Some(GLWESwitchingKeyLayout { - n: ks_glwe.n(), - base2k: ks_glwe.base2k(), - k: ks_glwe.k(), - rank_in: ks_glwe.rank_in(), - rank_out: ks_glwe.rank_out(), - dnum: ks_glwe.dnum(), - dsize: ks_glwe.dsize(), - }) - } else { - None - } + self.ks_glwe.as_ref().map(|ks_glwe| GLWESwitchingKeyLayout { + n: ks_glwe.n(), + base2k: ks_glwe.base2k(), + k: ks_glwe.k(), + rank_in: ks_glwe.rank_in(), + rank_out: ks_glwe.rank_out(), + dnum: ks_glwe.dnum(), + dsize: ks_glwe.dsize(), + }) } fn ks_lwe_infos(&self) -> GLWEToLWEKeyLayout { GLWEToLWEKeyLayout { @@ -301,6 +294,7 @@ impl BDDKeyHelper f } pub trait BDDKeyHelper { + #[allow(clippy::type_complexity)] fn get_cbt_key( &self, ) -> ( diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/mod.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/mod.rs similarity index 100% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/mod.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/mod.rs diff --git a/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/fft64_avx.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/fft64_avx.rs new file mode 100644 index 0000000..5a3c8a5 --- /dev/null +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/fft64_avx.rs @@ -0,0 +1,113 @@ +use std::sync::LazyLock; + +use poulpy_cpu_avx::FFT64Avx; + +use crate::bin_fhe::{bdd_arithmetic::tests::test_suite, blind_rotation::CGGI}; + +static TEST_CONTEXT_CGGI_FFT64_REF: LazyLock> = + LazyLock::new(|| test_suite::TestContext::::new()); + +#[test] +fn glwe_blind_retriever() { + test_suite::test_glwe_blind_retriever(&TEST_CONTEXT_CGGI_FFT64_REF); +} + +#[test] +fn glwe_blind_retrieval_statefull() { + test_suite::test_glwe_blind_retrieval_statefull(&TEST_CONTEXT_CGGI_FFT64_REF); +} + +#[test] +fn fhe_uint_swap() { + test_suite::test_fhe_uint_swap(&TEST_CONTEXT_CGGI_FFT64_REF); +} + +#[test] +fn fhe_uint_get_bit_glwe() { + test_suite::test_fhe_uint_get_bit_glwe(&TEST_CONTEXT_CGGI_FFT64_REF); +} + +#[test] +fn fhe_uint_sext() { + test_suite::test_fhe_uint_sext(&TEST_CONTEXT_CGGI_FFT64_REF); +} + +#[test] +fn glwe_blind_selection() { + test_suite::test_glwe_blind_selection(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn fhe_uint_splice_u8() { + test_suite::test_fhe_uint_splice_u8(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn fhe_uint_splice_u16() { + test_suite::test_fhe_uint_splice_u16(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn glwe_to_glwe_blind_rotation() { + test_suite::test_glwe_to_glwe_blind_rotation(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn scalar_to_ggsw_blind_rotation() { + test_suite::test_scalar_to_ggsw_blind_rotation(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_prepare() { + test_suite::test_bdd_prepare(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_add() { + test_suite::test_bdd_add(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_and() { + test_suite::test_bdd_and(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_or() { + test_suite::test_bdd_or(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_sll() { + test_suite::test_bdd_sll(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_slt() { + test_suite::test_bdd_slt(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_sltu() { + test_suite::test_bdd_sltu(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_sra() { + test_suite::test_bdd_sra(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_srl() { + test_suite::test_bdd_srl(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_sub() { + test_suite::test_bdd_sub(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_xor() { + test_suite::test_bdd_xor(&TEST_CONTEXT_CGGI_FFT64_REF) +} diff --git a/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/fft64_ref.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/fft64_ref.rs new file mode 100644 index 0000000..66039cd --- /dev/null +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/fft64_ref.rs @@ -0,0 +1,113 @@ +use std::sync::LazyLock; + +use poulpy_cpu_ref::FFT64Ref; + +use crate::tfhe::{bdd_arithmetic::tests::test_suite, blind_rotation::CGGI}; + +static TEST_CONTEXT_CGGI_FFT64_REF: LazyLock> = + LazyLock::new(|| test_suite::TestContext::::new()); + +#[test] +fn glwe_blind_retriever() { + test_suite::test_glwe_blind_retriever(&TEST_CONTEXT_CGGI_FFT64_REF); +} + +#[test] +fn glwe_blind_retrieval_statefull() { + test_suite::test_glwe_blind_retrieval_statefull(&TEST_CONTEXT_CGGI_FFT64_REF); +} + +#[test] +fn fhe_uint_swap() { + test_suite::test_fhe_uint_swap(&TEST_CONTEXT_CGGI_FFT64_REF); +} + +#[test] +fn fhe_uint_get_bit_glwe() { + test_suite::test_fhe_uint_get_bit_glwe(&TEST_CONTEXT_CGGI_FFT64_REF); +} + +#[test] +fn fhe_uint_sext() { + test_suite::test_fhe_uint_sext(&TEST_CONTEXT_CGGI_FFT64_REF); +} + +#[test] +fn glwe_blind_selection() { + test_suite::test_glwe_blind_selection(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn fhe_uint_splice_u8() { + test_suite::test_fhe_uint_splice_u8(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn fhe_uint_splice_u16() { + test_suite::test_fhe_uint_splice_u16(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn glwe_to_glwe_blind_rotation() { + test_suite::test_glwe_to_glwe_blind_rotation(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn scalar_to_ggsw_blind_rotation() { + test_suite::test_scalar_to_ggsw_blind_rotation(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_prepare() { + test_suite::test_bdd_prepare(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_add() { + test_suite::test_bdd_add(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_and() { + test_suite::test_bdd_and(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_or() { + test_suite::test_bdd_or(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_sll() { + test_suite::test_bdd_sll(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_slt() { + test_suite::test_bdd_slt(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_sltu() { + test_suite::test_bdd_sltu(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_sra() { + test_suite::test_bdd_sra(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_srl() { + test_suite::test_bdd_srl(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_sub() { + test_suite::test_bdd_sub(&TEST_CONTEXT_CGGI_FFT64_REF) +} + +#[test] +fn bdd_xor() { + test_suite::test_bdd_xor(&TEST_CONTEXT_CGGI_FFT64_REF) +} diff --git a/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/mod.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/mod.rs new file mode 100644 index 0000000..18e8e5a --- /dev/null +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/mod.rs @@ -0,0 +1,9 @@ +pub mod test_suite; + +#[cfg(test)] +#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))] +mod fft64_ref; + +#[cfg(test)] +#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] +mod fft64_avx; diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/add.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/add.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/add.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/add.rs index d41f18b..53f7a46 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/add.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/add.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ Add, BDDKeyEncryptSk, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintPrepare, FheUintPrepareDebug, FheUintPrepared, FheUintPreparedEncryptSk, FheUintPreparedFactory, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/and.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/and.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/and.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/and.rs index 0c74fe9..e122485 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/and.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/and.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ And, BDDKeyEncryptSk, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintPrepare, FheUintPrepareDebug, FheUintPrepared, FheUintPreparedEncryptSk, FheUintPreparedFactory, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/fheuint.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/fheuint.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/fheuint.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/fheuint.rs index f1b8c7a..eb13d30 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/fheuint.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/fheuint.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ BDDKeyPrepared, FheUint, ScratchTakeBDD, ToBits, tests::test_suite::{TEST_GLWE_INFOS, TestContext}, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/ggsw_blind_rotations.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/ggsw_blind_rotations.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/ggsw_blind_rotations.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/ggsw_blind_rotations.rs index d265a6c..0d9272f 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/ggsw_blind_rotations.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/ggsw_blind_rotations.rs @@ -12,7 +12,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ FheUintPrepared, GGSWBlindRotation, tests::test_suite::{TEST_FHEUINT_BASE2K, TEST_RANK, TestContext}, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/glwe_blind_rotation.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/glwe_blind_rotation.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/glwe_blind_rotation.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/glwe_blind_rotation.rs index 394d30e..7797713 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/glwe_blind_rotation.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/glwe_blind_rotation.rs @@ -12,7 +12,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ FheUintPrepared, GLWEBlindRotation, tests::test_suite::{TEST_FHEUINT_BASE2K, TEST_RANK, TestContext}, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/glwe_blind_selection.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/glwe_blind_selection.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/glwe_blind_selection.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/glwe_blind_selection.rs index c9c2e66..c7a2724 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/glwe_blind_selection.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/glwe_blind_selection.rs @@ -14,7 +14,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ FheUintPrepared, GLWEBlinSelection, tests::test_suite::{TEST_FHEUINT_BASE2K, TEST_RANK, TestContext}, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/mod.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/mod.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/mod.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/mod.rs index a11a51e..d9f8b2c 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/mod.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/mod.rs @@ -46,7 +46,7 @@ use poulpy_core::{ }, }; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{BDDKey, BDDKeyEncryptSk, BDDKeyLayout, BDDKeyPrepared, BDDKeyPreparedFactory}, blind_rotation::{ BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory, BlindRotationKeyLayout, BlindRotationKeyPreparedFactory, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/or.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/or.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/or.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/or.rs index 2564ae7..ac9e3d4 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/or.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/or.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ BDDKeyEncryptSk, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintPrepare, FheUintPrepareDebug, FheUintPrepared, FheUintPreparedEncryptSk, FheUintPreparedFactory, Or, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/prepare.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/prepare.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/prepare.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/prepare.rs index 384bf3f..382669e 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/prepare.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/prepare.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ BDDKeyEncryptSk, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintPrepare, FheUintPrepareDebug, FheUintPreparedDebug, FheUintPreparedEncryptSk, FheUintPreparedFactory, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sll.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/sll.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sll.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/sll.rs index b20ad5a..dd2bd06 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sll.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/sll.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ BDDKeyEncryptSk, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintPrepare, FheUintPrepareDebug, FheUintPrepared, FheUintPreparedEncryptSk, FheUintPreparedFactory, Sll, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/slt.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/slt.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/slt.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/slt.rs index 6e55738..7d5f01f 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/slt.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/slt.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ BDDKeyEncryptSk, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintPrepare, FheUintPrepareDebug, FheUintPrepared, FheUintPreparedEncryptSk, FheUintPreparedFactory, Slt, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sltu.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/sltu.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sltu.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/sltu.rs index 4195fbe..88146e6 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sltu.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/sltu.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ BDDKeyEncryptSk, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintPrepare, FheUintPrepareDebug, FheUintPrepared, FheUintPreparedEncryptSk, FheUintPreparedFactory, Sltu, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sra.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/sra.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sra.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/sra.rs index 364c880..7ff0b17 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sra.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/sra.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ BDDKeyEncryptSk, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintPrepare, FheUintPrepareDebug, FheUintPrepared, FheUintPreparedEncryptSk, FheUintPreparedFactory, Sra, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/srl.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/srl.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/srl.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/srl.rs index ce9a65d..03e00b1 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/srl.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/srl.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ BDDKeyEncryptSk, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintPrepare, FheUintPrepareDebug, FheUintPrepared, FheUintPreparedEncryptSk, FheUintPreparedFactory, Srl, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sub.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/sub.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sub.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/sub.rs index 445279d..e765ed3 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sub.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/sub.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ BDDKeyEncryptSk, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintPrepare, FheUintPrepareDebug, FheUintPrepared, FheUintPreparedEncryptSk, FheUintPreparedFactory, Sub, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/swap.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/swap.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/swap.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/swap.rs index 3535254..150ac36 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/swap.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/swap.rs @@ -10,7 +10,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ Cswap, FheUint, FheUintPrepared, GLWEBlindRetrieval, GLWEBlindRetriever, ScratchTakeBDD, tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS, TestContext}, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/xor.rs b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/xor.rs similarity index 99% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/xor.rs rename to poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/xor.rs index 8db9fcd..8b58c18 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/xor.rs +++ b/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/test_suite/xor.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::{ +use crate::bin_fhe::{ bdd_arithmetic::{ BDDKeyEncryptSk, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintPrepare, FheUintPrepareDebug, FheUintPrepared, FheUintPreparedEncryptSk, FheUintPreparedFactory, Xor, diff --git a/poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/algorithm.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/algorithm.rs similarity index 99% rename from poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/algorithm.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/algorithm.rs index c65db52..18b6f05 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/algorithm.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/algorithm.rs @@ -13,7 +13,7 @@ use poulpy_core::{ layouts::{GGSWInfos, GLWE, GLWEInfos, GLWEToMut, LWE, LWEInfos, LWEToRef}, }; -use crate::tfhe::blind_rotation::{ +use crate::bin_fhe::blind_rotation::{ BlindRotationExecute, BlindRotationKeyInfos, BlindRotationKeyPrepared, CGGI, LookupTable, mod_switch_2n, }; diff --git a/poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/key.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/key.rs similarity index 98% rename from poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/key.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/key.rs index ee3f454..4877334 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/key.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/key.rs @@ -10,7 +10,7 @@ use poulpy_core::{ layouts::{GGSW, GGSWInfos, GLWEInfos, GLWESecretPreparedToRef, LWEInfos, LWESecret, LWESecretToRef}, }; -use crate::tfhe::blind_rotation::{ +use crate::bin_fhe::blind_rotation::{ BlindRotationKey, BlindRotationKeyEncryptSk, BlindRotationKeyFactory, BlindRotationKeyInfos, CGGI, }; diff --git a/poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/key_compressed.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/key_compressed.rs similarity index 98% rename from poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/key_compressed.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/key_compressed.rs index 255f8f2..62160af 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/key_compressed.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/key_compressed.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ source::Source, }; -use crate::tfhe::blind_rotation::{ +use crate::bin_fhe::blind_rotation::{ BlindRotationKeyCompressed, BlindRotationKeyCompressedEncryptSk, BlindRotationKeyCompressedFactory, BlindRotationKeyInfos, CGGI, }; diff --git a/poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/key_prepared.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/key_prepared.rs similarity index 98% rename from poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/key_prepared.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/key_prepared.rs index bc1ab98..888d7ea 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/key_prepared.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/key_prepared.rs @@ -10,7 +10,7 @@ use poulpy_core::{ layouts::{GGSWPreparedFactory, LWEInfos, prepared::GGSWPrepared}, }; -use crate::tfhe::blind_rotation::{ +use crate::bin_fhe::blind_rotation::{ BlindRotationKey, BlindRotationKeyInfos, BlindRotationKeyPrepared, BlindRotationKeyPreparedFactory, CGGI, utils::set_xai_plus_y, }; diff --git a/poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/mod.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/mod.rs similarity index 71% rename from poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/mod.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/mod.rs index d67ee45..9d60c85 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/algorithms/cggi/mod.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/cggi/mod.rs @@ -3,7 +3,7 @@ mod key; mod key_compressed; mod key_prepared; -use crate::tfhe::blind_rotation::BlindRotationAlgo; +use crate::bin_fhe::blind_rotation::BlindRotationAlgo; #[derive(Clone)] pub struct CGGI {} diff --git a/poulpy-schemes/src/tfhe/blind_rotation/algorithms/mod.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/mod.rs similarity index 95% rename from poulpy-schemes/src/tfhe/blind_rotation/algorithms/mod.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/mod.rs index 0cc4859..4572608 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/algorithms/mod.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/algorithms/mod.rs @@ -9,7 +9,9 @@ use poulpy_core::{ }; use poulpy_hal::layouts::{Backend, DataMut, DataRef, Scratch, ZnxView}; -use crate::tfhe::blind_rotation::{BlindRotationKeyInfos, BlindRotationKeyPrepared, LookUpTableRotationDirection, LookupTable}; +use crate::bin_fhe::blind_rotation::{ + BlindRotationKeyInfos, BlindRotationKeyPrepared, LookUpTableRotationDirection, LookupTable, +}; pub trait BlindRotationAlgo: Sync {} diff --git a/poulpy-schemes/src/tfhe/blind_rotation/encryption/key.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/encryption/key.rs similarity index 95% rename from poulpy-schemes/src/tfhe/blind_rotation/encryption/key.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/encryption/key.rs index b250e07..4e4efeb 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/encryption/key.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/encryption/key.rs @@ -8,7 +8,7 @@ use poulpy_core::{ layouts::{GGSWInfos, GLWEInfos, GLWESecretPreparedToRef, LWEInfos, LWESecretToRef}, }; -use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKey}; +use crate::bin_fhe::blind_rotation::{BlindRotationAlgo, BlindRotationKey}; pub trait BlindRotationKeyEncryptSk { fn blind_rotation_key_encrypt_sk_tmp_bytes
(&self, infos: &A) -> usize diff --git a/poulpy-schemes/src/tfhe/blind_rotation/encryption/key_compressed.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/encryption/key_compressed.rs similarity index 91% rename from poulpy-schemes/src/tfhe/blind_rotation/encryption/key_compressed.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/encryption/key_compressed.rs index 4898365..a3a24b7 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/encryption/key_compressed.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/encryption/key_compressed.rs @@ -7,7 +7,7 @@ use poulpy_hal::{ source::Source, }; -use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKeyCompressed}; +use crate::bin_fhe::blind_rotation::{BlindRotationAlgo, BlindRotationKeyCompressed}; pub trait BlindRotationKeyCompressedEncryptSk { fn blind_rotation_key_compressed_encrypt_sk_tmp_bytes(&self, infos: &A) -> usize diff --git a/poulpy-schemes/src/tfhe/blind_rotation/encryption/mod.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/encryption/mod.rs similarity index 100% rename from poulpy-schemes/src/tfhe/blind_rotation/encryption/mod.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/encryption/mod.rs diff --git a/poulpy-schemes/src/tfhe/blind_rotation/layouts/key.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/layouts/key.rs similarity index 99% rename from poulpy-schemes/src/tfhe/blind_rotation/layouts/key.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/layouts/key.rs index e8748be..1fc57a8 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/layouts/key.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/layouts/key.rs @@ -12,7 +12,7 @@ use poulpy_core::{ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; -use crate::tfhe::blind_rotation::BlindRotationAlgo; +use crate::bin_fhe::blind_rotation::BlindRotationAlgo; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct BlindRotationKeyLayout { diff --git a/poulpy-schemes/src/tfhe/blind_rotation/layouts/key_compressed.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/layouts/key_compressed.rs similarity index 98% rename from poulpy-schemes/src/tfhe/blind_rotation/layouts/key_compressed.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/layouts/key_compressed.rs index 26539e1..6ec1fee 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/layouts/key_compressed.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/layouts/key_compressed.rs @@ -11,7 +11,7 @@ use poulpy_core::{ layouts::{Base2K, Degree, Dsize, GGSWInfos, GLWEInfos, LWEInfos, TorusPrecision, compressed::GGSWCompressed}, }; -use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKeyInfos}; +use crate::bin_fhe::blind_rotation::{BlindRotationAlgo, BlindRotationKeyInfos}; #[derive(Clone)] pub struct BlindRotationKeyCompressed { diff --git a/poulpy-schemes/src/tfhe/blind_rotation/layouts/key_prepared.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/layouts/key_prepared.rs similarity index 97% rename from poulpy-schemes/src/tfhe/blind_rotation/layouts/key_prepared.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/layouts/key_prepared.rs index cf533c1..4e48d9c 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/layouts/key_prepared.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/layouts/key_prepared.rs @@ -7,7 +7,7 @@ use poulpy_core::{ layouts::{Base2K, Degree, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, prepared::GGSWPrepared}, }; -use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyInfos}; +use crate::bin_fhe::blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyInfos}; pub trait BlindRotationKeyPreparedFactory { fn blind_rotation_key_prepared_alloc(&self, infos: &A) -> BlindRotationKeyPrepared, BRA, BE> diff --git a/poulpy-schemes/src/tfhe/blind_rotation/layouts/mod.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/layouts/mod.rs similarity index 100% rename from poulpy-schemes/src/tfhe/blind_rotation/layouts/mod.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/layouts/mod.rs diff --git a/poulpy-schemes/src/tfhe/blind_rotation/lut.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/lut.rs similarity index 100% rename from poulpy-schemes/src/tfhe/blind_rotation/lut.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/lut.rs diff --git a/poulpy-schemes/src/tfhe/blind_rotation/mod.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/mod.rs similarity index 100% rename from poulpy-schemes/src/tfhe/blind_rotation/mod.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/mod.rs diff --git a/poulpy-schemes/src/bin_fhe/blind_rotation/tests/fft64_avx.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/fft64_avx.rs new file mode 100644 index 0000000..0d59499 --- /dev/null +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/fft64_avx.rs @@ -0,0 +1,40 @@ +use poulpy_cpu_avx::FFT64Avx; +use poulpy_hal::{api::ModuleNew, layouts::Module}; + +use crate::bin_fhe::blind_rotation::{ + CGGI, + tests::test_suite::{ + generic_blind_rotation::test_blind_rotation, + generic_lut::{test_lut_extended, test_lut_standard}, + }, +}; + +#[test] +fn lut_standard() { + let module: Module = Module::::new(32); + test_lut_standard(&module); +} + +#[test] +fn lut_extended() { + let module: Module = Module::::new(32); + test_lut_extended(&module); +} + +#[test] +fn standard() { + let module: Module = Module::::new(512); + test_blind_rotation::(&module, 224, 1, 1); +} + +#[test] +fn block_binary() { + let module: Module = Module::::new(512); + test_blind_rotation::(&module, 224, 7, 1); +} + +#[test] +fn block_binary_extended() { + let module: Module = Module::::new(512); + test_blind_rotation::(&module, 224, 7, 2); +} diff --git a/poulpy-schemes/src/tfhe/blind_rotation/tests/implementation/fft64.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/fft64_ref.rs similarity index 94% rename from poulpy-schemes/src/tfhe/blind_rotation/tests/implementation/fft64.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/tests/fft64_ref.rs index 5a471e2..5166951 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/tests/implementation/fft64.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/fft64_ref.rs @@ -1,9 +1,9 @@ -use poulpy_backend::cpu_fft64_ref::FFT64Ref; +use poulpy_cpu_ref::FFT64Ref; use poulpy_hal::{api::ModuleNew, layouts::Module}; use crate::tfhe::blind_rotation::{ CGGI, - tests::{ + tests::test_suite::{ generic_blind_rotation::test_blind_rotation, generic_lut::{test_lut_extended, test_lut_standard}, }, diff --git a/poulpy-schemes/src/bin_fhe/blind_rotation/tests/mod.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/mod.rs new file mode 100644 index 0000000..a136f7f --- /dev/null +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/mod.rs @@ -0,0 +1,10 @@ +#[cfg(test)] +#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))] +mod fft64_ref; + +#[cfg(test)] +#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] +mod fft64_avx; + +#[cfg(test)] +mod test_suite; diff --git a/poulpy-schemes/src/tfhe/blind_rotation/tests/generic_blind_rotation.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/test_suite/generic_blind_rotation.rs similarity index 99% rename from poulpy-schemes/src/tfhe/blind_rotation/tests/generic_blind_rotation.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/tests/test_suite/generic_blind_rotation.rs index 9f91538..7686325 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/tests/generic_blind_rotation.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/test_suite/generic_blind_rotation.rs @@ -4,7 +4,7 @@ use poulpy_hal::{ source::Source, }; -use crate::tfhe::blind_rotation::{ +use crate::bin_fhe::blind_rotation::{ BlindRotationAlgo, BlindRotationExecute, BlindRotationKey, BlindRotationKeyEncryptSk, BlindRotationKeyFactory, BlindRotationKeyLayout, BlindRotationKeyPrepared, BlindRotationKeyPreparedFactory, LookUpTableLayout, LookupTable, LookupTableFactory, mod_switch_2n, diff --git a/poulpy-schemes/src/tfhe/blind_rotation/tests/generic_lut.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/test_suite/generic_lut.rs similarity index 96% rename from poulpy-schemes/src/tfhe/blind_rotation/tests/generic_lut.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/tests/test_suite/generic_lut.rs index 80d7663..f933913 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/tests/generic_lut.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/test_suite/generic_lut.rs @@ -2,7 +2,7 @@ use std::vec; use poulpy_hal::api::ModuleN; -use crate::tfhe::blind_rotation::{DivRound, LookUpTableLayout, LookupTable, LookupTableFactory}; +use crate::bin_fhe::blind_rotation::{DivRound, LookUpTableLayout, LookupTable, LookupTableFactory}; pub fn test_lut_standard(module: &M) where diff --git a/poulpy-schemes/src/tfhe/blind_rotation/tests/generic_serialization.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/test_suite/generic_serialization.rs similarity index 89% rename from poulpy-schemes/src/tfhe/blind_rotation/tests/generic_serialization.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/tests/test_suite/generic_serialization.rs index 341dd49..e7b0e6e 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/tests/generic_serialization.rs +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/test_suite/generic_serialization.rs @@ -1,6 +1,6 @@ use poulpy_hal::test_suite::serialization::test_reader_writer_interface; -use crate::tfhe::blind_rotation::{BlindRotationKey, BlindRotationKeyCompressed, BlindRotationKeyLayout, CGGI}; +use crate::bin_fhe::blind_rotation::{BlindRotationKey, BlindRotationKeyCompressed, BlindRotationKeyLayout, CGGI}; #[test] fn test_cggi_blind_rotation_key_serialization() { diff --git a/poulpy-schemes/src/bin_fhe/blind_rotation/tests/test_suite/mod.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/test_suite/mod.rs new file mode 100644 index 0000000..c986059 --- /dev/null +++ b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/test_suite/mod.rs @@ -0,0 +1,3 @@ +pub mod generic_blind_rotation; +pub mod generic_lut; +pub mod generic_serialization; diff --git a/poulpy-schemes/src/tfhe/blind_rotation/utils.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/utils.rs similarity index 100% rename from poulpy-schemes/src/tfhe/blind_rotation/utils.rs rename to poulpy-schemes/src/bin_fhe/blind_rotation/utils.rs diff --git a/poulpy-schemes/src/tfhe/circuit_bootstrapping/circuit.rs b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/circuit.rs similarity index 99% rename from poulpy-schemes/src/tfhe/circuit_bootstrapping/circuit.rs rename to poulpy-schemes/src/bin_fhe/circuit_bootstrapping/circuit.rs index 0bb2d83..f47dcc2 100644 --- a/poulpy-schemes/src/tfhe/circuit_bootstrapping/circuit.rs +++ b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/circuit.rs @@ -15,7 +15,7 @@ use poulpy_core::{ use poulpy_core::layouts::{GGSW, GLWE, LWE}; -use crate::tfhe::{ +use crate::bin_fhe::{ blind_rotation::{ BlindRotationAlgo, BlindRotationExecute, LookUpTableLayout, LookUpTableRotationDirection, LookupTable, LookupTableFactory, }, diff --git a/poulpy-schemes/src/tfhe/circuit_bootstrapping/key.rs b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/key.rs similarity index 99% rename from poulpy-schemes/src/tfhe/circuit_bootstrapping/key.rs rename to poulpy-schemes/src/bin_fhe/circuit_bootstrapping/key.rs index fd68106..bfc95e5 100644 --- a/poulpy-schemes/src/tfhe/circuit_bootstrapping/key.rs +++ b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/key.rs @@ -13,7 +13,7 @@ use poulpy_hal::{ source::Source, }; -use crate::tfhe::blind_rotation::{ +use crate::bin_fhe::blind_rotation::{ BlindRotationAlgo, BlindRotationKey, BlindRotationKeyEncryptSk, BlindRotationKeyFactory, BlindRotationKeyInfos, BlindRotationKeyLayout, }; diff --git a/poulpy-schemes/src/tfhe/circuit_bootstrapping/key_compressed.rs b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/key_compressed.rs similarity index 83% rename from poulpy-schemes/src/tfhe/circuit_bootstrapping/key_compressed.rs rename to poulpy-schemes/src/bin_fhe/circuit_bootstrapping/key_compressed.rs index 223c193..f0c43a6 100644 --- a/poulpy-schemes/src/tfhe/circuit_bootstrapping/key_compressed.rs +++ b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/key_compressed.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use poulpy_core::layouts::{GLWEAutomorphismKeyCompressed, GLWETensorKeyCompressed}; use poulpy_hal::layouts::Data; -use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKeyCompressed}; +use crate::bin_fhe::blind_rotation::{BlindRotationAlgo, BlindRotationKeyCompressed}; #[allow(dead_code)] pub struct CircuitBootstrappingKey { diff --git a/poulpy-schemes/src/tfhe/circuit_bootstrapping/key_prepared.rs b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/key_prepared.rs similarity index 99% rename from poulpy-schemes/src/tfhe/circuit_bootstrapping/key_prepared.rs rename to poulpy-schemes/src/bin_fhe/circuit_bootstrapping/key_prepared.rs index ee071bd..d3c747d 100644 --- a/poulpy-schemes/src/tfhe/circuit_bootstrapping/key_prepared.rs +++ b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/key_prepared.rs @@ -10,7 +10,7 @@ use std::collections::HashMap; use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}; -use crate::tfhe::{ +use crate::bin_fhe::{ blind_rotation::{ BlindRotationAlgo, BlindRotationKeyInfos, BlindRotationKeyLayout, BlindRotationKeyPrepared, BlindRotationKeyPreparedFactory, diff --git a/poulpy-schemes/src/tfhe/circuit_bootstrapping/mod.rs b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/mod.rs similarity index 100% rename from poulpy-schemes/src/tfhe/circuit_bootstrapping/mod.rs rename to poulpy-schemes/src/bin_fhe/circuit_bootstrapping/mod.rs diff --git a/poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs similarity index 99% rename from poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs rename to poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs index c55f2a7..bc529cc 100644 --- a/poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs +++ b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs @@ -6,7 +6,7 @@ use poulpy_hal::{ source::Source, }; -use crate::tfhe::{ +use crate::bin_fhe::{ blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory, BlindRotationKeyLayout}, circuit_bootstrapping::{ CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyLayout, diff --git a/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/fft64_avx.rs b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/fft64_avx.rs new file mode 100644 index 0000000..26c0205 --- /dev/null +++ b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/fft64_avx.rs @@ -0,0 +1,21 @@ +use poulpy_cpu_avx::FFT64Avx; +use poulpy_hal::{api::ModuleNew, layouts::Module}; + +use crate::bin_fhe::{ + blind_rotation::CGGI, + circuit_bootstrapping::tests::circuit_bootstrapping::{ + test_circuit_bootstrapping_to_constant, test_circuit_bootstrapping_to_exponent, + }, +}; + +#[test] +fn to_constant_cggi() { + let module: Module = Module::::new(256); + test_circuit_bootstrapping_to_constant::(&module); +} + +#[test] +fn to_exponent_cggi() { + let module: Module = Module::::new(256); + test_circuit_bootstrapping_to_exponent::(&module); +} diff --git a/poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/fft64.rs b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/fft64_ref.rs similarity index 81% rename from poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/fft64.rs rename to poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/fft64_ref.rs index a1fdab2..06ac98e 100644 --- a/poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/fft64.rs +++ b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/fft64_ref.rs @@ -1,7 +1,7 @@ -use poulpy_backend::cpu_fft64_ref::FFT64Ref; +use poulpy_cpu_ref::FFT64Ref; use poulpy_hal::{api::ModuleNew, layouts::Module}; -use crate::tfhe::{ +use crate::bin_fhe::{ blind_rotation::CGGI, circuit_bootstrapping::tests::circuit_bootstrapping::{ test_circuit_bootstrapping_to_constant, test_circuit_bootstrapping_to_exponent, @@ -9,13 +9,13 @@ use crate::tfhe::{ }; #[test] -fn test_to_constant_cggi() { +fn to_constant_cggi() { let module: Module = Module::::new(256); test_circuit_bootstrapping_to_constant::(&module); } #[test] -fn test_to_exponent_cggi() { +fn to_exponent_cggi() { let module: Module = Module::::new(256); test_circuit_bootstrapping_to_exponent::(&module); } diff --git a/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/mod.rs b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/mod.rs new file mode 100644 index 0000000..5fd20ad --- /dev/null +++ b/poulpy-schemes/src/bin_fhe/circuit_bootstrapping/tests/mod.rs @@ -0,0 +1,9 @@ +pub mod circuit_bootstrapping; + +#[cfg(test)] +#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))] +mod fft64_ref; + +#[cfg(test)] +#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] +mod fft64_avx; diff --git a/poulpy-schemes/src/tfhe/mod.rs b/poulpy-schemes/src/bin_fhe/mod.rs similarity index 100% rename from poulpy-schemes/src/tfhe/mod.rs rename to poulpy-schemes/src/bin_fhe/mod.rs diff --git a/poulpy-schemes/src/lib.rs b/poulpy-schemes/src/lib.rs index a610e1d..de5d944 100644 --- a/poulpy-schemes/src/lib.rs +++ b/poulpy-schemes/src/lib.rs @@ -1 +1 @@ -pub mod tfhe; +pub mod bin_fhe; diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/fft64_ref.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/fft64_ref.rs deleted file mode 100644 index 736f641..0000000 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/fft64_ref.rs +++ /dev/null @@ -1,122 +0,0 @@ -use std::sync::LazyLock; - -use poulpy_backend::FFT64Ref; - -use crate::tfhe::{ - bdd_arithmetic::tests::test_suite::{ - TestContext, test_bdd_add, test_bdd_and, test_bdd_or, test_bdd_prepare, test_bdd_sll, test_bdd_slt, test_bdd_sltu, - test_bdd_sra, test_bdd_srl, test_bdd_sub, test_bdd_xor, test_fhe_uint_get_bit_glwe, test_fhe_uint_sext, - test_fhe_uint_splice_u8, test_fhe_uint_splice_u16, test_fhe_uint_swap, test_glwe_blind_retrieval_statefull, - test_glwe_blind_retriever, test_glwe_blind_selection, test_glwe_to_glwe_blind_rotation, - test_scalar_to_ggsw_blind_rotation, - }, - blind_rotation::CGGI, -}; - -static TEST_CONTEXT_CGGI_FFT64_REF: LazyLock> = - LazyLock::new(|| TestContext::::new()); - -#[test] -fn test_glwe_blind_retriever_fft64_ref() { - test_glwe_blind_retriever(&TEST_CONTEXT_CGGI_FFT64_REF); -} - -#[test] -fn test_glwe_blind_retrieval_statefull_fft64_ref() { - test_glwe_blind_retrieval_statefull(&TEST_CONTEXT_CGGI_FFT64_REF); -} - -#[test] -fn test_fhe_uint_swap_fft64_ref() { - test_fhe_uint_swap(&TEST_CONTEXT_CGGI_FFT64_REF); -} - -#[test] -fn test_fhe_uint_get_bit_glwe_fft64_ref() { - test_fhe_uint_get_bit_glwe(&TEST_CONTEXT_CGGI_FFT64_REF); -} - -#[test] -fn test_fhe_uint_sext_fft64_ref() { - test_fhe_uint_sext(&TEST_CONTEXT_CGGI_FFT64_REF); -} - -#[test] -fn test_glwe_blind_selection_fft64_ref() { - test_glwe_blind_selection(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_fhe_uint_splice_u8_fft64_ref() { - test_fhe_uint_splice_u8(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_fhe_uint_splice_u16_fft64_ref() { - test_fhe_uint_splice_u16(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_glwe_to_glwe_blind_rotation_fft64_ref() { - test_glwe_to_glwe_blind_rotation(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_scalar_to_ggsw_blind_rotation_fft64_ref() { - test_scalar_to_ggsw_blind_rotation(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_bdd_prepare_fft64_ref() { - test_bdd_prepare(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_bdd_add_fft64_ref() { - test_bdd_add(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_bdd_and_fft64_ref() { - test_bdd_and(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_bdd_or_fft64_ref() { - test_bdd_or(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_bdd_sll_fft64_ref() { - test_bdd_sll(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_bdd_slt_fft64_ref() { - test_bdd_slt(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_bdd_sltu_fft64_ref() { - test_bdd_sltu(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_bdd_sra_fft64_ref() { - test_bdd_sra(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_bdd_srl_fft64_ref() { - test_bdd_srl(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_bdd_sub_fft64_ref() { - test_bdd_sub(&TEST_CONTEXT_CGGI_FFT64_REF) -} - -#[test] -fn test_bdd_xor_fft64_ref() { - test_bdd_xor(&TEST_CONTEXT_CGGI_FFT64_REF) -} diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/mod.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/mod.rs deleted file mode 100644 index d1828a6..0000000 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod test_suite; - -#[cfg(test)] -mod fft64_ref; diff --git a/poulpy-schemes/src/tfhe/blind_rotation/tests/implementation/mod.rs b/poulpy-schemes/src/tfhe/blind_rotation/tests/implementation/mod.rs deleted file mode 100644 index aebaafb..0000000 --- a/poulpy-schemes/src/tfhe/blind_rotation/tests/implementation/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod fft64; diff --git a/poulpy-schemes/src/tfhe/blind_rotation/tests/mod.rs b/poulpy-schemes/src/tfhe/blind_rotation/tests/mod.rs deleted file mode 100644 index 025de5b..0000000 --- a/poulpy-schemes/src/tfhe/blind_rotation/tests/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(test)] -mod generic_serialization; -#[cfg(test)] -mod implementation; - -pub mod generic_blind_rotation; -pub mod generic_lut; diff --git a/poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/mod.rs b/poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/mod.rs deleted file mode 100644 index 893a6be..0000000 --- a/poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod circuit_bootstrapping; - -mod fft64;