mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Non-avx build (wip)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
#![cfg(target_arch = "x86_64")]
|
||||||
use std::hint::black_box;
|
use std::hint::black_box;
|
||||||
|
|
||||||
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#![cfg(target_arch = "x86_64")]
|
||||||
// poulpy-backend/benches/vec_znx_add.rs
|
// poulpy-backend/benches/vec_znx_add.rs
|
||||||
use criterion::{Criterion, criterion_group, criterion_main};
|
use criterion::{Criterion, criterion_group, criterion_main};
|
||||||
use poulpy_cpu_avx::FFT64Avx;
|
use poulpy_cpu_avx::FFT64Avx;
|
||||||
|
|||||||
@@ -1,11 +1,27 @@
|
|||||||
// poulpy-backend/benches/vec_znx_add.rs
|
// poulpy-backend/benches/vec_znx_add.rs
|
||||||
use criterion::{Criterion, criterion_group, criterion_main};
|
use criterion::{Criterion, criterion_group, criterion_main};
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
use poulpy_cpu_avx::FFT64Avx;
|
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;
|
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) {
|
fn bench_vmp_apply_dft_to_dft_cpu_avx_fft64(c: &mut Criterion) {
|
||||||
bench_vmp_apply_dft_to_dft::<FFT64Avx>(c, "FFT64Avx");
|
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,);
|
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);
|
criterion_main!(benches_x86);
|
||||||
|
#[cfg(not(target_arch = "x86_64"))]
|
||||||
|
criterion_main!(benches_ref);
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
use itertools::izip;
|
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::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{
|
||||||
ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPrepare, VecZnxAddNormal,
|
ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPrepare, VecZnxAddNormal,
|
||||||
@@ -16,9 +21,9 @@ fn main() {
|
|||||||
let ct_size: usize = 3;
|
let ct_size: usize = 3;
|
||||||
let msg_size: usize = 2;
|
let msg_size: usize = 2;
|
||||||
let log_scale: usize = msg_size * base2k - 5;
|
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 seed: [u8; 32] = [0; 32];
|
||||||
let mut source: Source = Source::new(seed);
|
let mut source: Source = Source::new(seed);
|
||||||
@@ -28,7 +33,7 @@ fn main() {
|
|||||||
s.fill_ternary_prob(0, 0.5, &mut source);
|
s.fill_ternary_prob(0, 0.5, &mut source);
|
||||||
|
|
||||||
// Buffer to store s in the DFT domain
|
// 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)
|
// s_dft <- DFT(s)
|
||||||
module.svp_prepare(&mut s_dft, 0, &s, 0);
|
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)
|
// Fill the second column with random values: ct = (0, a)
|
||||||
module.vec_znx_fill_uniform(base2k, &mut ct, 1, &mut source);
|
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);
|
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>)
|
// 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)
|
// 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);
|
module.vec_znx_idft_apply_tmpa(&mut buf_big, 0, &mut buf_dft, 0);
|
||||||
|
|
||||||
// Creates a plaintext: VecZnx with 1 column
|
// Creates a plaintext: VecZnx with 1 column
|
||||||
@@ -138,3 +143,4 @@ fn main() {
|
|||||||
println!("{}: {} {}", i, a, (*b as f64) / scale);
|
println!("{}: {} {}", i, a, (*b as f64) / scale);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||||
|
|
||||||
mod module;
|
mod module;
|
||||||
mod reim;
|
mod reim;
|
||||||
mod reim4;
|
mod reim4;
|
||||||
|
|||||||
@@ -8,8 +8,11 @@ use poulpy_core::{
|
|||||||
GLWESecretPreparedFactory, LWE, LWELayout, LWESecret,
|
GLWESecretPreparedFactory, LWE, LWELayout, LWESecret,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
use poulpy_cpu_avx::FFT64Avx;
|
use poulpy_cpu_avx::FFT64Avx;
|
||||||
|
#[cfg(not(target_arch = "x86_64"))]
|
||||||
use poulpy_cpu_ref::FFT64Ref;
|
use poulpy_cpu_ref::FFT64Ref;
|
||||||
|
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{ModuleN, ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxRotateInplace},
|
api::{ModuleN, ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxRotateInplace},
|
||||||
layouts::{Backend, Module, Scratch, ScratchOwned},
|
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||||
@@ -180,18 +183,18 @@ where
|
|||||||
group.finish();
|
group.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "x86_64"))]
|
||||||
fn bench_circuit_bootstrapping_cpu_ref_fft64(c: &mut Criterion) {
|
fn bench_circuit_bootstrapping_cpu_ref_fft64(c: &mut Criterion) {
|
||||||
benc_circuit_bootstrapping::<FFT64Ref, CGGI>(c, "fft64_ref");
|
benc_circuit_bootstrapping::<FFT64Ref, CGGI>(c, "fft64_ref");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
fn bench_circuit_bootstrapping_cpu_avx_fft64(c: &mut Criterion) {
|
fn bench_circuit_bootstrapping_cpu_avx_fft64(c: &mut Criterion) {
|
||||||
benc_circuit_bootstrapping::<FFT64Avx, CGGI>(c, "fft64_avx");
|
benc_circuit_bootstrapping::<FFT64Avx, CGGI>(c, "fft64_avx");
|
||||||
}
|
}
|
||||||
|
|
||||||
criterion_group!(
|
#[cfg(target_arch = "x86_64")]
|
||||||
benches,
|
criterion_group!(benches, bench_circuit_bootstrapping_cpu_ref_fft64, bench_circuit_bootstrapping_cpu_avx_fft64,);
|
||||||
bench_circuit_bootstrapping_cpu_ref_fft64,
|
#[cfg(not(target_arch = "x86_64"))]
|
||||||
bench_circuit_bootstrapping_cpu_avx_fft64,
|
criterion_group!(benches, bench_circuit_bootstrapping_cpu_ref_fft64,);
|
||||||
);
|
|
||||||
|
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::sync::LazyLock;
|
|||||||
|
|
||||||
use poulpy_cpu_ref::FFT64Ref;
|
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>> =
|
static TEST_CONTEXT_CGGI_FFT64_REF: LazyLock<test_suite::TestContext<CGGI, FFT64Ref>> =
|
||||||
LazyLock::new(|| test_suite::TestContext::<CGGI, FFT64Ref>::new());
|
LazyLock::new(|| test_suite::TestContext::<CGGI, FFT64Ref>::new());
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use poulpy_cpu_ref::FFT64Ref;
|
use poulpy_cpu_ref::FFT64Ref;
|
||||||
use poulpy_hal::{api::ModuleNew, layouts::Module};
|
use poulpy_hal::{api::ModuleNew, layouts::Module};
|
||||||
|
|
||||||
use crate::tfhe::blind_rotation::{
|
use crate::bin_fhe::blind_rotation::{
|
||||||
CGGI,
|
CGGI,
|
||||||
tests::test_suite::{
|
tests::test_suite::{
|
||||||
generic_blind_rotation::test_blind_rotation,
|
generic_blind_rotation::test_blind_rotation,
|
||||||
|
|||||||
Reference in New Issue
Block a user