Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test = []
parallel = ["rayon"]

[dependencies]
openfhe = { git = "https://github.com/MachinaIO/openfhe-rs.git" }
openfhe = { git = "https://github.com/MachinaIO/openfhe-rs.git", branch = "exp/trapdoor_gen" }
digest = "0.10"
num-bigint = { version = "0.4", default-features = false }
num-traits = "0.2"
Expand Down
18 changes: 10 additions & 8 deletions src/poly/dcrt/sampler/trapdoor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl DCRTMatrixPtr {
}

pub struct DCRTTrapdoor {
ptr_dcrt_trapdoor: Arc<UniquePtr<openfhe::ffi::DCRTTrapdoor>>,
ptr_dcrt_trapdoor: UniquePtr<openfhe::ffi::DCRTTrapdoor>,
}

impl DCRTTrapdoor {
Expand All @@ -128,8 +128,8 @@ impl DCRTTrapdoor {
RLWETrapdoor { ptr_trapdoor: self.ptr_dcrt_trapdoor.GetTrapdoorPair().into() }
}

fn get_public_matrix(&self, row: usize, col: usize) -> DCRTPoly {
DCRTPoly::new(self.ptr_dcrt_trapdoor.GetPublicMatrixElement(row, col))
fn get_public_matrix(&mut self, row: usize, col: usize) -> DCRTPoly {
DCRTPoly::new(self.ptr_dcrt_trapdoor.as_mut().unwrap().GetPublicMatrixElement(row, col))
}
}

Expand Down Expand Up @@ -165,7 +165,8 @@ impl PolyTrapdoorSampler for DCRTPolyTrapdoorSampler {
params: &<<Self::M as PolyMatrix>::P as Poly>::Params,
size: usize,
) -> (Self::Trapdoor, Self::M) {
let dcrt_trapdoor = DCRTTrapdoor::new(
debug_mem("Before trap gen");
let mut dcrt_trapdoor = DCRTTrapdoor::new(
params.ring_dimension(),
params.crt_depth(),
params.crt_bits(),
Expand All @@ -174,17 +175,18 @@ impl PolyTrapdoorSampler for DCRTPolyTrapdoorSampler {
2_i64,
false,
);
debug_mem("After trap gen");
let rlwe_trapdoor = dcrt_trapdoor.get_trapdoor_pair();
debug_mem("After get trapdoor pair");
let nrow = size;
let ncol = (&params.modulus_bits() + 2) * size;
let public_matrix = DCRTPolyMatrix::from_poly_vec(
params,
parallel_iter!(0..nrow)
.map(|i| {
parallel_iter!(0..ncol).map(|j| dcrt_trapdoor.get_public_matrix(i, j)).collect()
})
(0..nrow)
.map(|i| (0..ncol).map(|j| dcrt_trapdoor.get_public_matrix(i, j)).collect())
.collect(),
);
debug_mem("After get public matrix");
Comment on lines +185 to +189
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd be curious to check time/memory difference with larger scale (e.g run middle param up to point reach trapdoor gen?) little worry if this non parallel loop might be too slow.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this non parallel loop might be too slow.

I have the same concern.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I can modify the PR and add the parallel feature then :)

(rlwe_trapdoor, public_matrix)
}

Expand Down