arnaucube
arnaucube/poulpyPublic Self-hosted repository
Non-avx build (wip)
Rasoul Akhavan Mahdavi rasoul.akhavan.mahdavi@uwaterloo.ca
Thu, 20 Nov 2025 10:22:20 -0500
commit

0fb88c9bd3564e7795a26142cdd61c5a8be464fc

parent

8a039e1c3aeb1cecf7267d3a076bc8f1066fa6f1

M poulpy-cpu-avx/benches/fft.rs → poulpy-cpu-avx/benches/fft.rs

@@ -1,3 +1,4 @@

+#![cfg(target_arch = "x86_64")] use std::hint::black_box; use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
M poulpy-cpu-avx/benches/vec_znx.rs → poulpy-cpu-avx/benches/vec_znx.rs

@@ -1,3 +1,4 @@

+#![cfg(target_arch = "x86_64")] // poulpy-backend/benches/vec_znx_add.rs use criterion::{Criterion, criterion_group, criterion_main}; use poulpy_cpu_avx::FFT64Avx;
M poulpy-cpu-avx/benches/vmp.rs → poulpy-cpu-avx/benches/vmp.rs

@@ -1,11 +1,27 @@

// poulpy-backend/benches/vec_znx_add.rs use criterion::{Criterion, criterion_group, criterion_main}; +#[cfg(target_arch = "x86_64")] use poulpy_cpu_avx::FFT64Avx; +#[cfg(not(target_arch = "x86_64"))] +use poulpy_cpu_ref::FFT64Ref; + use poulpy_hal::bench_suite::vmp::bench_vmp_apply_dft_to_dft; +#[cfg(target_arch = "x86_64")] fn bench_vmp_apply_dft_to_dft_cpu_avx_fft64(c: &mut Criterion) { bench_vmp_apply_dft_to_dft::<FFT64Avx>(c, "FFT64Avx"); } +#[cfg(not(target_arch = "x86_64"))] +fn bench_vmp_apply_dft_to_dft_cpu_ref_fft64(c: &mut Criterion) { + bench_vmp_apply_dft_to_dft::<FFT64Ref>(c, "FFT64Ref"); +} +#[cfg(target_arch = "x86_64")] criterion_group!(benches_x86, bench_vmp_apply_dft_to_dft_cpu_avx_fft64,); +#[cfg(not(target_arch = "x86_64"))] +criterion_group!(benches_ref, bench_vmp_apply_dft_to_dft_cpu_ref_fft64,); + +#[cfg(target_arch = "x86_64")] criterion_main!(benches_x86); +#[cfg(not(target_arch = "x86_64"))] +criterion_main!(benches_ref);
M poulpy-cpu-avx/examples/rlwe_encrypt.rs → poulpy-cpu-avx/examples/rlwe_encrypt.rs

@@ -1,5 +1,10 @@

use itertools::izip; -use poulpy_cpu_avx::FFT64Avx; + +#[cfg(target_arch = "x86_64")] +use poulpy_cpu_avx::FFT64Avx as BackendImpl; +#[cfg(not(target_arch = "x86_64"))] +use poulpy_cpu_ref::FFT64Ref as BackendImpl; + use poulpy_hal::{ api::{ ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPrepare, VecZnxAddNormal,

@@ -16,9 +21,9 @@ let base2k: usize = 18;

let ct_size: usize = 3; let msg_size: usize = 2; let log_scale: usize = msg_size * base2k - 5; - let module: Module<FFT64Avx> = Module::<FFT64Avx>::new(n as u64); + let module: Module<BackendImpl> = Module::<BackendImpl>::new(n as u64); - let mut scratch: ScratchOwned<FFT64Avx> = ScratchOwned::<FFT64Avx>::alloc(module.vec_znx_big_normalize_tmp_bytes()); + let mut scratch: ScratchOwned<BackendImpl> = ScratchOwned::<BackendImpl>::alloc(module.vec_znx_big_normalize_tmp_bytes()); let seed: [u8; 32] = [0; 32]; let mut source: Source = Source::new(seed);

@@ -28,7 +33,7 @@ let mut s: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(module.n(), 1);

s.fill_ternary_prob(0, 0.5, &mut source); // Buffer to store s in the DFT domain - let mut s_dft: SvpPPol<Vec<u8>, FFT64Avx> = module.svp_ppol_alloc(s.cols()); + let mut s_dft: SvpPPol<Vec<u8>, BackendImpl> = module.svp_ppol_alloc(s.cols()); // s_dft <- DFT(s) module.svp_prepare(&mut s_dft, 0, &s, 0);

