added vmp_prepare_dblptr

This commit is contained in:
Jean-Philippe Bossuat
2025-01-31 15:39:08 +01:00
parent 7704e14d45
commit 0b8bf98b2a
6 changed files with 39 additions and 10 deletions

5
.gitmodules vendored
View File

@@ -1,6 +1,3 @@
[submodule "spqlios/spqlios-arithmetic"]
path = spqlios/spqlios-arithmetic
url = https://github.com/tfhe/spqlios-arithmetic
[submodule "base2k/spqlios-arithmetic"] [submodule "base2k/spqlios-arithmetic"]
path = base2k/spqlios-arithmetic path = base2k/spqlios-arithmetic
url = https://github.com/tfhe/spqlios-arithmetic url = https://github.com/tfhe/spqlios-arithmetic

11
base2k/README.md Normal file
View File

@@ -0,0 +1,11 @@
# DISCLAIMER: ONLY TESTED ON UBUNTU
To use this crate you need to build spqlios-arithmetic, which is provided a as a git submodule:
1) Initialize the sub-modile
2) $ cd base2k/spqlios-arithmetic
3) mdkir build
4) cd build
5) cmake ..
6) make
Steps 3 to 6 might change depending of your platform. See [spqlios-arithmetic/wiki/build](https://github.com/tfhe/spqlios-arithmetic/wiki/build) for additional information and build options.

View File

@@ -68,7 +68,7 @@ unsafe extern "C" {
} }
unsafe extern "C" { unsafe extern "C" {
pub fn vmp_prepare_contiguous( pub unsafe fn vmp_prepare_contiguous(
module: *const MODULE, module: *const MODULE,
pmat: *mut VMP_PMAT, pmat: *mut VMP_PMAT,
mat: *const i64, mat: *const i64,
@@ -78,10 +78,10 @@ unsafe extern "C" {
); );
} }
unsafe extern "C" { unsafe extern "C" {
pub fn vmp_prepare_dblptr( pub unsafe fn vmp_prepare_dblptr(
module: *const MODULE, module: *const MODULE,
pmat: *mut VMP_PMAT, pmat: *mut VMP_PMAT,
mat: *mut *const i64, mat: *const *const i64,
nrows: u64, nrows: u64,
ncols: u64, ncols: u64,
tmp_space: *mut u8, tmp_space: *mut u8,

View File

@@ -22,7 +22,7 @@ impl Scalar {
} }
pub fn from_buffer(&mut self, n: usize, buf: &[i64]) { pub fn from_buffer(&mut self, n: usize, buf: &[i64]) {
let size = Self::buffer_size(n); let size: usize = Self::buffer_size(n);
assert!( assert!(
buf.len() >= size, buf.len() >= size,
"invalid buffer: buf.len()={} < self.buffer_size(n={})={}", "invalid buffer: buf.len()={} < self.buffer_size(n={})={}",

View File

@@ -1,7 +1,7 @@
use crate::ffi::vmp::{ use crate::ffi::vmp::{
delete_vmp_pmat, new_vmp_pmat, vmp_apply_dft, vmp_apply_dft_tmp_bytes, vmp_apply_dft_to_dft, delete_vmp_pmat, new_vmp_pmat, vmp_apply_dft, vmp_apply_dft_tmp_bytes, vmp_apply_dft_to_dft,
vmp_apply_dft_to_dft_tmp_bytes, vmp_pmat_t, vmp_prepare_contiguous, vmp_apply_dft_to_dft_tmp_bytes, vmp_pmat_t, vmp_prepare_contiguous,
vmp_prepare_contiguous_tmp_bytes, vmp_prepare_contiguous_tmp_bytes, vmp_prepare_dblptr,
}; };
use crate::{Module, VecZnx, VecZnxDft}; use crate::{Module, VecZnx, VecZnxDft};
@@ -110,6 +110,21 @@ impl Module {
} }
} }
pub fn vmp_prepare_dblptr(&self, b: &mut VmpPMat, a: &Vec<&Vec<i64>>, buf: &mut [u8]) {
let ptrs: Vec<*const i64> = a.iter().map(|v| v.as_ptr()).collect();
unsafe {
vmp_prepare_dblptr(
self.0,
b.data(),
ptrs.as_ptr(),
b.rows() as u64,
b.cols() as u64,
buf.as_mut_ptr(),
);
}
}
pub fn vmp_apply_dft_tmp_bytes( pub fn vmp_apply_dft_tmp_bytes(
&self, &self,
c_limbs: usize, c_limbs: usize,
@@ -209,7 +224,7 @@ pub struct Matrix3D<T> {
pub n: usize, pub n: usize,
} }
impl<T: Default + Clone> Matrix3D<T> { impl<T: Default + Clone + std::marker::Copy> Matrix3D<T> {
pub fn new(rows: usize, cols: usize, n: usize) -> Self { pub fn new(rows: usize, cols: usize, n: usize) -> Self {
let size = rows * cols * n; let size = rows * cols * n;
Self { Self {
@@ -231,4 +246,9 @@ impl<T: Default + Clone> Matrix3D<T> {
let idx: usize = col * (self.n * self.rows) + row * self.n; let idx: usize = col * (self.n * self.rows) + row * self.n;
&mut self.data[idx..idx + self.n] &mut self.data[idx..idx + self.n]
} }
pub fn set_col(&mut self, col: usize, a: &[T]) {
let idx: usize = col * (self.n * self.rows);
self.data[idx..idx + self.rows * self.n].copy_from_slice(a);
}
} }