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>
impl<C: ComplexScalar> MatMulPlan<C>
Sourcepub fn new(m: usize, n: usize, k: usize) -> Self
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
MatMulPlaninstance.
Sourcepub fn execute_unchecked(
&self,
lhs: MatRef<'_, C>,
rhs: MatRef<'_, C>,
out: MatMut<'_, C>,
)
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
outmust belhs.nrows() * rhs.nrows()bylhs.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);Sourcepub 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,
)
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.
Sourcepub fn execute_add_unchecked(
&self,
lhs: MatRef<'_, C>,
rhs: MatRef<'_, C>,
out: MatMut<'_, C>,
)
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
outmust belhs.nrows() * rhs.nrows()bylhs.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);Sourcepub 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,
)
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.