Matrix to PIM-Matrix conversion

This commit is contained in:
2024-02-20 22:12:10 +01:00
parent 5509577526
commit cf83e27f50
3 changed files with 22 additions and 13 deletions

View File

@@ -26,17 +26,10 @@ const X16_COLUMNS: usize = COLUMNS / 16;
pub extern "C" fn main() {
pim::state::set_kernel(&samsung_matrix_vector_mul::KERNEL);
let matrix = Box::new(pim::continuous_array::Matrix::<ROWS, X16_COLUMNS>(
SMatrix::from_fn(|r, c| {
if c > 0 {
return F16x16::zero();
}
let mut entry = F16x16::zero();
entry.0.iter_mut().take(r).for_each(|val| *val = F16x1::one());
entry
})));
let mut matrix = SMatrix::<_, ROWS, COLUMNS>::zeros();
matrix.fill_lower_triangle(F16x1::one(), 0);
let pim_matrix = Box::new(pim::continuous_array::Matrix::from(matrix));
let input_vector = SVector::<_, X16_COLUMNS>::from_element(F16x16::one());
let interleaved_input_vector = Box::new(interleaved_array::Vector::from(input_vector));
@@ -53,7 +46,7 @@ pub extern "C" fn main() {
pim::state::set_bank_mode(BankMode::PimAllBank);
samsung_matrix_vector_mul::execute(
matrix.as_ref(),
pim_matrix.as_ref(),
interleaved_input_vector.as_ref(),
output_partial_sum_vector.as_mut(),
dummy.as_ref(),

View File

@@ -1,3 +1,4 @@
#![feature(iter_array_chunks)]
#![no_std]
use core::sync::atomic::{compiler_fence, Ordering};

View File

@@ -1,4 +1,4 @@
use super::vector::F16x16;
use super::vector::{F16x1, F16x16};
use core::fmt::Display;
use nalgebra::SMatrix;
@@ -11,3 +11,18 @@ impl<const R: usize, const C: usize> Display for Matrix<R, C> {
self.0.fmt(f)
}
}
impl<const R: usize, const C: usize, const X16C: usize> From<SMatrix<F16x1, R, C>>
for Matrix<R, X16C>
{
fn from(matrix: SMatrix<F16x1, R, C>) -> Self {
Self(SMatrix::from_row_iterator(
matrix
.transpose()
.iter()
.map(|e| *e)
.array_chunks::<16>()
.map(|chunk| F16x16(chunk)),
))
}
}