@@ -43,7 +48,7 @@

// 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<Vec<u8>, FFT64Avx> = module.vec_znx_dft_alloc(1, ct_size); + let mut buf_dft: VecZnxDft<Vec<u8>, BackendImpl> = module.vec_znx_dft_alloc(1, ct_size); module.vec_znx_dft_apply(1, 0, &mut buf_dft, 0, &ct, 1);

@@ -58,7 +63,7 @@

// Alias scratch space (VecZnxDft<B> is always at least as big as VecZnxBig<B>) // BIG(ct[1] * s) <- IDFT(DFT(ct[1] * s)) (not normalized) - let mut buf_big: VecZnxBig<Vec<u8>, FFT64Avx> = module.vec_znx_big_alloc(1, ct_size); + let mut buf_big: VecZnxBig<Vec<u8>, BackendImpl> = 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

@@ -138,3 +143,4 @@ .for_each(|(i, (a, b))| {

println!("{}: {} {}", i, a, (*b as f64) / scale); }); } +
M poulpy-cpu-avx/src/lib.rs → poulpy-cpu-avx/src/lib.rs

@@ -1,3 +1,5 @@

+#![cfg(any(target_arch = "x86", target_arch = "x86_64"))] + mod module; mod reim; mod reim4;
M poulpy-schemes/benches/circuit_bootstrapping.rs → poulpy-schemes/benches/circuit_bootstrapping.rs

@@ -8,8 +8,11 @@ Dsize, GGLWEToGGSWKeyLayout, GGSW, GGSWLayout, GGSWPreparedFactory, GLWEAutomorphismKeyLayout, GLWESecret,

GLWESecretPreparedFactory, LWE, LWELayout, LWESecret, }, }; +#[cfg(target_arch = "x86_64")] use poulpy_cpu_avx::FFT64Avx; +#[cfg(not(target_arch = "x86_64"))] use poulpy_cpu_ref::FFT64Ref; + use poulpy_hal::{ api::{ModuleN, ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxRotateInplace}, layouts::{Backend, Module, Scratch, ScratchOwned},

@@ -180,18 +183,18 @@

group.finish(); } +#[cfg(not(target_arch = "x86_64"))] fn bench_circuit_bootstrapping_cpu_ref_fft64(c: &mut Criterion) { benc_circuit_bootstrapping::<FFT64Ref, CGGI>(c, "fft64_ref"); } +#[cfg(target_arch = "x86_64")] fn bench_circuit_bootstrapping_cpu_avx_fft64(c: &mut Criterion) { benc_circuit_bootstrapping::<FFT64Avx, CGGI>(c, "fft64_avx"); } -criterion_group!( - benches, - bench_circuit_bootstrapping_cpu_ref_fft64, - bench_circuit_bootstrapping_cpu_avx_fft64, -); - +#[cfg(target_arch = "x86_64")] +criterion_group!(benches, bench_circuit_bootstrapping_cpu_ref_fft64, bench_circuit_bootstrapping_cpu_avx_fft64,); +#[cfg(not(target_arch = "x86_64"))] +criterion_group!(benches, bench_circuit_bootstrapping_cpu_ref_fft64,); criterion_main!(benches);
M poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/fft64_ref.rs → poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/fft64_ref.rs

@@ -2,7 +2,7 @@ use std::sync::LazyLock;

use poulpy_cpu_ref::FFT64Ref; -use crate::tfhe::{bdd_arithmetic::tests::test_suite, blind_rotation::CGGI}; +use crate::bin_fhe::{bdd_arithmetic::tests::test_suite, blind_rotation::CGGI}; static TEST_CONTEXT_CGGI_FFT64_REF: LazyLock<test_suite::TestContext<CGGI, FFT64Ref>> = LazyLock::new(|| test_suite::TestContext::<CGGI, FFT64Ref>::new());
M poulpy-schemes/src/bin_fhe/blind_rotation/tests/fft64_ref.rs → poulpy-schemes/src/bin_fhe/blind_rotation/tests/fft64_ref.rs

@@ -1,7 +1,7 @@

use poulpy_cpu_ref::FFT64Ref; use poulpy_hal::{api::ModuleNew, layouts::Module}; -use crate::tfhe::blind_rotation::{ +use crate::bin_fhe::blind_rotation::{ CGGI, tests::test_suite::{ generic_blind_rotation::test_blind_rotation,