rename raw dft ops

This commit is contained in:
Pro7ech
2025-08-25 09:08:27 +02:00
parent 62448e0293
commit 1551f7a6f0
69 changed files with 666 additions and 715 deletions

View File

@@ -2,9 +2,9 @@ use itertools::izip;
use poulpy_backend::cpu_spqlios::FFT64;
use poulpy_hal::{
api::{
ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPrepare, VecZnxAddNormal,
VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallBInplace,
VecZnxDftAlloc, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigTmpA, VecZnxFillUniform, VecZnxNormalizeInplace,
DFT, IDFTTmpA, ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPrepare,
VecZnxAddNormal, VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes,
VecZnxBigSubSmallBInplace, VecZnxDftAlloc, VecZnxFillUniform, VecZnxNormalizeInplace,
},
layouts::{Module, ScalarZnx, ScratchOwned, SvpPPol, VecZnx, VecZnxBig, VecZnxDft, ZnxInfos},
source::Source,
@@ -45,7 +45,7 @@ fn main() {
let mut buf_dft: VecZnxDft<Vec<u8>, FFT64> = module.vec_znx_dft_alloc(1, ct_size);
module.vec_znx_dft_from_vec_znx(1, 0, &mut buf_dft, 0, &ct, 1);
module.dft(1, 0, &mut buf_dft, 0, &ct, 1);
// Applies DFT(ct[1]) * DFT(s)
module.svp_apply_inplace(
@@ -59,7 +59,7 @@ fn main() {
// BIG(ct[1] * s) <- IDFT(DFT(ct[1] * s)) (not normalized)
let mut buf_big: VecZnxBig<Vec<u8>, FFT64> = module.vec_znx_big_alloc(1, ct_size);
module.vec_znx_dft_to_vec_znx_big_tmp_a(&mut buf_big, 0, &mut buf_dft, 0);
module.idft_tmp_a(&mut buf_big, 0, &mut buf_dft, 0);
// Creates a plaintext: VecZnx with 1 column
let mut m = VecZnx::alloc(
@@ -109,7 +109,7 @@ fn main() {
// Decryption
// DFT(ct[1] * s)
module.vec_znx_dft_from_vec_znx(1, 0, &mut buf_dft, 0, &ct, 1);
module.dft(1, 0, &mut buf_dft, 0, &ct, 1);
module.svp_apply_inplace(
&mut buf_dft,
0, // Selects the first column of res.
@@ -118,7 +118,7 @@ fn main() {
);
// BIG(c1 * s) = IDFT(DFT(c1 * s))
module.vec_znx_dft_to_vec_znx_big_tmp_a(&mut buf_big, 0, &mut buf_dft, 0);
module.idft_tmp_a(&mut buf_big, 0, &mut buf_dft, 0);
// BIG(c1 * s) + ct[0]
module.vec_znx_big_add_small_inplace(&mut buf_big, 0, &ct, 0);

View File

@@ -1,14 +1,13 @@
use poulpy_hal::{
api::{TakeSlice, VecZnxDftToVecZnxBigTmpBytes},
api::{TakeSlice, VecZnxIDFTTmpBytes},
layouts::{
Backend, Data, Module, Scratch, VecZnx, VecZnxBig, VecZnxBigToMut, VecZnxDft, VecZnxDftOwned, VecZnxDftToMut,
VecZnxDftToRef, VecZnxToRef, ZnxInfos, ZnxSliceSize, ZnxView, ZnxViewMut, ZnxZero,
},
oep::{
VecZnxDftAddImpl, VecZnxDftAddInplaceImpl, VecZnxDftAllocBytesImpl, VecZnxDftAllocImpl, VecZnxDftCopyImpl,
VecZnxDftFromBytesImpl, VecZnxDftFromVecZnxImpl, VecZnxDftSubABInplaceImpl, VecZnxDftSubBAInplaceImpl, VecZnxDftSubImpl,
VecZnxDftToVecZnxBigConsumeImpl, VecZnxDftToVecZnxBigImpl, VecZnxDftToVecZnxBigTmpAImpl,
VecZnxDftToVecZnxBigTmpBytesImpl, VecZnxDftZeroImpl,
DFTImpl, IDFTConsumeImpl, IDFTImpl, IDFTTmpAImpl, VecZnxDftAddImpl, VecZnxDftAddInplaceImpl, VecZnxDftAllocBytesImpl,
VecZnxDftAllocImpl, VecZnxDftCopyImpl, VecZnxDftFromBytesImpl, VecZnxDftSubABInplaceImpl, VecZnxDftSubBAInplaceImpl,
VecZnxDftSubImpl, VecZnxDftZeroImpl, VecZnxIDFTTmpBytesImpl,
},
};
@@ -35,21 +34,15 @@ unsafe impl VecZnxDftAllocImpl<Self> for FFT64 {
}
}
unsafe impl VecZnxDftToVecZnxBigTmpBytesImpl<Self> for FFT64 {
fn vec_znx_dft_to_vec_znx_big_tmp_bytes_impl(module: &Module<Self>) -> usize {
unsafe impl VecZnxIDFTTmpBytesImpl<Self> for FFT64 {
fn vec_znx_idft_tmp_bytes_impl(module: &Module<Self>) -> usize {
unsafe { vec_znx_dft::vec_znx_idft_tmp_bytes(module.ptr()) as usize }
}
}
unsafe impl VecZnxDftToVecZnxBigImpl<Self> for FFT64 {
fn vec_znx_dft_to_vec_znx_big_impl<R, A>(
module: &Module<Self>,
res: &mut R,
res_col: usize,
a: &A,
a_col: usize,
scratch: &mut Scratch<Self>,
) where
unsafe impl IDFTImpl<Self> for FFT64 {
fn idft_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>,
{
@@ -61,7 +54,7 @@ unsafe impl VecZnxDftToVecZnxBigImpl<Self> for FFT64 {
assert_eq!(res.n(), a.n())
}
let (tmp_bytes, _) = scratch.take_slice(module.vec_znx_dft_to_vec_znx_big_tmp_bytes());
let (tmp_bytes, _) = scratch.take_slice(module.vec_znx_idft_tmp_bytes());
let min_size: usize = res.size().min(a.size());
@@ -83,8 +76,8 @@ unsafe impl VecZnxDftToVecZnxBigImpl<Self> for FFT64 {
}
}
unsafe impl VecZnxDftToVecZnxBigTmpAImpl<Self> for FFT64 {
fn vec_znx_dft_to_vec_znx_big_tmp_a_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &mut A, a_col: usize)
unsafe impl IDFTTmpAImpl<Self> for FFT64 {
fn idft_tmp_a_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>,
@@ -111,8 +104,8 @@ unsafe impl VecZnxDftToVecZnxBigTmpAImpl<Self> for FFT64 {
}
}
unsafe impl VecZnxDftToVecZnxBigConsumeImpl<Self> for FFT64 {
fn vec_znx_dft_to_vec_znx_big_consume_impl<D: Data>(module: &Module<Self>, mut a: VecZnxDft<D, FFT64>) -> VecZnxBig<D, FFT64>
unsafe impl IDFTConsumeImpl<Self> for FFT64 {
fn idft_consume_impl<D: Data>(module: &Module<Self>, mut a: VecZnxDft<D, FFT64>) -> VecZnxBig<D, FFT64>
where
VecZnxDft<D, FFT64>: VecZnxDftToMut<Self>,
{
@@ -137,16 +130,9 @@ unsafe impl VecZnxDftToVecZnxBigConsumeImpl<Self> for FFT64 {
}
}
unsafe impl VecZnxDftFromVecZnxImpl<Self> for FFT64 {
fn vec_znx_dft_from_vec_znx_impl<R, A>(
module: &Module<Self>,
step: usize,
offset: usize,
res: &mut R,
res_col: usize,
a: &A,
a_col: usize,
) where
unsafe impl DFTImpl<Self> for FFT64 {
fn dft_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,
{