mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
updated submodule remote & added vmp_prepare_contiguous
This commit is contained in:
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
|||||||
[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/Pro7ech/spqlios-arithmetic
|
||||||
|
|||||||
60
.vscode/settings.json
vendored
60
.vscode/settings.json
vendored
@@ -1,3 +1,61 @@
|
|||||||
{
|
{
|
||||||
"cmake.sourceDirectory": "C:/Users/boss_/go/src/github.com/gausslabs/fhe/base2k/spqlios-arithmetic"
|
"cmake.sourceDirectory": "C:/Users/boss_/go/src/github.com/gausslabs/fhe/base2k/spqlios-arithmetic",
|
||||||
|
"files.associations": {
|
||||||
|
"vector": "cpp",
|
||||||
|
"xstring": "cpp",
|
||||||
|
"xutility": "cpp",
|
||||||
|
"algorithm": "cpp",
|
||||||
|
"atomic": "cpp",
|
||||||
|
"bit": "cpp",
|
||||||
|
"cctype": "cpp",
|
||||||
|
"charconv": "cpp",
|
||||||
|
"cinttypes": "cpp",
|
||||||
|
"clocale": "cpp",
|
||||||
|
"cmath": "cpp",
|
||||||
|
"compare": "cpp",
|
||||||
|
"complex": "cpp",
|
||||||
|
"concepts": "cpp",
|
||||||
|
"cstddef": "cpp",
|
||||||
|
"cstdint": "cpp",
|
||||||
|
"cstdio": "cpp",
|
||||||
|
"cstdlib": "cpp",
|
||||||
|
"cstring": "cpp",
|
||||||
|
"ctime": "cpp",
|
||||||
|
"cwchar": "cpp",
|
||||||
|
"exception": "cpp",
|
||||||
|
"format": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
|
"ios": "cpp",
|
||||||
|
"iosfwd": "cpp",
|
||||||
|
"iostream": "cpp",
|
||||||
|
"istream": "cpp",
|
||||||
|
"iterator": "cpp",
|
||||||
|
"limits": "cpp",
|
||||||
|
"locale": "cpp",
|
||||||
|
"memory": "cpp",
|
||||||
|
"new": "cpp",
|
||||||
|
"optional": "cpp",
|
||||||
|
"ostream": "cpp",
|
||||||
|
"random": "cpp",
|
||||||
|
"sstream": "cpp",
|
||||||
|
"stdexcept": "cpp",
|
||||||
|
"streambuf": "cpp",
|
||||||
|
"string": "cpp",
|
||||||
|
"system_error": "cpp",
|
||||||
|
"tuple": "cpp",
|
||||||
|
"type_traits": "cpp",
|
||||||
|
"typeinfo": "cpp",
|
||||||
|
"utility": "cpp",
|
||||||
|
"xfacet": "cpp",
|
||||||
|
"xiosbase": "cpp",
|
||||||
|
"xlocale": "cpp",
|
||||||
|
"xlocbuf": "cpp",
|
||||||
|
"xlocinfo": "cpp",
|
||||||
|
"xlocmes": "cpp",
|
||||||
|
"xlocmon": "cpp",
|
||||||
|
"xlocnum": "cpp",
|
||||||
|
"xloctime": "cpp",
|
||||||
|
"xmemory": "cpp",
|
||||||
|
"xtr1common": "cpp"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ fn main() {
|
|||||||
let cols: usize = limbs + 1;
|
let cols: usize = limbs + 1;
|
||||||
|
|
||||||
// Maximum size of the byte scratch needed
|
// Maximum size of the byte scratch needed
|
||||||
let tmp_bytes: usize = module.vmp_prepare_contiguous_tmp_bytes(rows, cols)
|
let tmp_bytes: usize = module.vmp_prepare_tmp_bytes(rows, cols)
|
||||||
| module.vmp_apply_dft_tmp_bytes(limbs, limbs, rows, cols);
|
| module.vmp_apply_dft_tmp_bytes(limbs, limbs, rows, cols);
|
||||||
|
|
||||||
let mut buf: Vec<u8> = vec![0; tmp_bytes];
|
let mut buf: Vec<u8> = vec![0; tmp_bytes];
|
||||||
@@ -29,16 +29,21 @@ fn main() {
|
|||||||
a.encode_vec_i64(log_base2k, log_k, &a_values, 32);
|
a.encode_vec_i64(log_base2k, log_k, &a_values, 32);
|
||||||
a.normalize(log_base2k, &mut buf);
|
a.normalize(log_base2k, &mut buf);
|
||||||
|
|
||||||
(0..a.limbs()).for_each(|i| println!("{}: {:?}", i, a.at(i)));
|
a.print_limbs(a.limbs(), n);
|
||||||
|
println!();
|
||||||
|
|
||||||
let mut b_mat: Matrix3D<i64> = Matrix3D::new(rows, cols, n);
|
let mut vecznx: Vec<VecZnx>= Vec::new();
|
||||||
|
(0..rows).for_each(|_|{
|
||||||
(0..min(rows, cols)).for_each(|i| {
|
vecznx.push(module.new_vec_znx(cols));
|
||||||
b_mat.at_mut(i, i)[1] = 1 as i64;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
(0..rows).for_each(|i|{
|
||||||
|
vecznx[i].data[i*n+1] = 1 as i64;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
let mut vmp_pmat: VmpPMat = module.new_vmp_pmat(rows, cols);
|
let mut vmp_pmat: VmpPMat = module.new_vmp_pmat(rows, cols);
|
||||||
module.vmp_prepare_contiguous(&mut vmp_pmat, &b_mat.data, &mut buf);
|
module.vmp_prepare_dblptr(&mut vmp_pmat, &vecznx, &mut buf);
|
||||||
|
|
||||||
let mut c_dft: VecZnxDft = module.new_vec_znx_dft(cols);
|
let mut c_dft: VecZnxDft = module.new_vec_znx_dft(cols);
|
||||||
module.vmp_apply_dft(&mut c_dft, &a, &vmp_pmat, &mut buf);
|
module.vmp_apply_dft(&mut c_dft, &a, &vmp_pmat, &mut buf);
|
||||||
@@ -52,7 +57,8 @@ fn main() {
|
|||||||
let mut values_res: Vec<i64> = vec![i64::default(); n];
|
let mut values_res: Vec<i64> = vec![i64::default(); n];
|
||||||
res.decode_vec_i64(log_base2k, log_k, &mut values_res);
|
res.decode_vec_i64(log_base2k, log_k, &mut values_res);
|
||||||
|
|
||||||
(0..res.limbs()).for_each(|i| println!("{}: {:?}", i, res.at(i)));
|
|
||||||
|
res.print_limbs(res.limbs(), n);
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
c_dft.free();
|
c_dft.free();
|
||||||
@@ -60,3 +66,48 @@ fn main() {
|
|||||||
|
|
||||||
//println!("{:?}", values_res)
|
//println!("{:?}", values_res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
use base2k::{
|
||||||
|
Encoding, Free, Infos, Matrix3D, Module, VecZnx, VecZnxBig, VecZnxDft, VecZnxOps, VmpPMat,
|
||||||
|
VmpPMatOps, FFT64,
|
||||||
|
};
|
||||||
|
use std::cmp::min;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
use base2k::{Module, FFT64, Matrix3D, VmpPMat, VmpPMatOps, VecZnx, VecZnxOps, Free};
|
||||||
|
use std::cmp::min;
|
||||||
|
|
||||||
|
let n: usize = 32;
|
||||||
|
let module: Module = Module::new::<FFT64>(n);
|
||||||
|
let rows: usize = 5;
|
||||||
|
let cols: usize = 6;
|
||||||
|
|
||||||
|
let mut vecznx: Vec<VecZnx>= Vec::new();
|
||||||
|
(0..rows).for_each(|_|{
|
||||||
|
vecznx.push(module.new_vec_znx(cols));
|
||||||
|
});
|
||||||
|
|
||||||
|
(0..rows).for_each(|i|{
|
||||||
|
vecznx[i].data[i*n] = 1 as i64;
|
||||||
|
vecznx[i].print_limbs(cols, n);
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut buf: Vec<u8> = vec![u8::default(); module.vmp_prepare_tmp_bytes(rows, cols)];
|
||||||
|
|
||||||
|
let mut vmp_pmat: VmpPMat = module.new_vmp_pmat(rows, cols);
|
||||||
|
|
||||||
|
println!("123");
|
||||||
|
|
||||||
|
module.vmp_prepare_dblptr(&mut vmp_pmat, &vecznx, &mut buf);
|
||||||
|
|
||||||
|
|
||||||
|
module.vmp_apply_dft(c, a, b, buf);
|
||||||
|
|
||||||
|
vmp_pmat.free();
|
||||||
|
module.free();
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
Submodule base2k/spqlios-arithmetic updated: 7ea875f61c...83555cc664
@@ -80,8 +80,6 @@ unsafe extern "C" {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
NOT IMPLEMENTED IN SPQLIOS
|
|
||||||
unsafe extern "C" {
|
unsafe extern "C" {
|
||||||
pub unsafe fn vmp_prepare_dblptr(
|
pub unsafe fn vmp_prepare_dblptr(
|
||||||
module: *const MODULE,
|
module: *const MODULE,
|
||||||
@@ -92,9 +90,9 @@ unsafe extern "C" {
|
|||||||
tmp_space: *mut u8,
|
tmp_space: *mut u8,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
unsafe extern "C" {
|
unsafe extern "C" {
|
||||||
pub unsafe fn vmp_prepare_contiguous_tmp_bytes(
|
pub unsafe fn vmp_prepare_tmp_bytes(
|
||||||
module: *const MODULE,
|
module: *const MODULE,
|
||||||
nrows: u64,
|
nrows: u64,
|
||||||
ncols: u64,
|
ncols: u64,
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ pub trait VmpPMatOps {
|
|||||||
///
|
///
|
||||||
/// * `rows`: number of rows of the [VmpPMat] used in [VmpPMatOps::vmp_prepare_contiguous].
|
/// * `rows`: number of rows of the [VmpPMat] used in [VmpPMatOps::vmp_prepare_contiguous].
|
||||||
/// * `cols`: number of cols of the [VmpPMat] used in [VmpPMatOps::vmp_prepare_contiguous].
|
/// * `cols`: number of cols of the [VmpPMat] used in [VmpPMatOps::vmp_prepare_contiguous].
|
||||||
fn vmp_prepare_contiguous_tmp_bytes(&self, rows: usize, cols: usize) -> usize;
|
fn vmp_prepare_tmp_bytes(&self, rows: usize, cols: usize) -> usize;
|
||||||
|
|
||||||
/// Prepares a [VmpPMat] from a contiguous array of [i64].
|
/// Prepares a [VmpPMat] from a contiguous array of [i64].
|
||||||
/// The helper struct [Matrix3D] can be used to contruct and populate
|
/// The helper struct [Matrix3D] can be used to contruct and populate
|
||||||
@@ -106,7 +106,7 @@ pub trait VmpPMatOps {
|
|||||||
///
|
///
|
||||||
/// * `b`: [VmpPMat] on which the values are encoded.
|
/// * `b`: [VmpPMat] on which the values are encoded.
|
||||||
/// * `a`: the contiguous array of [i64] of the 3D matrix to encode on the [VmpPMat].
|
/// * `a`: the contiguous array of [i64] of the 3D matrix to encode on the [VmpPMat].
|
||||||
/// * `buf`: scratch space, the size of buf can be obtained with [VmpPMatOps::vmp_prepare_contiguous_tmp_bytes].
|
/// * `buf`: scratch space, the size of buf can be obtained with [VmpPMatOps::vmp_prepare_tmp_bytes].
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
@@ -125,7 +125,7 @@ pub trait VmpPMatOps {
|
|||||||
/// b_mat.at_mut(i, i)[1] = 1 as i64;
|
/// b_mat.at_mut(i, i)[1] = 1 as i64;
|
||||||
/// });
|
/// });
|
||||||
///
|
///
|
||||||
/// let mut buf: Vec<u8> = vec![u8::default(); module.vmp_prepare_contiguous_tmp_bytes(rows, cols)];
|
/// let mut buf: Vec<u8> = vec![u8::default(); module.vmp_prepare_tmp_bytes(rows, cols)];
|
||||||
///
|
///
|
||||||
/// let mut vmp_pmat: VmpPMat = module.new_vmp_pmat(rows, cols);
|
/// let mut vmp_pmat: VmpPMat = module.new_vmp_pmat(rows, cols);
|
||||||
/// module.vmp_prepare_contiguous(&mut vmp_pmat, &b_mat.data, &mut buf);
|
/// module.vmp_prepare_contiguous(&mut vmp_pmat, &b_mat.data, &mut buf);
|
||||||
@@ -140,9 +140,9 @@ pub trait VmpPMatOps {
|
|||||||
///
|
///
|
||||||
/// * `b`: [VmpPMat] on which the values are encoded.
|
/// * `b`: [VmpPMat] on which the values are encoded.
|
||||||
/// * `a`: the vector of [VecZnx] to encode on the [VmpPMat].
|
/// * `a`: the vector of [VecZnx] to encode on the [VmpPMat].
|
||||||
/// * `buf`: scratch space, the size of buf can be obtained with [VmpPMatOps::vmp_prepare_contiguous_tmp_bytes].
|
/// * `buf`: scratch space, the size of buf can be obtained with [VmpPMatOps::vmp_prepare_tmp_bytes].
|
||||||
///
|
///
|
||||||
/// The size of buf can be obtained with [VmpPMatOps::vmp_prepare_contiguous_tmp_bytes].
|
/// The size of buf can be obtained with [VmpPMatOps::vmp_prepare_tmp_bytes].
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
@@ -159,7 +159,7 @@ pub trait VmpPMatOps {
|
|||||||
/// vecznx.push(module.new_vec_znx(cols));
|
/// vecznx.push(module.new_vec_znx(cols));
|
||||||
/// });
|
/// });
|
||||||
///
|
///
|
||||||
/// let mut buf: Vec<u8> = vec![u8::default(); module.vmp_prepare_contiguous_tmp_bytes(rows, cols)];
|
/// let mut buf: Vec<u8> = vec![u8::default(); module.vmp_prepare_tmp_bytes(rows, cols)];
|
||||||
///
|
///
|
||||||
/// let mut vmp_pmat: VmpPMat = module.new_vmp_pmat(rows, cols);
|
/// let mut vmp_pmat: VmpPMat = module.new_vmp_pmat(rows, cols);
|
||||||
/// module.vmp_prepare_dblptr(&mut vmp_pmat, &vecznx, &mut buf);
|
/// module.vmp_prepare_dblptr(&mut vmp_pmat, &vecznx, &mut buf);
|
||||||
@@ -373,8 +373,8 @@ impl VmpPMatOps for Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vmp_prepare_contiguous_tmp_bytes(&self, rows: usize, cols: usize) -> usize {
|
fn vmp_prepare_tmp_bytes(&self, rows: usize, cols: usize) -> usize {
|
||||||
unsafe { vmp::vmp_prepare_contiguous_tmp_bytes(self.0, rows as u64, cols as u64) as usize }
|
unsafe { vmp::vmp_prepare_tmp_bytes(self.0, rows as u64, cols as u64) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vmp_prepare_contiguous(&self, b: &mut VmpPMat, a: &[i64], buf: &mut [u8]) {
|
fn vmp_prepare_contiguous(&self, b: &mut VmpPMat, a: &[i64], buf: &mut [u8]) {
|
||||||
@@ -391,31 +391,17 @@ impl VmpPMatOps for Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn vmp_prepare_dblptr(&self, b: &mut VmpPMat, a: &Vec<VecZnx>, buf: &mut [u8]) {
|
fn vmp_prepare_dblptr(&self, b: &mut VmpPMat, a: &Vec<VecZnx>, buf: &mut [u8]) {
|
||||||
let rows: usize = b.rows();
|
let ptrs: Vec<*const i64> = a.iter().map(|v| v.data.as_ptr()).collect();
|
||||||
let cols: usize = b.cols();
|
|
||||||
|
|
||||||
let mut mat: Matrix3D<i64> = Matrix3D::<i64>::new(rows, cols, self.n());
|
|
||||||
|
|
||||||
(0..min(rows, a.len())).for_each(|i| {
|
|
||||||
mat.set_row(i, &a[i].data);
|
|
||||||
});
|
|
||||||
|
|
||||||
self.vmp_prepare_contiguous(b, &mat.data, buf);
|
|
||||||
|
|
||||||
/*
|
|
||||||
NOT IMPLEMENTED IN SPQLIOS
|
|
||||||
let mut ptrs: Vec<*const i64> = a.iter().map(|v| v.data.as_ptr()).collect();
|
|
||||||
unsafe {
|
unsafe {
|
||||||
vmp_prepare_dblptr(
|
vmp::vmp_prepare_dblptr(
|
||||||
self.0,
|
self.0,
|
||||||
b.data(),
|
b.data(),
|
||||||
ptrs.as_mut_ptr(),
|
ptrs.as_ptr(),
|
||||||
b.rows() as u64,
|
b.rows() as u64,
|
||||||
b.cols() as u64,
|
b.cols() as u64,
|
||||||
buf.as_mut_ptr(),
|
buf.as_mut_ptr(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vmp_apply_dft_tmp_bytes(
|
fn vmp_apply_dft_tmp_bytes(
|
||||||
|
|||||||
Reference in New Issue
Block a user