Add prepare multi thread

This commit is contained in:
Pro7ech
2025-11-11 21:24:39 +01:00
parent af45595848
commit 6924ffd94a
27 changed files with 361 additions and 86 deletions

View File

@@ -1,15 +1,14 @@
use std::collections::HashMap;
use poulpy_hal::{
api::{ModuleLogN, ModuleN, ScratchOwnedAlloc, ScratchOwnedBorrow},
api::{ModuleLogN, ModuleN, ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow},
layouts::{Backend, DataRef, Module, Scratch, ScratchOwned, ToOwnedDeep},
};
use poulpy_core::{
GGSWFromGGLWE, GLWEDecrypt, GLWEPacking, GLWERotate, GLWETrace, ScratchTakeCore,
layouts::{
Dsize, GGLWEInfos, GGLWELayout, GGLWEPreparedToRef, GGSWInfos, GGSWToMut, GLWEAutomorphismKeyHelper, GLWEInfos,
GLWESecretPreparedFactory, GLWEToMut, GLWEToRef, GetGaloisElement, LWEInfos, LWEToRef,
Dsize, GGLWE, GGLWEInfos, GGLWELayout, GGLWEPreparedToRef, GGSWInfos, GGSWToMut, GLWEAutomorphismKeyHelper, GLWEInfos, GLWESecretPreparedFactory, GLWEToMut, GLWEToRef, GetGaloisElement, LWEInfos, LWEToRef, Rank
},
};
@@ -132,6 +131,17 @@ where
R: GGSWInfos,
A: CircuitBootstrappingKeyInfos,
{
let gglwe_infos: GGLWELayout = GGLWELayout {
n: res_infos.n(),
base2k: res_infos.base2k(),
k: res_infos.k(),
dnum: res_infos.dnum(),
dsize: Dsize(1),
rank_in: res_infos.rank().max(Rank(1)).into(),
rank_out: res_infos.rank(),
};
self.blind_rotation_execute_tmp_bytes(
block_size,
extension_factor,
@@ -139,7 +149,7 @@ where
&cbt_infos.brk_infos(),
)
.max(self.glwe_trace_tmp_bytes(res_infos, res_infos, &cbt_infos.atk_infos()))
.max(self.ggsw_from_gglwe_tmp_bytes(res_infos, &cbt_infos.tsk_infos()))
.max(self.ggsw_from_gglwe_tmp_bytes(res_infos, &cbt_infos.tsk_infos())) + GLWE::bytes_of_from_infos(res_infos) + GGLWE::bytes_of_from_infos(&gglwe_infos)
}
fn circuit_bootstrapping_execute_to_constant<R, L, D>(
@@ -154,7 +164,10 @@ where
R: GGSWToMut + GGSWInfos,
L: LWEToRef + LWEInfos,
D: DataRef,
{
{
assert!(scratch.available() >= self.circuit_bootstrapping_execute_tmp_bytes(key.block_size(), extension_factor, res, key));
circuit_bootstrap_core(
false,
self,
@@ -181,7 +194,10 @@ where
R: GGSWToMut + GGSWInfos,
L: LWEToRef + LWEInfos,
D: DataRef,
{
{
assert!(scratch.available() >= self.circuit_bootstrapping_execute_tmp_bytes(key.block_size(), extension_factor, res, key));
circuit_bootstrap_core(
true,
self,
@@ -223,7 +239,7 @@ pub fn circuit_bootstrap_core<R, L, D, M, BRA: BlindRotationAlgo, BE: Backend>(
+ ModuleLogN,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchTakeCore<BE>,
{
{
let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();
let lwe: &LWE<&[u8]> = &lwe.to_ref();