Skip to main content

Application

Struct Application 

Source
pub struct Application {
Show 17 fields pub prog: Program, pub mir: Mir, pub compiled: Box<dyn Compiled<f64>>, pub compiled_simd: Option<Box<dyn Compiled<f64>>>, pub compiled_fast: Option<Box<dyn Compiled<f64>>>, pub params: Vec<f64>, pub use_simd: bool, pub use_threads: bool, pub can_fast: bool, pub first_state: usize, pub first_param: usize, pub first_obs: usize, pub first_diff: usize, pub count_states: usize, pub count_params: usize, pub count_obs: usize, pub count_diffs: usize,
}

Fields§

§prog: Program§mir: Mir§compiled: Box<dyn Compiled<f64>>§compiled_simd: Option<Box<dyn Compiled<f64>>>§compiled_fast: Option<Box<dyn Compiled<f64>>>§params: Vec<f64>§use_simd: bool§use_threads: bool§can_fast: bool§first_state: usize§first_param: usize§first_obs: usize§first_diff: usize§count_states: usize§count_params: usize§count_obs: usize§count_diffs: usize

Implementations§

Source§

impl Application

Source

pub fn call(&mut self, args: &[f64]) -> Vec<f64>

Calls the compiled function.

args is a slice of f64 values, corresponding to the states.

The output is a Vec<f64>, corresponding to the observables (the expressions passed to compile).

Source

pub fn call_params(&mut self, args: &[f64], params: &[f64]) -> Vec<f64>

Sets the params and calls the compiled function.

args is a slice of f64 values, corresponding to the states. params is a slice of f64 values, corresponding to the params.

The output is a Vec<f64>, corresponding to the observables (the expressions passed to compile).

Source

pub fn evaluate<T>(&mut self, args: &[T], outs: &mut [T])
where T: Copy,

Generic evaluate function for compiled Symbolica expressions

Source

pub fn evaluate_single<T>(&mut self, args: &[T]) -> T
where T: Copy + Default,

Generic evaluate_single function for compiled Symbolica expressions

Source

pub fn evaluate_simd<T>(&mut self, args: &[T], outs: &mut [T])
where T: Copy,

Generic SIMD evaluate function for compiled Symbolica expressions

Source

pub fn evaluate_simd_single<T>(&mut self, args: &[T]) -> T
where T: Copy + Default,

Generic SIMD evaluate_single function for compiled Symbolica expressions

Source

pub fn evaluate_matrix_with_threads( &mut self, args: &[f64], outs: &mut [f64], n: usize, )

Generic evaluate function for compiled Symbolica expressions

Source

pub fn evaluate_matrix_without_threads( &mut self, args: &[f64], outs: &mut [f64], n: usize, )

Generic evaluate function for compiled Symbolica expressions

Source

pub fn evaluate_matrix_with_threads_simd( &mut self, args: &[f64], outs: &mut [f64], n: usize, transpose: bool, )

Source

pub fn evaluate_matrix_without_threads_simd( &mut self, args: &[f64], outs: &mut [f64], n: usize, transpose: bool, )

Source

pub fn evaluate_matrix_bytecode( &mut self, args: &[f64], outs: &mut [f64], n: usize, )

Source

pub fn evaluate_matrix(&mut self, args: &[f64], outs: &mut [f64], n: usize)

Generic evaluate function for compiled Symbolica expressions

Source

pub fn evaluate_complex_matrix( &mut self, args: &[Complex<f64>], outs: &mut [Complex<f64>], n: usize, )

Source

pub fn evaluate_simd_matrix<T>(&mut self, args: &[T], outs: &mut [T], n: usize)
where T: Copy,

Generic evaluate function for compiled Symbolica expressions

Source

pub fn call_simd(&mut self, args: &[__m256d]) -> Result<Vec<__m256d>, Error>

Calls the compiled SIMD function.

args is a slice of __m256d values, corresponding to the states.

The output is an Result wrapping Vec<__m256d>, corresponding to the observables (the expressions passed to compile).

Note: currently, this function only works on X86-64 CPUs with the AVX extension. Intel introduced the AVX instruction set in 2011; therefore, most intel and AMD processors support it. If SIMD is not supported, this function returns None.

Source

pub fn call_simd_params( &mut self, args: &[__m256d], params: &[f64], ) -> Result<Vec<__m256d>, Error>

Sets the params and calls the compiled SIMD function.

args is a slice of __m256d values, corresponding to the states.

params is a slice of f64 values.

The output is a Result wrapping a Vec<__m256d>, corresponding to the observables (the expressions passed to compile).

Note: currently, this function only works on X86-64 CPUs with the AVX extension. Intel introduced the AVX instruction set in 2011; therefore, most intel and AMD processors support it. If SIMD is not supported, this function returns None.

Source

pub fn fast_func(&mut self) -> Result<FastFunc<'_>, Error>

Returns a fast function.

Application call functions need to copy the input argument slice into the function memory area and then copy the output to a Vec. This process is acceptable for large and complex functions but incurs a penalty for small functions. Therefore, for a certain subset of applications, Symjit can compile a fast funcction and return a function pointer. Examples:

fn test_fast() -> Result<()> {
    let x = Expr::var("x");
    let y = Expr::var("y");
    let z = Expr::var("z");
    let u = &x * &(&y - &z).pow(&Expr::from(2));

    let mut comp = Compiler::new();
    let mut app = comp.compile(&[x, y, z], &[u])?;
    let f = app.fast_func()?;

    if let FastFunc::F3(f, _) = f {
        let res = f(3.0, 5.0, 9.0);
        println!("fast\t{:?}", &res);
    }

    Ok(())
}

The conditions for a fast function are:

  • A fast function can have 1 to 8 arguments.
  • No SIMD and no parameters.
  • It returns only a single value.

If these conditions are met, you can generate a fast functin by calling app.fast_func(), with a return type of Result<FastFunc>. FastFunc is an enum with eight variants F1, F2, ..., F8`, corresponding to functions with 1 to 8 arguments.

Source§

impl Application

Source

pub fn new( prog: Program, reals: HashSet<Loc>, df: &Defuns, ) -> Result<Application, Error>

Source

pub fn exec(&mut self)

Source

pub fn exec_callable(&mut self, xx: &[f64]) -> f64

Source

pub fn prepare_simd(&mut self)

Source

pub fn get_fast( &mut self, ) -> Option<fn(*const f64, *const *mut f64, usize, *const f64)>

Source

pub fn exec_vectorized(&mut self, states: &Matrix, obs: &mut Matrix)

Source

pub fn exec_vectorized_simple(&mut self, states: &Matrix, obs: &mut Matrix)

Source

pub fn exec_vectorized_scalar( &mut self, states: &Matrix, obs: &mut Matrix, threads: bool, )

Source

pub fn exec_vectorized_simd( &mut self, states: &Matrix, obs: &mut Matrix, threads: bool, l: usize, )

Source

pub fn dump(&mut self, name: &str, what: &str) -> bool

Source

pub fn dumps(&self) -> Vec<u8>

Trait Implementations§

Source§

impl Storage for Application

Source§

fn save(&self, stream: &mut impl Write) -> Result<(), Error>

Source§

fn load(stream: &mut impl Read) -> Result<Application, Error>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.