Skip to content

Commit

Permalink
ldlt rank update
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah-quinones committed Oct 12, 2024
1 parent fa6ceeb commit 32e16ff
Show file tree
Hide file tree
Showing 22 changed files with 1,625 additions and 418 deletions.
83 changes: 82 additions & 1 deletion faer-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ macro_rules! help2 {

#[allow(unused_macros)]
macro_rules! write2 {
($mat: ident[$idx: expr] = $val: expr) => {{
let __val = $val;
$crate::utils::write::<$C, _>(&mut $mat.rb_mut().__at_mut($idx), __val)
}};
($place: expr, $val: expr) => {{
let __val = $val;
$crate::utils::write::<$C, _>(&mut $place, __val)
Expand Down Expand Up @@ -1060,6 +1064,15 @@ impl<C: ComplexContainer, T: ComplexField<C>, S: Simd> SimdCtx<C, T, S> {
pub fn tail_mask(&self, len: usize) -> T::SimdMask<S> {
T::simd_tail_mask(&self.0, len)
}
#[inline(always)]
pub fn head_mask(&self, len: usize) -> T::SimdMask<S> {
T::simd_head_mask(&self.0, len)
}
#[inline(always)]
pub fn and_mask(&self, lhs: T::SimdMask<S>, rhs: T::SimdMask<S>) -> T::SimdMask<S> {
T::simd_and_mask(&self.0, lhs, rhs)
}

#[inline(always)]
pub unsafe fn mask_load(
&self,
Expand Down Expand Up @@ -1344,6 +1357,14 @@ impl<C: ComplexContainer, T: ComplexField<C>, S: Simd> SimdCtxCopy<C, T, S> {
unsafe { core::mem::transmute_copy(&T::simd_tail_mask(&self.0, len)) }
}
#[inline(always)]
pub fn head_mask(&self, len: usize) -> T::SimdMask<S> {
unsafe { core::mem::transmute_copy(&T::simd_head_mask(&self.0, len)) }
}
#[inline(always)]
pub fn and_mask(&self, lhs: T::SimdMask<S>, rhs: T::SimdMask<S>) -> T::SimdMask<S> {
T::simd_and_mask(&self.0, lhs, rhs)
}
#[inline(always)]
pub unsafe fn mask_load(
&self,
mask: T::SimdMask<S>,
Expand Down Expand Up @@ -1381,7 +1402,7 @@ pub unsafe trait ConjUnit {
type Canonical: ConjUnit<Canonical = Self::Canonical>;
}

pub unsafe trait Container: 'static {
pub unsafe trait Container: 'static + core::fmt::Debug {
type Of<T>;
type OfCopy<T: Copy>: Copy;
type OfDebug<T: Debug>: Debug;
Expand Down Expand Up @@ -2264,6 +2285,12 @@ pub trait ComplexField<C: ComplexContainer = Unit>:
) -> Self::SimdIndex<S>;

fn simd_tail_mask<S: Simd>(ctx: &Self::SimdCtx<S>, len: usize) -> Self::SimdMask<S>;
fn simd_and_mask<S: Simd>(
ctx: &Self::SimdCtx<S>,
lhs: Self::SimdMask<S>,
rhs: Self::SimdMask<S>,
) -> Self::SimdMask<S>;
fn simd_head_mask<S: Simd>(ctx: &Self::SimdCtx<S>, len: usize) -> Self::SimdMask<S>;
unsafe fn simd_mask_load<S: Simd>(
ctx: &Self::SimdCtx<S>,
mask: Self::SimdMask<S>,
Expand Down Expand Up @@ -2926,6 +2953,11 @@ impl<C: RealContainer, T: RealField<C>> ComplexField<Complex<C>> for T {
let ctx = SimdCtx::<C, T, S>::new(ctx);
ctx.tail_mask(len)
}
#[inline(always)]
fn simd_head_mask<S: Simd>(ctx: &Self::SimdCtx<S>, len: usize) -> Self::SimdMask<S> {
let ctx = SimdCtx::<C, T, S>::new(ctx);
ctx.head_mask(len)
}

#[inline(always)]
unsafe fn simd_mask_load<S: Simd>(
Expand Down Expand Up @@ -2996,6 +3028,15 @@ impl<C: RealContainer, T: RealField<C>> ComplexField<Complex<C>> for T {
fn ctx_from_simd<S: Simd>(ctx: &Self::SimdCtx<S>) -> (Self::MathCtx, S) {
T::ctx_from_simd(ctx)
}

#[inline(always)]
fn simd_and_mask<S: Simd>(
ctx: &Self::SimdCtx<S>,
lhs: Self::SimdMask<S>,
rhs: Self::SimdMask<S>,
) -> Self::SimdMask<S> {
T::simd_and_mask(ctx, lhs, rhs)
}
}

impl AsRef<Unit> for Unit {
Expand Down Expand Up @@ -3343,6 +3384,10 @@ impl ComplexField for f32 {
ctx.tail_mask_f32s(len)
}
#[inline(always)]
fn simd_head_mask<S: Simd>(ctx: &Self::SimdCtx<S>, len: usize) -> Self::SimdMask<S> {
ctx.head_mask_f32s(len)
}
#[inline(always)]
unsafe fn simd_mask_load<S: Simd>(
ctx: &Self::SimdCtx<S>,
mask: Self::SimdMask<S>,
Expand Down Expand Up @@ -3399,6 +3444,15 @@ impl ComplexField for f32 {
fn ctx_from_simd<S: Simd>(ctx: &Self::SimdCtx<S>) -> (Self::MathCtx, S) {
(Unit, *ctx)
}

#[inline(always)]
fn simd_and_mask<S: Simd>(
simd: &Self::SimdCtx<S>,
lhs: Self::SimdMask<S>,
rhs: Self::SimdMask<S>,
) -> Self::SimdMask<S> {
simd.and_m32s(lhs, rhs)
}
}

impl RealField for f32 {
Expand Down Expand Up @@ -3769,6 +3823,10 @@ impl ComplexField for f64 {
ctx.tail_mask_f64s(len)
}
#[inline(always)]
fn simd_head_mask<S: Simd>(ctx: &Self::SimdCtx<S>, len: usize) -> Self::SimdMask<S> {
ctx.head_mask_f64s(len)
}
#[inline(always)]
unsafe fn simd_mask_load<S: Simd>(
ctx: &Self::SimdCtx<S>,
mask: Self::SimdMask<S>,
Expand Down Expand Up @@ -3824,6 +3882,15 @@ impl ComplexField for f64 {
fn ctx_from_simd<S: Simd>(ctx: &Self::SimdCtx<S>) -> (Self::MathCtx, S) {
(Unit, *ctx)
}

#[inline(always)]
fn simd_and_mask<S: Simd>(
simd: &Self::SimdCtx<S>,
lhs: Self::SimdMask<S>,
rhs: Self::SimdMask<S>,
) -> Self::SimdMask<S> {
simd.and_m64s(lhs, rhs)
}
}

impl RealField for f64 {
Expand Down Expand Up @@ -4272,6 +4339,11 @@ impl<T: EnableComplex> ComplexField for Complex<T> {
let ctx = SimdCtx::<Unit, T, S>::new(ctx);
ctx.tail_mask(2 * len)
}
#[inline(always)]
fn simd_head_mask<S: Simd>(ctx: &Self::SimdCtx<S>, len: usize) -> Self::SimdMask<S> {
let ctx = SimdCtx::<Unit, T, S>::new(ctx);
ctx.head_mask(2 * len)
}

#[inline(always)]
unsafe fn simd_mask_load<S: Simd>(
Expand Down Expand Up @@ -4324,6 +4396,15 @@ impl<T: EnableComplex> ComplexField for Complex<T> {
fn ctx_from_simd<S: Simd>(ctx: &Self::SimdCtx<S>) -> (Self::MathCtx, S) {
T::ctx_from_simd(ctx)
}

#[inline(always)]
fn simd_and_mask<S: Simd>(
simd: &Self::SimdCtx<S>,
lhs: Self::SimdMask<S>,
rhs: Self::SimdMask<S>,
) -> Self::SimdMask<S> {
T::simd_and_mask(simd, lhs, rhs)
}
}

impl EnableComplex for f32 {
Expand Down
23 changes: 19 additions & 4 deletions faer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
#![allow(non_snake_case)]

use core::{num::NonZeroUsize, sync::atomic::AtomicUsize};
use core::{num::NonZero, sync::atomic::AtomicUsize};
use equator::{assert, debug_assert};
use faer_traits::*;

macro_rules! stack_mat {
($ctx: expr, $name: ident, $m: expr, $n: expr, $M: expr, $N: expr, $C: ty, $T: ty $(,)?) => {
let mut __tmp = {
#[repr(align(64))]
struct __Col<T, const M: usize>([T; M]);
struct __Mat<T, const M: usize, const N: usize>([__Col<T, M>; N]);

core::mem::MaybeUninit::<C::Of<__Mat<T, $M, $N>>>::uninit()
};
let __stack = DynStack::new_any(core::slice::from_mut(&mut __tmp));
let mut $name = unsafe { temp_mat_uninit($ctx, $m, $n, __stack) }.0;
let mut $name = $name.as_mat_mut();
};
}

#[macro_export]
#[doc(hidden)]
macro_rules! __dbg {
Expand Down Expand Up @@ -448,16 +463,16 @@ impl Conj {
pub enum Parallelism {
None,
#[cfg(feature = "rayon")]
Rayon(NonZeroUsize),
Rayon(NonZero<usize>),
}

impl Parallelism {
#[cfg(feature = "rayon")]
pub fn rayon(nthreads: usize) -> Self {
if nthreads == 0 {
Self::Rayon(NonZeroUsize::new(rayon::current_num_threads()).unwrap())
Self::Rayon(NonZero::new(rayon::current_num_threads()).unwrap())
} else {
Self::Rayon(NonZeroUsize::new(nthreads).unwrap())
Self::Rayon(NonZero::new(nthreads).unwrap())
}
}
}
Expand Down
Loading

0 comments on commit 32e16ff

Please sign in to comment.