mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Update to non-avx builds
This commit is contained in:
@@ -8,12 +8,16 @@ repository = "https://github.com/phantomzone-org/poulpy"
|
||||
homepage = "https://github.com/phantomzone-org/poulpy"
|
||||
documentation = "https://docs.rs/poulpy"
|
||||
|
||||
[features]
|
||||
enable-avx = ["dep:poulpy-cpu-avx"]
|
||||
default = ["dep:poulpy-cpu-ref"]
|
||||
|
||||
[dependencies]
|
||||
rug = {workspace = true}
|
||||
criterion = {workspace = true}
|
||||
poulpy-hal = {workspace = true}
|
||||
poulpy-cpu-avx = {workspace = true}
|
||||
poulpy-cpu-ref = {workspace = true}
|
||||
poulpy-cpu-avx = {workspace = true, optional = true}
|
||||
poulpy-cpu-ref = {workspace = true, optional = true}
|
||||
itertools = {workspace = true}
|
||||
byteorder = {workspace = true}
|
||||
bytemuck = {workspace = true}
|
||||
|
||||
@@ -6,7 +6,12 @@ use std::hint::black_box;
|
||||
|
||||
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
||||
|
||||
use poulpy_cpu_ref::FFT64Ref;
|
||||
#[cfg(all(feature = "enable-avx", target_arch = "x86_64"))]
|
||||
pub use poulpy_cpu_avx::FFT64Avx as BackendImpl;
|
||||
|
||||
#[cfg(not(all(feature = "enable-avx", target_arch = "x86_64")))]
|
||||
pub use poulpy_cpu_ref::FFT64Ref as BackendImpl;
|
||||
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||
layouts::{Module, ScalarZnx, ScratchOwned},
|
||||
@@ -26,7 +31,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
fn runner(p: Params) -> impl FnMut() {
|
||||
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(1 << p.log_n);
|
||||
let module: Module<BackendImpl> = Module::<BackendImpl>::new(1 << p.log_n);
|
||||
|
||||
let n: Degree = Degree(module.n() as u32);
|
||||
let base2k: Base2K = p.base2k;
|
||||
@@ -42,8 +47,8 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
||||
n,
|
||||
base2k,
|
||||
k: k_ggsw,
|
||||
dnum: dnum,
|
||||
dsize: dsize,
|
||||
dnum,
|
||||
dsize,
|
||||
rank,
|
||||
};
|
||||
|
||||
@@ -66,7 +71,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
||||
let mut ct_glwe_out: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_out_layout);
|
||||
let pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n.into(), 1);
|
||||
|
||||
let mut scratch: ScratchOwned<FFT64Ref> = ScratchOwned::alloc(
|
||||
let mut scratch: ScratchOwned<BackendImpl> = 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 +84,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_in_layout);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_dft: GLWESecretPrepared<Vec<u8>, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank);
|
||||
let mut sk_dft: GLWESecretPrepared<Vec<u8>, BackendImpl> = GLWESecretPrepared::alloc(&module, rank);
|
||||
sk_dft.prepare(&module, &sk);
|
||||
|
||||
ct_ggsw.encrypt_sk(
|
||||
@@ -99,7 +104,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut ggsw_prepared: GGSWPrepared<Vec<u8>, FFT64Ref> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw);
|
||||
let mut ggsw_prepared: GGSWPrepared<Vec<u8>, BackendImpl> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw);
|
||||
ggsw_prepared.prepare(&module, &ct_ggsw, scratch.borrow());
|
||||
|
||||
move || {
|
||||
@@ -138,7 +143,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
fn runner(p: Params) -> impl FnMut() {
|
||||
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(1 << p.log_n);
|
||||
let module: Module<BackendImpl> = Module::<BackendImpl>::new(1 << p.log_n);
|
||||
|
||||
let n: Degree = Degree(module.n() as u32);
|
||||
let base2k: Base2K = p.base2k;
|
||||
@@ -153,8 +158,8 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
n,
|
||||
base2k,
|
||||
k: k_ggsw,
|
||||
dnum: dnum,
|
||||
dsize: dsize,
|
||||
dnum,
|
||||
dsize,
|
||||
rank,
|
||||
};
|
||||
|
||||
@@ -169,7 +174,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
let mut ct_glwe: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_layout);
|
||||
let pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n.into(), 1);
|
||||
|
||||
let mut scratch: ScratchOwned<FFT64Ref> = ScratchOwned::alloc(
|
||||
let mut scratch: ScratchOwned<BackendImpl> = 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 +187,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_layout);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_dft: GLWESecretPrepared<Vec<u8>, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank);
|
||||
let mut sk_dft: GLWESecretPrepared<Vec<u8>, BackendImpl> = GLWESecretPrepared::alloc(&module, rank);
|
||||
sk_dft.prepare(&module, &sk);
|
||||
|
||||
ct_ggsw.encrypt_sk(
|
||||
@@ -202,7 +207,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut ggsw_prepared: GGSWPrepared<Vec<u8>, FFT64Ref> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw);
|
||||
let mut ggsw_prepared: GGSWPrepared<Vec<u8>, BackendImpl> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw);
|
||||
ggsw_prepared.prepare(&module, &ct_ggsw, scratch.borrow());
|
||||
move || {
|
||||
let scratch_borrow = scratch.borrow();
|
||||
|
||||
@@ -6,7 +6,13 @@ use poulpy_core::layouts::{
|
||||
use std::{hint::black_box, time::Duration};
|
||||
|
||||
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
||||
use poulpy_cpu_ref::FFT64Ref;
|
||||
|
||||
#[cfg(all(feature = "enable-avx", target_arch = "x86_64"))]
|
||||
pub use poulpy_cpu_avx::FFT64Avx as BackendImpl;
|
||||
|
||||
#[cfg(not(all(feature = "enable-avx", target_arch = "x86_64")))]
|
||||
pub use poulpy_cpu_ref::FFT64Ref as BackendImpl;
|
||||
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||
layouts::{Module, ScratchOwned},
|
||||
@@ -27,7 +33,7 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
fn runner(p: Params) -> impl FnMut() {
|
||||
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(1 << p.log_n);
|
||||
let module: Module<BackendImpl> = Module::<BackendImpl>::new(1 << p.log_n);
|
||||
|
||||
let n: Degree = Degree(module.n() as u32);
|
||||
let base2k: Base2K = p.base2k;
|
||||
@@ -66,7 +72,7 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
|
||||
let mut ct_in: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_in_layout);
|
||||
let mut ct_out: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_out_layout);
|
||||
|
||||
let mut scratch: ScratchOwned<FFT64Ref> = ScratchOwned::alloc(
|
||||
let mut scratch: ScratchOwned<BackendImpl> = 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 +90,7 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
|
||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_in_layout);
|
||||
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_in_dft: GLWESecretPrepared<Vec<u8>, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank);
|
||||
let mut sk_in_dft: GLWESecretPrepared<Vec<u8>, BackendImpl> = GLWESecretPrepared::alloc(&module, rank);
|
||||
sk_in_dft.prepare(&module, &sk_in);
|
||||
|
||||
ksk.encrypt_sk(
|
||||
@@ -150,7 +156,7 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
fn runner(p: Params) -> impl FnMut() {
|
||||
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(1 << p.log_n);
|
||||
let module: Module<BackendImpl> = Module::<BackendImpl>::new(1 << p.log_n);
|
||||
|
||||
let n: Degree = Degree(module.n() as u32);
|
||||
let base2k: Base2K = p.base2k;
|
||||
@@ -181,7 +187,7 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&gglwe_layout);
|
||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_layout);
|
||||
|
||||
let mut scratch: ScratchOwned<FFT64Ref> = ScratchOwned::alloc(
|
||||
let mut scratch: ScratchOwned<BackendImpl> = 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 +200,7 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_layout);
|
||||
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_in_dft: GLWESecretPrepared<Vec<u8>, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank);
|
||||
let mut sk_in_dft: GLWESecretPrepared<Vec<u8>, BackendImpl> = GLWESecretPrepared::alloc(&module, rank);
|
||||
sk_in_dft.prepare(&module, &sk_in);
|
||||
|
||||
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_layout);
|
||||
|
||||
@@ -5,7 +5,13 @@ use poulpy_core::{
|
||||
prepared::GLWESecretPrepared,
|
||||
},
|
||||
};
|
||||
use poulpy_cpu_ref::FFT64Ref;
|
||||
|
||||
#[cfg(all(feature = "enable-avx", target_arch = "x86_64"))]
|
||||
pub use poulpy_cpu_avx::FFT64Avx as BackendImpl;
|
||||
|
||||
#[cfg(not(all(feature = "enable-avx", target_arch = "x86_64")))]
|
||||
pub use poulpy_cpu_ref::FFT64Ref as BackendImpl;
|
||||
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxFillUniform},
|
||||
layouts::{Module, ScratchOwned},
|
||||
@@ -31,7 +37,7 @@ fn main() {
|
||||
let rank: Rank = Rank(1);
|
||||
|
||||
// Instantiate Module (DFT Tables)
|
||||
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(n.0 as u64);
|
||||
let module: Module<BackendImpl> = Module::<BackendImpl>::new(n.0 as u64);
|
||||
|
||||
let glwe_ct_infos: GLWELayout = GLWELayout {
|
||||
n,
|
||||
@@ -53,7 +59,7 @@ fn main() {
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
|
||||
// Scratch space
|
||||
let mut scratch: ScratchOwned<FFT64Ref> = ScratchOwned::alloc(
|
||||
let mut scratch: ScratchOwned<BackendImpl> = ScratchOwned::alloc(
|
||||
GLWE::encrypt_sk_tmp_bytes(&module, &glwe_ct_infos) | GLWE::decrypt_tmp_bytes(&module, &glwe_ct_infos),
|
||||
);
|
||||
|
||||
@@ -62,7 +68,7 @@ fn main() {
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
// Backend-prepared secret
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank);
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BackendImpl> = GLWESecretPrepared::alloc(&module, rank);
|
||||
sk_prepared.prepare(&module, &sk);
|
||||
|
||||
// Uniform plaintext
|
||||
|
||||
@@ -358,7 +358,7 @@ where
|
||||
let pairs: u32 = (((infos.rank_out().0 + 1) * infos.rank_out().0) >> 1).max(1);
|
||||
let mut ksk_infos: GGLWELayout = infos.gglwe_layout();
|
||||
ksk_infos.rank_in = Rank(pairs);
|
||||
let (data, scratch) = self.take_gglwe(infos);
|
||||
let (data, scratch) = self.take_gglwe(&ksk_infos);
|
||||
(GLWETensorKey(data), scratch)
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ where
|
||||
let pairs: u32 = (((infos.rank_out().0 + 1) * infos.rank_out().0) >> 1).max(1);
|
||||
let mut ksk_infos: GGLWELayout = infos.gglwe_layout();
|
||||
ksk_infos.rank_in = Rank(pairs);
|
||||
let (data, scratch) = self.take_gglwe_prepared(module, infos);
|
||||
let (data, scratch) = self.take_gglwe_prepared(module, &ksk_infos);
|
||||
(GLWETensorKeyPrepared(data), scratch)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ pub mod test_suite;
|
||||
mod serialization;
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(feature = "enable-avx", target_arch = "x86_64"))]
|
||||
mod poulpy_core {
|
||||
use poulpy_hal::backend_test_suite;
|
||||
|
||||
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
|
||||
backend_test_suite!(
|
||||
mod cpu_avx,
|
||||
backend = poulpy_cpu_avx::FFT64Avx,
|
||||
@@ -69,8 +69,13 @@ mod poulpy_core {
|
||||
lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(not(all(feature = "enable-avx", target_arch = "x86_64")))]
|
||||
mod poulpy_core {
|
||||
use poulpy_hal::backend_test_suite;
|
||||
|
||||
#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))]
|
||||
backend_test_suite!(
|
||||
mod cpu_ref,
|
||||
backend = poulpy_cpu_ref::FFT64Ref,
|
||||
|
||||
Reference in New Issue
Block a user