Non-avx build (wip)

This commit is contained in:
Rasoul Akhavan Mahdavi
2025-11-20 10:22:20 -05:00
parent 8a039e1c3a
commit 0fb88c9bd3
8 changed files with 43 additions and 14 deletions

View File

@@ -1,3 +1,4 @@
#![cfg(target_arch = "x86_64")]
use std::hint::black_box;
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};

View File

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

View File

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

View File

@@ -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<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 @@ fn main() {
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 @@ 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<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 @@ fn main() {
// 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 @@ fn main() {
println!("{}: {} {}", i, a, (*b as f64) / scale);
});
}

View File

@@ -1,3 +1,5 @@
#![cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod module;
mod reim;
mod reim4;

View File

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

View File

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

View File

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