added vmp_prepare_dblptr
Jean-Philippe Bossuat jeanphilippe.bossuat@gmail.com
Fri, 31 Jan 2025 15:39:08 +0100
5 files changed,
38 insertions(+),
10 deletions(-)
M
.gitmodules
→
.gitmodules
@@ -1,6 +1,3 @@
-[submodule "spqlios/spqlios-arithmetic"] - path = spqlios/spqlios-arithmetic - url = https://github.com/tfhe/spqlios-arithmetic [submodule "base2k/spqlios-arithmetic"] path = base2k/spqlios-arithmetic - url = https://github.com/tfhe/spqlios-arithmetic + url = https://github.com/tfhe/spqlios-arithmetic
A
base2k/README.md
@@ -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.
M
base2k/src/ffi/vmp.rs
→
base2k/src/ffi/vmp.rs
@@ -68,7 +68,7 @@ ) -> u64;
} unsafe extern "C" { - pub fn vmp_prepare_contiguous( + pub unsafe fn vmp_prepare_contiguous( module: *const MODULE, pmat: *mut VMP_PMAT, mat: *const i64,@@ -78,10 +78,10 @@ tmp_space: *mut u8,
); } unsafe extern "C" { - pub fn vmp_prepare_dblptr( + pub unsafe fn vmp_prepare_dblptr( module: *const MODULE, pmat: *mut VMP_PMAT, - mat: *mut *const i64, + mat: *const *const i64, nrows: u64, ncols: u64, tmp_space: *mut u8,
M
base2k/src/scalar.rs
→
base2k/src/scalar.rs
@@ -22,7 +22,7 @@ n
} pub fn from_buffer(&mut self, n: usize, buf: &[i64]) { - let size = Self::buffer_size(n); + let size: usize = Self::buffer_size(n); assert!( buf.len() >= size, "invalid buffer: buf.len()={} < self.buffer_size(n={})={}",
M
base2k/src/vector_matrix_product.rs
→
base2k/src/vector_matrix_product.rs
@@ -1,7 +1,7 @@
use crate::ffi::vmp::{ 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_prepare_contiguous_tmp_bytes, + vmp_prepare_contiguous_tmp_bytes, vmp_prepare_dblptr, }; use crate::{Module, VecZnx, VecZnxDft};@@ -110,6 +110,21 @@ );
} } + 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( &self, c_limbs: usize,@@ -209,7 +224,7 @@ pub cols: 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 { let size = rows * cols * n; Self {@@ -230,5 +245,10 @@ pub fn at_mut(&mut self, row: usize, col: usize) -> &mut [T] {
assert!(row <= self.rows && col <= self.cols); let idx: usize = col * (self.n * self.rows) + row * 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); } }