diff --git a/src/array/native_atomic.rs b/src/array/native_atomic.rs index ff664ea4..b0cc6481 100644 --- a/src/array/native_atomic.rs +++ b/src/array/native_atomic.rs @@ -244,39 +244,45 @@ macro_rules! impl_shift { ($self:ident,$op:tt,$val:ident) => { // mul, div unsafe { - *match $self.array.orig_t { + match $self.array.orig_t { //deref to the original type NativeAtomicType::I8 => { - &compare_exchange_op!(i8, AtomicI8, $self, $val, $op) as *const i8 as *mut T + *(&compare_exchange_op!(i8, AtomicI8, $self, $val, $op) as *const i8 as *mut T) } NativeAtomicType::I16 => { - &compare_exchange_op!(i16, AtomicI16, $self, $val, $op) as *const i16 as *mut T + *(&compare_exchange_op!(i16, AtomicI16, $self, $val, $op) as *const i16 + as *mut T) } NativeAtomicType::I32 => { - &compare_exchange_op!(i32, AtomicI32, $self, $val, $op) as *const i32 as *mut T + *(&compare_exchange_op!(i32, AtomicI32, $self, $val, $op) as *const i32 + as *mut T) } NativeAtomicType::I64 => { - &compare_exchange_op!(i64, AtomicI64, $self, $val, $op) as *const i64 as *mut T + *(&compare_exchange_op!(i64, AtomicI64, $self, $val, $op) as *const i64 + as *mut T) } NativeAtomicType::Isize => { - &compare_exchange_op!(isize, AtomicIsize, $self, $val, $op) as *const isize - as *mut T + *(&compare_exchange_op!(isize, AtomicIsize, $self, $val, $op) as *const isize + as *mut T) } NativeAtomicType::U8 => { - &compare_exchange_op!(u8, AtomicU8, $self, $val, $op) as *const u8 as *mut T + *(&compare_exchange_op!(u8, AtomicU8, $self, $val, $op) as *const u8 as *mut T) } NativeAtomicType::U16 => { - &compare_exchange_op!(u16, AtomicU16, $self, $val, $op) as *const u16 as *mut T + *(&compare_exchange_op!(u16, AtomicU16, $self, $val, $op) as *const u16 + as *mut T) } NativeAtomicType::U32 => { - &compare_exchange_op!(u32, AtomicU32, $self, $val, $op) as *const u32 as *mut T + *(&compare_exchange_op!(u32, AtomicU32, $self, $val, $op) as *const u32 + as *mut T) } NativeAtomicType::U64 => { - &compare_exchange_op!(u64, AtomicU64, $self, $val, $op) as *const u64 as *mut T + *(&compare_exchange_op!(u64, AtomicU64, $self, $val, $op) as *const u64 + as *mut T) } NativeAtomicType::Usize => { - &compare_exchange_op!(usize, AtomicUsize, $self, $val, $op) as *const usize - as *mut T + *(&compare_exchange_op!(usize, AtomicUsize, $self, $val, $op) as *const usize + as *mut T) } } } @@ -286,39 +292,45 @@ macro_rules! impl_mul_div { ($self:ident,$op:tt,$val:ident) => { // mul, div unsafe { - *match $self.array.orig_t { + match $self.array.orig_t { //deref to the original type NativeAtomicType::I8 => { - &compare_exchange_op!(i8, AtomicI8, $self, $val, $op) as *const i8 as *mut T + *(&compare_exchange_op!(i8, AtomicI8, $self, $val, $op) as *const i8 as *mut T) } NativeAtomicType::I16 => { - &compare_exchange_op!(i16, AtomicI16, $self, $val, $op) as *const i16 as *mut T + *(&compare_exchange_op!(i16, AtomicI16, $self, $val, $op) as *const i16 + as *mut T) } NativeAtomicType::I32 => { - &compare_exchange_op!(i32, AtomicI32, $self, $val, $op) as *const i32 as *mut T + *(&compare_exchange_op!(i32, AtomicI32, $self, $val, $op) as *const i32 + as *mut T) } NativeAtomicType::I64 => { - &compare_exchange_op!(i64, AtomicI64, $self, $val, $op) as *const i64 as *mut T + *(&compare_exchange_op!(i64, AtomicI64, $self, $val, $op) as *const i64 + as *mut T) } NativeAtomicType::Isize => { - &compare_exchange_op!(isize, AtomicIsize, $self, $val, $op) as *const isize - as *mut T + *(&compare_exchange_op!(isize, AtomicIsize, $self, $val, $op) as *const isize + as *mut T) } NativeAtomicType::U8 => { - &compare_exchange_op!(u8, AtomicU8, $self, $val, $op) as *const u8 as *mut T + *(&compare_exchange_op!(u8, AtomicU8, $self, $val, $op) as *const u8 as *mut T) } NativeAtomicType::U16 => { - &compare_exchange_op!(u16, AtomicU16, $self, $val, $op) as *const u16 as *mut T + *(&compare_exchange_op!(u16, AtomicU16, $self, $val, $op) as *const u16 + as *mut T) } NativeAtomicType::U32 => { - &compare_exchange_op!(u32, AtomicU32, $self, $val, $op) as *const u32 as *mut T + *(&compare_exchange_op!(u32, AtomicU32, $self, $val, $op) as *const u32 + as *mut T) } NativeAtomicType::U64 => { - &compare_exchange_op!(u64, AtomicU64, $self, $val, $op) as *const u64 as *mut T + *(&compare_exchange_op!(u64, AtomicU64, $self, $val, $op) as *const u64 + as *mut T) } NativeAtomicType::Usize => { - &compare_exchange_op!(usize, AtomicUsize, $self, $val, $op) as *const usize - as *mut T + *(&compare_exchange_op!(usize, AtomicUsize, $self, $val, $op) as *const usize + as *mut T) } } } @@ -329,52 +341,58 @@ macro_rules! impl_add_sub_and_or_xor { //add,sub,and,or (returns value) unsafe { let slice = $self.array.__local_as_mut_slice(); - *match $self.array.orig_t { + match $self.array.orig_t { //deref to the original type - NativeAtomicType::I8 => &slice_as_atomic!(i8, AtomicI8, slice)[$self.local_index] - .$op(as_type!($val, i8), Ordering::SeqCst) - as *const i8 as *mut T, + NativeAtomicType::I8 => { + *(&slice_as_atomic!(i8, AtomicI8, slice)[$self.local_index] + .$op(as_type!($val, i8), Ordering::SeqCst) as *const i8 + as *mut T) + } NativeAtomicType::I16 => { - &slice_as_atomic!(i16, AtomicI16, slice)[$self.local_index] + *(&slice_as_atomic!(i16, AtomicI16, slice)[$self.local_index] .$op(as_type!($val, i16), Ordering::SeqCst) as *const i16 - as *mut T + as *mut T) } NativeAtomicType::I32 => { - &slice_as_atomic!(i32, AtomicI32, slice)[$self.local_index] + *(&slice_as_atomic!(i32, AtomicI32, slice)[$self.local_index] .$op(as_type!($val, i32), Ordering::SeqCst) as *const i32 - as *mut T + as *mut T) } NativeAtomicType::I64 => { - &slice_as_atomic!(i64, AtomicI64, slice)[$self.local_index] + *(&slice_as_atomic!(i64, AtomicI64, slice)[$self.local_index] .$op(as_type!($val, i64), Ordering::SeqCst) as *const i64 - as *mut T - } - NativeAtomicType::Isize => &slice_as_atomic!(isize, AtomicIsize, slice) - [$self.local_index] - .$op(as_type!($val, isize), Ordering::SeqCst) - as *const isize as *mut T, - NativeAtomicType::U8 => &slice_as_atomic!(u8, AtomicU8, slice)[$self.local_index] - .$op(as_type!($val, u8), Ordering::SeqCst) - as *const u8 as *mut T, + as *mut T) + } + NativeAtomicType::Isize => { + *(&slice_as_atomic!(isize, AtomicIsize, slice)[$self.local_index] + .$op(as_type!($val, isize), Ordering::SeqCst) + as *const isize as *mut T) + } + NativeAtomicType::U8 => { + *(&slice_as_atomic!(u8, AtomicU8, slice)[$self.local_index] + .$op(as_type!($val, u8), Ordering::SeqCst) as *const u8 + as *mut T) + } NativeAtomicType::U16 => { - &slice_as_atomic!(u16, AtomicU16, slice)[$self.local_index] + *(&slice_as_atomic!(u16, AtomicU16, slice)[$self.local_index] .$op(as_type!($val, u16), Ordering::SeqCst) as *const u16 - as *mut T + as *mut T) } NativeAtomicType::U32 => { - &slice_as_atomic!(u32, AtomicU32, slice)[$self.local_index] + *(&slice_as_atomic!(u32, AtomicU32, slice)[$self.local_index] .$op(as_type!($val, u32), Ordering::SeqCst) as *const u32 - as *mut T + as *mut T) } NativeAtomicType::U64 => { - &slice_as_atomic!(u64, AtomicU64, slice)[$self.local_index] + *(&slice_as_atomic!(u64, AtomicU64, slice)[$self.local_index] .$op(as_type!($val, u64), Ordering::SeqCst) as *const u64 - as *mut T + as *mut T) + } + NativeAtomicType::Usize => { + *(&slice_as_atomic!(usize, AtomicUsize, slice)[$self.local_index] + .$op(as_type!($val, usize), Ordering::SeqCst) + as *const usize as *mut T) } - NativeAtomicType::Usize => &slice_as_atomic!(usize, AtomicUsize, slice) - [$self.local_index] - .$op(as_type!($val, usize), Ordering::SeqCst) - as *const usize as *mut T, } } }; @@ -486,37 +504,39 @@ macro_rules! impl_swap { //swap unsafe { - *match $self.array.orig_t { + match $self.array.orig_t { //deref to the original type NativeAtomicType::I8 => { - &compare_exchange_op!(i8, AtomicI8, $self, $val) as *const i8 as *mut T + *(&compare_exchange_op!(i8, AtomicI8, $self, $val) as *const i8 as *mut T) } NativeAtomicType::I16 => { - &compare_exchange_op!(i16, AtomicI16, $self, $val) as *const i16 as *mut T + *(&compare_exchange_op!(i16, AtomicI16, $self, $val) as *const i16 as *mut T) } NativeAtomicType::I32 => { - &compare_exchange_op!(i32, AtomicI32, $self, $val) as *const i32 as *mut T + *(&compare_exchange_op!(i32, AtomicI32, $self, $val) as *const i32 as *mut T) } NativeAtomicType::I64 => { - &compare_exchange_op!(i64, AtomicI64, $self, $val) as *const i64 as *mut T + *(&compare_exchange_op!(i64, AtomicI64, $self, $val) as *const i64 as *mut T) } NativeAtomicType::Isize => { - &compare_exchange_op!(isize, AtomicIsize, $self, $val) as *const isize as *mut T + *(&compare_exchange_op!(isize, AtomicIsize, $self, $val) as *const isize + as *mut T) } NativeAtomicType::U8 => { - &compare_exchange_op!(u8, AtomicU8, $self, $val) as *const u8 as *mut T + *(&compare_exchange_op!(u8, AtomicU8, $self, $val) as *const u8 as *mut T) } NativeAtomicType::U16 => { - &compare_exchange_op!(u16, AtomicU16, $self, $val) as *const u16 as *mut T + *(&compare_exchange_op!(u16, AtomicU16, $self, $val) as *const u16 as *mut T) } NativeAtomicType::U32 => { - &compare_exchange_op!(u32, AtomicU32, $self, $val) as *const u32 as *mut T + *(&compare_exchange_op!(u32, AtomicU32, $self, $val) as *const u32 as *mut T) } NativeAtomicType::U64 => { - &compare_exchange_op!(u64, AtomicU64, $self, $val) as *const u64 as *mut T + *(&compare_exchange_op!(u64, AtomicU64, $self, $val) as *const u64 as *mut T) } NativeAtomicType::Usize => { - &compare_exchange_op!(usize, AtomicUsize, $self, $val) as *const usize as *mut T + *(&compare_exchange_op!(usize, AtomicUsize, $self, $val) as *const usize + as *mut T) } } } @@ -526,39 +546,47 @@ macro_rules! impl_swap { macro_rules! impl_compare_exchange { ($self:ident,$old:ident,$val:ident) => { unsafe { - *match $self.array.orig_t { + match $self.array.orig_t { //deref to the original type - NativeAtomicType::I8 => &compare_exchange_op!(i8, AtomicI8, $self, $old, $val) - as *const Result - as *mut Result, - NativeAtomicType::I16 => &compare_exchange_op!(i16, AtomicI16, $self, $old, $val) - as *const Result - as *mut Result, - NativeAtomicType::I32 => &compare_exchange_op!(i32, AtomicI32, $self, $old, $val) - as *const Result - as *mut Result, - NativeAtomicType::I64 => &compare_exchange_op!(i64, AtomicI64, $self, $old, $val) - as *const Result - as *mut Result, + NativeAtomicType::I8 => { + *(&compare_exchange_op!(i8, AtomicI8, $self, $old, $val) + as *const Result as *mut Result) + } + NativeAtomicType::I16 => { + *(&compare_exchange_op!(i16, AtomicI16, $self, $old, $val) + as *const Result as *mut Result) + } + NativeAtomicType::I32 => { + *(&compare_exchange_op!(i32, AtomicI32, $self, $old, $val) + as *const Result as *mut Result) + } + NativeAtomicType::I64 => { + *(&compare_exchange_op!(i64, AtomicI64, $self, $old, $val) + as *const Result as *mut Result) + } NativeAtomicType::Isize => { - &compare_exchange_op!(isize, AtomicIsize, $self, $old, $val) - as *const Result as *mut Result - } - NativeAtomicType::U8 => &compare_exchange_op!(u8, AtomicU8, $self, $old, $val) - as *const Result - as *mut Result, - NativeAtomicType::U16 => &compare_exchange_op!(u16, AtomicU16, $self, $old, $val) - as *const Result - as *mut Result, - NativeAtomicType::U32 => &compare_exchange_op!(u32, AtomicU32, $self, $old, $val) - as *const Result - as *mut Result, - NativeAtomicType::U64 => &compare_exchange_op!(u64, AtomicU64, $self, $old, $val) - as *const Result - as *mut Result, + *(&compare_exchange_op!(isize, AtomicIsize, $self, $old, $val) + as *const Result as *mut Result) + } + NativeAtomicType::U8 => { + *(&compare_exchange_op!(u8, AtomicU8, $self, $old, $val) + as *const Result as *mut Result) + } + NativeAtomicType::U16 => { + *(&compare_exchange_op!(u16, AtomicU16, $self, $old, $val) + as *const Result as *mut Result) + } + NativeAtomicType::U32 => { + *(&compare_exchange_op!(u32, AtomicU32, $self, $old, $val) + as *const Result as *mut Result) + } + NativeAtomicType::U64 => { + *(&compare_exchange_op!(u64, AtomicU64, $self, $old, $val) + as *const Result as *mut Result) + } NativeAtomicType::Usize => { - &compare_exchange_op!(usize, AtomicUsize, $self, $old, $val) - as *const Result as *mut Result + *(&compare_exchange_op!(usize, AtomicUsize, $self, $old, $val) + as *const Result as *mut Result) } } } @@ -568,47 +596,47 @@ macro_rules! impl_compare_exchange { macro_rules! impl_compare_exchange_eps { ($self:ident,$old:ident,$val:ident,$eps:ident) => { unsafe { - *match $self.array.orig_t { + match $self.array.orig_t { //deref to the original type NativeAtomicType::I8 => { - &compare_exchange_op!(i8, AtomicI8, $self, $old, $val, $eps) - as *const Result as *mut Result + *(&compare_exchange_op!(i8, AtomicI8, $self, $old, $val, $eps) + as *const Result as *mut Result) } NativeAtomicType::I16 => { - &compare_exchange_op!(i16, AtomicI16, $self, $old, $val, $eps) - as *const Result as *mut Result + *(&compare_exchange_op!(i16, AtomicI16, $self, $old, $val, $eps) + as *const Result as *mut Result) } NativeAtomicType::I32 => { - &compare_exchange_op!(i32, AtomicI32, $self, $old, $val, $eps) - as *const Result as *mut Result + *(&compare_exchange_op!(i32, AtomicI32, $self, $old, $val, $eps) + as *const Result as *mut Result) } NativeAtomicType::I64 => { - &compare_exchange_op!(i64, AtomicI64, $self, $old, $val, $eps) - as *const Result as *mut Result + *(&compare_exchange_op!(i64, AtomicI64, $self, $old, $val, $eps) + as *const Result as *mut Result) } NativeAtomicType::Isize => { - &compare_exchange_op!(isize, AtomicIsize, $self, $old, $val, $eps) - as *const Result as *mut Result + *(&compare_exchange_op!(isize, AtomicIsize, $self, $old, $val, $eps) + as *const Result as *mut Result) } NativeAtomicType::U8 => { - &compare_exchange_op!(u8, AtomicU8, $self, $old, $val, $eps) - as *const Result as *mut Result + *(&compare_exchange_op!(u8, AtomicU8, $self, $old, $val, $eps) + as *const Result as *mut Result) } NativeAtomicType::U16 => { - &compare_exchange_op!(u16, AtomicU16, $self, $old, $val, $eps) - as *const Result as *mut Result + *(&compare_exchange_op!(u16, AtomicU16, $self, $old, $val, $eps) + as *const Result as *mut Result) } NativeAtomicType::U32 => { - &compare_exchange_op!(u32, AtomicU32, $self, $old, $val, $eps) - as *const Result as *mut Result + *(&compare_exchange_op!(u32, AtomicU32, $self, $old, $val, $eps) + as *const Result as *mut Result) } NativeAtomicType::U64 => { - &compare_exchange_op!(u64, AtomicU64, $self, $old, $val, $eps) - as *const Result as *mut Result + *(&compare_exchange_op!(u64, AtomicU64, $self, $old, $val, $eps) + as *const Result as *mut Result) } NativeAtomicType::Usize => { - &compare_exchange_op!(usize, AtomicUsize, $self, $old, $val, $eps) - as *const Result as *mut Result + *(&compare_exchange_op!(usize, AtomicUsize, $self, $old, $val, $eps) + as *const Result as *mut Result) } } } diff --git a/src/lamellae/rofi/rofi_comm.rs b/src/lamellae/rofi/rofi_comm.rs index 94473cf7..b6025ebc 100644 --- a/src/lamellae/rofi/rofi_comm.rs +++ b/src/lamellae/rofi/rofi_comm.rs @@ -125,6 +125,8 @@ impl RofiComm { let num_r = (dst_addr.len() * std::mem::size_of::()) / std::mem::size_of::(); let r_ptr = dst_addr.as_ptr() as *mut T as *mut R; + // println!("num_r {:?}", num_r); + let mut timer = std::time::Instant::now(); for i in 0..num_r - 2 { while r_ptr.offset(i as isize).read_unaligned() == val @@ -160,12 +162,16 @@ impl RofiComm { //#[tracing::instrument(skip_all)] fn check_buffer(&self, dst_addr: &mut [T]) -> TxResult<()> { let bytes_len = dst_addr.len() * std::mem::size_of::(); + // if bytes_len > 0 { + + // find largest int size that evenly divides bytes_len + // we multiply by 2 because we check two ints at a time unsafe { - if bytes_len % std::mem::size_of::() == 0 { + if bytes_len % (2 * std::mem::size_of::()) == 0 { self.check_buffer_elems(dst_addr, ROFI_MAGIC_8)?; - } else if bytes_len % std::mem::size_of::() == 0 { + } else if bytes_len % (2 * std::mem::size_of::()) == 0 { self.check_buffer_elems(dst_addr, ROFI_MAGIC_4)?; - } else if bytes_len % std::mem::size_of::() == 0 { + } else if bytes_len % (2 * std::mem::size_of::()) == 0 { self.check_buffer_elems(dst_addr, ROFI_MAGIC_2)?; } else { self.check_buffer_elems(dst_addr, ROFI_MAGIC_1)?; diff --git a/src/memregion.rs b/src/memregion.rs index a5bda9fe..af499e5e 100644 --- a/src/memregion.rs +++ b/src/memregion.rs @@ -983,7 +983,16 @@ impl MemoryRegion { let num_bytes = data.len() * std::mem::size_of::(); if let Ok(ptr) = data.as_mut_ptr() { let bytes = std::slice::from_raw_parts_mut(ptr as *mut u8, num_bytes); - // println!("getting {:?} {:?} {:?} {:?} {:?} {:?} {:?}",pe,index,std::mem::size_of::(),data.len(), num_bytes,self.size, self.num_bytes); + // println!( + // "getting {:?} {:?} {:?} {:?} {:?} {:?} {:?}", + // pe, + // index, + // std::mem::size_of::(), + // data.len(), + // num_bytes, + // self.size, + // self.num_bytes + // ); self.rdma .iget(pe, self.addr + index * std::mem::size_of::(), bytes); //(remote pe, src, dst)