Added memory layout field

This commit is contained in:
Jean-Philippe Bossuat
2025-04-25 08:57:08 +02:00
parent f64d786819
commit f0eaddb63e
3 changed files with 17 additions and 1 deletions

View File

@@ -27,6 +27,14 @@ pub use vmp::*;
pub const GALOISGENERATOR: u64 = 5; pub const GALOISGENERATOR: u64 = 5;
pub const DEFAULTALIGN: usize = 64; pub const DEFAULTALIGN: usize = 64;
#[derive(Copy, Clone)]
#[repr(u8)]
pub enum LAYOUT {
ROW,
COL,
}
pub fn is_aligned_custom<T>(ptr: *const T, align: usize) -> bool { pub fn is_aligned_custom<T>(ptr: *const T, align: usize) -> bool {
(ptr as usize) % align == 0 (ptr as usize) % align == 0
} }

View File

@@ -1,6 +1,6 @@
use crate::ffi::svp::{self, svp_ppol_t}; use crate::ffi::svp::{self, svp_ppol_t};
use crate::ffi::vec_znx_dft::vec_znx_dft_t; use crate::ffi::vec_znx_dft::vec_znx_dft_t;
use crate::{BACKEND, Module, VecZnx, VecZnxDft, assert_alignement}; use crate::{assert_alignement, Module, VecZnx, VecZnxDft, BACKEND, LAYOUT};
use crate::{Infos, alloc_aligned, cast_mut}; use crate::{Infos, alloc_aligned, cast_mut};
use rand::seq::SliceRandom; use rand::seq::SliceRandom;
@@ -119,6 +119,7 @@ impl Scalar {
n: self.n, n: self.n,
size: 1, // TODO REVIEW IF NEED TO ADD size TO SCALAR size: 1, // TODO REVIEW IF NEED TO ADD size TO SCALAR
cols: 1, cols: 1,
layout: LAYOUT::COL,
data: Vec::new(), data: Vec::new(),
ptr: self.ptr, ptr: self.ptr,
} }

View File

@@ -1,6 +1,7 @@
use crate::cast_mut; use crate::cast_mut;
use crate::ffi::vec_znx; use crate::ffi::vec_znx;
use crate::ffi::znx; use crate::ffi::znx;
use crate::LAYOUT;
use crate::{Infos, Module}; use crate::{Infos, Module};
use crate::{alloc_aligned, assert_alignement}; use crate::{alloc_aligned, assert_alignement};
use itertools::izip; use itertools::izip;
@@ -24,6 +25,9 @@ pub struct VecZnx {
/// Stack size /// Stack size
pub size: usize, pub size: usize,
/// Stacking layout
pub layout: LAYOUT,
/// Number of columns. /// Number of columns.
pub cols: usize, pub cols: usize,
@@ -59,6 +63,7 @@ impl VecZnx {
n: n, n: n,
size: size, size: size,
cols: cols, cols: cols,
layout: LAYOUT::COL,
data: Vec::from_raw_parts(ptr, bytes.len(), bytes.len()), data: Vec::from_raw_parts(ptr, bytes.len(), bytes.len()),
ptr: ptr, ptr: ptr,
} }
@@ -76,6 +81,7 @@ impl VecZnx {
n: n, n: n,
size: size, size: size,
cols: cols, cols: cols,
layout: LAYOUT::COL,
data: Vec::new(), data: Vec::new(),
ptr: bytes.as_mut_ptr() as *mut i64, ptr: bytes.as_mut_ptr() as *mut i64,
} }
@@ -254,6 +260,7 @@ impl VecZnx {
Self { Self {
n: n, n: n,
size: size, size: size,
layout: LAYOUT::COL,
cols: cols, cols: cols,
data: data, data: data,
ptr: ptr, ptr: ptr,