mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Backend refactor (#120)
* remove spqlios, split cpu_ref and cpu_avx into different crates * remove spqlios submodule * update crate naming & add avx tests
This commit is contained in:
committed by
GitHub
parent
84598e42fe
commit
9e007c988f
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
|||||||
[submodule "poulpy-backend/src/cpu_spqlios/spqlios-arithmetic"]
|
|
||||||
path = poulpy-backend/src/cpu_spqlios/spqlios-arithmetic
|
|
||||||
url = https://github.com/phantomzone-org/spqlios-arithmetic
|
|
||||||
33
Cargo.lock
generated
33
Cargo.lock
generated
@@ -358,14 +358,31 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "poulpy-backend"
|
name = "poulpy-core"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bytemuck",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"cmake",
|
|
||||||
"criterion",
|
"criterion",
|
||||||
"itertools 0.14.0",
|
"itertools 0.14.0",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"paste",
|
||||||
|
"poulpy-cpu-avx",
|
||||||
|
"poulpy-cpu-ref",
|
||||||
|
"poulpy-hal",
|
||||||
|
"rug",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "poulpy-cpu-avx"
|
||||||
|
version = "0.3.2"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
"criterion",
|
||||||
|
"itertools 0.14.0",
|
||||||
|
"once_cell",
|
||||||
|
"paste",
|
||||||
|
"poulpy-cpu-ref",
|
||||||
"poulpy-hal",
|
"poulpy-hal",
|
||||||
"rand",
|
"rand",
|
||||||
"rand_chacha",
|
"rand_chacha",
|
||||||
@@ -375,16 +392,18 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "poulpy-core"
|
name = "poulpy-cpu-ref"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"criterion",
|
"criterion",
|
||||||
"itertools 0.14.0",
|
"itertools 0.14.0",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"poulpy-backend",
|
|
||||||
"poulpy-hal",
|
"poulpy-hal",
|
||||||
|
"rand",
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
"rand_distr",
|
||||||
"rug",
|
"rug",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -398,6 +417,7 @@ dependencies = [
|
|||||||
"criterion",
|
"criterion",
|
||||||
"itertools 0.14.0",
|
"itertools 0.14.0",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"paste",
|
||||||
"rand",
|
"rand",
|
||||||
"rand_chacha",
|
"rand_chacha",
|
||||||
"rand_core",
|
"rand_core",
|
||||||
@@ -413,8 +433,9 @@ dependencies = [
|
|||||||
"criterion",
|
"criterion",
|
||||||
"itertools 0.14.0",
|
"itertools 0.14.0",
|
||||||
"paste",
|
"paste",
|
||||||
"poulpy-backend",
|
|
||||||
"poulpy-core",
|
"poulpy-core",
|
||||||
|
"poulpy-cpu-avx",
|
||||||
|
"poulpy-cpu-ref",
|
||||||
"poulpy-hal",
|
"poulpy-hal",
|
||||||
"rand",
|
"rand",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = ["poulpy-hal", "poulpy-core", "poulpy-backend", "poulpy-schemes"]
|
members = ["poulpy-hal", "poulpy-core", "poulpy-cpu-avx", "poulpy-schemes", "poulpy-cpu-ref"]
|
||||||
resolver = "3"
|
resolver = "3"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
poulpy-hal = {path = "poulpy-hal"}
|
poulpy-hal = {path = "poulpy-hal"}
|
||||||
poulpy-core = {path = "poulpy-core"}
|
poulpy-core = {path = "poulpy-core"}
|
||||||
poulpy-backend = {path = "poulpy-backend"}
|
poulpy-cpu-avx = {path = "poulpy-cpu-avx"}
|
||||||
|
poulpy-cpu-ref = {path = "poulpy-cpu-ref"}
|
||||||
poulpy-schemes = {path = "poulpy-schemes"}
|
poulpy-schemes = {path = "poulpy-schemes"}
|
||||||
rug = "1.28.0"
|
rug = "1.28.0"
|
||||||
rand = "0.9.2"
|
rand = "0.9.2"
|
||||||
@@ -18,3 +19,4 @@ byteorder = "1.5.0"
|
|||||||
zstd = "0.13.3"
|
zstd = "0.13.3"
|
||||||
once_cell = "1.21.3"
|
once_cell = "1.21.3"
|
||||||
bytemuck = "1.24.0"
|
bytemuck = "1.24.0"
|
||||||
|
paste = "1.0.15"
|
||||||
@@ -1,227 +0,0 @@
|
|||||||
use std::{ffi::c_void, hint::black_box};
|
|
||||||
|
|
||||||
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
|
||||||
use poulpy_backend::cpu_spqlios::reim;
|
|
||||||
use poulpy_hal::reference::fft64::reim::{ReimDFTExecute, ReimFFTRef, ReimFFTTable, ReimIFFTRef, ReimIFFTTable};
|
|
||||||
|
|
||||||
pub fn bench_fft_ref(c: &mut Criterion) {
|
|
||||||
let group_name: String = "fft_ref".to_string();
|
|
||||||
|
|
||||||
let mut group = c.benchmark_group(group_name);
|
|
||||||
|
|
||||||
fn runner(m: usize) -> impl FnMut() {
|
|
||||||
let mut values: Vec<f64> = vec![0f64; m << 1];
|
|
||||||
let scale: f64 = 1.0f64 / (2 * m) as f64;
|
|
||||||
values
|
|
||||||
.iter_mut()
|
|
||||||
.enumerate()
|
|
||||||
.for_each(|(i, x)| *x = (i + 1) as f64 * scale);
|
|
||||||
let table: ReimFFTTable<f64> = ReimFFTTable::<f64>::new(m);
|
|
||||||
move || {
|
|
||||||
ReimFFTRef::reim_dft_execute(&table, &mut values);
|
|
||||||
black_box(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for log_m in [9, 10, 11, 12, 13, 14, 15] {
|
|
||||||
let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m));
|
|
||||||
let mut runner = runner(1 << log_m);
|
|
||||||
group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
|
|
||||||
}
|
|
||||||
|
|
||||||
group.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bench_fft_spqlios(c: &mut Criterion) {
|
|
||||||
let group_name: String = "fft_spqlios".to_string();
|
|
||||||
|
|
||||||
let mut group = c.benchmark_group(group_name);
|
|
||||||
|
|
||||||
fn runner(m: usize) -> impl FnMut() {
|
|
||||||
let mut values: Vec<f64> = vec![0f64; m << 1];
|
|
||||||
|
|
||||||
let scale = 1.0f64 / (2 * m) as f64;
|
|
||||||
values
|
|
||||||
.iter_mut()
|
|
||||||
.enumerate()
|
|
||||||
.for_each(|(i, x)| *x = (i + 1) as f64 * scale);
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
reim::reim_fft_simple(m as u32, values.as_mut_ptr() as *mut c_void);
|
|
||||||
}
|
|
||||||
|
|
||||||
move || {
|
|
||||||
unsafe {
|
|
||||||
reim::reim_fft_simple(m as u32, values.as_mut_ptr() as *mut c_void);
|
|
||||||
}
|
|
||||||
black_box(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for log_m in [9, 10, 11, 12, 13, 14, 15] {
|
|
||||||
let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m));
|
|
||||||
let mut runner = runner(1 << log_m);
|
|
||||||
group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
|
|
||||||
}
|
|
||||||
|
|
||||||
group.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bench_ifft_ref(c: &mut Criterion) {
|
|
||||||
let group_name: String = "ifft_ref".to_string();
|
|
||||||
|
|
||||||
let mut group = c.benchmark_group(group_name);
|
|
||||||
|
|
||||||
fn runner(m: usize) -> impl FnMut() {
|
|
||||||
let mut values: Vec<f64> = vec![0f64; m << 1];
|
|
||||||
let scale: f64 = 1.0f64 / (2 * m) as f64;
|
|
||||||
values
|
|
||||||
.iter_mut()
|
|
||||||
.enumerate()
|
|
||||||
.for_each(|(i, x)| *x = (i + 1) as f64 * scale);
|
|
||||||
let table: ReimIFFTTable<f64> = ReimIFFTTable::<f64>::new(m);
|
|
||||||
move || {
|
|
||||||
ReimIFFTRef::reim_dft_execute(&table, &mut values);
|
|
||||||
black_box(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for log_m in [9, 10, 11, 12, 13, 14, 15] {
|
|
||||||
let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m));
|
|
||||||
let mut runner = runner(1 << log_m);
|
|
||||||
group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
|
|
||||||
}
|
|
||||||
|
|
||||||
group.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bench_ifft_spqlios(c: &mut Criterion) {
|
|
||||||
let group_name: String = "ifft_spqlios".to_string();
|
|
||||||
|
|
||||||
let mut group = c.benchmark_group(group_name);
|
|
||||||
|
|
||||||
fn runner(m: usize) -> impl FnMut() {
|
|
||||||
let mut values: Vec<f64> = vec![0f64; m << 1];
|
|
||||||
|
|
||||||
let scale = 1.0f64 / (2 * m) as f64;
|
|
||||||
values
|
|
||||||
.iter_mut()
|
|
||||||
.enumerate()
|
|
||||||
.for_each(|(i, x)| *x = (i + 1) as f64 * scale);
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
reim::reim_ifft_simple(m as u32, values.as_mut_ptr() as *mut c_void);
|
|
||||||
}
|
|
||||||
|
|
||||||
move || {
|
|
||||||
unsafe {
|
|
||||||
reim::reim_ifft_simple(m as u32, values.as_mut_ptr() as *mut c_void);
|
|
||||||
}
|
|
||||||
black_box(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for log_m in [9, 10, 11, 12, 13, 14, 15] {
|
|
||||||
let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m));
|
|
||||||
let mut runner = runner(1 << log_m);
|
|
||||||
group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
|
|
||||||
}
|
|
||||||
|
|
||||||
group.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
|
|
||||||
mod x86 {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn bench_ifft_avx2_fma(c: &mut Criterion) {
|
|
||||||
let group_name: String = "ifft_avx2_fma".to_string();
|
|
||||||
|
|
||||||
let mut group = c.benchmark_group(group_name);
|
|
||||||
|
|
||||||
if std::is_x86_feature_detected!("avx2") {
|
|
||||||
fn runner(m: usize) -> impl FnMut() {
|
|
||||||
let mut values: Vec<f64> = vec![0f64; m << 1];
|
|
||||||
|
|
||||||
let scale = 1.0f64 / (2 * m) as f64;
|
|
||||||
values
|
|
||||||
.iter_mut()
|
|
||||||
.enumerate()
|
|
||||||
.for_each(|(i, x)| *x = (i + 1) as f64 * scale);
|
|
||||||
|
|
||||||
let table: ReimIFFTTable<f64> = ReimIFFTTable::<f64>::new(m);
|
|
||||||
move || {
|
|
||||||
use poulpy_backend::cpu_fft64_avx::ReimIFFTAvx;
|
|
||||||
|
|
||||||
ReimIFFTAvx::reim_dft_execute(&table, &mut values);
|
|
||||||
black_box(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for log_m in [9, 10, 11, 12, 13, 14, 15] {
|
|
||||||
let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m));
|
|
||||||
|
|
||||||
let mut runner = runner(1 << log_m);
|
|
||||||
group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
eprintln!("skipping: CPU lacks avx2");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
group.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn bench_fft_avx2_fma(c: &mut Criterion) {
|
|
||||||
let group_name: String = "fft_avx2_fma".to_string();
|
|
||||||
|
|
||||||
let mut group = c.benchmark_group(group_name);
|
|
||||||
|
|
||||||
if std::is_x86_feature_detected!("avx2") {
|
|
||||||
fn runner(m: usize) -> impl FnMut() {
|
|
||||||
let mut values: Vec<f64> = vec![0f64; m << 1];
|
|
||||||
|
|
||||||
let scale = 1.0f64 / (2 * m) as f64;
|
|
||||||
values
|
|
||||||
.iter_mut()
|
|
||||||
.enumerate()
|
|
||||||
.for_each(|(i, x)| *x = (i + 1) as f64 * scale);
|
|
||||||
|
|
||||||
let table: ReimFFTTable<f64> = ReimFFTTable::<f64>::new(m);
|
|
||||||
move || {
|
|
||||||
use poulpy_backend::cpu_fft64_avx::ReimFFTAvx;
|
|
||||||
|
|
||||||
ReimFFTAvx::reim_dft_execute(&table, &mut values);
|
|
||||||
black_box(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for log_m in [9, 10, 11, 12, 13, 14, 15] {
|
|
||||||
let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m));
|
|
||||||
|
|
||||||
let mut runner = runner(1 << log_m);
|
|
||||||
group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
eprintln!("skipping: CPU lacks avx2");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
group.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
criterion_group!(benches_x86, bench_fft_avx2_fma, bench_ifft_avx2_fma,);
|
|
||||||
criterion_main!(benches_x86);
|
|
||||||
}
|
|
||||||
|
|
||||||
criterion_group!(
|
|
||||||
benches,
|
|
||||||
bench_fft_ref,
|
|
||||||
bench_fft_spqlios,
|
|
||||||
bench_ifft_ref,
|
|
||||||
bench_ifft_spqlios
|
|
||||||
);
|
|
||||||
|
|
||||||
criterion_main!(benches);
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
// poulpy-backend/benches/vec_znx_add.rs
|
|
||||||
use criterion::{Criterion, criterion_group, criterion_main};
|
|
||||||
use poulpy_backend::{cpu_fft64_ref, cpu_spqlios};
|
|
||||||
use poulpy_hal::reference::vec_znx::{bench_vec_znx_add, bench_vec_znx_automorphism, bench_vec_znx_normalize_inplace};
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn bench_vec_znx_add_cpu_spqlios_fft64(c: &mut Criterion) {
|
|
||||||
bench_vec_znx_add::<cpu_spqlios::FFT64Spqlios>(c, "cpu_spqlios::fft64");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn bench_vec_znx_add_cpu_ref_fft64(c: &mut Criterion) {
|
|
||||||
bench_vec_znx_add::<cpu_fft64_ref::FFT64Ref>(c, "cpu_spqlios::fft64");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn bench_vec_znx_normalize_inplace_cpu_ref_fft64(c: &mut Criterion) {
|
|
||||||
bench_vec_znx_normalize_inplace::<cpu_fft64_ref::FFT64Ref>(c, "cpu_ref::fft64");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn bench_vec_znx_normalize_inplace_cpu_spqlios_fft64(c: &mut Criterion) {
|
|
||||||
bench_vec_znx_normalize_inplace::<cpu_spqlios::FFT64Spqlios>(c, "cpu_spqlios::fft64");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bench_vec_znx_automorphism_cpu_ref_fft64(c: &mut Criterion) {
|
|
||||||
bench_vec_znx_automorphism::<cpu_fft64_ref::FFT64Ref>(c, "cpu_ref::fft64");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bench_vec_znx_automorphism_cpu_spqlios_fft64(c: &mut Criterion) {
|
|
||||||
bench_vec_znx_automorphism::<cpu_spqlios::FFT64Spqlios>(c, "cpu_spqlios::fft64");
|
|
||||||
}
|
|
||||||
|
|
||||||
criterion_group!(
|
|
||||||
benches,
|
|
||||||
// bench_vec_znx_add_cpu_spqlios_fft64,
|
|
||||||
// bench_vec_znx_add_cpu_ref_fft64,
|
|
||||||
// bench_vec_znx_normalize_inplace_cpu_ref_fft64,
|
|
||||||
// bench_vec_znx_normalize_inplace_cpu_spqlios_fft64,
|
|
||||||
bench_vec_znx_automorphism_cpu_ref_fft64,
|
|
||||||
bench_vec_znx_automorphism_cpu_spqlios_fft64,
|
|
||||||
);
|
|
||||||
criterion_main!(benches);
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
// poulpy-backend/benches/vec_znx_add.rs
|
|
||||||
use criterion::{Criterion, criterion_group, criterion_main};
|
|
||||||
use poulpy_backend::{FFT64Ref, FFT64Spqlios};
|
|
||||||
use poulpy_hal::bench_suite::vmp::bench_vmp_apply_dft_to_dft;
|
|
||||||
|
|
||||||
fn bench_vmp_apply_dft_to_dft_cpu_spqlios_fft64(c: &mut Criterion) {
|
|
||||||
bench_vmp_apply_dft_to_dft::<FFT64Spqlios>(c, "cpu_spqlios::fft64");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bench_vmp_apply_dft_to_dft_cpu_ref_fft64(c: &mut Criterion) {
|
|
||||||
bench_vmp_apply_dft_to_dft::<FFT64Ref>(c, "cpu_ref::fft64");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
|
|
||||||
mod x86 {
|
|
||||||
use super::*;
|
|
||||||
use poulpy_backend::FFT64Avx;
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn bench_vmp_apply_dft_to_dft_cpu_avx_fft64(c: &mut Criterion) {
|
|
||||||
bench_vmp_apply_dft_to_dft::<FFT64Avx>(c, "cpu_avx::fft64");
|
|
||||||
}
|
|
||||||
|
|
||||||
criterion_group!(benches_x86, bench_vmp_apply_dft_to_dft_cpu_avx_fft64,);
|
|
||||||
criterion_main!(benches_x86);
|
|
||||||
}
|
|
||||||
|
|
||||||
criterion_group!(
|
|
||||||
benches,
|
|
||||||
bench_vmp_apply_dft_to_dft_cpu_spqlios_fft64,
|
|
||||||
bench_vmp_apply_dft_to_dft_cpu_ref_fft64,
|
|
||||||
);
|
|
||||||
criterion_main!(benches);
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
mod builds {
|
|
||||||
pub mod cpu_spqlios;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
builds::cpu_spqlios::build()
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
pub fn build() {
|
|
||||||
let dst: PathBuf = cmake::Config::new("src/cpu_spqlios/spqlios-arithmetic")
|
|
||||||
.define("ENABLE_TESTING", "FALSE")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let lib_dir: PathBuf = dst.join("lib");
|
|
||||||
|
|
||||||
println!("cargo:rustc-link-search=native={}", lib_dir.display());
|
|
||||||
println!("cargo:rustc-link-lib=static=spqlios");
|
|
||||||
}
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
use poulpy_hal::{
|
|
||||||
api::ModuleNew, backend_test_suite, cross_backend_test_suite, layouts::Module,
|
|
||||||
test_suite::convolution::test_bivariate_tensoring,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::FFT64Avx;
|
|
||||||
|
|
||||||
cross_backend_test_suite! {
|
|
||||||
mod vec_znx,
|
|
||||||
backend_ref = crate::cpu_fft64_ref::FFT64Ref,
|
|
||||||
backend_test = crate::cpu_fft64_avx::FFT64Avx,
|
|
||||||
size = 1 << 5,
|
|
||||||
base2k = 12,
|
|
||||||
tests = {
|
|
||||||
test_vec_znx_add => poulpy_hal::test_suite::vec_znx::test_vec_znx_add,
|
|
||||||
test_vec_znx_add_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_inplace,
|
|
||||||
test_vec_znx_add_scalar => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_scalar,
|
|
||||||
test_vec_znx_add_scalar_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_scalar_inplace,
|
|
||||||
test_vec_znx_sub => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub,
|
|
||||||
test_vec_znx_sub_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_inplace,
|
|
||||||
test_vec_znx_sub_negate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_negate_inplace,
|
|
||||||
test_vec_znx_sub_scalar => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_scalar,
|
|
||||||
test_vec_znx_sub_scalar_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_scalar_inplace,
|
|
||||||
test_vec_znx_rsh => poulpy_hal::test_suite::vec_znx::test_vec_znx_rsh,
|
|
||||||
test_vec_znx_rsh_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_rsh_inplace,
|
|
||||||
test_vec_znx_lsh => poulpy_hal::test_suite::vec_znx::test_vec_znx_lsh,
|
|
||||||
test_vec_znx_lsh_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_lsh_inplace,
|
|
||||||
test_vec_znx_negate => poulpy_hal::test_suite::vec_znx::test_vec_znx_negate,
|
|
||||||
test_vec_znx_negate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_negate_inplace,
|
|
||||||
test_vec_znx_rotate => poulpy_hal::test_suite::vec_znx::test_vec_znx_rotate,
|
|
||||||
test_vec_znx_rotate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_rotate_inplace,
|
|
||||||
test_vec_znx_automorphism => poulpy_hal::test_suite::vec_znx::test_vec_znx_automorphism,
|
|
||||||
test_vec_znx_automorphism_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_automorphism_inplace,
|
|
||||||
test_vec_znx_mul_xp_minus_one => poulpy_hal::test_suite::vec_znx::test_vec_znx_mul_xp_minus_one,
|
|
||||||
test_vec_znx_mul_xp_minus_one_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_mul_xp_minus_one_inplace,
|
|
||||||
test_vec_znx_normalize => poulpy_hal::test_suite::vec_znx::test_vec_znx_normalize,
|
|
||||||
test_vec_znx_normalize_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_normalize_inplace,
|
|
||||||
test_vec_znx_switch_ring => poulpy_hal::test_suite::vec_znx::test_vec_znx_switch_ring,
|
|
||||||
test_vec_znx_split_ring => poulpy_hal::test_suite::vec_znx::test_vec_znx_split_ring,
|
|
||||||
test_vec_znx_copy => poulpy_hal::test_suite::vec_znx::test_vec_znx_copy,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cross_backend_test_suite! {
|
|
||||||
mod svp,
|
|
||||||
backend_ref = crate::cpu_fft64_ref::FFT64Ref,
|
|
||||||
backend_test = crate::cpu_fft64_avx::FFT64Avx,
|
|
||||||
size = 1 << 5,
|
|
||||||
base2k = 12,
|
|
||||||
tests = {
|
|
||||||
test_svp_apply_dft_to_dft => poulpy_hal::test_suite::svp::test_svp_apply_dft_to_dft,
|
|
||||||
test_svp_apply_dft_to_dft_inplace => poulpy_hal::test_suite::svp::test_svp_apply_dft_to_dft_inplace,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cross_backend_test_suite! {
|
|
||||||
mod vec_znx_big,
|
|
||||||
backend_ref = crate::cpu_fft64_ref::FFT64Ref,
|
|
||||||
backend_test = crate::cpu_fft64_avx::FFT64Avx,
|
|
||||||
size = 1 << 5,
|
|
||||||
base2k = 12,
|
|
||||||
tests = {
|
|
||||||
test_vec_znx_big_add => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add,
|
|
||||||
test_vec_znx_big_add_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_inplace,
|
|
||||||
test_vec_znx_big_add_small => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_small,
|
|
||||||
test_vec_znx_big_add_small_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_small_inplace,
|
|
||||||
test_vec_znx_big_sub => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub,
|
|
||||||
test_vec_znx_big_sub_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_inplace,
|
|
||||||
test_vec_znx_big_automorphism => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_automorphism,
|
|
||||||
test_vec_znx_big_automorphism_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_automorphism_inplace,
|
|
||||||
test_vec_znx_big_negate => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_negate,
|
|
||||||
test_vec_znx_big_negate_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_negate_inplace,
|
|
||||||
test_vec_znx_big_normalize => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_normalize,
|
|
||||||
test_vec_znx_big_sub_negate_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_negate_inplace,
|
|
||||||
test_vec_znx_big_sub_small_a => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_a,
|
|
||||||
test_vec_znx_big_sub_small_a_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_a_inplace,
|
|
||||||
test_vec_znx_big_sub_small_b => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_b,
|
|
||||||
test_vec_znx_big_sub_small_b_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_b_inplace,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cross_backend_test_suite! {
|
|
||||||
mod vec_znx_dft,
|
|
||||||
backend_ref = crate::cpu_fft64_ref::FFT64Ref,
|
|
||||||
backend_test = crate::cpu_fft64_avx::FFT64Avx,
|
|
||||||
size = 1 << 5,
|
|
||||||
base2k = 12,
|
|
||||||
tests = {
|
|
||||||
test_vec_znx_dft_add => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_add,
|
|
||||||
test_vec_znx_dft_add_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_add_inplace,
|
|
||||||
test_vec_znx_dft_sub => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub,
|
|
||||||
test_vec_znx_dft_sub_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub_inplace,
|
|
||||||
test_vec_znx_dft_sub_negate_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub_negate_inplace,
|
|
||||||
test_vec_znx_idft_apply => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply,
|
|
||||||
test_vec_znx_idft_apply_consume => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply_consume,
|
|
||||||
test_vec_znx_idft_apply_tmpa => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply_tmpa,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cross_backend_test_suite! {
|
|
||||||
mod vmp,
|
|
||||||
backend_ref = crate::cpu_fft64_ref::FFT64Ref,
|
|
||||||
backend_test = crate::cpu_fft64_avx::FFT64Avx,
|
|
||||||
size = 1 << 5,
|
|
||||||
base2k = 12,
|
|
||||||
tests = {
|
|
||||||
test_vmp_apply_dft_to_dft => poulpy_hal::test_suite::vmp::test_vmp_apply_dft_to_dft,
|
|
||||||
test_vmp_apply_dft_to_dft_add => poulpy_hal::test_suite::vmp::test_vmp_apply_dft_to_dft_add,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
backend_test_suite! {
|
|
||||||
mod sampling,
|
|
||||||
backend = crate::cpu_fft64_avx::FFT64Avx,
|
|
||||||
size = 1 << 12,
|
|
||||||
tests = {
|
|
||||||
test_vec_znx_fill_uniform => poulpy_hal::test_suite::vec_znx::test_vec_znx_fill_uniform,
|
|
||||||
test_vec_znx_fill_normal => poulpy_hal::test_suite::vec_znx::test_vec_znx_fill_normal,
|
|
||||||
test_vec_znx_add_normal => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_normal,
|
|
||||||
test_vec_znx_big_sub_small_b_inplace => poulpy_hal::reference::fft64::vec_znx_big::test_vec_znx_big_add_normal,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_convolution_fft64_avx() {
|
|
||||||
let module: Module<FFT64Avx> = Module::<FFT64Avx>::new(64);
|
|
||||||
test_bivariate_tensoring(&module);
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
pub type CNV_PVEC_L = cnv_pvec_l_t;
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct cnv_pvec_r_t {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type CNV_PVEC_R = cnv_pvec_r_t;
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#[allow(non_camel_case_types)]
|
|
||||||
pub mod module;
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
pub mod reim;
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
pub mod svp;
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
pub mod vec_znx;
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
pub mod vec_znx_big;
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
pub mod vec_znx_dft;
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
pub mod vmp;
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
pub mod zn64;
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
pub mod znx;
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#[repr(C)]
|
|
||||||
pub struct module_info_t {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type module_type_t = ::std::os::raw::c_uint;
|
|
||||||
pub use self::module_type_t as MODULE_TYPE;
|
|
||||||
|
|
||||||
#[allow(clippy::upper_case_acronyms)]
|
|
||||||
pub type MODULE = module_info_t;
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn new_module_info(N: u64, mode: MODULE_TYPE) -> *mut MODULE;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn delete_module_info(module_info: *mut MODULE);
|
|
||||||
}
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct reim_fft_precomp {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type REIM_FFT_PRECOMP = reim_fft_precomp;
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct reim_ifft_precomp {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type REIM_IFFT_PRECOMP = reim_ifft_precomp;
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct reim_mul_precomp {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type REIM_FFTVEC_MUL_PRECOMP = reim_mul_precomp;
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct reim_addmul_precomp {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type REIM_FFTVEC_ADDMUL_PRECOMP = reim_addmul_precomp;
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct reim_from_znx32_precomp {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type REIM_FROM_ZNX32_PRECOMP = reim_from_znx32_precomp;
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct reim_from_znx64_precomp {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type REIM_FROM_ZNX64_PRECOMP = reim_from_znx64_precomp;
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct reim_from_tnx32_precomp {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type REIM_FROM_TNX32_PRECOMP = reim_from_tnx32_precomp;
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct reim_to_tnx32_precomp {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type REIM_TO_TNX32_PRECOMP = reim_to_tnx32_precomp;
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct reim_to_tnx_precomp {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type REIM_TO_TNX_PRECOMP = reim_to_tnx_precomp;
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct reim_to_znx64_precomp {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type REIM_TO_ZNX64_PRECOMP = reim_to_znx64_precomp;
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn new_reim_fft_precomp(m: u32, num_buffers: u32) -> *mut REIM_FFT_PRECOMP;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_fft_precomp_get_buffer(tables: *const REIM_FFT_PRECOMP, buffer_index: u32) -> *mut f64;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn new_reim_fft_buffer(m: u32) -> *mut f64;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn delete_reim_fft_buffer(buffer: *mut f64);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_fft(tables: *const REIM_FFT_PRECOMP, data: *mut f64);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn new_reim_ifft_precomp(m: u32, num_buffers: u32) -> *mut REIM_IFFT_PRECOMP;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_ifft_precomp_get_buffer(tables: *const REIM_IFFT_PRECOMP, buffer_index: u32) -> *mut f64;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_ifft(tables: *const REIM_IFFT_PRECOMP, data: *mut f64);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn new_reim_fftvec_mul_precomp(m: u32) -> *mut REIM_FFTVEC_MUL_PRECOMP;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_fftvec_mul(tables: *const REIM_FFTVEC_MUL_PRECOMP, r: *mut f64, a: *const f64, b: *const f64);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn new_reim_fftvec_addmul_precomp(m: u32) -> *mut REIM_FFTVEC_ADDMUL_PRECOMP;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_fftvec_addmul(tables: *const REIM_FFTVEC_ADDMUL_PRECOMP, r: *mut f64, a: *const f64, b: *const f64);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn new_reim_from_znx32_precomp(m: u32, log2bound: u32) -> *mut REIM_FROM_ZNX32_PRECOMP;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_from_znx32(tables: *const REIM_FROM_ZNX32_PRECOMP, r: *mut ::std::os::raw::c_void, a: *const i32);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_from_znx64(tables: *const REIM_FROM_ZNX64_PRECOMP, r: *mut ::std::os::raw::c_void, a: *const i64);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn new_reim_from_znx64_precomp(m: u32, maxbnd: u32) -> *mut REIM_FROM_ZNX64_PRECOMP;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_from_znx64_simple(m: u32, log2bound: u32, r: *mut ::std::os::raw::c_void, a: *const i64);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn new_reim_from_tnx32_precomp(m: u32) -> *mut REIM_FROM_TNX32_PRECOMP;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_from_tnx32(tables: *const REIM_FROM_TNX32_PRECOMP, r: *mut ::std::os::raw::c_void, a: *const i32);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn new_reim_to_tnx32_precomp(m: u32, divisor: f64, log2overhead: u32) -> *mut REIM_TO_TNX32_PRECOMP;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_to_tnx32(tables: *const REIM_TO_TNX32_PRECOMP, r: *mut i32, a: *const ::std::os::raw::c_void);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn new_reim_to_tnx_precomp(m: u32, divisor: f64, log2overhead: u32) -> *mut REIM_TO_TNX_PRECOMP;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_to_tnx(tables: *const REIM_TO_TNX_PRECOMP, r: *mut f64, a: *const f64);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_to_tnx_simple(m: u32, divisor: f64, log2overhead: u32, r: *mut f64, a: *const f64);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn new_reim_to_znx64_precomp(m: u32, divisor: f64, log2bound: u32) -> *mut REIM_TO_ZNX64_PRECOMP;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_to_znx64(precomp: *const REIM_TO_ZNX64_PRECOMP, r: *mut i64, a: *const ::std::os::raw::c_void);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_to_znx64_simple(m: u32, divisor: f64, log2bound: u32, r: *mut i64, a: *const ::std::os::raw::c_void);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_fft_simple(m: u32, data: *mut ::std::os::raw::c_void);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_ifft_simple(m: u32, data: *mut ::std::os::raw::c_void);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_fftvec_mul_simple(
|
|
||||||
m: u32,
|
|
||||||
r: *mut ::std::os::raw::c_void,
|
|
||||||
a: *const ::std::os::raw::c_void,
|
|
||||||
b: *const ::std::os::raw::c_void,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_fftvec_addmul_simple(
|
|
||||||
m: u32,
|
|
||||||
r: *mut ::std::os::raw::c_void,
|
|
||||||
a: *const ::std::os::raw::c_void,
|
|
||||||
b: *const ::std::os::raw::c_void,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_from_znx32_simple(m: u32, log2bound: u32, r: *mut ::std::os::raw::c_void, x: *const i32);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_from_tnx32_simple(m: u32, r: *mut ::std::os::raw::c_void, x: *const i32);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn reim_to_tnx32_simple(m: u32, divisor: f64, log2overhead: u32, r: *mut i32, x: *const ::std::os::raw::c_void);
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
use crate::cpu_spqlios::ffi::{module::MODULE, vec_znx_dft::VEC_ZNX_DFT};
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct svp_ppol_t {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type SVP_PPOL = svp_ppol_t;
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn svp_prepare(module: *const MODULE, ppol: *mut SVP_PPOL, pol: *const i64);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn svp_apply_dft(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *const VEC_ZNX_DFT,
|
|
||||||
res_size: u64,
|
|
||||||
ppol: *const SVP_PPOL,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn svp_apply_dft_to_dft(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *const VEC_ZNX_DFT,
|
|
||||||
res_size: u64,
|
|
||||||
res_cols: u64,
|
|
||||||
ppol: *const SVP_PPOL,
|
|
||||||
a: *const VEC_ZNX_DFT,
|
|
||||||
a_size: u64,
|
|
||||||
a_cols: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
use crate::cpu_spqlios::ffi::module::MODULE;
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_add(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut i64,
|
|
||||||
res_size: u64,
|
|
||||||
res_sl: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
b: *const i64,
|
|
||||||
b_size: u64,
|
|
||||||
b_sl: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_automorphism(
|
|
||||||
module: *const MODULE,
|
|
||||||
p: i64,
|
|
||||||
res: *mut i64,
|
|
||||||
res_size: u64,
|
|
||||||
res_sl: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_mul_xp_minus_one(
|
|
||||||
module: *const MODULE,
|
|
||||||
p: i64,
|
|
||||||
res: *mut i64,
|
|
||||||
res_size: u64,
|
|
||||||
res_sl: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_negate(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut i64,
|
|
||||||
res_size: u64,
|
|
||||||
res_sl: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_rotate(
|
|
||||||
module: *const MODULE,
|
|
||||||
p: i64,
|
|
||||||
res: *mut i64,
|
|
||||||
res_size: u64,
|
|
||||||
res_sl: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_sub(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut i64,
|
|
||||||
res_size: u64,
|
|
||||||
res_sl: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
b: *const i64,
|
|
||||||
b_size: u64,
|
|
||||||
b_sl: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_zero(module: *const MODULE, res: *mut i64, res_size: u64, res_sl: u64);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_copy(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut i64,
|
|
||||||
res_size: u64,
|
|
||||||
res_sl: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_normalize_base2k(
|
|
||||||
module: *const MODULE,
|
|
||||||
base2k: u64,
|
|
||||||
res: *mut i64,
|
|
||||||
res_size: u64,
|
|
||||||
res_sl: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
tmp_space: *mut u8,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_normalize_base2k_tmp_bytes(module: *const MODULE) -> u64;
|
|
||||||
}
|
|
||||||
@@ -1,151 +0,0 @@
|
|||||||
use crate::cpu_spqlios::ffi::module::MODULE;
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct vec_znx_big_t {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type VEC_ZNX_BIG = vec_znx_big_t;
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_big_add(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_BIG,
|
|
||||||
res_size: u64,
|
|
||||||
a: *const VEC_ZNX_BIG,
|
|
||||||
a_size: u64,
|
|
||||||
b: *const VEC_ZNX_BIG,
|
|
||||||
b_size: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_big_add_small(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_BIG,
|
|
||||||
res_size: u64,
|
|
||||||
a: *const VEC_ZNX_BIG,
|
|
||||||
a_size: u64,
|
|
||||||
b: *const i64,
|
|
||||||
b_size: u64,
|
|
||||||
b_sl: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_big_add_small2(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_BIG,
|
|
||||||
res_size: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
b: *const i64,
|
|
||||||
b_size: u64,
|
|
||||||
b_sl: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_big_sub(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_BIG,
|
|
||||||
res_size: u64,
|
|
||||||
a: *const VEC_ZNX_BIG,
|
|
||||||
a_size: u64,
|
|
||||||
b: *const VEC_ZNX_BIG,
|
|
||||||
b_size: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_big_sub_small_b(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_BIG,
|
|
||||||
res_size: u64,
|
|
||||||
a: *const VEC_ZNX_BIG,
|
|
||||||
a_size: u64,
|
|
||||||
b: *const i64,
|
|
||||||
b_size: u64,
|
|
||||||
b_sl: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_big_sub_small_a(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_BIG,
|
|
||||||
res_size: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
b: *const VEC_ZNX_BIG,
|
|
||||||
b_size: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_big_sub_small2(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_BIG,
|
|
||||||
res_size: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
b: *const i64,
|
|
||||||
b_size: u64,
|
|
||||||
b_sl: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_big_normalize_base2k_tmp_bytes(module: *const MODULE) -> u64;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_big_normalize_base2k(
|
|
||||||
module: *const MODULE,
|
|
||||||
log2_base2k: u64,
|
|
||||||
res: *mut i64,
|
|
||||||
res_size: u64,
|
|
||||||
res_sl: u64,
|
|
||||||
a: *const VEC_ZNX_BIG,
|
|
||||||
a_size: u64,
|
|
||||||
tmp_space: *mut u8,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_big_range_normalize_base2k(
|
|
||||||
module: *const MODULE,
|
|
||||||
log2_base2k: u64,
|
|
||||||
res: *mut i64,
|
|
||||||
res_size: u64,
|
|
||||||
res_sl: u64,
|
|
||||||
a: *const VEC_ZNX_BIG,
|
|
||||||
a_range_begin: u64,
|
|
||||||
a_range_xend: u64,
|
|
||||||
a_range_step: u64,
|
|
||||||
tmp_space: *mut u8,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_big_range_normalize_base2k_tmp_bytes(module: *const MODULE) -> u64;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_big_automorphism(
|
|
||||||
module: *const MODULE,
|
|
||||||
p: i64,
|
|
||||||
res: *mut VEC_ZNX_BIG,
|
|
||||||
res_size: u64,
|
|
||||||
a: *const VEC_ZNX_BIG,
|
|
||||||
a_size: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_big_rotate(
|
|
||||||
module: *const MODULE,
|
|
||||||
p: i64,
|
|
||||||
res: *mut VEC_ZNX_BIG,
|
|
||||||
res_size: u64,
|
|
||||||
a: *const VEC_ZNX_BIG,
|
|
||||||
a_size: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
use crate::cpu_spqlios::ffi::{module::MODULE, vec_znx_big::VEC_ZNX_BIG};
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct vec_znx_dft_t {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type VEC_ZNX_DFT = vec_znx_dft_t;
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_dft_add(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_DFT,
|
|
||||||
res_size: u64,
|
|
||||||
a: *const VEC_ZNX_DFT,
|
|
||||||
a_size: u64,
|
|
||||||
b: *const VEC_ZNX_DFT,
|
|
||||||
b_size: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_dft_sub(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_DFT,
|
|
||||||
res_size: u64,
|
|
||||||
a: *const VEC_ZNX_DFT,
|
|
||||||
a_size: u64,
|
|
||||||
b: *const VEC_ZNX_DFT,
|
|
||||||
b_size: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_dft(module: *const MODULE, res: *mut VEC_ZNX_DFT, res_size: u64, a: *const i64, a_size: u64, a_sl: u64);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_idft(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_BIG,
|
|
||||||
res_size: u64,
|
|
||||||
a_dft: *const VEC_ZNX_DFT,
|
|
||||||
a_size: u64,
|
|
||||||
tmp: *mut u8,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_idft_tmp_bytes(module: *const MODULE) -> u64;
|
|
||||||
}
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vec_znx_idft_tmp_a(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_BIG,
|
|
||||||
res_size: u64,
|
|
||||||
a_dft: *mut VEC_ZNX_DFT,
|
|
||||||
a_size: u64,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
use crate::cpu_spqlios::ffi::{module::MODULE, vec_znx_dft::VEC_ZNX_DFT};
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct vmp_pmat_t {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
|
|
||||||
// [rows][cols] = [#Decomposition][#Limbs]
|
|
||||||
pub type VMP_PMAT = vmp_pmat_t;
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vmp_apply_dft(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_DFT,
|
|
||||||
res_size: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
pmat: *const VMP_PMAT,
|
|
||||||
nrows: u64,
|
|
||||||
ncols: u64,
|
|
||||||
tmp_space: *mut u8,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vmp_apply_dft_add(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_DFT,
|
|
||||||
res_size: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
pmat: *const VMP_PMAT,
|
|
||||||
nrows: u64,
|
|
||||||
ncols: u64,
|
|
||||||
pmat_scale: u64,
|
|
||||||
tmp_space: *mut u8,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vmp_apply_dft_tmp_bytes(module: *const MODULE, res_size: u64, a_size: u64, nrows: u64, ncols: u64) -> u64;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vmp_apply_dft_to_dft(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_DFT,
|
|
||||||
res_size: u64,
|
|
||||||
a_dft: *const VEC_ZNX_DFT,
|
|
||||||
a_size: u64,
|
|
||||||
pmat: *const VMP_PMAT,
|
|
||||||
nrows: u64,
|
|
||||||
ncols: u64,
|
|
||||||
tmp_space: *mut u8,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vmp_apply_dft_to_dft_add(
|
|
||||||
module: *const MODULE,
|
|
||||||
res: *mut VEC_ZNX_DFT,
|
|
||||||
res_size: u64,
|
|
||||||
a_dft: *const VEC_ZNX_DFT,
|
|
||||||
a_size: u64,
|
|
||||||
pmat: *const VMP_PMAT,
|
|
||||||
nrows: u64,
|
|
||||||
ncols: u64,
|
|
||||||
pmat_scale: u64,
|
|
||||||
tmp_space: *mut u8,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vmp_apply_dft_to_dft_tmp_bytes(
|
|
||||||
module: *const MODULE,
|
|
||||||
res_size: u64,
|
|
||||||
a_size: u64,
|
|
||||||
nrows: u64,
|
|
||||||
ncols: u64,
|
|
||||||
) -> u64;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vmp_prepare_contiguous(
|
|
||||||
module: *const MODULE,
|
|
||||||
pmat: *mut VMP_PMAT,
|
|
||||||
mat: *const i64,
|
|
||||||
nrows: u64,
|
|
||||||
ncols: u64,
|
|
||||||
tmp_space: *mut u8,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn vmp_prepare_tmp_bytes(module: *const MODULE, nrows: u64, ncols: u64) -> u64;
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn zn64_normalize_base2k_ref(
|
|
||||||
n: u64,
|
|
||||||
base2k: u64,
|
|
||||||
res: *mut i64,
|
|
||||||
res_size: u64,
|
|
||||||
res_sl: u64,
|
|
||||||
a: *const i64,
|
|
||||||
a_size: u64,
|
|
||||||
a_sl: u64,
|
|
||||||
tmp_space: *mut u8,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn znx_rotate_i64(nn: u64, p: i64, res: *mut i64, in_: *const i64);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub unsafe fn znx_rotate_inplace_i64(nn: u64, p: i64, res: *mut i64);
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
mod module;
|
|
||||||
mod scratch;
|
|
||||||
mod svp_ppol;
|
|
||||||
mod vec_znx;
|
|
||||||
mod vec_znx_big;
|
|
||||||
mod vec_znx_dft;
|
|
||||||
mod vmp_pmat;
|
|
||||||
mod znx;
|
|
||||||
|
|
||||||
pub struct FFT64Spqlios;
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
use std::ptr::NonNull;
|
|
||||||
|
|
||||||
use poulpy_hal::{
|
|
||||||
layouts::{Backend, Module},
|
|
||||||
oep::ModuleNewImpl,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::cpu_spqlios::{
|
|
||||||
FFT64Spqlios,
|
|
||||||
ffi::module::{MODULE, delete_module_info, new_module_info},
|
|
||||||
};
|
|
||||||
|
|
||||||
impl Backend for FFT64Spqlios {
|
|
||||||
type ScalarPrep = f64;
|
|
||||||
type ScalarBig = i64;
|
|
||||||
type Handle = MODULE;
|
|
||||||
unsafe fn destroy(handle: NonNull<Self::Handle>) {
|
|
||||||
unsafe { delete_module_info(handle.as_ptr()) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn layout_big_word_count() -> usize {
|
|
||||||
1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn layout_prep_word_count() -> usize {
|
|
||||||
1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl ModuleNewImpl<Self> for FFT64Spqlios {
|
|
||||||
fn new_impl(n: u64) -> Module<Self> {
|
|
||||||
unsafe { Module::from_raw_parts(new_module_info(n, 0), n) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
use std::marker::PhantomData;
|
|
||||||
|
|
||||||
use poulpy_hal::{
|
|
||||||
DEFAULTALIGN, alloc_aligned,
|
|
||||||
api::ScratchFromBytes,
|
|
||||||
layouts::{Backend, Scratch, ScratchOwned},
|
|
||||||
oep::{ScratchAvailableImpl, ScratchFromBytesImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeSliceImpl},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::cpu_spqlios::FFT64Spqlios;
|
|
||||||
|
|
||||||
unsafe impl<B: Backend> ScratchOwnedAllocImpl<B> for FFT64Spqlios {
|
|
||||||
fn scratch_owned_alloc_impl(size: usize) -> ScratchOwned<B> {
|
|
||||||
let data: Vec<u8> = alloc_aligned(size);
|
|
||||||
ScratchOwned {
|
|
||||||
data,
|
|
||||||
_phantom: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl<B: Backend> ScratchOwnedBorrowImpl<B> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
B: ScratchFromBytesImpl<B>,
|
|
||||||
{
|
|
||||||
fn scratch_owned_borrow_impl(scratch: &mut ScratchOwned<B>) -> &mut Scratch<B> {
|
|
||||||
Scratch::from_bytes(&mut scratch.data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl<B: Backend> ScratchFromBytesImpl<B> for FFT64Spqlios {
|
|
||||||
fn scratch_from_bytes_impl(data: &mut [u8]) -> &mut Scratch<B> {
|
|
||||||
unsafe { &mut *(data as *mut [u8] as *mut Scratch<B>) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl<B: Backend> ScratchAvailableImpl<B> for FFT64Spqlios {
|
|
||||||
fn scratch_available_impl(scratch: &Scratch<B>) -> usize {
|
|
||||||
let ptr: *const u8 = scratch.data.as_ptr();
|
|
||||||
let self_len: usize = scratch.data.len();
|
|
||||||
let aligned_offset: usize = ptr.align_offset(DEFAULTALIGN);
|
|
||||||
self_len.saturating_sub(aligned_offset)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl<B: Backend> TakeSliceImpl<B> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
B: ScratchFromBytesImpl<B>,
|
|
||||||
{
|
|
||||||
fn take_slice_impl<T>(scratch: &mut Scratch<B>, len: usize) -> (&mut [T], &mut Scratch<B>) {
|
|
||||||
let (take_slice, rem_slice) = take_slice_aligned(&mut scratch.data, len * std::mem::size_of::<T>());
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
(
|
|
||||||
&mut *(std::ptr::slice_from_raw_parts_mut(take_slice.as_mut_ptr() as *mut T, len)),
|
|
||||||
Scratch::from_bytes(rem_slice),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn take_slice_aligned(data: &mut [u8], take_len: usize) -> (&mut [u8], &mut [u8]) {
|
|
||||||
let ptr: *mut u8 = data.as_mut_ptr();
|
|
||||||
let self_len: usize = data.len();
|
|
||||||
|
|
||||||
let aligned_offset: usize = ptr.align_offset(DEFAULTALIGN);
|
|
||||||
let aligned_len: usize = self_len.saturating_sub(aligned_offset);
|
|
||||||
|
|
||||||
if let Some(rem_len) = aligned_len.checked_sub(take_len) {
|
|
||||||
unsafe {
|
|
||||||
let rem_ptr: *mut u8 = ptr.add(aligned_offset).add(take_len);
|
|
||||||
let rem_slice: &mut [u8] = &mut *std::ptr::slice_from_raw_parts_mut(rem_ptr, rem_len);
|
|
||||||
|
|
||||||
let take_slice: &mut [u8] = &mut *std::ptr::slice_from_raw_parts_mut(ptr.add(aligned_offset), take_len);
|
|
||||||
|
|
||||||
(take_slice, rem_slice)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
panic!("Attempted to take {take_len} from scratch with {aligned_len} aligned bytes left");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
use poulpy_hal::{
|
|
||||||
layouts::{
|
|
||||||
Backend, Module, ScalarZnxToRef, SvpPPol, SvpPPolOwned, SvpPPolToMut, SvpPPolToRef, VecZnxDft, VecZnxDftToMut,
|
|
||||||
VecZnxDftToRef, ZnxInfos, ZnxView, ZnxViewMut,
|
|
||||||
},
|
|
||||||
oep::{
|
|
||||||
SvpApplyDftToDftImpl, SvpApplyDftToDftInplaceImpl, SvpPPolAllocBytesImpl, SvpPPolAllocImpl, SvpPPolFromBytesImpl,
|
|
||||||
SvpPrepareImpl,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::cpu_spqlios::{
|
|
||||||
FFT64Spqlios,
|
|
||||||
ffi::{svp, vec_znx_dft::vec_znx_dft_t},
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe impl SvpPPolFromBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn svp_ppol_from_bytes_impl(n: usize, cols: usize, bytes: Vec<u8>) -> SvpPPolOwned<Self> {
|
|
||||||
SvpPPolOwned::from_bytes(n, cols, bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl SvpPPolAllocImpl<Self> for FFT64Spqlios {
|
|
||||||
fn svp_ppol_alloc_impl(n: usize, cols: usize) -> SvpPPolOwned<Self> {
|
|
||||||
SvpPPolOwned::alloc(n, cols)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl SvpPPolAllocBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn svp_ppol_bytes_of_impl(n: usize, cols: usize) -> usize {
|
|
||||||
FFT64Spqlios::layout_prep_word_count() * n * cols * size_of::<f64>()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl SvpPrepareImpl<Self> for FFT64Spqlios {
|
|
||||||
fn svp_prepare_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: SvpPPolToMut<Self>,
|
|
||||||
A: ScalarZnxToRef,
|
|
||||||
{
|
|
||||||
unsafe {
|
|
||||||
svp::svp_prepare(
|
|
||||||
module.ptr(),
|
|
||||||
res.to_mut().at_mut_ptr(res_col, 0) as *mut svp::svp_ppol_t,
|
|
||||||
a.to_ref().at_ptr(a_col, 0),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl SvpApplyDftToDftImpl<Self> for FFT64Spqlios {
|
|
||||||
fn svp_apply_dft_to_dft_impl<R, A, B>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
b: &B,
|
|
||||||
b_col: usize,
|
|
||||||
) where
|
|
||||||
R: VecZnxDftToMut<Self>,
|
|
||||||
A: SvpPPolToRef<Self>,
|
|
||||||
B: VecZnxDftToRef<Self>,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut();
|
|
||||||
let a: SvpPPol<&[u8], Self> = a.to_ref();
|
|
||||||
let b: VecZnxDft<&[u8], Self> = b.to_ref();
|
|
||||||
unsafe {
|
|
||||||
svp::svp_apply_dft_to_dft(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0) as *mut vec_znx_dft_t,
|
|
||||||
res.size() as u64,
|
|
||||||
res.cols() as u64,
|
|
||||||
a.at_ptr(a_col, 0) as *const svp::svp_ppol_t,
|
|
||||||
b.at_ptr(b_col, 0) as *const vec_znx_dft_t,
|
|
||||||
b.size() as u64,
|
|
||||||
b.cols() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl SvpApplyDftToDftInplaceImpl for FFT64Spqlios {
|
|
||||||
fn svp_apply_dft_to_dft_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxDftToMut<Self>,
|
|
||||||
A: SvpPPolToRef<Self>,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut();
|
|
||||||
let a: SvpPPol<&[u8], Self> = a.to_ref();
|
|
||||||
unsafe {
|
|
||||||
svp::svp_apply_dft_to_dft(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0) as *mut vec_znx_dft_t,
|
|
||||||
res.size() as u64,
|
|
||||||
res.cols() as u64,
|
|
||||||
a.at_ptr(a_col, 0) as *const svp::svp_ppol_t,
|
|
||||||
res.at_ptr(res_col, 0) as *const vec_znx_dft_t,
|
|
||||||
res.size() as u64,
|
|
||||||
res.cols() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,908 +0,0 @@
|
|||||||
use poulpy_hal::{
|
|
||||||
api::{
|
|
||||||
TakeSlice, VecZnxLshTmpBytes, VecZnxMergeRingsTmpBytes, VecZnxNormalizeTmpBytes, VecZnxRshTmpBytes,
|
|
||||||
VecZnxSplitRingTmpBytes,
|
|
||||||
},
|
|
||||||
layouts::{
|
|
||||||
Module, ScalarZnx, ScalarZnxToRef, Scratch, VecZnx, VecZnxToMut, VecZnxToRef, ZnxInfos, ZnxSliceSize, ZnxView, ZnxViewMut,
|
|
||||||
},
|
|
||||||
oep::{
|
|
||||||
TakeSliceImpl, VecZnxAddImpl, VecZnxAddInplaceImpl, VecZnxAddNormalImpl, VecZnxAddScalarImpl, VecZnxAddScalarInplaceImpl,
|
|
||||||
VecZnxAutomorphismImpl, VecZnxAutomorphismInplaceImpl, VecZnxAutomorphismInplaceTmpBytesImpl, VecZnxCopyImpl,
|
|
||||||
VecZnxFillNormalImpl, VecZnxFillUniformImpl, VecZnxLshImpl, VecZnxLshInplaceImpl, VecZnxLshTmpBytesImpl,
|
|
||||||
VecZnxMergeRingsImpl, VecZnxMergeRingsTmpBytesImpl, VecZnxMulXpMinusOneImpl, VecZnxMulXpMinusOneInplaceImpl,
|
|
||||||
VecZnxMulXpMinusOneInplaceTmpBytesImpl, VecZnxNegateImpl, VecZnxNegateInplaceImpl, VecZnxNormalizeImpl,
|
|
||||||
VecZnxNormalizeInplaceImpl, VecZnxNormalizeTmpBytesImpl, VecZnxRotateImpl, VecZnxRotateInplaceImpl,
|
|
||||||
VecZnxRotateInplaceTmpBytesImpl, VecZnxRshImpl, VecZnxRshInplaceImpl, VecZnxRshTmpBytesImpl, VecZnxSplitRingImpl,
|
|
||||||
VecZnxSplitRingTmpBytesImpl, VecZnxSubImpl, VecZnxSubInplaceImpl, VecZnxSubNegateInplaceImpl, VecZnxSubScalarImpl,
|
|
||||||
VecZnxSubScalarInplaceImpl, VecZnxSwitchRingImpl, VecZnxZeroImpl,
|
|
||||||
},
|
|
||||||
reference::{
|
|
||||||
vec_znx::{
|
|
||||||
vec_znx_add_normal_ref, vec_znx_automorphism_inplace_tmp_bytes, vec_znx_copy, vec_znx_fill_normal_ref,
|
|
||||||
vec_znx_fill_uniform_ref, vec_znx_lsh, vec_znx_lsh_inplace, vec_znx_lsh_tmp_bytes, vec_znx_merge_rings,
|
|
||||||
vec_znx_merge_rings_tmp_bytes, vec_znx_mul_xp_minus_one_inplace_tmp_bytes, vec_znx_normalize_tmp_bytes,
|
|
||||||
vec_znx_rotate_inplace_tmp_bytes, vec_znx_rsh, vec_znx_rsh_inplace, vec_znx_rsh_tmp_bytes, vec_znx_split_ring,
|
|
||||||
vec_znx_split_ring_tmp_bytes, vec_znx_switch_ring, vec_znx_zero,
|
|
||||||
},
|
|
||||||
znx::{znx_copy_ref, znx_zero_ref},
|
|
||||||
},
|
|
||||||
source::Source,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::cpu_spqlios::{
|
|
||||||
FFT64Spqlios,
|
|
||||||
ffi::{module::module_info_t, vec_znx, znx},
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe impl VecZnxZeroImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_zero_impl<R>(_module: &Module<Self>, res: &mut R, res_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
{
|
|
||||||
vec_znx_zero::<_, FFT64Spqlios>(res, res_col);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxNormalizeTmpBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_normalize_tmp_bytes_impl(module: &Module<Self>) -> usize {
|
|
||||||
vec_znx_normalize_tmp_bytes(module.n())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxNormalizeImpl<Self> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
Self: TakeSliceImpl<Self> + VecZnxNormalizeTmpBytesImpl<Self>,
|
|
||||||
{
|
|
||||||
fn vec_znx_normalize_impl<R, A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res_basek: usize,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
_a_basek: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
scratch: &mut Scratch<Self>,
|
|
||||||
) where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(res.n(), a.n());
|
|
||||||
assert_eq!(
|
|
||||||
res_basek, _a_basek,
|
|
||||||
"res_basek != a_basek -> base2k conversion is not supported"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
let (tmp_bytes, _) = scratch.take_slice(module.vec_znx_normalize_tmp_bytes());
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_normalize_base2k(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
res_basek as u64,
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
tmp_bytes.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxNormalizeInplaceImpl<Self> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
Self: TakeSliceImpl<Self> + VecZnxNormalizeTmpBytesImpl<Self>,
|
|
||||||
{
|
|
||||||
fn vec_znx_normalize_inplace_impl<A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
base2k: usize,
|
|
||||||
a: &mut A,
|
|
||||||
a_col: usize,
|
|
||||||
scratch: &mut Scratch<Self>,
|
|
||||||
) where
|
|
||||||
A: VecZnxToMut,
|
|
||||||
{
|
|
||||||
let mut a: VecZnx<&mut [u8]> = a.to_mut();
|
|
||||||
|
|
||||||
let (tmp_bytes, _) = scratch.take_slice(module.vec_znx_normalize_tmp_bytes());
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_normalize_base2k(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
base2k as u64,
|
|
||||||
a.at_mut_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
tmp_bytes.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxAddImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_add_impl<R, A, C>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
C: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let b: VecZnx<&[u8]> = b.to_ref();
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
assert_eq!(b.n(), res.n());
|
|
||||||
assert_ne!(a.as_ptr(), b.as_ptr());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_add(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
b.at_ptr(b_col, 0),
|
|
||||||
b.size() as u64,
|
|
||||||
b.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxAddInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_add_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_add(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
res.at_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxAddScalarInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_add_scalar_inplace_impl<R, A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
res_limb: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
) where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: ScalarZnxToRef,
|
|
||||||
{
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
let a: ScalarZnx<&[u8]> = a.to_ref();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_add(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
res.at_mut_ptr(res_col, res_limb),
|
|
||||||
1_u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
res.at_ptr(res_col, res_limb),
|
|
||||||
1_u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxAddScalarImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_add_scalar_impl<R, A, B>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
b: &B,
|
|
||||||
b_col: usize,
|
|
||||||
b_limb: usize,
|
|
||||||
) where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: ScalarZnxToRef,
|
|
||||||
B: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
let a: ScalarZnx<&[u8]> = a.to_ref();
|
|
||||||
let b: VecZnx<&[u8]> = b.to_ref();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
|
|
||||||
let min_size: usize = b.size().min(res.size());
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_add(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
res.at_mut_ptr(res_col, b_limb),
|
|
||||||
1_u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
b.at_ptr(b_col, b_limb),
|
|
||||||
1_u64,
|
|
||||||
b.sl() as u64,
|
|
||||||
);
|
|
||||||
|
|
||||||
for j in 0..min_size {
|
|
||||||
if j != b_limb {
|
|
||||||
znx_copy_ref(res.at_mut(res_col, j), b.at(b_col, j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for j in min_size..res.size() {
|
|
||||||
znx_zero_ref(res.at_mut(res_col, j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxSubImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_sub_impl<R, A, C>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
C: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let b: VecZnx<&[u8]> = b.to_ref();
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
assert_eq!(b.n(), res.n());
|
|
||||||
assert_ne!(a.as_ptr(), b.as_ptr());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_sub(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
b.at_ptr(b_col, 0),
|
|
||||||
b.size() as u64,
|
|
||||||
b.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxSubInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_sub_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_sub(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
res.at_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxSubNegateInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_sub_negate_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_sub(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
res.at_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxSubScalarImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_sub_scalar_impl<R, A, B>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
b: &B,
|
|
||||||
b_col: usize,
|
|
||||||
b_limb: usize,
|
|
||||||
) where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: ScalarZnxToRef,
|
|
||||||
B: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
let a: ScalarZnx<&[u8]> = a.to_ref();
|
|
||||||
let b: VecZnx<&[u8]> = b.to_ref();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
|
|
||||||
let min_size: usize = b.size().min(res.size());
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_sub(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
res.at_mut_ptr(res_col, b_limb),
|
|
||||||
1_u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
b.at_ptr(b_col, b_limb),
|
|
||||||
1_u64,
|
|
||||||
b.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
);
|
|
||||||
|
|
||||||
for j in 0..min_size {
|
|
||||||
if j != b_limb {
|
|
||||||
res.at_mut(res_col, j).copy_from_slice(b.at(b_col, j))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for j in min_size..res.size() {
|
|
||||||
znx_zero_ref(res.at_mut(res_col, j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxSubScalarInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_sub_scalar_inplace_impl<R, A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
res_limb: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
) where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: ScalarZnxToRef,
|
|
||||||
{
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
let a: ScalarZnx<&[u8]> = a.to_ref();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_sub(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
res.at_mut_ptr(res_col, res_limb),
|
|
||||||
1_u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
res.at_ptr(res_col, res_limb),
|
|
||||||
1_u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxNegateImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_negate_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_negate(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxNegateInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_negate_inplace_impl<A>(module: &Module<Self>, a: &mut A, a_col: usize)
|
|
||||||
where
|
|
||||||
A: VecZnxToMut,
|
|
||||||
{
|
|
||||||
let mut a: VecZnx<&mut [u8]> = a.to_mut();
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_negate(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
a.at_mut_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxLshTmpBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_lsh_tmp_bytes_impl(module: &Module<Self>) -> usize {
|
|
||||||
vec_znx_lsh_tmp_bytes(module.n())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxRshTmpBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_rsh_tmp_bytes_impl(module: &Module<Self>) -> usize {
|
|
||||||
vec_znx_rsh_tmp_bytes(module.n())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxLshImpl<Self> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
Module<Self>: VecZnxNormalizeTmpBytes,
|
|
||||||
Scratch<Self>: TakeSlice,
|
|
||||||
{
|
|
||||||
fn vec_znx_lsh_impl<R, A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
base2k: usize,
|
|
||||||
k: usize,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
scratch: &mut Scratch<Self>,
|
|
||||||
) where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let (carry, _) = scratch.take_slice(module.vec_znx_lsh_tmp_bytes() / size_of::<i64>());
|
|
||||||
vec_znx_lsh::<_, _, FFT64Spqlios>(base2k, k, res, res_col, a, a_col, carry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxLshInplaceImpl<Self> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
Module<Self>: VecZnxNormalizeTmpBytes,
|
|
||||||
Scratch<Self>: TakeSlice,
|
|
||||||
{
|
|
||||||
fn vec_znx_lsh_inplace_impl<A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
base2k: usize,
|
|
||||||
k: usize,
|
|
||||||
a: &mut A,
|
|
||||||
a_col: usize,
|
|
||||||
scratch: &mut Scratch<Self>,
|
|
||||||
) where
|
|
||||||
A: VecZnxToMut,
|
|
||||||
{
|
|
||||||
let (carry, _) = scratch.take_slice(module.vec_znx_lsh_tmp_bytes() / size_of::<i64>());
|
|
||||||
vec_znx_lsh_inplace::<_, FFT64Spqlios>(base2k, k, a, a_col, carry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxRshImpl<Self> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
Module<Self>: VecZnxNormalizeTmpBytes,
|
|
||||||
Scratch<Self>: TakeSlice,
|
|
||||||
{
|
|
||||||
fn vec_znx_rsh_impl<R, A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
base2k: usize,
|
|
||||||
k: usize,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
scratch: &mut Scratch<Self>,
|
|
||||||
) where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let (carry, _) = scratch.take_slice(module.vec_znx_rsh_tmp_bytes() / size_of::<i64>());
|
|
||||||
vec_znx_rsh::<_, _, FFT64Spqlios>(base2k, k, res, res_col, a, a_col, carry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxRshInplaceImpl<Self> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
Module<Self>: VecZnxNormalizeTmpBytes,
|
|
||||||
Scratch<Self>: TakeSlice,
|
|
||||||
{
|
|
||||||
fn vec_znx_rsh_inplace_impl<A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
base2k: usize,
|
|
||||||
k: usize,
|
|
||||||
a: &mut A,
|
|
||||||
a_col: usize,
|
|
||||||
scratch: &mut Scratch<Self>,
|
|
||||||
) where
|
|
||||||
A: VecZnxToMut,
|
|
||||||
{
|
|
||||||
let (carry, _) = scratch.take_slice(module.vec_znx_rsh_tmp_bytes() / size_of::<i64>());
|
|
||||||
vec_znx_rsh_inplace::<_, FFT64Spqlios>(base2k, k, a, a_col, carry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxRotateImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_rotate_impl<R, A>(_module: &Module<Self>, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(res.n(), a.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
let min_size = res.size().min(a.size());
|
|
||||||
(0..min_size).for_each(|j| {
|
|
||||||
znx::znx_rotate_i64(
|
|
||||||
a.n() as u64,
|
|
||||||
k,
|
|
||||||
res.at_mut_ptr(res_col, j),
|
|
||||||
a.at_ptr(a_col, j),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
(min_size..res.size()).for_each(|j| {
|
|
||||||
znx_zero_ref(res.at_mut(res_col, j));
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxRotateInplaceTmpBytesImpl<Self> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
Scratch<Self>: TakeSlice,
|
|
||||||
{
|
|
||||||
fn vec_znx_rotate_inplace_tmp_bytes_impl(module: &Module<Self>) -> usize {
|
|
||||||
vec_znx_rotate_inplace_tmp_bytes(module.n())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxRotateInplaceImpl<Self> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
Scratch<Self>: TakeSlice,
|
|
||||||
{
|
|
||||||
fn vec_znx_rotate_inplace_impl<A>(_module: &Module<Self>, k: i64, a: &mut A, a_col: usize, _scratch: &mut Scratch<Self>)
|
|
||||||
where
|
|
||||||
A: VecZnxToMut,
|
|
||||||
{
|
|
||||||
let mut a: VecZnx<&mut [u8]> = a.to_mut();
|
|
||||||
unsafe {
|
|
||||||
(0..a.size()).for_each(|j| {
|
|
||||||
znx::znx_rotate_inplace_i64(a.n() as u64, k, a.at_mut_ptr(a_col, j));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxAutomorphismImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_automorphism_impl<R, A>(module: &Module<Self>, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_automorphism(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
k,
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxAutomorphismInplaceTmpBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_automorphism_inplace_tmp_bytes_impl(module: &Module<Self>) -> usize {
|
|
||||||
vec_znx_automorphism_inplace_tmp_bytes(module.n())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxAutomorphismInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_automorphism_inplace_impl<A>(module: &Module<Self>, k: i64, a: &mut A, a_col: usize, _scratch: &mut Scratch<Self>)
|
|
||||||
where
|
|
||||||
A: VecZnxToMut,
|
|
||||||
{
|
|
||||||
let mut a: VecZnx<&mut [u8]> = a.to_mut();
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert!(k & 1 != 0, "invalid galois element: must be odd but is {k}");
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_automorphism(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
k,
|
|
||||||
a.at_mut_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxMulXpMinusOneImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_mul_xp_minus_one_impl<R, A>(module: &Module<Self>, p: i64, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
assert_eq!(res.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_mul_xp_minus_one(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
p,
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxMulXpMinusOneInplaceTmpBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_mul_xp_minus_one_inplace_tmp_bytes_impl(module: &Module<Self>) -> usize {
|
|
||||||
vec_znx_mul_xp_minus_one_inplace_tmp_bytes(module.n())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxMulXpMinusOneInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_mul_xp_minus_one_inplace_impl<R>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
p: i64,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
_scratch: &mut Scratch<Self>,
|
|
||||||
) where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
{
|
|
||||||
let mut res: VecZnx<&mut [u8]> = res.to_mut();
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(res.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_mul_xp_minus_one(
|
|
||||||
module.ptr() as *const module_info_t,
|
|
||||||
p,
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
res.at_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxSplitRingTmpBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_split_ring_tmp_bytes_impl(module: &Module<Self>) -> usize {
|
|
||||||
vec_znx_split_ring_tmp_bytes(module.n())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxSplitRingImpl<Self> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
Module<Self>: VecZnxSplitRingTmpBytes,
|
|
||||||
Scratch<Self>: TakeSlice,
|
|
||||||
{
|
|
||||||
fn vec_znx_split_ring_impl<R, A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res: &mut [R],
|
|
||||||
res_col: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
scratch: &mut Scratch<Self>,
|
|
||||||
) where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let (tmp, _) = scratch.take_slice(module.vec_znx_split_ring_tmp_bytes() / size_of::<i64>());
|
|
||||||
vec_znx_split_ring::<_, _, FFT64Spqlios>(res, res_col, a, a_col, tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxMergeRingsTmpBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_merge_rings_tmp_bytes_impl(module: &Module<Self>) -> usize {
|
|
||||||
vec_znx_merge_rings_tmp_bytes(module.n())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxMergeRingsImpl<Self> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
Module<Self>: VecZnxMergeRingsTmpBytes,
|
|
||||||
{
|
|
||||||
fn vec_znx_merge_rings_impl<R, A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
a: &[A],
|
|
||||||
a_col: usize,
|
|
||||||
scratch: &mut Scratch<Self>,
|
|
||||||
) where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let (tmp, _) = scratch.take_slice(module.vec_znx_merge_rings_tmp_bytes() / size_of::<i64>());
|
|
||||||
vec_znx_merge_rings::<_, _, FFT64Spqlios>(res, res_col, a, a_col, tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxSwitchRingImpl<Self> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
Self: VecZnxCopyImpl<Self>,
|
|
||||||
{
|
|
||||||
fn vec_znx_switch_ring_impl<R, A>(_module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
vec_znx_switch_ring::<_, _, FFT64Spqlios>(res, res_col, a, a_col);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxCopyImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_copy_impl<R, A>(_module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
vec_znx_copy::<_, _, FFT64Spqlios>(res, res_col, a, a_col)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxFillUniformImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_fill_uniform_impl<R>(_module: &Module<Self>, base2k: usize, res: &mut R, res_col: usize, source: &mut Source)
|
|
||||||
where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
{
|
|
||||||
vec_znx_fill_uniform_ref(base2k, res, res_col, source)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxFillNormalImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_fill_normal_impl<R>(
|
|
||||||
_module: &Module<Self>,
|
|
||||||
base2k: usize,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
k: usize,
|
|
||||||
source: &mut Source,
|
|
||||||
sigma: f64,
|
|
||||||
bound: f64,
|
|
||||||
) where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
{
|
|
||||||
vec_znx_fill_normal_ref(base2k, res, res_col, k, sigma, bound, source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxAddNormalImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_add_normal_impl<R>(
|
|
||||||
_module: &Module<Self>,
|
|
||||||
base2k: usize,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
k: usize,
|
|
||||||
source: &mut Source,
|
|
||||||
sigma: f64,
|
|
||||||
bound: f64,
|
|
||||||
) where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
{
|
|
||||||
vec_znx_add_normal_ref(base2k, res, res_col, k, sigma, bound, source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,621 +0,0 @@
|
|||||||
use crate::cpu_spqlios::{FFT64Spqlios, ffi::vec_znx};
|
|
||||||
use poulpy_hal::{
|
|
||||||
api::{TakeSlice, VecZnxBigNormalizeTmpBytes},
|
|
||||||
layouts::{
|
|
||||||
Backend, Module, Scratch, VecZnx, VecZnxBig, VecZnxBigOwned, VecZnxBigToMut, VecZnxBigToRef, VecZnxToMut, VecZnxToRef,
|
|
||||||
ZnxInfos, ZnxSliceSize, ZnxView, ZnxViewMut,
|
|
||||||
},
|
|
||||||
oep::{
|
|
||||||
TakeSliceImpl, VecZnxBigAddImpl, VecZnxBigAddInplaceImpl, VecZnxBigAddNormalImpl, VecZnxBigAddSmallImpl,
|
|
||||||
VecZnxBigAddSmallInplaceImpl, VecZnxBigAllocBytesImpl, VecZnxBigAllocImpl, VecZnxBigAutomorphismImpl,
|
|
||||||
VecZnxBigAutomorphismInplaceImpl, VecZnxBigAutomorphismInplaceTmpBytesImpl, VecZnxBigFromBytesImpl,
|
|
||||||
VecZnxBigFromSmallImpl, VecZnxBigNegateImpl, VecZnxBigNegateInplaceImpl, VecZnxBigNormalizeImpl,
|
|
||||||
VecZnxBigNormalizeTmpBytesImpl, VecZnxBigSubImpl, VecZnxBigSubInplaceImpl, VecZnxBigSubNegateInplaceImpl,
|
|
||||||
VecZnxBigSubSmallAImpl, VecZnxBigSubSmallBImpl, VecZnxBigSubSmallInplaceImpl, VecZnxBigSubSmallNegateInplaceImpl,
|
|
||||||
},
|
|
||||||
reference::{
|
|
||||||
fft64::vec_znx_big::vec_znx_big_normalize,
|
|
||||||
vec_znx::{vec_znx_add_normal_ref, vec_znx_normalize_tmp_bytes},
|
|
||||||
znx::{znx_copy_ref, znx_zero_ref},
|
|
||||||
},
|
|
||||||
source::Source,
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigAllocBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_big_bytes_of_impl(n: usize, cols: usize, size: usize) -> usize {
|
|
||||||
Self::layout_big_word_count() * n * cols * size * size_of::<f64>()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigAllocImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_big_alloc_impl(n: usize, cols: usize, size: usize) -> VecZnxBigOwned<Self> {
|
|
||||||
VecZnxBig::alloc(n, cols, size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigFromBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_big_from_bytes_impl(n: usize, cols: usize, size: usize, bytes: Vec<u8>) -> VecZnxBigOwned<Self> {
|
|
||||||
VecZnxBig::from_bytes(n, cols, size, bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigFromSmallImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_big_from_small_impl<R, A>(res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(res.n(), a.n());
|
|
||||||
}
|
|
||||||
|
|
||||||
let res_size: usize = res.size();
|
|
||||||
let a_size: usize = a.size();
|
|
||||||
|
|
||||||
let min_size: usize = res_size.min(a_size);
|
|
||||||
|
|
||||||
for j in 0..min_size {
|
|
||||||
znx_copy_ref(res.at_mut(res_col, j), a.at(a_col, j));
|
|
||||||
}
|
|
||||||
|
|
||||||
for j in min_size..res_size {
|
|
||||||
znx_zero_ref(res.at_mut(res_col, j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigAddNormalImpl<Self> for FFT64Spqlios {
|
|
||||||
fn add_normal_impl<R: VecZnxBigToMut<Self>>(
|
|
||||||
_module: &Module<Self>,
|
|
||||||
base2k: usize,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
k: usize,
|
|
||||||
source: &mut Source,
|
|
||||||
sigma: f64,
|
|
||||||
bound: f64,
|
|
||||||
) {
|
|
||||||
let res: VecZnxBig<&mut [u8], FFT64Spqlios> = res.to_mut();
|
|
||||||
|
|
||||||
let mut res_znx: VecZnx<&mut [u8]> = VecZnx {
|
|
||||||
data: res.data,
|
|
||||||
n: res.n,
|
|
||||||
cols: res.cols,
|
|
||||||
size: res.size,
|
|
||||||
max_size: res.max_size,
|
|
||||||
};
|
|
||||||
|
|
||||||
vec_znx_add_normal_ref(base2k, &mut res_znx, res_col, k, sigma, bound, source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigAddImpl<Self> for FFT64Spqlios {
|
|
||||||
/// Adds `a` to `b` and stores the result on `c`.
|
|
||||||
fn vec_znx_big_add_impl<R, A, B>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &B, b_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxBigToRef<Self>,
|
|
||||||
B: VecZnxBigToRef<Self>,
|
|
||||||
{
|
|
||||||
let a: VecZnxBig<&[u8], Self> = a.to_ref();
|
|
||||||
let b: VecZnxBig<&[u8], Self> = b.to_ref();
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
assert_eq!(b.n(), res.n());
|
|
||||||
assert_ne!(a.as_ptr(), b.as_ptr());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_add(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
b.at_ptr(b_col, 0),
|
|
||||||
b.size() as u64,
|
|
||||||
b.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigAddInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
/// Adds `a` to `b` and stores the result on `b`.
|
|
||||||
fn vec_znx_big_add_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxBigToRef<Self>,
|
|
||||||
{
|
|
||||||
let a: VecZnxBig<&[u8], Self> = a.to_ref();
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_add(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
res.at_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigAddSmallImpl<Self> for FFT64Spqlios {
|
|
||||||
/// Adds `a` to `b` and stores the result on `c`.
|
|
||||||
fn vec_znx_big_add_small_impl<R, A, B>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
b: &B,
|
|
||||||
b_col: usize,
|
|
||||||
) where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxBigToRef<Self>,
|
|
||||||
B: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnxBig<&[u8], Self> = a.to_ref();
|
|
||||||
let b: VecZnx<&[u8]> = b.to_ref();
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
assert_eq!(b.n(), res.n());
|
|
||||||
assert_ne!(a.as_ptr(), b.as_ptr());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_add(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
b.at_ptr(b_col, 0),
|
|
||||||
b.size() as u64,
|
|
||||||
b.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigAddSmallInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
/// Adds `a` to `b` and stores the result on `b`.
|
|
||||||
fn vec_znx_big_add_small_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_add(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
res.at_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigSubImpl<Self> for FFT64Spqlios {
|
|
||||||
/// Subtracts `a` to `b` and stores the result on `c`.
|
|
||||||
fn vec_znx_big_sub_impl<R, A, B>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &B, b_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxBigToRef<Self>,
|
|
||||||
B: VecZnxBigToRef<Self>,
|
|
||||||
{
|
|
||||||
let a: VecZnxBig<&[u8], Self> = a.to_ref();
|
|
||||||
let b: VecZnxBig<&[u8], Self> = b.to_ref();
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
assert_eq!(b.n(), res.n());
|
|
||||||
assert_ne!(a.as_ptr(), b.as_ptr());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_sub(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
b.at_ptr(b_col, 0),
|
|
||||||
b.size() as u64,
|
|
||||||
b.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigSubInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
/// Subtracts `a` from `b` and stores the result on `b`.
|
|
||||||
fn vec_znx_big_sub_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxBigToRef<Self>,
|
|
||||||
{
|
|
||||||
let a: VecZnxBig<&[u8], Self> = a.to_ref();
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_sub(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
res.at_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigSubNegateInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
/// Subtracts `b` from `a` and stores the result on `b`.
|
|
||||||
fn vec_znx_big_sub_negate_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxBigToRef<Self>,
|
|
||||||
{
|
|
||||||
let a: VecZnxBig<&[u8], Self> = a.to_ref();
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_sub(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
res.at_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigSubSmallAImpl<Self> for FFT64Spqlios {
|
|
||||||
/// Subtracts `b` from `a` and stores the result on `c`.
|
|
||||||
fn vec_znx_big_sub_small_a_impl<R, A, B>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
b: &B,
|
|
||||||
b_col: usize,
|
|
||||||
) where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
B: VecZnxBigToRef<Self>,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let b: VecZnxBig<&[u8], Self> = b.to_ref();
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
assert_eq!(b.n(), res.n());
|
|
||||||
assert_ne!(a.as_ptr(), b.as_ptr());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_sub(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
b.at_ptr(b_col, 0),
|
|
||||||
b.size() as u64,
|
|
||||||
b.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigSubSmallInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
/// Subtracts `a` from `res` and stores the result on `res`.
|
|
||||||
fn vec_znx_big_sub_small_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_sub(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
res.at_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigSubSmallBImpl<Self> for FFT64Spqlios {
|
|
||||||
/// Subtracts `b` from `a` and stores the result on `c`.
|
|
||||||
fn vec_znx_big_sub_small_b_impl<R, A, B>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
b: &B,
|
|
||||||
b_col: usize,
|
|
||||||
) where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxBigToRef<Self>,
|
|
||||||
B: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnxBig<&[u8], Self> = a.to_ref();
|
|
||||||
let b: VecZnx<&[u8]> = b.to_ref();
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
assert_eq!(b.n(), res.n());
|
|
||||||
assert_ne!(a.as_ptr(), b.as_ptr());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_sub(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
b.at_ptr(b_col, 0),
|
|
||||||
b.size() as u64,
|
|
||||||
b.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigSubSmallNegateInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
/// Subtracts `res` from `a` and stores the result on `res`.
|
|
||||||
fn vec_znx_big_sub_small_negate_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_sub(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
res.at_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigNegateImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_big_negate_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxBigToRef<Self>,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
let a: VecZnxBig<&[u8], Self> = a.to_ref();
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_negate(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigNegateInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_big_negate_inplace_impl<A>(module: &Module<Self>, a: &mut A, a_col: usize)
|
|
||||||
where
|
|
||||||
A: VecZnxBigToMut<Self>,
|
|
||||||
{
|
|
||||||
let mut a: VecZnxBig<&mut [u8], Self> = a.to_mut();
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_negate(
|
|
||||||
module.ptr(),
|
|
||||||
a.at_mut_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigNormalizeTmpBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_big_normalize_tmp_bytes_impl(module: &Module<Self>) -> usize {
|
|
||||||
vec_znx_normalize_tmp_bytes(module.n())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigNormalizeImpl<Self> for FFT64Spqlios
|
|
||||||
where
|
|
||||||
Self: TakeSliceImpl<Self>,
|
|
||||||
{
|
|
||||||
fn vec_znx_big_normalize_impl<R, A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res_basek: usize,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
a_basek: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
scratch: &mut Scratch<Self>,
|
|
||||||
) where
|
|
||||||
R: VecZnxToMut,
|
|
||||||
A: VecZnxBigToRef<Self>,
|
|
||||||
{
|
|
||||||
let (carry, _) = scratch.take_slice(module.vec_znx_big_normalize_tmp_bytes() / size_of::<i64>());
|
|
||||||
// unsafe {
|
|
||||||
// vec_znx::vec_znx_normalize_base2k(
|
|
||||||
// module.ptr(),
|
|
||||||
// base2k as u64,
|
|
||||||
// res.at_mut_ptr(res_col, 0),
|
|
||||||
// res.size() as u64,
|
|
||||||
// res.sl() as u64,
|
|
||||||
// a.at_ptr(a_col, 0),
|
|
||||||
// a.size() as u64,
|
|
||||||
// a.sl() as u64,
|
|
||||||
// tmp_bytes.as_mut_ptr(),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
vec_znx_big_normalize(res_basek, res, res_col, a_basek, a, a_col, carry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigAutomorphismImpl<Self> for FFT64Spqlios {
|
|
||||||
/// Applies the automorphism X^i -> X^ik on `a` and stores the result on `b`.
|
|
||||||
fn vec_znx_big_automorphism_impl<R, A>(module: &Module<Self>, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxBigToRef<Self>,
|
|
||||||
{
|
|
||||||
let a: VecZnxBig<&[u8], Self> = a.to_ref();
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_automorphism(
|
|
||||||
module.ptr(),
|
|
||||||
k,
|
|
||||||
res.at_mut_ptr(res_col, 0),
|
|
||||||
res.size() as u64,
|
|
||||||
res.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigAutomorphismInplaceTmpBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_big_automorphism_inplace_tmp_bytes_impl(_module: &Module<Self>) -> usize {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigAutomorphismInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
/// Applies the automorphism X^i -> X^ik on `a` and stores the result on `a`.
|
|
||||||
fn vec_znx_big_automorphism_inplace_impl<A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
k: i64,
|
|
||||||
a: &mut A,
|
|
||||||
a_col: usize,
|
|
||||||
_scratch: &mut Scratch<Self>,
|
|
||||||
) where
|
|
||||||
A: VecZnxBigToMut<Self>,
|
|
||||||
{
|
|
||||||
let mut a: VecZnxBig<&mut [u8], Self> = a.to_mut();
|
|
||||||
unsafe {
|
|
||||||
vec_znx::vec_znx_automorphism(
|
|
||||||
module.ptr(),
|
|
||||||
k,
|
|
||||||
a.at_mut_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
a.at_ptr(a_col, 0),
|
|
||||||
a.size() as u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,435 +0,0 @@
|
|||||||
use poulpy_hal::{
|
|
||||||
api::{TakeSlice, VecZnxIdftApplyTmpBytes},
|
|
||||||
layouts::{
|
|
||||||
Backend, Data, Module, Scratch, VecZnx, VecZnxBig, VecZnxBigToMut, VecZnxDft, VecZnxDftOwned, VecZnxDftToMut,
|
|
||||||
VecZnxDftToRef, VecZnxToRef, ZnxInfos, ZnxSliceSize, ZnxView, ZnxViewMut,
|
|
||||||
},
|
|
||||||
oep::{
|
|
||||||
VecZnxDftAddImpl, VecZnxDftAddInplaceImpl, VecZnxDftAllocBytesImpl, VecZnxDftAllocImpl, VecZnxDftApplyImpl,
|
|
||||||
VecZnxDftCopyImpl, VecZnxDftFromBytesImpl, VecZnxDftSubImpl, VecZnxDftSubInplaceImpl, VecZnxDftSubNegateInplaceImpl,
|
|
||||||
VecZnxDftZeroImpl, VecZnxIdftApplyConsumeImpl, VecZnxIdftApplyImpl, VecZnxIdftApplyTmpAImpl, VecZnxIdftApplyTmpBytesImpl,
|
|
||||||
},
|
|
||||||
reference::{
|
|
||||||
fft64::{
|
|
||||||
reim::{ReimCopy, ReimZero, reim_copy_ref, reim_negate_inplace_ref, reim_negate_ref, reim_zero_ref},
|
|
||||||
vec_znx_dft::{vec_znx_dft_copy, vec_znx_dft_zero},
|
|
||||||
},
|
|
||||||
znx::znx_zero_ref,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::cpu_spqlios::{
|
|
||||||
FFT64Spqlios,
|
|
||||||
ffi::{vec_znx_big, vec_znx_dft},
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe impl VecZnxDftFromBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_dft_from_bytes_impl(n: usize, cols: usize, size: usize, bytes: Vec<u8>) -> VecZnxDftOwned<Self> {
|
|
||||||
VecZnxDft::<Vec<u8>, Self>::from_bytes(n, cols, size, bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxDftAllocBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_dft_bytes_of_impl(n: usize, cols: usize, size: usize) -> usize {
|
|
||||||
Self::layout_prep_word_count() * n * cols * size * size_of::<<FFT64Spqlios as Backend>::ScalarPrep>()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxDftAllocImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_dft_alloc_impl(n: usize, cols: usize, size: usize) -> VecZnxDftOwned<Self> {
|
|
||||||
VecZnxDftOwned::alloc(n, cols, size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxIdftApplyTmpBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_idft_apply_tmp_bytes_impl(module: &Module<Self>) -> usize {
|
|
||||||
unsafe { vec_znx_dft::vec_znx_idft_tmp_bytes(module.ptr()) as usize }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxIdftApplyImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_idft_apply_impl<R, A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
scratch: &mut Scratch<Self>,
|
|
||||||
) where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxDftToRef<Self>,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
let a: VecZnxDft<&[u8], Self> = a.to_ref();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(res.n(), a.n())
|
|
||||||
}
|
|
||||||
|
|
||||||
let (tmp_bytes, _) = scratch.take_slice(module.vec_znx_idft_apply_tmp_bytes());
|
|
||||||
|
|
||||||
let min_size: usize = res.size().min(a.size());
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
(0..min_size).for_each(|j| {
|
|
||||||
vec_znx_dft::vec_znx_idft(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, j) as *mut vec_znx_big::vec_znx_big_t,
|
|
||||||
1_u64,
|
|
||||||
a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1_u64,
|
|
||||||
tmp_bytes.as_mut_ptr(),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
(min_size..res.size()).for_each(|j| znx_zero_ref(res.at_mut(res_col, j)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxIdftApplyTmpAImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_idft_apply_tmpa_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &mut A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxBigToMut<Self>,
|
|
||||||
A: VecZnxDftToMut<Self>,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxBig<&mut [u8], Self> = res.to_mut();
|
|
||||||
let mut a_mut: VecZnxDft<&mut [u8], Self> = a.to_mut();
|
|
||||||
|
|
||||||
let min_size: usize = res.size().min(a_mut.size());
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
(0..min_size).for_each(|j| {
|
|
||||||
vec_znx_dft::vec_znx_idft_tmp_a(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, j) as *mut vec_znx_big::vec_znx_big_t,
|
|
||||||
1_u64,
|
|
||||||
a_mut.at_mut_ptr(a_col, j) as *mut vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1_u64,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
(min_size..res.size()).for_each(|j| znx_zero_ref(res.at_mut(res_col, j)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxIdftApplyConsumeImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_idft_apply_consume_impl<D: Data>(module: &Module<Self>, mut a: VecZnxDft<D, Self>) -> VecZnxBig<D, Self>
|
|
||||||
where
|
|
||||||
VecZnxDft<D, Self>: VecZnxDftToMut<Self>,
|
|
||||||
{
|
|
||||||
let mut a_mut: VecZnxDft<&mut [u8], Self> = a.to_mut();
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
// Rev col and rows because ZnxDft.sl() >= ZnxBig.sl()
|
|
||||||
(0..a_mut.size()).for_each(|j| {
|
|
||||||
(0..a_mut.cols()).for_each(|i| {
|
|
||||||
vec_znx_dft::vec_znx_idft_tmp_a(
|
|
||||||
module.ptr(),
|
|
||||||
a_mut.at_mut_ptr(i, j) as *mut vec_znx_big::vec_znx_big_t,
|
|
||||||
1_u64,
|
|
||||||
a_mut.at_mut_ptr(i, j) as *mut vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1_u64,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
a.into_big()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxDftApplyImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_dft_apply_impl<R, A>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
step: usize,
|
|
||||||
offset: usize,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
) where
|
|
||||||
R: VecZnxDftToMut<Self>,
|
|
||||||
A: VecZnxToRef,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut();
|
|
||||||
let a: VecZnx<&[u8]> = a.to_ref();
|
|
||||||
let steps: usize = a.size().div_ceil(step);
|
|
||||||
let min_steps: usize = res.size().min(steps);
|
|
||||||
unsafe {
|
|
||||||
(0..min_steps).for_each(|j| {
|
|
||||||
let limb: usize = offset + j * step;
|
|
||||||
if limb < a.size() {
|
|
||||||
vec_znx_dft::vec_znx_dft(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1_u64,
|
|
||||||
a.at_ptr(a_col, limb),
|
|
||||||
1_u64,
|
|
||||||
a.sl() as u64,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
(min_steps..res.size()).for_each(|j| reim_zero_ref(res.at_mut(res_col, j)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxDftAddImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_dft_add_impl<R, A, D>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &D, b_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxDftToMut<Self>,
|
|
||||||
A: VecZnxDftToRef<Self>,
|
|
||||||
D: VecZnxDftToRef<Self>,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut();
|
|
||||||
let a: VecZnxDft<&[u8], Self> = a.to_ref();
|
|
||||||
let b: VecZnxDft<&[u8], Self> = b.to_ref();
|
|
||||||
|
|
||||||
let res_size: usize = res.size();
|
|
||||||
let a_size: usize = a.size();
|
|
||||||
let b_size: usize = b.size();
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
if a_size <= b_size {
|
|
||||||
let sum_size: usize = a_size.min(res_size);
|
|
||||||
let cpy_size: usize = b_size.min(res_size);
|
|
||||||
|
|
||||||
(0..sum_size).for_each(|j| {
|
|
||||||
vec_znx_dft::vec_dft_add(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
b.at_ptr(b_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
for j in sum_size..cpy_size {
|
|
||||||
reim_copy_ref(res.at_mut(res_col, j), b.at(b_col, j));
|
|
||||||
}
|
|
||||||
|
|
||||||
for j in cpy_size..res_size {
|
|
||||||
reim_zero_ref(res.at_mut(res_col, j));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let sum_size: usize = b_size.min(res_size);
|
|
||||||
let cpy_size: usize = a_size.min(res_size);
|
|
||||||
|
|
||||||
(0..sum_size).for_each(|j| {
|
|
||||||
vec_znx_dft::vec_dft_add(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
b.at_ptr(b_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
for j in sum_size..cpy_size {
|
|
||||||
reim_copy_ref(res.at_mut(res_col, j), a.at(b_col, j));
|
|
||||||
}
|
|
||||||
|
|
||||||
for j in cpy_size..res_size {
|
|
||||||
reim_zero_ref(res.at_mut(res_col, j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxDftAddInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_dft_add_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxDftToMut<Self>,
|
|
||||||
A: VecZnxDftToRef<Self>,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut();
|
|
||||||
let a: VecZnxDft<&[u8], Self> = a.to_ref();
|
|
||||||
|
|
||||||
let min_size: usize = res.size().min(a.size());
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
(0..min_size).for_each(|j| {
|
|
||||||
vec_znx_dft::vec_dft_add(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
res.at_ptr(res_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxDftSubImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_dft_sub_impl<R, A, D>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &D, b_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxDftToMut<Self>,
|
|
||||||
A: VecZnxDftToRef<Self>,
|
|
||||||
D: VecZnxDftToRef<Self>,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut();
|
|
||||||
let a: VecZnxDft<&[u8], Self> = a.to_ref();
|
|
||||||
let b: VecZnxDft<&[u8], Self> = b.to_ref();
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
let res_size: usize = res.size();
|
|
||||||
let a_size: usize = a.size();
|
|
||||||
let b_size: usize = b.size();
|
|
||||||
|
|
||||||
if a_size <= b_size {
|
|
||||||
let sum_size: usize = a_size.min(res_size);
|
|
||||||
let cpy_size: usize = b_size.min(res_size);
|
|
||||||
|
|
||||||
(0..sum_size).for_each(|j| {
|
|
||||||
vec_znx_dft::vec_dft_sub(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
b.at_ptr(b_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
for j in sum_size..cpy_size {
|
|
||||||
reim_negate_ref(res.at_mut(res_col, j), b.at(b_col, j));
|
|
||||||
}
|
|
||||||
|
|
||||||
for j in cpy_size..res_size {
|
|
||||||
reim_zero_ref(res.at_mut(res_col, j));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let sum_size: usize = b_size.min(res_size);
|
|
||||||
let cpy_size: usize = a_size.min(res_size);
|
|
||||||
|
|
||||||
(0..sum_size).for_each(|j| {
|
|
||||||
vec_znx_dft::vec_dft_sub(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
b.at_ptr(b_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
for j in sum_size..cpy_size {
|
|
||||||
reim_copy_ref(res.at_mut(res_col, j), a.at(a_col, j));
|
|
||||||
}
|
|
||||||
|
|
||||||
for j in cpy_size..res_size {
|
|
||||||
reim_zero_ref(res.at_mut(res_col, j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxDftSubInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_dft_sub_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxDftToMut<Self>,
|
|
||||||
A: VecZnxDftToRef<Self>,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut();
|
|
||||||
let a: VecZnxDft<&[u8], Self> = a.to_ref();
|
|
||||||
|
|
||||||
let min_size: usize = res.size().min(a.size());
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
(0..min_size).for_each(|j| {
|
|
||||||
vec_znx_dft::vec_dft_sub(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
res.at_ptr(res_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxDftSubNegateInplaceImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_dft_sub_negate_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxDftToMut<Self>,
|
|
||||||
A: VecZnxDftToRef<Self>,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxDft<&mut [u8], Self> = res.to_mut();
|
|
||||||
let a: VecZnxDft<&[u8], Self> = a.to_ref();
|
|
||||||
|
|
||||||
let min_size: usize = res.size().min(a.size());
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
(0..min_size).for_each(|j| {
|
|
||||||
vec_znx_dft::vec_dft_sub(
|
|
||||||
module.ptr(),
|
|
||||||
res.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
res.at_ptr(res_col, j) as *const vec_znx_dft::vec_znx_dft_t,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
for j in min_size..res.size() {
|
|
||||||
reim_negate_inplace_ref(res.at_mut(res_col, j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxDftCopyImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_dft_copy_impl<R, A>(
|
|
||||||
_module: &Module<Self>,
|
|
||||||
step: usize,
|
|
||||||
offset: usize,
|
|
||||||
res: &mut R,
|
|
||||||
res_col: usize,
|
|
||||||
a: &A,
|
|
||||||
a_col: usize,
|
|
||||||
) where
|
|
||||||
R: VecZnxDftToMut<Self>,
|
|
||||||
A: VecZnxDftToRef<Self>,
|
|
||||||
{
|
|
||||||
vec_znx_dft_copy(step, offset, res, res_col, a, a_col);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ReimCopy for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn reim_copy(res: &mut [f64], a: &[f64]) {
|
|
||||||
reim_copy_ref(res, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ReimZero for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn reim_zero(res: &mut [f64]) {
|
|
||||||
reim_zero_ref(res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxDftZeroImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vec_znx_dft_zero_impl<R>(_module: &Module<Self>, res: &mut R, res_col: usize)
|
|
||||||
where
|
|
||||||
R: VecZnxDftToMut<Self>,
|
|
||||||
{
|
|
||||||
vec_znx_dft_zero(res, res_col);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,281 +0,0 @@
|
|||||||
use poulpy_hal::{
|
|
||||||
api::{TakeSlice, VmpApplyDftToDftTmpBytes, VmpPrepareTmpBytes},
|
|
||||||
layouts::{
|
|
||||||
Backend, MatZnx, MatZnxToRef, Module, Scratch, VecZnxDft, VecZnxDftToMut, VecZnxDftToRef, VmpPMat, VmpPMatOwned,
|
|
||||||
VmpPMatToMut, VmpPMatToRef, ZnxInfos, ZnxView, ZnxViewMut,
|
|
||||||
},
|
|
||||||
oep::{
|
|
||||||
VmpApplyDftToDftAddImpl, VmpApplyDftToDftAddTmpBytesImpl, VmpApplyDftToDftImpl, VmpApplyDftToDftTmpBytesImpl,
|
|
||||||
VmpPMatAllocBytesImpl, VmpPMatAllocImpl, VmpPMatFromBytesImpl, VmpPrepareImpl, VmpPrepareTmpBytesImpl, VmpZeroImpl,
|
|
||||||
},
|
|
||||||
reference::fft64::vmp::vmp_zero,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::cpu_spqlios::{
|
|
||||||
FFT64Spqlios,
|
|
||||||
ffi::{vec_znx_dft::vec_znx_dft_t, vmp},
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe impl VmpPMatAllocBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vmp_pmat_bytes_of_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize {
|
|
||||||
Self::layout_prep_word_count() * n * rows * cols_in * cols_out * size * size_of::<f64>()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VmpPMatFromBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vmp_pmat_from_bytes_impl(
|
|
||||||
n: usize,
|
|
||||||
rows: usize,
|
|
||||||
cols_in: usize,
|
|
||||||
cols_out: usize,
|
|
||||||
size: usize,
|
|
||||||
bytes: Vec<u8>,
|
|
||||||
) -> VmpPMatOwned<Self> {
|
|
||||||
VmpPMatOwned::from_bytes(n, rows, cols_in, cols_out, size, bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VmpPMatAllocImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vmp_pmat_alloc_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> VmpPMatOwned<Self> {
|
|
||||||
VmpPMatOwned::alloc(n, rows, cols_in, cols_out, size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VmpPrepareTmpBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vmp_prepare_tmp_bytes_impl(module: &Module<Self>, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize {
|
|
||||||
unsafe {
|
|
||||||
vmp::vmp_prepare_tmp_bytes(
|
|
||||||
module.ptr(),
|
|
||||||
(rows * cols_in) as u64,
|
|
||||||
(cols_out * size) as u64,
|
|
||||||
) as usize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VmpPrepareImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vmp_prepare_impl<R, A>(module: &Module<Self>, res: &mut R, a: &A, scratch: &mut Scratch<Self>)
|
|
||||||
where
|
|
||||||
R: VmpPMatToMut<Self>,
|
|
||||||
A: MatZnxToRef,
|
|
||||||
{
|
|
||||||
let mut res: VmpPMat<&mut [u8], Self> = res.to_mut();
|
|
||||||
let a: MatZnx<&[u8]> = a.to_ref();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
assert_eq!(
|
|
||||||
res.cols_in(),
|
|
||||||
a.cols_in(),
|
|
||||||
"res.cols_in: {} != a.cols_in: {}",
|
|
||||||
res.cols_in(),
|
|
||||||
a.cols_in()
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
res.rows(),
|
|
||||||
a.rows(),
|
|
||||||
"res.rows: {} != a.rows: {}",
|
|
||||||
res.rows(),
|
|
||||||
a.rows()
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
res.cols_out(),
|
|
||||||
a.cols_out(),
|
|
||||||
"res.cols_out: {} != a.cols_out: {}",
|
|
||||||
res.cols_out(),
|
|
||||||
a.cols_out()
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
res.size(),
|
|
||||||
a.size(),
|
|
||||||
"res.size: {} != a.size: {}",
|
|
||||||
res.size(),
|
|
||||||
a.size()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let (tmp_bytes, _) = scratch.take_slice(module.vmp_prepare_tmp_bytes(a.rows(), a.cols_in(), a.cols_out(), a.size()));
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
vmp::vmp_prepare_contiguous(
|
|
||||||
module.ptr(),
|
|
||||||
res.as_mut_ptr() as *mut vmp::vmp_pmat_t,
|
|
||||||
a.as_ptr(),
|
|
||||||
(a.rows() * a.cols_in()) as u64,
|
|
||||||
(a.size() * a.cols_out()) as u64,
|
|
||||||
tmp_bytes.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VmpApplyDftToDftTmpBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vmp_apply_dft_to_dft_tmp_bytes_impl(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res_size: usize,
|
|
||||||
a_size: usize,
|
|
||||||
b_rows: usize,
|
|
||||||
b_cols_in: usize,
|
|
||||||
b_cols_out: usize,
|
|
||||||
b_size: usize,
|
|
||||||
) -> usize {
|
|
||||||
unsafe {
|
|
||||||
vmp::vmp_apply_dft_to_dft_tmp_bytes(
|
|
||||||
module.ptr(),
|
|
||||||
(res_size * b_cols_out) as u64,
|
|
||||||
(a_size * b_cols_in) as u64,
|
|
||||||
(b_rows * b_cols_in) as u64,
|
|
||||||
(b_size * b_cols_out) as u64,
|
|
||||||
) as usize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VmpApplyDftToDftImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vmp_apply_dft_to_dft_impl<R, A, C>(module: &Module<Self>, res: &mut R, a: &A, b: &C, scratch: &mut Scratch<Self>)
|
|
||||||
where
|
|
||||||
R: VecZnxDftToMut<Self>,
|
|
||||||
A: VecZnxDftToRef<Self>,
|
|
||||||
C: VmpPMatToRef<Self>,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxDft<&mut [u8], _> = res.to_mut();
|
|
||||||
let a: VecZnxDft<&[u8], _> = a.to_ref();
|
|
||||||
let b: VmpPMat<&[u8], _> = b.to_ref();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(b.n(), res.n());
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
assert_eq!(
|
|
||||||
res.cols(),
|
|
||||||
b.cols_out(),
|
|
||||||
"res.cols(): {} != b.cols_out: {}",
|
|
||||||
res.cols(),
|
|
||||||
b.cols_out()
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
a.cols(),
|
|
||||||
b.cols_in(),
|
|
||||||
"a.cols(): {} != b.cols_in: {}",
|
|
||||||
a.cols(),
|
|
||||||
b.cols_in()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let (tmp_bytes, _) = scratch.take_slice(module.vmp_apply_dft_to_dft_tmp_bytes(
|
|
||||||
res.size(),
|
|
||||||
a.size(),
|
|
||||||
b.rows(),
|
|
||||||
b.cols_in(),
|
|
||||||
b.cols_out(),
|
|
||||||
b.size(),
|
|
||||||
));
|
|
||||||
unsafe {
|
|
||||||
vmp::vmp_apply_dft_to_dft(
|
|
||||||
module.ptr(),
|
|
||||||
res.as_mut_ptr() as *mut vec_znx_dft_t,
|
|
||||||
(res.size() * res.cols()) as u64,
|
|
||||||
a.as_ptr() as *const vec_znx_dft_t,
|
|
||||||
(a.size() * a.cols()) as u64,
|
|
||||||
b.as_ptr() as *const vmp::vmp_pmat_t,
|
|
||||||
(b.rows() * b.cols_in()) as u64,
|
|
||||||
(b.size() * b.cols_out()) as u64,
|
|
||||||
tmp_bytes.as_mut_ptr(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VmpApplyDftToDftAddTmpBytesImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vmp_apply_dft_to_dft_add_tmp_bytes_impl(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res_size: usize,
|
|
||||||
a_size: usize,
|
|
||||||
b_rows: usize,
|
|
||||||
b_cols_in: usize,
|
|
||||||
b_cols_out: usize,
|
|
||||||
b_size: usize,
|
|
||||||
) -> usize {
|
|
||||||
unsafe {
|
|
||||||
vmp::vmp_apply_dft_to_dft_tmp_bytes(
|
|
||||||
module.ptr(),
|
|
||||||
(res_size * b_cols_out) as u64,
|
|
||||||
(a_size * b_cols_in) as u64,
|
|
||||||
(b_rows * b_cols_in) as u64,
|
|
||||||
(b_size * b_cols_out) as u64,
|
|
||||||
) as usize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VmpApplyDftToDftAddImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vmp_apply_dft_to_dft_add_impl<R, A, C>(
|
|
||||||
module: &Module<Self>,
|
|
||||||
res: &mut R,
|
|
||||||
a: &A,
|
|
||||||
b: &C,
|
|
||||||
scale: usize,
|
|
||||||
scratch: &mut Scratch<Self>,
|
|
||||||
) where
|
|
||||||
R: VecZnxDftToMut<Self>,
|
|
||||||
A: VecZnxDftToRef<Self>,
|
|
||||||
C: VmpPMatToRef<Self>,
|
|
||||||
{
|
|
||||||
let mut res: VecZnxDft<&mut [u8], _> = res.to_mut();
|
|
||||||
let a: VecZnxDft<&[u8], _> = a.to_ref();
|
|
||||||
let b: VmpPMat<&[u8], _> = b.to_ref();
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
assert_eq!(b.n(), res.n());
|
|
||||||
assert_eq!(a.n(), res.n());
|
|
||||||
assert_eq!(
|
|
||||||
res.cols(),
|
|
||||||
b.cols_out(),
|
|
||||||
"res.cols(): {} != b.cols_out: {}",
|
|
||||||
res.cols(),
|
|
||||||
b.cols_out()
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
a.cols(),
|
|
||||||
b.cols_in(),
|
|
||||||
"a.cols(): {} != b.cols_in: {}",
|
|
||||||
a.cols(),
|
|
||||||
b.cols_in()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let (tmp_bytes, _) = scratch.take_slice(module.vmp_apply_dft_to_dft_tmp_bytes(
|
|
||||||
res.size(),
|
|
||||||
a.size(),
|
|
||||||
b.rows(),
|
|
||||||
b.cols_in(),
|
|
||||||
b.cols_out(),
|
|
||||||
b.size(),
|
|
||||||
));
|
|
||||||
unsafe {
|
|
||||||
vmp::vmp_apply_dft_to_dft_add(
|
|
||||||
module.ptr(),
|
|
||||||
res.as_mut_ptr() as *mut vec_znx_dft_t,
|
|
||||||
(res.size() * res.cols()) as u64,
|
|
||||||
a.as_ptr() as *const vec_znx_dft_t,
|
|
||||||
(a.size() * a.cols()) as u64,
|
|
||||||
b.as_ptr() as *const vmp::vmp_pmat_t,
|
|
||||||
(b.rows() * b.cols_in()) as u64,
|
|
||||||
(b.size() * b.cols_out()) as u64,
|
|
||||||
(scale * b.cols_out()) as u64,
|
|
||||||
tmp_bytes.as_mut_ptr(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VmpZeroImpl<Self> for FFT64Spqlios {
|
|
||||||
fn vmp_zero_impl<R>(_module: &Module<Self>, res: &mut R)
|
|
||||||
where
|
|
||||||
R: VmpPMatToMut<Self>,
|
|
||||||
{
|
|
||||||
vmp_zero(res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,189 +0,0 @@
|
|||||||
use poulpy_hal::reference::znx::{
|
|
||||||
ZnxAdd, ZnxAddInplace, ZnxAutomorphism, ZnxCopy, ZnxExtractDigitAddMul, ZnxMulAddPowerOfTwo, ZnxMulPowerOfTwo,
|
|
||||||
ZnxMulPowerOfTwoInplace, ZnxNegate, ZnxNegateInplace, ZnxNormalizeDigit, ZnxNormalizeFinalStep, ZnxNormalizeFinalStepInplace,
|
|
||||||
ZnxNormalizeFirstStep, ZnxNormalizeFirstStepCarryOnly, ZnxNormalizeFirstStepInplace, ZnxNormalizeMiddleStep,
|
|
||||||
ZnxNormalizeMiddleStepCarryOnly, ZnxNormalizeMiddleStepInplace, ZnxRotate, ZnxSub, ZnxSubInplace, ZnxSubNegateInplace,
|
|
||||||
ZnxSwitchRing, ZnxZero, znx_add_inplace_ref, znx_add_ref, znx_automorphism_ref, znx_copy_ref, znx_extract_digit_addmul_ref,
|
|
||||||
znx_mul_add_power_of_two_ref, znx_mul_power_of_two_inplace_ref, znx_mul_power_of_two_ref, znx_negate_inplace_ref,
|
|
||||||
znx_negate_ref, znx_normalize_digit_ref, znx_normalize_final_step_inplace_ref, znx_normalize_final_step_ref,
|
|
||||||
znx_normalize_first_step_carry_only_ref, znx_normalize_first_step_inplace_ref, znx_normalize_first_step_ref,
|
|
||||||
znx_normalize_middle_step_carry_only_ref, znx_normalize_middle_step_inplace_ref, znx_normalize_middle_step_ref, znx_rotate,
|
|
||||||
znx_sub_inplace_ref, znx_sub_negate_inplace_ref, znx_sub_ref, znx_switch_ring_ref, znx_zero_ref,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::FFT64Spqlios;
|
|
||||||
|
|
||||||
impl ZnxAdd for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_add(res: &mut [i64], a: &[i64], b: &[i64]) {
|
|
||||||
znx_add_ref(res, a, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxAddInplace for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_add_inplace(res: &mut [i64], a: &[i64]) {
|
|
||||||
znx_add_inplace_ref(res, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxSub for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_sub(res: &mut [i64], a: &[i64], b: &[i64]) {
|
|
||||||
znx_sub_ref(res, a, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxSubInplace for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_sub_inplace(res: &mut [i64], a: &[i64]) {
|
|
||||||
znx_sub_inplace_ref(res, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxSubNegateInplace for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_sub_negate_inplace(res: &mut [i64], a: &[i64]) {
|
|
||||||
znx_sub_negate_inplace_ref(res, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxMulAddPowerOfTwo for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_muladd_power_of_two(k: i64, res: &mut [i64], a: &[i64]) {
|
|
||||||
znx_mul_add_power_of_two_ref(k, res, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxMulPowerOfTwo for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_mul_power_of_two(k: i64, res: &mut [i64], a: &[i64]) {
|
|
||||||
znx_mul_power_of_two_ref(k, res, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxMulPowerOfTwoInplace for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_mul_power_of_two_inplace(k: i64, res: &mut [i64]) {
|
|
||||||
znx_mul_power_of_two_inplace_ref(k, res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxAutomorphism for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_automorphism(p: i64, res: &mut [i64], a: &[i64]) {
|
|
||||||
znx_automorphism_ref(p, res, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxCopy for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_copy(res: &mut [i64], a: &[i64]) {
|
|
||||||
znx_copy_ref(res, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxNegate for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_negate(res: &mut [i64], src: &[i64]) {
|
|
||||||
znx_negate_ref(res, src);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxNegateInplace for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_negate_inplace(res: &mut [i64]) {
|
|
||||||
znx_negate_inplace_ref(res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxRotate for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_rotate(p: i64, res: &mut [i64], src: &[i64]) {
|
|
||||||
znx_rotate::<Self>(p, res, src);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxZero for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_zero(res: &mut [i64]) {
|
|
||||||
znx_zero_ref(res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxSwitchRing for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_switch_ring(res: &mut [i64], a: &[i64]) {
|
|
||||||
znx_switch_ring_ref(res, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxNormalizeFinalStep for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_normalize_final_step(base2k: usize, lsh: usize, x: &mut [i64], a: &[i64], carry: &mut [i64]) {
|
|
||||||
znx_normalize_final_step_ref(base2k, lsh, x, a, carry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxNormalizeFinalStepInplace for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_normalize_final_step_inplace(base2k: usize, lsh: usize, x: &mut [i64], carry: &mut [i64]) {
|
|
||||||
znx_normalize_final_step_inplace_ref(base2k, lsh, x, carry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxNormalizeFirstStep for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_normalize_first_step(base2k: usize, lsh: usize, x: &mut [i64], a: &[i64], carry: &mut [i64]) {
|
|
||||||
znx_normalize_first_step_ref(base2k, lsh, x, a, carry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxNormalizeFirstStepCarryOnly for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_normalize_first_step_carry_only(base2k: usize, lsh: usize, x: &[i64], carry: &mut [i64]) {
|
|
||||||
znx_normalize_first_step_carry_only_ref(base2k, lsh, x, carry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxNormalizeFirstStepInplace for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_normalize_first_step_inplace(base2k: usize, lsh: usize, x: &mut [i64], carry: &mut [i64]) {
|
|
||||||
znx_normalize_first_step_inplace_ref(base2k, lsh, x, carry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxNormalizeMiddleStep for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_normalize_middle_step(base2k: usize, lsh: usize, x: &mut [i64], a: &[i64], carry: &mut [i64]) {
|
|
||||||
znx_normalize_middle_step_ref(base2k, lsh, x, a, carry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxNormalizeMiddleStepCarryOnly for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_normalize_middle_step_carry_only(base2k: usize, lsh: usize, x: &[i64], carry: &mut [i64]) {
|
|
||||||
znx_normalize_middle_step_carry_only_ref(base2k, lsh, x, carry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxNormalizeMiddleStepInplace for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_normalize_middle_step_inplace(base2k: usize, lsh: usize, x: &mut [i64], carry: &mut [i64]) {
|
|
||||||
znx_normalize_middle_step_inplace_ref(base2k, lsh, x, carry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxExtractDigitAddMul for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_extract_digit_addmul(base2k: usize, lsh: usize, res: &mut [i64], src: &mut [i64]) {
|
|
||||||
znx_extract_digit_addmul_ref(base2k, lsh, res, src);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ZnxNormalizeDigit for FFT64Spqlios {
|
|
||||||
#[inline(always)]
|
|
||||||
fn znx_normalize_digit(base2k: usize, res: &mut [i64], src: &mut [i64]) {
|
|
||||||
znx_normalize_digit_ref(base2k, res, src);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
mod ffi;
|
|
||||||
mod fft64;
|
|
||||||
mod ntt120;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests;
|
|
||||||
|
|
||||||
pub use ffi::*;
|
|
||||||
pub use fft64::*;
|
|
||||||
pub use ntt120::*;
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
mod module;
|
|
||||||
mod svp_ppol;
|
|
||||||
mod vec_znx_big;
|
|
||||||
mod vec_znx_dft;
|
|
||||||
mod vmp_pmat;
|
|
||||||
|
|
||||||
pub use module::NTT120;
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
use std::ptr::NonNull;
|
|
||||||
|
|
||||||
use poulpy_hal::{
|
|
||||||
layouts::{Backend, Module},
|
|
||||||
oep::ModuleNewImpl,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::cpu_spqlios::ffi::module::{MODULE, delete_module_info, new_module_info};
|
|
||||||
|
|
||||||
pub struct NTT120;
|
|
||||||
|
|
||||||
impl Backend for NTT120 {
|
|
||||||
type ScalarPrep = i64;
|
|
||||||
type ScalarBig = i128;
|
|
||||||
type Handle = MODULE;
|
|
||||||
unsafe fn destroy(handle: NonNull<Self::Handle>) {
|
|
||||||
unsafe { delete_module_info(handle.as_ptr()) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn layout_big_word_count() -> usize {
|
|
||||||
4
|
|
||||||
}
|
|
||||||
|
|
||||||
fn layout_prep_word_count() -> usize {
|
|
||||||
1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl ModuleNewImpl<Self> for NTT120 {
|
|
||||||
fn new_impl(n: u64) -> Module<Self> {
|
|
||||||
unsafe { Module::from_raw_parts(new_module_info(n, 1), n) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
use poulpy_hal::{
|
|
||||||
layouts::{Backend, SvpPPolOwned},
|
|
||||||
oep::{SvpPPolAllocBytesImpl, SvpPPolAllocImpl, SvpPPolFromBytesImpl},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::cpu_spqlios::NTT120;
|
|
||||||
|
|
||||||
unsafe impl SvpPPolFromBytesImpl<Self> for NTT120 {
|
|
||||||
fn svp_ppol_from_bytes_impl(n: usize, cols: usize, bytes: Vec<u8>) -> SvpPPolOwned<NTT120> {
|
|
||||||
SvpPPolOwned::from_bytes(n, cols, bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl SvpPPolAllocImpl<Self> for NTT120 {
|
|
||||||
fn svp_ppol_alloc_impl(n: usize, cols: usize) -> SvpPPolOwned<NTT120> {
|
|
||||||
SvpPPolOwned::alloc(n, cols)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl SvpPPolAllocBytesImpl<Self> for NTT120 {
|
|
||||||
fn svp_ppol_bytes_of_impl(n: usize, cols: usize) -> usize {
|
|
||||||
NTT120::layout_prep_word_count() * n * cols * size_of::<i64>()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
use poulpy_hal::{layouts::Backend, oep::VecZnxBigAllocBytesImpl};
|
|
||||||
|
|
||||||
use crate::cpu_spqlios::NTT120;
|
|
||||||
|
|
||||||
unsafe impl VecZnxBigAllocBytesImpl<NTT120> for NTT120 {
|
|
||||||
fn vec_znx_big_bytes_of_impl(n: usize, cols: usize, size: usize) -> usize {
|
|
||||||
NTT120::layout_big_word_count() * n * cols * size * size_of::<i128>()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
use poulpy_hal::{
|
|
||||||
layouts::{Backend, VecZnxDftOwned},
|
|
||||||
oep::{VecZnxDftAllocBytesImpl, VecZnxDftAllocImpl},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::cpu_spqlios::NTT120;
|
|
||||||
|
|
||||||
unsafe impl VecZnxDftAllocBytesImpl<NTT120> for NTT120 {
|
|
||||||
fn vec_znx_dft_bytes_of_impl(n: usize, cols: usize, size: usize) -> usize {
|
|
||||||
NTT120::layout_prep_word_count() * n * cols * size * size_of::<i64>()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl VecZnxDftAllocImpl<NTT120> for NTT120 {
|
|
||||||
fn vec_znx_dft_alloc_impl(n: usize, cols: usize, size: usize) -> VecZnxDftOwned<NTT120> {
|
|
||||||
VecZnxDftOwned::alloc(n, cols, size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
Submodule poulpy-backend/src/cpu_spqlios/spqlios-arithmetic deleted from e8aed6384c
@@ -1,117 +0,0 @@
|
|||||||
use poulpy_hal::{backend_test_suite, cross_backend_test_suite};
|
|
||||||
|
|
||||||
cross_backend_test_suite! {
|
|
||||||
mod vec_znx,
|
|
||||||
backend_ref = crate::cpu_fft64_ref::FFT64Ref,
|
|
||||||
backend_test = crate::cpu_spqlios::FFT64Spqlios,
|
|
||||||
size = 1 << 5,
|
|
||||||
base2k = 12,
|
|
||||||
tests = {
|
|
||||||
test_vec_znx_add => poulpy_hal::test_suite::vec_znx::test_vec_znx_add,
|
|
||||||
test_vec_znx_add_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_inplace,
|
|
||||||
test_vec_znx_add_scalar => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_scalar,
|
|
||||||
test_vec_znx_add_scalar_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_scalar_inplace,
|
|
||||||
test_vec_znx_sub => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub,
|
|
||||||
test_vec_znx_sub_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_inplace,
|
|
||||||
test_vec_znx_sub_negate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_negate_inplace,
|
|
||||||
test_vec_znx_sub_scalar => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_scalar,
|
|
||||||
test_vec_znx_sub_scalar_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_scalar_inplace,
|
|
||||||
test_vec_znx_rsh => poulpy_hal::test_suite::vec_znx::test_vec_znx_rsh,
|
|
||||||
test_vec_znx_rsh_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_rsh_inplace,
|
|
||||||
test_vec_znx_lsh => poulpy_hal::test_suite::vec_znx::test_vec_znx_lsh,
|
|
||||||
test_vec_znx_lsh_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_lsh_inplace,
|
|
||||||
test_vec_znx_negate => poulpy_hal::test_suite::vec_znx::test_vec_znx_negate,
|
|
||||||
test_vec_znx_negate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_negate_inplace,
|
|
||||||
test_vec_znx_rotate => poulpy_hal::test_suite::vec_znx::test_vec_znx_rotate,
|
|
||||||
test_vec_znx_rotate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_rotate_inplace,
|
|
||||||
test_vec_znx_automorphism => poulpy_hal::test_suite::vec_znx::test_vec_znx_automorphism,
|
|
||||||
test_vec_znx_automorphism_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_automorphism_inplace,
|
|
||||||
test_vec_znx_mul_xp_minus_one => poulpy_hal::test_suite::vec_znx::test_vec_znx_mul_xp_minus_one,
|
|
||||||
test_vec_znx_mul_xp_minus_one_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_mul_xp_minus_one_inplace,
|
|
||||||
test_vec_znx_normalize => poulpy_hal::test_suite::vec_znx::test_vec_znx_normalize,
|
|
||||||
test_vec_znx_normalize_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_normalize_inplace,
|
|
||||||
test_vec_znx_switch_ring => poulpy_hal::test_suite::vec_znx::test_vec_znx_switch_ring,
|
|
||||||
test_vec_znx_split_ring => poulpy_hal::test_suite::vec_znx::test_vec_znx_split_ring,
|
|
||||||
test_vec_znx_copy => poulpy_hal::test_suite::vec_znx::test_vec_znx_copy,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cross_backend_test_suite! {
|
|
||||||
mod svp,
|
|
||||||
backend_ref = crate::cpu_fft64_ref::FFT64Ref,
|
|
||||||
backend_test = crate::cpu_spqlios::FFT64Spqlios,
|
|
||||||
size = 1 << 5,
|
|
||||||
base2k = 12,
|
|
||||||
tests = {
|
|
||||||
test_svp_apply_dft_to_dft => poulpy_hal::test_suite::svp::test_svp_apply_dft_to_dft,
|
|
||||||
test_svp_apply_dft_to_dft_inplace => poulpy_hal::test_suite::svp::test_svp_apply_dft_to_dft_inplace,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cross_backend_test_suite! {
|
|
||||||
mod vec_znx_big,
|
|
||||||
backend_ref = crate::cpu_fft64_ref::FFT64Ref,
|
|
||||||
backend_test = crate::cpu_spqlios::FFT64Spqlios,
|
|
||||||
size = 1 << 5,
|
|
||||||
base2k = 12,
|
|
||||||
tests = {
|
|
||||||
test_vec_znx_big_add => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add,
|
|
||||||
test_vec_znx_big_add_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_inplace,
|
|
||||||
test_vec_znx_big_add_small => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_small,
|
|
||||||
test_vec_znx_big_add_small_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_small_inplace,
|
|
||||||
test_vec_znx_big_sub => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub,
|
|
||||||
test_vec_znx_big_sub_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_inplace,
|
|
||||||
test_vec_znx_big_automorphism => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_automorphism,
|
|
||||||
test_vec_znx_big_automorphism_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_automorphism_inplace,
|
|
||||||
test_vec_znx_big_negate => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_negate,
|
|
||||||
test_vec_znx_big_negate_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_negate_inplace,
|
|
||||||
test_vec_znx_big_normalize => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_normalize,
|
|
||||||
test_vec_znx_big_sub_negate_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_negate_inplace,
|
|
||||||
test_vec_znx_big_sub_small_a => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_a,
|
|
||||||
test_vec_znx_big_sub_small_a_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_a_inplace,
|
|
||||||
test_vec_znx_big_sub_small_b => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_b,
|
|
||||||
test_vec_znx_big_sub_small_b_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_b_inplace,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cross_backend_test_suite! {
|
|
||||||
mod vec_znx_dft,
|
|
||||||
backend_ref = crate::cpu_fft64_ref::FFT64Ref,
|
|
||||||
backend_test = crate::cpu_spqlios::FFT64Spqlios,
|
|
||||||
size = 1 << 5,
|
|
||||||
base2k = 12,
|
|
||||||
tests = {
|
|
||||||
test_vec_znx_dft_add => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_add,
|
|
||||||
test_vec_znx_dft_add_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_add_inplace,
|
|
||||||
test_vec_znx_dft_sub => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub,
|
|
||||||
test_vec_znx_dft_sub_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub_inplace,
|
|
||||||
test_vec_znx_dft_sub_negate_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub_negate_inplace,
|
|
||||||
test_vec_znx_idft_apply => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply,
|
|
||||||
test_vec_znx_idft_apply_consume => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply_consume,
|
|
||||||
test_vec_znx_idft_apply_tmpa => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply_tmpa,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cross_backend_test_suite! {
|
|
||||||
mod vmp,
|
|
||||||
backend_ref = crate::cpu_fft64_ref::FFT64Ref,
|
|
||||||
backend_test = crate::cpu_spqlios::FFT64Spqlios,
|
|
||||||
size = 1 << 5,
|
|
||||||
base2k = 12,
|
|
||||||
tests = {
|
|
||||||
test_vmp_apply_dft_to_dft => poulpy_hal::test_suite::vmp::test_vmp_apply_dft_to_dft,
|
|
||||||
test_vmp_apply_dft_to_dft_add => poulpy_hal::test_suite::vmp::test_vmp_apply_dft_to_dft_add,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
backend_test_suite! {
|
|
||||||
mod sampling,
|
|
||||||
backend = crate::cpu_spqlios::FFT64Spqlios,
|
|
||||||
size = 1 << 12,
|
|
||||||
tests = {
|
|
||||||
test_vec_znx_fill_uniform => poulpy_hal::test_suite::vec_znx::test_vec_znx_fill_uniform,
|
|
||||||
test_vec_znx_fill_normal => poulpy_hal::test_suite::vec_znx::test_vec_znx_fill_normal,
|
|
||||||
test_vec_znx_add_normal => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_normal,
|
|
||||||
test_vec_znx_big_sub_small_b_inplace => poulpy_hal::reference::fft64::vec_znx_big::test_vec_znx_big_add_normal,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
|
|
||||||
pub mod cpu_fft64_avx;
|
|
||||||
|
|
||||||
pub mod cpu_fft64_ref;
|
|
||||||
pub mod cpu_spqlios;
|
|
||||||
|
|
||||||
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
|
|
||||||
pub use cpu_fft64_avx::FFT64Avx;
|
|
||||||
|
|
||||||
pub use cpu_fft64_ref::FFT64Ref;
|
|
||||||
pub use cpu_spqlios::FFT64Spqlios;
|
|
||||||
@@ -12,11 +12,13 @@ documentation = "https://docs.rs/poulpy"
|
|||||||
rug = {workspace = true}
|
rug = {workspace = true}
|
||||||
criterion = {workspace = true}
|
criterion = {workspace = true}
|
||||||
poulpy-hal = {workspace = true}
|
poulpy-hal = {workspace = true}
|
||||||
poulpy-backend = {workspace = true}
|
poulpy-cpu-avx = {workspace = true}
|
||||||
|
poulpy-cpu-ref = {workspace = true}
|
||||||
itertools = {workspace = true}
|
itertools = {workspace = true}
|
||||||
byteorder = {workspace = true}
|
byteorder = {workspace = true}
|
||||||
bytemuck = {workspace = true}
|
bytemuck = {workspace = true}
|
||||||
once_cell = {workspace = true}
|
once_cell = {workspace = true}
|
||||||
|
paste = {workspace = true}
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "external_product_glwe_fft64"
|
name = "external_product_glwe_fft64"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use std::hint::black_box;
|
|||||||
|
|
||||||
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
||||||
|
|
||||||
use poulpy_backend::cpu_spqlios::FFT64Spqlios;
|
use poulpy_cpu_ref::FFT64Ref;
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||||
layouts::{Module, ScalarZnx, ScratchOwned},
|
layouts::{Module, ScalarZnx, ScratchOwned},
|
||||||
@@ -26,7 +26,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn runner(p: Params) -> impl FnMut() {
|
fn runner(p: Params) -> impl FnMut() {
|
||||||
let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(1 << p.log_n);
|
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(1 << p.log_n);
|
||||||
|
|
||||||
let n: Degree = Degree(module.n() as u32);
|
let n: Degree = Degree(module.n() as u32);
|
||||||
let base2k: Base2K = p.base2k;
|
let base2k: Base2K = p.base2k;
|
||||||
@@ -66,7 +66,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 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 pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n.into(), 1);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<FFT64Ref> = ScratchOwned::alloc(
|
||||||
GGSW::encrypt_sk_tmp_bytes(&module, &ggsw_layout)
|
GGSW::encrypt_sk_tmp_bytes(&module, &ggsw_layout)
|
||||||
| GLWE::encrypt_sk_tmp_bytes(&module, &glwe_in_layout)
|
| GLWE::encrypt_sk_tmp_bytes(&module, &glwe_in_layout)
|
||||||
| GLWE::external_product_tmp_bytes(&module, &glwe_out_layout, &glwe_in_layout, &ggsw_layout),
|
| GLWE::external_product_tmp_bytes(&module, &glwe_out_layout, &glwe_in_layout, &ggsw_layout),
|
||||||
@@ -79,7 +79,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
|||||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_in_layout);
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_in_layout);
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
let mut sk_dft: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank);
|
let mut sk_dft: GLWESecretPrepared<Vec<u8>, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank);
|
||||||
sk_dft.prepare(&module, &sk);
|
sk_dft.prepare(&module, &sk);
|
||||||
|
|
||||||
ct_ggsw.encrypt_sk(
|
ct_ggsw.encrypt_sk(
|
||||||
@@ -99,7 +99,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut ggsw_prepared: GGSWPrepared<Vec<u8>, FFT64Spqlios> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw);
|
let mut ggsw_prepared: GGSWPrepared<Vec<u8>, FFT64Ref> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw);
|
||||||
ggsw_prepared.prepare(&module, &ct_ggsw, scratch.borrow());
|
ggsw_prepared.prepare(&module, &ct_ggsw, scratch.borrow());
|
||||||
|
|
||||||
move || {
|
move || {
|
||||||
@@ -138,7 +138,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn runner(p: Params) -> impl FnMut() {
|
fn runner(p: Params) -> impl FnMut() {
|
||||||
let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(1 << p.log_n);
|
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(1 << p.log_n);
|
||||||
|
|
||||||
let n: Degree = Degree(module.n() as u32);
|
let n: Degree = Degree(module.n() as u32);
|
||||||
let base2k: Base2K = p.base2k;
|
let base2k: Base2K = p.base2k;
|
||||||
@@ -169,7 +169,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 mut ct_glwe: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_layout);
|
||||||
let pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n.into(), 1);
|
let pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n.into(), 1);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<FFT64Ref> = ScratchOwned::alloc(
|
||||||
GGSW::encrypt_sk_tmp_bytes(&module, &ggsw_layout)
|
GGSW::encrypt_sk_tmp_bytes(&module, &ggsw_layout)
|
||||||
| GLWE::encrypt_sk_tmp_bytes(&module, &glwe_layout)
|
| GLWE::encrypt_sk_tmp_bytes(&module, &glwe_layout)
|
||||||
| GLWE::external_product_tmp_bytes(&module, &glwe_layout, &glwe_layout, &ggsw_layout),
|
| GLWE::external_product_tmp_bytes(&module, &glwe_layout, &glwe_layout, &ggsw_layout),
|
||||||
@@ -182,7 +182,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
|
|||||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_layout);
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_layout);
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
let mut sk_dft: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank);
|
let mut sk_dft: GLWESecretPrepared<Vec<u8>, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank);
|
||||||
sk_dft.prepare(&module, &sk);
|
sk_dft.prepare(&module, &sk);
|
||||||
|
|
||||||
ct_ggsw.encrypt_sk(
|
ct_ggsw.encrypt_sk(
|
||||||
@@ -202,7 +202,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut ggsw_prepared: GGSWPrepared<Vec<u8>, FFT64Spqlios> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw);
|
let mut ggsw_prepared: GGSWPrepared<Vec<u8>, FFT64Ref> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw);
|
||||||
ggsw_prepared.prepare(&module, &ct_ggsw, scratch.borrow());
|
ggsw_prepared.prepare(&module, &ct_ggsw, scratch.borrow());
|
||||||
move || {
|
move || {
|
||||||
let scratch_borrow = scratch.borrow();
|
let scratch_borrow = scratch.borrow();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use poulpy_core::layouts::{
|
|||||||
use std::{hint::black_box, time::Duration};
|
use std::{hint::black_box, time::Duration};
|
||||||
|
|
||||||
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
||||||
use poulpy_backend::cpu_spqlios::FFT64Spqlios;
|
use poulpy_cpu_ref::FFT64Ref;
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||||
layouts::{Module, ScratchOwned},
|
layouts::{Module, ScratchOwned},
|
||||||
@@ -27,7 +27,7 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn runner(p: Params) -> impl FnMut() {
|
fn runner(p: Params) -> impl FnMut() {
|
||||||
let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(1 << p.log_n);
|
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(1 << p.log_n);
|
||||||
|
|
||||||
let n: Degree = Degree(module.n() as u32);
|
let n: Degree = Degree(module.n() as u32);
|
||||||
let base2k: Base2K = p.base2k;
|
let base2k: Base2K = p.base2k;
|
||||||
@@ -66,7 +66,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_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 ct_out: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_out_layout);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<FFT64Ref> = ScratchOwned::alloc(
|
||||||
GLWESwitchingKey::encrypt_sk_tmp_bytes(&module, &gglwe_atk_layout)
|
GLWESwitchingKey::encrypt_sk_tmp_bytes(&module, &gglwe_atk_layout)
|
||||||
| GLWE::encrypt_sk_tmp_bytes(&module, &glwe_in_layout)
|
| GLWE::encrypt_sk_tmp_bytes(&module, &glwe_in_layout)
|
||||||
| GLWE::keyswitch_tmp_bytes(
|
| GLWE::keyswitch_tmp_bytes(
|
||||||
@@ -84,7 +84,7 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
|
|||||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_in_layout);
|
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_in_layout);
|
||||||
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
let mut sk_in_dft: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank);
|
let mut sk_in_dft: GLWESecretPrepared<Vec<u8>, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank);
|
||||||
sk_in_dft.prepare(&module, &sk_in);
|
sk_in_dft.prepare(&module, &sk_in);
|
||||||
|
|
||||||
ksk.encrypt_sk(
|
ksk.encrypt_sk(
|
||||||
@@ -150,7 +150,7 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn runner(p: Params) -> impl FnMut() {
|
fn runner(p: Params) -> impl FnMut() {
|
||||||
let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(1 << p.log_n);
|
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(1 << p.log_n);
|
||||||
|
|
||||||
let n: Degree = Degree(module.n() as u32);
|
let n: Degree = Degree(module.n() as u32);
|
||||||
let base2k: Base2K = p.base2k;
|
let base2k: Base2K = p.base2k;
|
||||||
@@ -181,7 +181,7 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
|
|||||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&gglwe_layout);
|
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 ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_layout);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<FFT64Ref> = ScratchOwned::alloc(
|
||||||
GLWESwitchingKey::encrypt_sk_tmp_bytes(&module, &gglwe_layout)
|
GLWESwitchingKey::encrypt_sk_tmp_bytes(&module, &gglwe_layout)
|
||||||
| GLWE::encrypt_sk_tmp_bytes(&module, &glwe_layout)
|
| GLWE::encrypt_sk_tmp_bytes(&module, &glwe_layout)
|
||||||
| GLWE::keyswitch_tmp_bytes(&module, &glwe_layout, &glwe_layout, &gglwe_layout),
|
| GLWE::keyswitch_tmp_bytes(&module, &glwe_layout, &glwe_layout, &gglwe_layout),
|
||||||
@@ -194,7 +194,7 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
|
|||||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_layout);
|
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_layout);
|
||||||
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
let mut sk_in_dft: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank);
|
let mut sk_in_dft: GLWESecretPrepared<Vec<u8>, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank);
|
||||||
sk_in_dft.prepare(&module, &sk_in);
|
sk_in_dft.prepare(&module, &sk_in);
|
||||||
|
|
||||||
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_layout);
|
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_layout);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use poulpy_backend::cpu_spqlios::FFT64Spqlios;
|
|
||||||
use poulpy_core::{
|
use poulpy_core::{
|
||||||
GLWESub, SIGMA,
|
GLWESub, SIGMA,
|
||||||
layouts::{
|
layouts::{
|
||||||
@@ -6,6 +5,7 @@ use poulpy_core::{
|
|||||||
prepared::GLWESecretPrepared,
|
prepared::GLWESecretPrepared,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use poulpy_cpu_ref::FFT64Ref;
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxFillUniform},
|
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxFillUniform},
|
||||||
layouts::{Module, ScratchOwned},
|
layouts::{Module, ScratchOwned},
|
||||||
@@ -31,7 +31,7 @@ fn main() {
|
|||||||
let rank: Rank = Rank(1);
|
let rank: Rank = Rank(1);
|
||||||
|
|
||||||
// Instantiate Module (DFT Tables)
|
// Instantiate Module (DFT Tables)
|
||||||
let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(n.0 as u64);
|
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(n.0 as u64);
|
||||||
|
|
||||||
let glwe_ct_infos: GLWELayout = GLWELayout {
|
let glwe_ct_infos: GLWELayout = GLWELayout {
|
||||||
n,
|
n,
|
||||||
@@ -53,7 +53,7 @@ fn main() {
|
|||||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||||
|
|
||||||
// Scratch space
|
// Scratch space
|
||||||
let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<FFT64Ref> = ScratchOwned::alloc(
|
||||||
GLWE::encrypt_sk_tmp_bytes(&module, &glwe_ct_infos) | GLWE::decrypt_tmp_bytes(&module, &glwe_ct_infos),
|
GLWE::encrypt_sk_tmp_bytes(&module, &glwe_ct_infos) | GLWE::decrypt_tmp_bytes(&module, &glwe_ct_infos),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ fn main() {
|
|||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
// Backend-prepared secret
|
// Backend-prepared secret
|
||||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank);
|
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank);
|
||||||
sk_prepared.prepare(&module, &sk);
|
sk_prepared.prepare(&module, &sk);
|
||||||
|
|
||||||
// Uniform plaintext
|
// Uniform plaintext
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ pub mod test_suite;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod serialization;
|
mod serialization;
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
#[cfg(test)]
|
||||||
|
mod poulpy_core {
|
||||||
use poulpy_hal::backend_test_suite;
|
use poulpy_hal::backend_test_suite;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
|
||||||
backend_test_suite!(
|
backend_test_suite!(
|
||||||
mod cpu_ref,
|
mod cpu_avx,
|
||||||
backend = poulpy_backend::cpu_fft64_ref::FFT64Ref,
|
backend = poulpy_cpu_avx::FFT64Avx,
|
||||||
size = 1<<8,
|
size = 1<<8,
|
||||||
tests = {
|
tests = {
|
||||||
//GLWE Encryption
|
//GLWE Encryption
|
||||||
@@ -69,11 +70,10 @@ lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe,
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
|
#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))]
|
||||||
#[cfg(test)]
|
|
||||||
backend_test_suite!(
|
backend_test_suite!(
|
||||||
mod cpu_avx,
|
mod cpu_ref,
|
||||||
backend = poulpy_backend::cpu_fft64_avx::FFT64Avx,
|
backend = poulpy_cpu_ref::FFT64Ref,
|
||||||
size = 1<<8,
|
size = 1<<8,
|
||||||
tests = {
|
tests = {
|
||||||
//GLWE Encryption
|
//GLWE Encryption
|
||||||
@@ -104,6 +104,7 @@ gglwe_automorphism_key_encrypt_sk => crate::tests::test_suite::encryption::test_
|
|||||||
gglwe_automorphism_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphism_key_compressed_encrypt_sk,
|
gglwe_automorphism_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphism_key_compressed_encrypt_sk,
|
||||||
gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk,
|
gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk,
|
||||||
gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk,
|
gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk,
|
||||||
|
gglwe_to_ggsw_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_to_ggsw_key_encrypt_sk,
|
||||||
// GGLWE Keyswitching
|
// GGLWE Keyswitching
|
||||||
gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch,
|
gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch,
|
||||||
gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace,
|
gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace,
|
||||||
@@ -131,3 +132,4 @@ glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe,
|
|||||||
lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe,
|
lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|||||||
33
poulpy-cpu-avx/Cargo.toml
Normal file
33
poulpy-cpu-avx/Cargo.toml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
[package]
|
||||||
|
name = "poulpy-cpu-avx"
|
||||||
|
version = "0.3.2"
|
||||||
|
edition = "2024"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
readme = "README.md"
|
||||||
|
description = "A crate providing concrete AVX accelerated CPU implementations of poulpy-hal through its open extension points"
|
||||||
|
repository = "https://github.com/phantomzone-org/poulpy"
|
||||||
|
homepage = "https://github.com/phantomzone-org/poulpy"
|
||||||
|
documentation = "https://docs.rs/poulpy"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
poulpy-hal = {workspace = true}
|
||||||
|
poulpy-cpu-ref = {workspace = true}
|
||||||
|
rug = {workspace = true}
|
||||||
|
criterion = {workspace = true}
|
||||||
|
itertools = {workspace = true}
|
||||||
|
rand = {workspace = true}
|
||||||
|
rand_distr = {workspace = true}
|
||||||
|
rand_core = {workspace = true}
|
||||||
|
byteorder = {workspace = true}
|
||||||
|
once_cell = {workspace = true}
|
||||||
|
rand_chacha = {workspace = true}
|
||||||
|
paste = {workspace = true}
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
all-features = true
|
||||||
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "vmp"
|
||||||
|
harness = false
|
||||||
18
poulpy-cpu-avx/README.md
Normal file
18
poulpy-cpu-avx/README.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# 🐙 Poulpy-Backend
|
||||||
|
|
||||||
|
**Poulpy-Backend-CPU-AVX** is a Rust crate that provides concrete implementations of **`poulpy-hal`**. This crate is used to instantiate projects implemented with **`poulpy-hal`**, **`poulpy-core`** and/or **`poulpy-schemes`**.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use poulpy_backend_cpu_avx::FFT64Avx;
|
||||||
|
use poulpy_hal::{api::ModuleNew, layouts::Module};
|
||||||
|
|
||||||
|
let log_n: usize = 10;
|
||||||
|
let module = Module<FFT64Avx> = Module<FFT64Avx>::new(1<<log_n);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
To add a backend, implement the open extension traits from **`poulpy-hal/oep`** for a struct that implements the `Backend` trait.
|
||||||
|
This will automatically make your backend compatible with the API of **`poulpy-hal`**, **`poulpy-core`** and **`poulpy-schemes`**.
|
||||||
80
poulpy-cpu-avx/benches/fft.rs
Normal file
80
poulpy-cpu-avx/benches/fft.rs
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
use std::hint::black_box;
|
||||||
|
|
||||||
|
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
||||||
|
use poulpy_cpu_avx::{ReimFFTAvx, ReimIFFTAvx};
|
||||||
|
use poulpy_hal::reference::fft64::reim::{ReimDFTExecute, ReimFFTTable, ReimIFFTTable};
|
||||||
|
|
||||||
|
pub fn bench_ifft_avx2_fma(c: &mut Criterion) {
|
||||||
|
let group_name: String = "ifft_avx2_fma".to_string();
|
||||||
|
|
||||||
|
let mut group = c.benchmark_group(group_name);
|
||||||
|
|
||||||
|
if std::is_x86_feature_detected!("avx2") {
|
||||||
|
fn runner(m: usize) -> impl FnMut() {
|
||||||
|
let mut values: Vec<f64> = vec![0f64; m << 1];
|
||||||
|
|
||||||
|
let scale = 1.0f64 / (2 * m) as f64;
|
||||||
|
values
|
||||||
|
.iter_mut()
|
||||||
|
.enumerate()
|
||||||
|
.for_each(|(i, x)| *x = (i + 1) as f64 * scale);
|
||||||
|
|
||||||
|
let table: ReimIFFTTable<f64> = ReimIFFTTable::<f64>::new(m);
|
||||||
|
move || {
|
||||||
|
ReimIFFTAvx::reim_dft_execute(&table, &mut values);
|
||||||
|
black_box(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for log_m in [9, 10, 11, 12, 13, 14, 15] {
|
||||||
|
let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m));
|
||||||
|
|
||||||
|
let mut runner = runner(1 << log_m);
|
||||||
|
group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("skipping: CPU lacks avx2");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
group.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bench_fft_avx2_fma(c: &mut Criterion) {
|
||||||
|
let group_name: String = "fft_avx2_fma".to_string();
|
||||||
|
|
||||||
|
let mut group = c.benchmark_group(group_name);
|
||||||
|
|
||||||
|
if std::is_x86_feature_detected!("avx2") {
|
||||||
|
fn runner(m: usize) -> impl FnMut() {
|
||||||
|
let mut values: Vec<f64> = vec![0f64; m << 1];
|
||||||
|
|
||||||
|
let scale = 1.0f64 / (2 * m) as f64;
|
||||||
|
values
|
||||||
|
.iter_mut()
|
||||||
|
.enumerate()
|
||||||
|
.for_each(|(i, x)| *x = (i + 1) as f64 * scale);
|
||||||
|
|
||||||
|
let table: ReimFFTTable<f64> = ReimFFTTable::<f64>::new(m);
|
||||||
|
move || {
|
||||||
|
ReimFFTAvx::reim_dft_execute(&table, &mut values);
|
||||||
|
black_box(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for log_m in [9, 10, 11, 12, 13, 14, 15] {
|
||||||
|
let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m));
|
||||||
|
|
||||||
|
let mut runner = runner(1 << log_m);
|
||||||
|
group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("skipping: CPU lacks avx2");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
group.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches_x86, bench_fft_avx2_fma, bench_ifft_avx2_fma,);
|
||||||
|
criterion_main!(benches_x86);
|
||||||
26
poulpy-cpu-avx/benches/vec_znx.rs
Normal file
26
poulpy-cpu-avx/benches/vec_znx.rs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// poulpy-backend/benches/vec_znx_add.rs
|
||||||
|
use criterion::{Criterion, criterion_group, criterion_main};
|
||||||
|
use poulpy_cpu_avx::FFT64Avx;
|
||||||
|
use poulpy_hal::reference::vec_znx::{bench_vec_znx_add, bench_vec_znx_automorphism, bench_vec_znx_normalize_inplace};
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn bench_vec_znx_add_cpu_avx_fft64(c: &mut Criterion) {
|
||||||
|
bench_vec_znx_add::<FFT64Avx>(c, "FFT64Avx");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn bench_vec_znx_normalize_inplace_cpu_avx_fft64(c: &mut Criterion) {
|
||||||
|
bench_vec_znx_normalize_inplace::<FFT64Avx>(c, "FFT64Avx");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench_vec_znx_automorphism_cpu_avx_fft64(c: &mut Criterion) {
|
||||||
|
bench_vec_znx_automorphism::<FFT64Avx>(c, "FFT64Avx");
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(
|
||||||
|
benches,
|
||||||
|
bench_vec_znx_add_cpu_avx_fft64,
|
||||||
|
bench_vec_znx_normalize_inplace_cpu_avx_fft64,
|
||||||
|
bench_vec_znx_automorphism_cpu_avx_fft64,
|
||||||
|
);
|
||||||
|
criterion_main!(benches);
|
||||||
11
poulpy-cpu-avx/benches/vmp.rs
Normal file
11
poulpy-cpu-avx/benches/vmp.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// poulpy-backend/benches/vec_znx_add.rs
|
||||||
|
use criterion::{Criterion, criterion_group, criterion_main};
|
||||||
|
use poulpy_cpu_avx::FFT64Avx;
|
||||||
|
use poulpy_hal::bench_suite::vmp::bench_vmp_apply_dft_to_dft;
|
||||||
|
|
||||||
|
fn bench_vmp_apply_dft_to_dft_cpu_avx_fft64(c: &mut Criterion) {
|
||||||
|
bench_vmp_apply_dft_to_dft::<FFT64Avx>(c, "FFT64Avx");
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches_x86, bench_vmp_apply_dft_to_dft_cpu_avx_fft64,);
|
||||||
|
criterion_main!(benches_x86);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
use itertools::izip;
|
use itertools::izip;
|
||||||
use poulpy_backend::cpu_fft64_ref::FFT64Ref;
|
use poulpy_cpu_avx::FFT64Avx;
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{
|
||||||
ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPrepare, VecZnxAddNormal,
|
ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPrepare, VecZnxAddNormal,
|
||||||
@@ -16,9 +16,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<FFT64Ref> = Module::<FFT64Ref>::new(n as u64);
|
let module: Module<FFT64Avx> = Module::<FFT64Avx>::new(n as u64);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<FFT64Ref> = ScratchOwned::<FFT64Ref>::alloc(module.vec_znx_big_normalize_tmp_bytes());
|
let mut scratch: ScratchOwned<FFT64Avx> = ScratchOwned::<FFT64Avx>::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 +28,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>, FFT64Ref> = module.svp_ppol_alloc(s.cols());
|
let mut s_dft: SvpPPol<Vec<u8>, FFT64Avx> = 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 +43,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>, FFT64Ref> = module.vec_znx_dft_alloc(1, ct_size);
|
let mut buf_dft: VecZnxDft<Vec<u8>, FFT64Avx> = 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 +58,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>, FFT64Ref> = module.vec_znx_big_alloc(1, ct_size);
|
let mut buf_big: VecZnxBig<Vec<u8>, FFT64Avx> = 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
|
||||||
@@ -24,7 +24,7 @@ use poulpy_hal::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_avx::{
|
use crate::{
|
||||||
FFT64Avx,
|
FFT64Avx,
|
||||||
reim::{
|
reim::{
|
||||||
ReimFFTAvx, ReimIFFTAvx, reim_add_avx2_fma, reim_add_inplace_avx2_fma, reim_addmul_avx2_fma, reim_from_znx_i64_bnd50_fma,
|
ReimFFTAvx, ReimIFFTAvx, reim_add_avx2_fma, reim_add_inplace_avx2_fma, reim_addmul_avx2_fma, reim_from_znx_i64_bnd50_fma,
|
||||||
@@ -3,7 +3,7 @@ use std::arch::x86_64::{
|
|||||||
_mm256_permute2f128_pd, _mm256_set_m128d, _mm256_storeu_pd, _mm256_sub_pd, _mm256_unpackhi_pd, _mm256_unpacklo_pd,
|
_mm256_permute2f128_pd, _mm256_set_m128d, _mm256_storeu_pd, _mm256_sub_pd, _mm256_unpackhi_pd, _mm256_unpacklo_pd,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_avx::reim::{as_arr, as_arr_mut};
|
use crate::reim::{as_arr, as_arr_mut};
|
||||||
|
|
||||||
#[target_feature(enable = "avx2,fma")]
|
#[target_feature(enable = "avx2,fma")]
|
||||||
pub(crate) fn fft_avx2_fma(m: usize, omg: &[f64], data: &mut [f64]) {
|
pub(crate) fn fft_avx2_fma(m: usize, omg: &[f64], data: &mut [f64]) {
|
||||||
@@ -3,7 +3,7 @@ use std::arch::x86_64::{
|
|||||||
_mm256_permute2f128_pd, _mm256_set_m128d, _mm256_storeu_pd, _mm256_sub_pd, _mm256_unpackhi_pd, _mm256_unpacklo_pd,
|
_mm256_permute2f128_pd, _mm256_set_m128d, _mm256_storeu_pd, _mm256_sub_pd, _mm256_unpackhi_pd, _mm256_unpacklo_pd,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_avx::reim::{as_arr, as_arr_mut};
|
use crate::reim::{as_arr, as_arr_mut};
|
||||||
|
|
||||||
#[target_feature(enable = "avx2,fma")]
|
#[target_feature(enable = "avx2,fma")]
|
||||||
pub(crate) fn ifft_avx2_fma(m: usize, omg: &[f64], data: &mut [f64]) {
|
pub(crate) fn ifft_avx2_fma(m: usize, omg: &[f64], data: &mut [f64]) {
|
||||||
@@ -30,7 +30,7 @@ pub(crate) use fft_vec_avx2_fma::*;
|
|||||||
use poulpy_hal::reference::fft64::reim::{ReimDFTExecute, ReimFFTTable, ReimIFFTTable};
|
use poulpy_hal::reference::fft64::reim::{ReimDFTExecute, ReimFFTTable, ReimIFFTTable};
|
||||||
use rand_distr::num_traits::{Float, FloatConst};
|
use rand_distr::num_traits::{Float, FloatConst};
|
||||||
|
|
||||||
use crate::cpu_fft64_avx::reim::{fft_avx2_fma::fft_avx2_fma, ifft_avx2_fma::ifft_avx2_fma};
|
use crate::reim::{fft_avx2_fma::fft_avx2_fma, ifft_avx2_fma::ifft_avx2_fma};
|
||||||
|
|
||||||
global_asm!(
|
global_asm!(
|
||||||
include_str!("fft16_avx2_fma.s"),
|
include_str!("fft16_avx2_fma.s"),
|
||||||
@@ -7,7 +7,7 @@ use poulpy_hal::{
|
|||||||
oep::{ScratchAvailableImpl, ScratchFromBytesImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeSliceImpl},
|
oep::{ScratchAvailableImpl, ScratchFromBytesImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeSliceImpl},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_avx::FFT64Avx;
|
use crate::FFT64Avx;
|
||||||
|
|
||||||
unsafe impl<B: Backend> ScratchOwnedAllocImpl<B> for FFT64Avx {
|
unsafe impl<B: Backend> ScratchOwnedAllocImpl<B> for FFT64Avx {
|
||||||
fn scratch_owned_alloc_impl(size: usize) -> ScratchOwned<B> {
|
fn scratch_owned_alloc_impl(size: usize) -> ScratchOwned<B> {
|
||||||
@@ -7,7 +7,7 @@ use poulpy_hal::{
|
|||||||
reference::fft64::svp::{svp_apply_dft_to_dft, svp_apply_dft_to_dft_inplace, svp_prepare},
|
reference::fft64::svp::{svp_apply_dft_to_dft, svp_apply_dft_to_dft_inplace, svp_prepare},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_avx::{FFT64Avx, module::FFT64ModuleHandle};
|
use crate::{FFT64Avx, module::FFT64ModuleHandle};
|
||||||
|
|
||||||
unsafe impl SvpPPolFromBytesImpl<Self> for FFT64Avx {
|
unsafe impl SvpPPolFromBytesImpl<Self> for FFT64Avx {
|
||||||
fn svp_ppol_from_bytes_impl(n: usize, cols: usize, bytes: Vec<u8>) -> SvpPPolOwned<Self> {
|
fn svp_ppol_from_bytes_impl(n: usize, cols: usize, bytes: Vec<u8>) -> SvpPPolOwned<Self> {
|
||||||
125
poulpy-cpu-avx/src/tests.rs
Normal file
125
poulpy-cpu-avx/src/tests.rs
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
use poulpy_hal::{api::ModuleNew, layouts::Module, test_suite::convolution::test_bivariate_tensoring};
|
||||||
|
|
||||||
|
use crate::FFT64Avx;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod poulpy_cpu_avx {
|
||||||
|
use poulpy_hal::{backend_test_suite, cross_backend_test_suite};
|
||||||
|
|
||||||
|
cross_backend_test_suite! {
|
||||||
|
mod vec_znx,
|
||||||
|
backend_ref = poulpy_cpu_ref::FFT64Ref,
|
||||||
|
backend_test = crate::FFT64Avx,
|
||||||
|
size = 1<<8,
|
||||||
|
base2k = 12,
|
||||||
|
tests = {
|
||||||
|
test_vec_znx_add => poulpy_hal::test_suite::vec_znx::test_vec_znx_add,
|
||||||
|
test_vec_znx_add_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_inplace,
|
||||||
|
test_vec_znx_add_scalar => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_scalar,
|
||||||
|
test_vec_znx_add_scalar_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_scalar_inplace,
|
||||||
|
test_vec_znx_sub => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub,
|
||||||
|
test_vec_znx_sub_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_inplace,
|
||||||
|
test_vec_znx_sub_negate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_negate_inplace,
|
||||||
|
test_vec_znx_sub_scalar => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_scalar,
|
||||||
|
test_vec_znx_sub_scalar_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_sub_scalar_inplace,
|
||||||
|
test_vec_znx_rsh => poulpy_hal::test_suite::vec_znx::test_vec_znx_rsh,
|
||||||
|
test_vec_znx_rsh_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_rsh_inplace,
|
||||||
|
test_vec_znx_lsh => poulpy_hal::test_suite::vec_znx::test_vec_znx_lsh,
|
||||||
|
test_vec_znx_lsh_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_lsh_inplace,
|
||||||
|
test_vec_znx_negate => poulpy_hal::test_suite::vec_znx::test_vec_znx_negate,
|
||||||
|
test_vec_znx_negate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_negate_inplace,
|
||||||
|
test_vec_znx_rotate => poulpy_hal::test_suite::vec_znx::test_vec_znx_rotate,
|
||||||
|
test_vec_znx_rotate_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_rotate_inplace,
|
||||||
|
test_vec_znx_automorphism => poulpy_hal::test_suite::vec_znx::test_vec_znx_automorphism,
|
||||||
|
test_vec_znx_automorphism_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_automorphism_inplace,
|
||||||
|
test_vec_znx_mul_xp_minus_one => poulpy_hal::test_suite::vec_znx::test_vec_znx_mul_xp_minus_one,
|
||||||
|
test_vec_znx_mul_xp_minus_one_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_mul_xp_minus_one_inplace,
|
||||||
|
test_vec_znx_normalize => poulpy_hal::test_suite::vec_znx::test_vec_znx_normalize,
|
||||||
|
test_vec_znx_normalize_inplace => poulpy_hal::test_suite::vec_znx::test_vec_znx_normalize_inplace,
|
||||||
|
test_vec_znx_switch_ring => poulpy_hal::test_suite::vec_znx::test_vec_znx_switch_ring,
|
||||||
|
test_vec_znx_split_ring => poulpy_hal::test_suite::vec_znx::test_vec_znx_split_ring,
|
||||||
|
test_vec_znx_copy => poulpy_hal::test_suite::vec_znx::test_vec_znx_copy,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cross_backend_test_suite! {
|
||||||
|
mod svp,
|
||||||
|
backend_ref = poulpy_cpu_ref::FFT64Ref,
|
||||||
|
backend_test = crate::FFT64Avx,
|
||||||
|
size = 1<<8,
|
||||||
|
base2k = 12,
|
||||||
|
tests = {
|
||||||
|
test_svp_apply_dft_to_dft => poulpy_hal::test_suite::svp::test_svp_apply_dft_to_dft,
|
||||||
|
test_svp_apply_dft_to_dft_inplace => poulpy_hal::test_suite::svp::test_svp_apply_dft_to_dft_inplace,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cross_backend_test_suite! {
|
||||||
|
mod vec_znx_big,
|
||||||
|
backend_ref = poulpy_cpu_ref::FFT64Ref,
|
||||||
|
backend_test = crate::FFT64Avx,
|
||||||
|
size = 1<<8,
|
||||||
|
base2k = 12,
|
||||||
|
tests = {
|
||||||
|
test_vec_znx_big_add => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add,
|
||||||
|
test_vec_znx_big_add_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_inplace,
|
||||||
|
test_vec_znx_big_add_small => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_small,
|
||||||
|
test_vec_znx_big_add_small_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_add_small_inplace,
|
||||||
|
test_vec_znx_big_sub => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub,
|
||||||
|
test_vec_znx_big_sub_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_inplace,
|
||||||
|
test_vec_znx_big_automorphism => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_automorphism,
|
||||||
|
test_vec_znx_big_automorphism_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_automorphism_inplace,
|
||||||
|
test_vec_znx_big_negate => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_negate,
|
||||||
|
test_vec_znx_big_negate_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_negate_inplace,
|
||||||
|
test_vec_znx_big_normalize => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_normalize,
|
||||||
|
test_vec_znx_big_sub_negate_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_negate_inplace,
|
||||||
|
test_vec_znx_big_sub_small_a => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_a,
|
||||||
|
test_vec_znx_big_sub_small_a_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_a_inplace,
|
||||||
|
test_vec_znx_big_sub_small_b => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_b,
|
||||||
|
test_vec_znx_big_sub_small_b_inplace => poulpy_hal::test_suite::vec_znx_big::test_vec_znx_big_sub_small_b_inplace,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cross_backend_test_suite! {
|
||||||
|
mod vec_znx_dft,
|
||||||
|
backend_ref = poulpy_cpu_ref::FFT64Ref,
|
||||||
|
backend_test = crate::FFT64Avx,
|
||||||
|
size = 1<<8,
|
||||||
|
base2k = 12,
|
||||||
|
tests = {
|
||||||
|
test_vec_znx_dft_add => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_add,
|
||||||
|
test_vec_znx_dft_add_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_add_inplace,
|
||||||
|
test_vec_znx_dft_sub => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub,
|
||||||
|
test_vec_znx_dft_sub_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub_inplace,
|
||||||
|
test_vec_znx_dft_sub_negate_inplace => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_dft_sub_negate_inplace,
|
||||||
|
test_vec_znx_idft_apply => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply,
|
||||||
|
test_vec_znx_idft_apply_consume => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply_consume,
|
||||||
|
test_vec_znx_idft_apply_tmpa => poulpy_hal::test_suite::vec_znx_dft::test_vec_znx_idft_apply_tmpa,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cross_backend_test_suite! {
|
||||||
|
mod vmp,
|
||||||
|
backend_ref = poulpy_cpu_ref::FFT64Ref,
|
||||||
|
backend_test = crate::FFT64Avx,
|
||||||
|
size = 1<<8,
|
||||||
|
base2k = 12,
|
||||||
|
tests = {
|
||||||
|
test_vmp_apply_dft_to_dft => poulpy_hal::test_suite::vmp::test_vmp_apply_dft_to_dft,
|
||||||
|
test_vmp_apply_dft_to_dft_add => poulpy_hal::test_suite::vmp::test_vmp_apply_dft_to_dft_add,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
backend_test_suite! {
|
||||||
|
mod sampling,
|
||||||
|
backend = crate::FFT64Avx,
|
||||||
|
size = 1<<12,
|
||||||
|
tests = {
|
||||||
|
test_vec_znx_fill_uniform => poulpy_hal::test_suite::vec_znx::test_vec_znx_fill_uniform,
|
||||||
|
test_vec_znx_fill_normal => poulpy_hal::test_suite::vec_znx::test_vec_znx_fill_normal,
|
||||||
|
test_vec_znx_add_normal => poulpy_hal::test_suite::vec_znx::test_vec_znx_add_normal,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_convolution_fft64_avx() {
|
||||||
|
let module: Module<FFT64Avx> = Module::<FFT64Avx>::new(64);
|
||||||
|
test_bivariate_tensoring(&module);
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ use poulpy_hal::{
|
|||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_avx::FFT64Avx;
|
use crate::FFT64Avx;
|
||||||
|
|
||||||
unsafe impl VecZnxZeroImpl<Self> for FFT64Avx {
|
unsafe impl VecZnxZeroImpl<Self> for FFT64Avx {
|
||||||
fn vec_znx_zero_impl<R>(_module: &Module<Self>, res: &mut R, res_col: usize)
|
fn vec_znx_zero_impl<R>(_module: &Module<Self>, res: &mut R, res_col: usize)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::cpu_fft64_avx::FFT64Avx;
|
use crate::FFT64Avx;
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{TakeSlice, VecZnxBigAutomorphismInplaceTmpBytes, VecZnxBigNormalizeTmpBytes},
|
api::{TakeSlice, VecZnxBigAutomorphismInplaceTmpBytes, VecZnxBigNormalizeTmpBytes},
|
||||||
layouts::{
|
layouts::{
|
||||||
@@ -16,7 +16,7 @@ use poulpy_hal::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_avx::{FFT64Avx, module::FFT64ModuleHandle};
|
use crate::{FFT64Avx, module::FFT64ModuleHandle};
|
||||||
|
|
||||||
unsafe impl VecZnxDftFromBytesImpl<Self> for FFT64Avx {
|
unsafe impl VecZnxDftFromBytesImpl<Self> for FFT64Avx {
|
||||||
fn vec_znx_dft_from_bytes_impl(n: usize, cols: usize, size: usize, bytes: Vec<u8>) -> VecZnxDftOwned<Self> {
|
fn vec_znx_dft_from_bytes_impl(n: usize, cols: usize, size: usize, bytes: Vec<u8>) -> VecZnxDftOwned<Self> {
|
||||||
@@ -14,7 +14,7 @@ use poulpy_hal::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_avx::{FFT64Avx, module::FFT64ModuleHandle};
|
use crate::{FFT64Avx, module::FFT64ModuleHandle};
|
||||||
|
|
||||||
unsafe impl VmpPMatAllocBytesImpl<Self> for FFT64Avx {
|
unsafe impl VmpPMatAllocBytesImpl<Self> for FFT64Avx {
|
||||||
fn vmp_pmat_bytes_of_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize {
|
fn vmp_pmat_bytes_of_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize {
|
||||||
@@ -232,7 +232,7 @@ pub unsafe fn znx_mul_add_power_of_two_avx(k: i64, res: &mut [i64], a: &[i64]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if k == 0 {
|
if k == 0 {
|
||||||
use crate::cpu_fft64_avx::znx_avx::znx_add_inplace_avx;
|
use crate::znx_avx::znx_add_inplace_avx;
|
||||||
|
|
||||||
znx_add_inplace_avx(res, a);
|
znx_add_inplace_avx(res, a);
|
||||||
return;
|
return;
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "poulpy-backend"
|
name = "poulpy-cpu-ref"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
description = "A crate providing concrete implementations of poulpy-hal through its open extension points"
|
description = "The providing concrete implementations of poulpy-hal through its open extension points and reference cpu code"
|
||||||
repository = "https://github.com/phantomzone-org/poulpy"
|
repository = "https://github.com/phantomzone-org/poulpy"
|
||||||
homepage = "https://github.com/phantomzone-org/poulpy"
|
homepage = "https://github.com/phantomzone-org/poulpy"
|
||||||
documentation = "https://docs.rs/poulpy"
|
documentation = "https://docs.rs/poulpy"
|
||||||
@@ -19,10 +19,7 @@ rand_distr = {workspace = true}
|
|||||||
rand_core = {workspace = true}
|
rand_core = {workspace = true}
|
||||||
byteorder = {workspace = true}
|
byteorder = {workspace = true}
|
||||||
once_cell = {workspace = true}
|
once_cell = {workspace = true}
|
||||||
rand_chacha = "0.9.0"
|
rand_chacha = {workspace = true}
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
cmake = "0.1.54"
|
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
64
poulpy-cpu-ref/benches/fft.rs
Normal file
64
poulpy-cpu-ref/benches/fft.rs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
use std::hint::black_box;
|
||||||
|
|
||||||
|
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
||||||
|
use poulpy_hal::reference::fft64::reim::{ReimDFTExecute, ReimFFTRef, ReimFFTTable, ReimIFFTRef, ReimIFFTTable};
|
||||||
|
|
||||||
|
pub fn bench_fft_ref(c: &mut Criterion) {
|
||||||
|
let group_name: String = "fft_ref".to_string();
|
||||||
|
|
||||||
|
let mut group = c.benchmark_group(group_name);
|
||||||
|
|
||||||
|
fn runner(m: usize) -> impl FnMut() {
|
||||||
|
let mut values: Vec<f64> = vec![0f64; m << 1];
|
||||||
|
let scale: f64 = 1.0f64 / (2 * m) as f64;
|
||||||
|
values
|
||||||
|
.iter_mut()
|
||||||
|
.enumerate()
|
||||||
|
.for_each(|(i, x)| *x = (i + 1) as f64 * scale);
|
||||||
|
let table: ReimFFTTable<f64> = ReimFFTTable::<f64>::new(m);
|
||||||
|
move || {
|
||||||
|
ReimFFTRef::reim_dft_execute(&table, &mut values);
|
||||||
|
black_box(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for log_m in [9, 10, 11, 12, 13, 14, 15] {
|
||||||
|
let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m));
|
||||||
|
let mut runner = runner(1 << log_m);
|
||||||
|
group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
|
||||||
|
}
|
||||||
|
|
||||||
|
group.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bench_ifft_ref(c: &mut Criterion) {
|
||||||
|
let group_name: String = "ifft_ref".to_string();
|
||||||
|
|
||||||
|
let mut group = c.benchmark_group(group_name);
|
||||||
|
|
||||||
|
fn runner(m: usize) -> impl FnMut() {
|
||||||
|
let mut values: Vec<f64> = vec![0f64; m << 1];
|
||||||
|
let scale: f64 = 1.0f64 / (2 * m) as f64;
|
||||||
|
values
|
||||||
|
.iter_mut()
|
||||||
|
.enumerate()
|
||||||
|
.for_each(|(i, x)| *x = (i + 1) as f64 * scale);
|
||||||
|
let table: ReimIFFTTable<f64> = ReimIFFTTable::<f64>::new(m);
|
||||||
|
move || {
|
||||||
|
ReimIFFTRef::reim_dft_execute(&table, &mut values);
|
||||||
|
black_box(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for log_m in [9, 10, 11, 12, 13, 14, 15] {
|
||||||
|
let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m));
|
||||||
|
let mut runner = runner(1 << log_m);
|
||||||
|
group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
|
||||||
|
}
|
||||||
|
|
||||||
|
group.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches, bench_fft_ref, bench_ifft_ref,);
|
||||||
|
|
||||||
|
criterion_main!(benches);
|
||||||
28
poulpy-cpu-ref/benches/vec_znx.rs
Normal file
28
poulpy-cpu-ref/benches/vec_znx.rs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// poulpy-backend/benches/vec_znx_add.rs
|
||||||
|
use criterion::{Criterion, criterion_group, criterion_main};
|
||||||
|
use poulpy_cpu_ref::FFT64Ref;
|
||||||
|
use poulpy_hal::reference::vec_znx::{bench_vec_znx_add, bench_vec_znx_automorphism, bench_vec_znx_normalize_inplace};
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn bench_vec_znx_add_cpu_ref_fft64(c: &mut Criterion) {
|
||||||
|
bench_vec_znx_add::<FFT64Ref>(c, "cpu_spqlios::fft64");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn bench_vec_znx_normalize_inplace_cpu_ref_fft64(c: &mut Criterion) {
|
||||||
|
bench_vec_znx_normalize_inplace::<FFT64Ref>(c, "cpu_ref::fft64");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench_vec_znx_automorphism_cpu_ref_fft64(c: &mut Criterion) {
|
||||||
|
bench_vec_znx_automorphism::<FFT64Ref>(c, "cpu_ref::fft64");
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(
|
||||||
|
benches,
|
||||||
|
// bench_vec_znx_add_cpu_spqlios_fft64,
|
||||||
|
// bench_vec_znx_add_cpu_ref_fft64,
|
||||||
|
// bench_vec_znx_normalize_inplace_cpu_ref_fft64,
|
||||||
|
// bench_vec_znx_normalize_inplace_cpu_spqlios_fft64,
|
||||||
|
bench_vec_znx_automorphism_cpu_ref_fft64,
|
||||||
|
);
|
||||||
|
criterion_main!(benches);
|
||||||
11
poulpy-cpu-ref/benches/vmp.rs
Normal file
11
poulpy-cpu-ref/benches/vmp.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// poulpy-backend/benches/vec_znx_add.rs
|
||||||
|
use criterion::{Criterion, criterion_group, criterion_main};
|
||||||
|
use poulpy_cpu_ref::FFT64Ref;
|
||||||
|
use poulpy_hal::bench_suite::vmp::bench_vmp_apply_dft_to_dft;
|
||||||
|
|
||||||
|
fn bench_vmp_apply_dft_to_dft_cpu_ref_fft64(c: &mut Criterion) {
|
||||||
|
bench_vmp_apply_dft_to_dft::<FFT64Ref>(c, "cpu_ref::fft64");
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches, bench_vmp_apply_dft_to_dft_cpu_ref_fft64,);
|
||||||
|
criterion_main!(benches);
|
||||||
3
poulpy-cpu-ref/src/main.rs
Normal file
3
poulpy-cpu-ref/src/main.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ use poulpy_hal::{
|
|||||||
reference::fft64::reim::{ReimFFTTable, ReimIFFTTable},
|
reference::fft64::reim::{ReimFFTTable, ReimIFFTTable},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_ref::FFT64Ref;
|
use crate::FFT64Ref;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct FFT64RefHandle {
|
pub struct FFT64RefHandle {
|
||||||
@@ -7,7 +7,7 @@ use poulpy_hal::{
|
|||||||
oep::{ScratchAvailableImpl, ScratchFromBytesImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeSliceImpl},
|
oep::{ScratchAvailableImpl, ScratchFromBytesImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeSliceImpl},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_ref::FFT64Ref;
|
use crate::FFT64Ref;
|
||||||
|
|
||||||
unsafe impl<B: Backend> ScratchOwnedAllocImpl<B> for FFT64Ref {
|
unsafe impl<B: Backend> ScratchOwnedAllocImpl<B> for FFT64Ref {
|
||||||
fn scratch_owned_alloc_impl(size: usize) -> ScratchOwned<B> {
|
fn scratch_owned_alloc_impl(size: usize) -> ScratchOwned<B> {
|
||||||
@@ -7,7 +7,7 @@ use poulpy_hal::{
|
|||||||
reference::fft64::svp::{svp_apply_dft_to_dft, svp_apply_dft_to_dft_inplace, svp_prepare},
|
reference::fft64::svp::{svp_apply_dft_to_dft, svp_apply_dft_to_dft_inplace, svp_prepare},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_ref::{FFT64Ref, module::FFT64ModuleHandle};
|
use crate::{FFT64Ref, module::FFT64ModuleHandle};
|
||||||
|
|
||||||
unsafe impl SvpPPolFromBytesImpl<Self> for FFT64Ref {
|
unsafe impl SvpPPolFromBytesImpl<Self> for FFT64Ref {
|
||||||
fn svp_ppol_from_bytes_impl(n: usize, cols: usize, bytes: Vec<u8>) -> SvpPPolOwned<Self> {
|
fn svp_ppol_from_bytes_impl(n: usize, cols: usize, bytes: Vec<u8>) -> SvpPPolOwned<Self> {
|
||||||
@@ -30,7 +30,7 @@ use poulpy_hal::{
|
|||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_ref::FFT64Ref;
|
use crate::FFT64Ref;
|
||||||
|
|
||||||
unsafe impl VecZnxZeroImpl<Self> for FFT64Ref {
|
unsafe impl VecZnxZeroImpl<Self> for FFT64Ref {
|
||||||
fn vec_znx_zero_impl<R>(_module: &Module<Self>, res: &mut R, res_col: usize)
|
fn vec_znx_zero_impl<R>(_module: &Module<Self>, res: &mut R, res_col: usize)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::cpu_fft64_ref::FFT64Ref;
|
use crate::FFT64Ref;
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{TakeSlice, VecZnxBigAutomorphismInplaceTmpBytes, VecZnxBigNormalizeTmpBytes},
|
api::{TakeSlice, VecZnxBigAutomorphismInplaceTmpBytes, VecZnxBigNormalizeTmpBytes},
|
||||||
layouts::{
|
layouts::{
|
||||||
@@ -16,7 +16,7 @@ use poulpy_hal::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_ref::{FFT64Ref, module::FFT64ModuleHandle};
|
use crate::{FFT64Ref, module::FFT64ModuleHandle};
|
||||||
|
|
||||||
unsafe impl VecZnxDftFromBytesImpl<Self> for FFT64Ref {
|
unsafe impl VecZnxDftFromBytesImpl<Self> for FFT64Ref {
|
||||||
fn vec_znx_dft_from_bytes_impl(n: usize, cols: usize, size: usize, bytes: Vec<u8>) -> VecZnxDftOwned<Self> {
|
fn vec_znx_dft_from_bytes_impl(n: usize, cols: usize, size: usize, bytes: Vec<u8>) -> VecZnxDftOwned<Self> {
|
||||||
@@ -14,7 +14,7 @@ use poulpy_hal::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_ref::{FFT64Ref, module::FFT64ModuleHandle};
|
use crate::{FFT64Ref, module::FFT64ModuleHandle};
|
||||||
|
|
||||||
unsafe impl VmpPMatAllocBytesImpl<Self> for FFT64Ref {
|
unsafe impl VmpPMatAllocBytesImpl<Self> for FFT64Ref {
|
||||||
fn vmp_pmat_bytes_of_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize {
|
fn vmp_pmat_bytes_of_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize {
|
||||||
@@ -11,7 +11,7 @@ use poulpy_hal::reference::znx::{
|
|||||||
znx_sub_inplace_ref, znx_sub_negate_inplace_ref, znx_sub_ref, znx_switch_ring_ref, znx_zero_ref,
|
znx_sub_inplace_ref, znx_sub_negate_inplace_ref, znx_sub_ref, znx_switch_ring_ref, znx_zero_ref,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::cpu_fft64_ref::FFT64Ref;
|
use crate::FFT64Ref;
|
||||||
|
|
||||||
impl ZnxAdd for FFT64Ref {
|
impl ZnxAdd for FFT64Ref {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@@ -20,6 +20,7 @@ byteorder = {workspace = true}
|
|||||||
once_cell = {workspace = true}
|
once_cell = {workspace = true}
|
||||||
rand_chacha = "0.9.0"
|
rand_chacha = "0.9.0"
|
||||||
bytemuck = {workspace = true}
|
bytemuck = {workspace = true}
|
||||||
|
paste = "1.0.15"
|
||||||
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
api::{
|
api::{
|
||||||
ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxBigNormalize, VecZnxDftAlloc, VecZnxDftApply,
|
ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftAlloc,
|
||||||
VecZnxIdftApplyConsume, VmpApplyDft, VmpApplyDftTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd,
|
VecZnxDftApply, VecZnxIdftApplyConsume, VmpApplyDft, VmpApplyDftTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd,
|
||||||
VmpApplyDftToDftAddTmpBytes, VmpApplyDftToDftTmpBytes, VmpPMatAlloc, VmpPrepare,
|
VmpApplyDftToDftAddTmpBytes, VmpApplyDftToDftTmpBytes, VmpPMatAlloc, VmpPrepare, VmpPrepareTmpBytes,
|
||||||
},
|
},
|
||||||
layouts::{DataViewMut, DigestU64, FillUniform, MatZnx, Module, ScratchOwned, VecZnx, VecZnxBig},
|
layouts::{DataViewMut, DigestU64, FillUniform, MatZnx, Module, ScratchOwned, VecZnx, VecZnxBig},
|
||||||
source::Source,
|
source::Source,
|
||||||
@@ -129,7 +129,9 @@ where
|
|||||||
+ VmpPrepare<BR>
|
+ VmpPrepare<BR>
|
||||||
+ VecZnxIdftApplyConsume<BR>
|
+ VecZnxIdftApplyConsume<BR>
|
||||||
+ VecZnxBigNormalize<BR>
|
+ VecZnxBigNormalize<BR>
|
||||||
+ VecZnxDftApply<BR>,
|
+ VecZnxDftApply<BR>
|
||||||
|
+ VmpPrepareTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes,
|
||||||
ScratchOwned<BR>: ScratchOwnedAlloc<BR> + ScratchOwnedBorrow<BR>,
|
ScratchOwned<BR>: ScratchOwnedAlloc<BR> + ScratchOwnedBorrow<BR>,
|
||||||
Module<BT>: ModuleNew<BT>
|
Module<BT>: ModuleNew<BT>
|
||||||
+ VmpApplyDftToDftTmpBytes
|
+ VmpApplyDftToDftTmpBytes
|
||||||
@@ -139,7 +141,9 @@ where
|
|||||||
+ VmpPrepare<BT>
|
+ VmpPrepare<BT>
|
||||||
+ VecZnxIdftApplyConsume<BT>
|
+ VecZnxIdftApplyConsume<BT>
|
||||||
+ VecZnxBigNormalize<BT>
|
+ VecZnxBigNormalize<BT>
|
||||||
+ VecZnxDftApply<BT>,
|
+ VecZnxDftApply<BT>
|
||||||
|
+ VmpPrepareTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes,
|
||||||
ScratchOwned<BT>: ScratchOwnedAlloc<BT> + ScratchOwnedBorrow<BT>,
|
ScratchOwned<BT>: ScratchOwnedAlloc<BT> + ScratchOwnedBorrow<BT>,
|
||||||
{
|
{
|
||||||
assert_eq!(module_ref.n(), module_test.n());
|
assert_eq!(module_ref.n(), module_test.n());
|
||||||
@@ -151,10 +155,16 @@ where
|
|||||||
let mut source: Source = Source::new([0u8; 32]);
|
let mut source: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
let mut scratch_ref: ScratchOwned<BR> = ScratchOwned::alloc(
|
let mut scratch_ref: ScratchOwned<BR> = ScratchOwned::alloc(
|
||||||
module_ref.vmp_apply_dft_to_dft_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size),
|
module_ref
|
||||||
|
.vmp_apply_dft_to_dft_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size)
|
||||||
|
.max(module_ref.vmp_prepare_tmp_bytes(max_size, max_cols, max_cols, max_size))
|
||||||
|
.max(module_ref.vec_znx_big_normalize_tmp_bytes()),
|
||||||
);
|
);
|
||||||
let mut scratch_test: ScratchOwned<BT> = ScratchOwned::alloc(
|
let mut scratch_test: ScratchOwned<BT> = ScratchOwned::alloc(
|
||||||
module_test.vmp_apply_dft_to_dft_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size),
|
module_test
|
||||||
|
.vmp_apply_dft_to_dft_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size)
|
||||||
|
.max(module_test.vmp_prepare_tmp_bytes(max_size, max_cols, max_cols, max_size))
|
||||||
|
.max(module_test.vec_znx_big_normalize_tmp_bytes()),
|
||||||
);
|
);
|
||||||
|
|
||||||
for cols_in in 1..max_cols + 1 {
|
for cols_in in 1..max_cols + 1 {
|
||||||
@@ -258,7 +268,9 @@ where
|
|||||||
+ VmpPrepare<BR>
|
+ VmpPrepare<BR>
|
||||||
+ VecZnxIdftApplyConsume<BR>
|
+ VecZnxIdftApplyConsume<BR>
|
||||||
+ VecZnxBigNormalize<BR>
|
+ VecZnxBigNormalize<BR>
|
||||||
+ VecZnxDftApply<BR>,
|
+ VecZnxDftApply<BR>
|
||||||
|
+ VmpPrepareTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes,
|
||||||
ScratchOwned<BR>: ScratchOwnedAlloc<BR> + ScratchOwnedBorrow<BR>,
|
ScratchOwned<BR>: ScratchOwnedAlloc<BR> + ScratchOwnedBorrow<BR>,
|
||||||
Module<BT>: ModuleNew<BT>
|
Module<BT>: ModuleNew<BT>
|
||||||
+ VmpApplyDftToDftAddTmpBytes
|
+ VmpApplyDftToDftAddTmpBytes
|
||||||
@@ -268,7 +280,9 @@ where
|
|||||||
+ VmpPrepare<BT>
|
+ VmpPrepare<BT>
|
||||||
+ VecZnxIdftApplyConsume<BT>
|
+ VecZnxIdftApplyConsume<BT>
|
||||||
+ VecZnxBigNormalize<BT>
|
+ VecZnxBigNormalize<BT>
|
||||||
+ VecZnxDftApply<BT>,
|
+ VecZnxDftApply<BT>
|
||||||
|
+ VmpPrepareTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes,
|
||||||
ScratchOwned<BT>: ScratchOwnedAlloc<BT> + ScratchOwnedBorrow<BT>,
|
ScratchOwned<BT>: ScratchOwnedAlloc<BT> + ScratchOwnedBorrow<BT>,
|
||||||
{
|
{
|
||||||
assert_eq!(module_ref.n(), module_test.n());
|
assert_eq!(module_ref.n(), module_test.n());
|
||||||
@@ -280,10 +294,16 @@ where
|
|||||||
let mut source: Source = Source::new([0u8; 32]);
|
let mut source: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
let mut scratch_ref: ScratchOwned<BR> = ScratchOwned::alloc(
|
let mut scratch_ref: ScratchOwned<BR> = ScratchOwned::alloc(
|
||||||
module_ref.vmp_apply_dft_to_dft_add_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size),
|
module_ref
|
||||||
|
.vmp_apply_dft_to_dft_add_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size)
|
||||||
|
.max(module_ref.vmp_prepare_tmp_bytes(max_size, max_cols, max_cols, max_size))
|
||||||
|
.max(module_ref.vec_znx_big_normalize_tmp_bytes()),
|
||||||
);
|
);
|
||||||
let mut scratch_test: ScratchOwned<BT> = ScratchOwned::alloc(
|
let mut scratch_test: ScratchOwned<BT> = ScratchOwned::alloc(
|
||||||
module_test.vmp_apply_dft_to_dft_add_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size),
|
module_test
|
||||||
|
.vmp_apply_dft_to_dft_add_tmp_bytes(max_size, max_size, max_size, max_cols, max_cols, max_size)
|
||||||
|
.max(module_test.vmp_prepare_tmp_bytes(max_size, max_cols, max_cols, max_size))
|
||||||
|
.max(module_test.vec_znx_big_normalize_tmp_bytes()),
|
||||||
);
|
);
|
||||||
|
|
||||||
for cols_in in 1..max_cols + 1 {
|
for cols_in in 1..max_cols + 1 {
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ homepage = "https://github.com/phantomzone-org/poulpy"
|
|||||||
documentation = "https://docs.rs/poulpy"
|
documentation = "https://docs.rs/poulpy"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
poulpy-backend = {workspace = true}
|
poulpy-cpu-avx = {workspace = true}
|
||||||
|
poulpy-cpu-ref = {workspace = true}
|
||||||
poulpy-hal = {workspace = true}
|
poulpy-hal = {workspace = true}
|
||||||
poulpy-core = {workspace = true}
|
poulpy-core = {workspace = true}
|
||||||
criterion = {workspace = true}
|
criterion = {workspace = true}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
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};
|
||||||
use poulpy_backend::{FFT64Avx, FFT64Ref, FFT64Spqlios};
|
|
||||||
use poulpy_core::{
|
use poulpy_core::{
|
||||||
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWEExternalProduct, LWEEncryptSk, ScratchTakeCore,
|
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWEExternalProduct, LWEEncryptSk, ScratchTakeCore,
|
||||||
layouts::{
|
layouts::{
|
||||||
@@ -9,12 +8,14 @@ use poulpy_core::{
|
|||||||
GLWESecretPreparedFactory, LWE, LWELayout, LWESecret,
|
GLWESecretPreparedFactory, LWE, LWELayout, LWESecret,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use poulpy_cpu_avx::FFT64Avx;
|
||||||
|
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},
|
||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
use poulpy_schemes::tfhe::{
|
use poulpy_schemes::bin_fhe::{
|
||||||
blind_rotation::{
|
blind_rotation::{
|
||||||
BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory, BlindRotationKeyInfos, BlindRotationKeyLayout, CGGI,
|
BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory, BlindRotationKeyInfos, BlindRotationKeyLayout, CGGI,
|
||||||
},
|
},
|
||||||
@@ -187,15 +188,10 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bench_circuit_bootstrapping_cpu_spqlios_fft64(c: &mut Criterion) {
|
|
||||||
benc_circuit_bootstrapping::<FFT64Spqlios, CGGI>(c, "fft64_spqlios");
|
|
||||||
}
|
|
||||||
|
|
||||||
criterion_group!(
|
criterion_group!(
|
||||||
benches,
|
benches,
|
||||||
bench_circuit_bootstrapping_cpu_ref_fft64,
|
bench_circuit_bootstrapping_cpu_ref_fft64,
|
||||||
bench_circuit_bootstrapping_cpu_avx_fft64,
|
bench_circuit_bootstrapping_cpu_avx_fft64,
|
||||||
bench_circuit_bootstrapping_cpu_spqlios_fft64,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ use poulpy_core::{
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
|
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
|
||||||
use poulpy_backend::FFT64Avx as BackendImpl;
|
use poulpy_cpu_avx::FFT64Avx as BackendImpl;
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))]
|
#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))]
|
||||||
use poulpy_backend::FFT64Ref as BackendImpl;
|
use poulpy_cpu_ref::FFT64Ref as BackendImpl;
|
||||||
|
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxNormalizeInplace},
|
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxNormalizeInplace},
|
||||||
@@ -20,7 +20,7 @@ use poulpy_hal::{
|
|||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
|
|
||||||
use poulpy_schemes::tfhe::{
|
use poulpy_schemes::bin_fhe::{
|
||||||
blind_rotation::{BlindRotationKeyLayout, CGGI},
|
blind_rotation::{BlindRotationKeyLayout, CGGI},
|
||||||
circuit_bootstrapping::{CircuitBootstrappingKey, CircuitBootstrappingKeyLayout, CircuitBootstrappingKeyPrepared},
|
circuit_bootstrapping::{CircuitBootstrappingKey, CircuitBootstrappingKeyLayout, CircuitBootstrappingKeyPrepared},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use poulpy_hal::{
|
|||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::tfhe::bdd_arithmetic::{ExecuteBDDCircuit, FheUint, FheUintPrepared, GetBitCircuitInfo, UnsignedInteger, circuits};
|
use crate::bin_fhe::bdd_arithmetic::{ExecuteBDDCircuit, FheUint, FheUintPrepared, GetBitCircuitInfo, UnsignedInteger, circuits};
|
||||||
|
|
||||||
impl<BE: Backend> ExecuteBDDCircuit1WTo1W<BE> for Module<BE> where Self: Sized + ExecuteBDDCircuit<BE> + GLWEPacking<BE> + GLWECopy
|
impl<BE: Backend> ExecuteBDDCircuit1WTo1W<BE> for Module<BE> where Self: Sized + ExecuteBDDCircuit<BE> + GLWEPacking<BE> + GLWECopy
|
||||||
{}
|
{}
|
||||||
@@ -9,7 +9,7 @@ use poulpy_hal::{
|
|||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::tfhe::bdd_arithmetic::{
|
use crate::bin_fhe::bdd_arithmetic::{
|
||||||
BitSize, ExecuteBDDCircuit, FheUint, FheUintPrepared, GetBitCircuitInfo, GetGGSWBit, UnsignedInteger, circuits,
|
BitSize, ExecuteBDDCircuit, FheUint, FheUintPrepared, GetBitCircuitInfo, GetGGSWBit, UnsignedInteger, circuits,
|
||||||
};
|
};
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user