diff --git a/poulpy-cpu-avx/benches/fft.rs b/poulpy-cpu-avx/benches/fft.rs index 18da418..c1e708f 100644 --- a/poulpy-cpu-avx/benches/fft.rs +++ b/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}; diff --git a/poulpy-cpu-avx/benches/vec_znx.rs b/poulpy-cpu-avx/benches/vec_znx.rs index fde4ac5..7719129 100644 --- a/poulpy-cpu-avx/benches/vec_znx.rs +++ b/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; diff --git a/poulpy-cpu-avx/benches/vmp.rs b/poulpy-cpu-avx/benches/vmp.rs index 195fa36..070345d 100644 --- a/poulpy-cpu-avx/benches/vmp.rs +++ b/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::(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::(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); diff --git a/poulpy-cpu-avx/examples/rlwe_encrypt.rs b/poulpy-cpu-avx/examples/rlwe_encrypt.rs index b312757..5bc586e 100644 --- a/poulpy-cpu-avx/examples/rlwe_encrypt.rs +++ b/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 @@ 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 +33,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, FFT64Avx> = module.svp_ppol_alloc(s.cols()); + let mut s_dft: SvpPPol, BackendImpl> = module.svp_ppol_alloc(s.cols()); // s_dft <- DFT(s) module.svp_prepare(&mut s_dft, 0, &s, 0); @@ -43,7 +48,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, FFT64Avx> = module.vec_znx_dft_alloc(1, ct_size); + let mut buf_dft: VecZnxDft, 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 @@ 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, FFT64Avx> = module.vec_znx_big_alloc(1, ct_size); + let mut buf_big: VecZnxBig, 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 @@ fn main() { println!("{}: {} {}", i, a, (*b as f64) / scale); }); } + diff --git a/poulpy-cpu-avx/src/lib.rs b/poulpy-cpu-avx/src/lib.rs index 4ba20c7..468f7be 100644 --- a/poulpy-cpu-avx/src/lib.rs +++ b/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; diff --git a/poulpy-schemes/benches/circuit_bootstrapping.rs b/poulpy-schemes/benches/circuit_bootstrapping.rs index 2a6cc0e..4d0b386 100644 --- a/poulpy-schemes/benches/circuit_bootstrapping.rs +++ b/poulpy-schemes/benches/circuit_bootstrapping.rs @@ -8,8 +8,11 @@ use poulpy_core::{ 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 @@ where group.finish(); } +#[cfg(not(target_arch = "x86_64"))] fn bench_circuit_bootstrapping_cpu_ref_fft64(c: &mut Criterion) { benc_circuit_bootstrapping::(c, "fft64_ref"); } +#[cfg(target_arch = "x86_64")] fn bench_circuit_bootstrapping_cpu_avx_fft64(c: &mut Criterion) { benc_circuit_bootstrapping::(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); 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 index 66039cd..1ddf7f1 100644 --- a/poulpy-schemes/src/bin_fhe/bdd_arithmetic/tests/fft64_ref.rs +++ b/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> = LazyLock::new(|| test_suite::TestContext::::new()); diff --git a/poulpy-schemes/src/bin_fhe/blind_rotation/tests/fft64_ref.rs b/poulpy-schemes/src/bin_fhe/blind_rotation/tests/fft64_ref.rs index 5166951..9f22652 100644 --- a/poulpy-schemes/src/bin_fhe/blind_rotation/tests/fft64_ref.rs +++ b/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,