MatMulPlan

Struct MatMulPlan 

Source
pub struct MatMulPlan<C: ComplexScalar> { /* private fields */ }
Expand description

Stores a plan for a generalized matrix multiplication (GEMM). Based on the dimensions and underlying field of the matrices, the plan will select the appropriate mili/micro-kernels for performance.

Implementations§

Source§

impl<C: ComplexScalar> MatMulPlan<C>

Source

pub fn new(m: usize, n: usize, k: usize) -> Self

Creates a new GEMM plan for column-major matrices.

§Arguments
  • m: Number of rows in the left-hand side matrix.
  • n: Number of columns in the right-hand side matrix.
  • k: Number of columns in the left-hand side matrix. This should equal the number of rows in the right-hand side matrix.
§Returns
  • A MatMulPlan instance.
Source

pub fn execute_unchecked( &self, lhs: MatRef<'_, C>, rhs: MatRef<'_, C>, out: MatMut<'_, C>, )

Executes the milikernel of the plan, for matrix multiplication. (alpha = 0, beta = 1) We do not perform comprehensive checks.

§Arguments
  • lhs: The left-hand side matrix to multiply.
  • rhs: The right-hand side matrix to multiply.
  • out: The output matrix where the result will be stored.
§Safety
  • The matrices must be column-major.
  • The dimensions of out must be lhs.nrows() * rhs.nrows() by lhs.ncols() * rhs.ncols().
§Examples
use qudit_core::accel::MatMulPlan;
use faer::{mat, Mat};
use qudit_core::c64;

let mut out = Mat::<c64>::zeros(2, 2);

let lhs = mat![
    [c64::new(1.0, 0.0), c64::new(2.0, 0.0)],
    [c64::new(3.0, 0.0), c64::new(4.0, 0.0)]
];
let rhs = mat![
    [c64::new(5.0, 0.0), c64::new(6.0, 0.0)],
    [c64::new(7.0, 0.0), c64::new(8.0, 0.0)]
];

let test_plan = MatMulPlan::new(lhs.nrows(), rhs.ncols(), lhs.ncols());
test_plan.execute_unchecked(lhs.as_ref(), rhs.as_ref(), out.as_mut());

let expected = mat![
    [c64::new(19.0, 0.0), c64::new(22.0, 0.0)],
    [c64::new(43.0, 0.0), c64::new(50.0, 0.0)]
];

assert_eq!(expected, out);
Source

pub unsafe fn execute_raw_unchecked( &self, lhs: *const C, rhs: *const C, out: *mut C, dst_rs: isize, dst_cs: isize, lhs_rs: isize, lhs_cs: isize, rhs_rs: isize, rhs_cs: isize, )

Perform the matrix multiplication given by the plan without checking bounds.

§Safety

The multiplication defined here must be valid. The pointers must point to adequately sized and proper buffers of memory that describe matrices with the dimensions and strides given.

Source

pub fn execute_add_unchecked( &self, lhs: MatRef<'_, C>, rhs: MatRef<'_, C>, out: MatMut<'_, C>, )

Executes the milikernel of the plan, for matrix multiplication followed by addition. (alpha = 1, beta = 1) We do not perform comprehensive checks.

§Arguments
  • lhs: The left-hand side matrix to add.
  • rhs: The right-hand side matrix to add.
  • out: The output matrix where the result will be stored.
§Safety
  • The matrices must be column-major.
  • The dimensions of out must be lhs.nrows() * rhs.nrows() by lhs.ncols() * rhs.ncols().
§Examples
use qudit_core::accel::MatMulPlan;
use faer::{mat, Mat};
use qudit_core::c64;

let mut out = Mat::<c64>::ones(2, 2);

let lhs = mat![
    [c64::new(1.0, 0.0), c64::new(2.0, 0.0)],
    [c64::new(3.0, 0.0), c64::new(4.0, 0.0)]
];
let rhs = mat![
    [c64::new(5.0, 0.0), c64::new(6.0, 0.0)],
    [c64::new(7.0, 0.0), c64::new(8.0, 0.0)]
];

let test_plan = MatMulPlan::new(lhs.nrows(), rhs.ncols(), lhs.ncols());
test_plan.execute_add_unchecked(lhs.as_ref(), rhs.as_ref(), out.as_mut());

let expected = mat![
    [c64::new(20.0, 0.0), c64::new(23.0, 0.0)],
    [c64::new(44.0, 0.0), c64::new(51.0, 0.0)]
];

assert_eq!(expected, out);
Source

pub unsafe fn execute_add_raw_unchecked( &self, lhs: *const C, rhs: *const C, out: *mut C, dst_rs: isize, dst_cs: isize, lhs_rs: isize, lhs_cs: isize, rhs_rs: isize, rhs_cs: isize, )

Perform the additive matrix multiplication given by the plan without checking bounds.

§Safety

The multiplication defined here must be valid. The pointers must point to adequately sized and proper buffers of memory that describe matrices with the dimensions and strides given.

Auto Trait Implementations§

§

impl<C> Freeze for MatMulPlan<C>

§

impl<C> RefUnwindSafe for MatMulPlan<C>

§

impl<C> !Send for MatMulPlan<C>

§

impl<C> !Sync for MatMulPlan<C>

§

impl<C> Unpin for MatMulPlan<C>

§

impl<C> UnwindSafe for MatMulPlan<C>

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> 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<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

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

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V