Restructure pim-os project
This commit is contained in:
@@ -10,9 +10,9 @@ use nalgebra::{SMatrix, SVector};
|
|||||||
use num_traits::{One, Zero};
|
use num_traits::{One, Zero};
|
||||||
use pim_isa::BankMode;
|
use pim_isa::BankMode;
|
||||||
use pim_os::{
|
use pim_os::{
|
||||||
|
kernel::gemv,
|
||||||
pim::{
|
pim::{
|
||||||
self, interleaved_array,
|
self, interleaved_array,
|
||||||
kernel::samsung_matrix_vector_mul,
|
|
||||||
vector::{F16x1, F16x16},
|
vector::{F16x1, F16x16},
|
||||||
},
|
},
|
||||||
uart::Uart0,
|
uart::Uart0,
|
||||||
@@ -25,7 +25,7 @@ const X16_COLUMNS: usize = COLUMNS / 16;
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn main() {
|
pub extern "C" fn main() {
|
||||||
pim::state::set_kernel(&samsung_matrix_vector_mul::KERNEL);
|
pim::state::set_kernel(&gemv::KERNEL);
|
||||||
|
|
||||||
let mut matrix = SMatrix::<_, ROWS, COLUMNS>::zeros();
|
let mut matrix = SMatrix::<_, ROWS, COLUMNS>::zeros();
|
||||||
matrix.fill_lower_triangle(F16x1::one(), 0);
|
matrix.fill_lower_triangle(F16x1::one(), 0);
|
||||||
@@ -46,7 +46,7 @@ pub extern "C" fn main() {
|
|||||||
{
|
{
|
||||||
pim::state::set_bank_mode(BankMode::PimAllBank);
|
pim::state::set_bank_mode(BankMode::PimAllBank);
|
||||||
|
|
||||||
samsung_matrix_vector_mul::execute(
|
gemv::execute(
|
||||||
pim_matrix.as_ref(),
|
pim_matrix.as_ref(),
|
||||||
interleaved_input_vector.as_ref(),
|
interleaved_input_vector.as_ref(),
|
||||||
output_partial_sum_vector.as_mut(),
|
output_partial_sum_vector.as_mut(),
|
||||||
69
pim-os/src/bin/vadd.rs
Normal file
69
pim-os/src/bin/vadd.rs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
use aarch64_cpu::asm::barrier;
|
||||||
|
use alloc::boxed::Box;
|
||||||
|
use core::fmt::Write;
|
||||||
|
use nalgebra::{SMatrix, SVector};
|
||||||
|
use num_traits::{One, Zero};
|
||||||
|
use pim_isa::BankMode;
|
||||||
|
use pim_os::{
|
||||||
|
kernel::gemv,
|
||||||
|
pim::{
|
||||||
|
self, interleaved_array,
|
||||||
|
vector::{F16x1, F16x16},
|
||||||
|
},
|
||||||
|
uart::Uart0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const ROWS: usize = 32;
|
||||||
|
const COLUMNS: usize = 128;
|
||||||
|
const X16_ROWS: usize = ROWS / 16;
|
||||||
|
const X16_COLUMNS: usize = COLUMNS / 16;
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn main() {
|
||||||
|
pim::state::set_kernel(&gemv::KERNEL);
|
||||||
|
|
||||||
|
let mut matrix = SMatrix::<_, ROWS, COLUMNS>::zeros();
|
||||||
|
matrix.fill_lower_triangle(F16x1::one(), 0);
|
||||||
|
|
||||||
|
let pim_matrix = Box::new(pim::continuous_array::Matrix::<X16_ROWS, X16_COLUMNS>::from(matrix));
|
||||||
|
|
||||||
|
let input_vector = SVector::<_, X16_COLUMNS>::from_element(F16x16::one());
|
||||||
|
let interleaved_input_vector = Box::new(interleaved_array::Vector::from(input_vector));
|
||||||
|
|
||||||
|
let mut output_partial_sum_vector = Box::new(SVector::<F16x16, ROWS>::zeros());
|
||||||
|
|
||||||
|
let dummy = Box::new(0);
|
||||||
|
|
||||||
|
// Verify everything is correctly initialized before PIM operation
|
||||||
|
barrier::dsb(barrier::SY);
|
||||||
|
|
||||||
|
// Execute kernel
|
||||||
|
{
|
||||||
|
pim::state::set_bank_mode(BankMode::PimAllBank);
|
||||||
|
|
||||||
|
gemv::execute(
|
||||||
|
pim_matrix.as_ref(),
|
||||||
|
interleaved_input_vector.as_ref(),
|
||||||
|
output_partial_sum_vector.as_mut(),
|
||||||
|
dummy.as_ref(),
|
||||||
|
);
|
||||||
|
|
||||||
|
pim::state::set_bank_mode(BankMode::SingleBank);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeln!(Uart0, "{output_partial_sum_vector}").unwrap();
|
||||||
|
|
||||||
|
let output_vector = SVector::<F16x1, ROWS>::from_fn(|r, _| {
|
||||||
|
output_partial_sum_vector[r]
|
||||||
|
.0
|
||||||
|
.iter()
|
||||||
|
.fold(F16x1::zero(), |acc, val| acc + *val)
|
||||||
|
});
|
||||||
|
|
||||||
|
writeln!(Uart0, "{output_vector}").unwrap();
|
||||||
|
}
|
||||||
2
pim-os/src/kernel.rs
Normal file
2
pim-os/src/kernel.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod legacy;
|
||||||
|
pub mod gemv;
|
||||||
3
pim-os/src/kernel/legacy.rs
Normal file
3
pim-os/src/kernel/legacy.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub mod matrix_matrix_mul;
|
||||||
|
pub mod matrix_scalar_mul;
|
||||||
|
pub mod matrix_vector_mul;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::pim::array::{DummyArray, PimMatrixArena, PimRegion};
|
use crate::pim::legacy::array::{DummyArray, PimMatrixArena, PimRegion};
|
||||||
use pim_isa::{File, Instruction, Kernel};
|
use pim_isa::{File, Instruction, Kernel};
|
||||||
|
|
||||||
pub const KERNEL: Kernel = Kernel([
|
pub const KERNEL: Kernel = Kernel([
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::pim::array::{DummyArray, PimMatrixArena, PimRegion};
|
use crate::pim::legacy::array::{DummyArray, PimMatrixArena, PimRegion};
|
||||||
use pim_isa::{File, Instruction, Kernel};
|
use pim_isa::{File, Instruction, Kernel};
|
||||||
|
|
||||||
pub const KERNEL: Kernel = Kernel([
|
pub const KERNEL: Kernel = Kernel([
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::pim::array::{DummyArray, PimMatrixArena, PimRegion, PimScalarArena};
|
use crate::pim::legacy::array::{DummyArray, PimMatrixArena, PimRegion, PimScalarArena};
|
||||||
use pim_isa::{File, Instruction, Kernel};
|
use pim_isa::{File, Instruction, Kernel};
|
||||||
|
|
||||||
pub const KERNEL: Kernel = Kernel([
|
pub const KERNEL: Kernel = Kernel([
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::pim::array::{DummyArray, PimMatrixArena, PimRegion};
|
use crate::pim::legacy::array::{DummyArray, PimMatrixArena, PimRegion};
|
||||||
use pim_isa::{File, Instruction, Kernel};
|
use pim_isa::{File, Instruction, Kernel};
|
||||||
|
|
||||||
pub const KERNEL: Kernel = Kernel([
|
pub const KERNEL: Kernel = Kernel([
|
||||||
@@ -4,10 +4,13 @@
|
|||||||
use core::sync::atomic::{compiler_fence, Ordering};
|
use core::sync::atomic::{compiler_fence, Ordering};
|
||||||
|
|
||||||
mod alloc;
|
mod alloc;
|
||||||
|
mod panic;
|
||||||
|
|
||||||
pub mod boot;
|
pub mod boot;
|
||||||
pub mod critical_section;
|
pub mod critical_section;
|
||||||
|
pub mod kernel;
|
||||||
pub mod m5op;
|
pub mod m5op;
|
||||||
mod panic;
|
pub mod memory_config;
|
||||||
pub mod pim;
|
pub mod pim;
|
||||||
pub mod uart;
|
pub mod uart;
|
||||||
|
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
#![no_std]
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
extern crate alloc;
|
|
||||||
|
|
||||||
use aarch64_cpu::asm::barrier;
|
|
||||||
use alloc::{boxed::Box, rc::Rc};
|
|
||||||
use core::{cell::RefCell, fmt::Write};
|
|
||||||
use half::f16;
|
|
||||||
use nalgebra::Matrix;
|
|
||||||
use pim_isa::BankMode;
|
|
||||||
use pim_os::{
|
|
||||||
m5op,
|
|
||||||
pim::{
|
|
||||||
self,
|
|
||||||
array::{DummyArray, PimMatrixArena, PimStorage, NUMBER_OF_BANKS},
|
|
||||||
kernel::matrix_matrix_mul,
|
|
||||||
vector::{F16x1, F16x16},
|
|
||||||
},
|
|
||||||
uart::Uart0,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn main() {
|
|
||||||
pim::state::set_kernel(&matrix_matrix_mul::KERNEL);
|
|
||||||
|
|
||||||
let pim_matrix_arena0 = Rc::new(RefCell::new(PimMatrixArena(
|
|
||||||
[[[F16x16::default(); NUMBER_OF_BANKS]; 8]; 8],
|
|
||||||
)));
|
|
||||||
let pim_matrix_arena1 = Rc::new(RefCell::new(PimMatrixArena(
|
|
||||||
[[[F16x16::default(); NUMBER_OF_BANKS]; 8]; 8],
|
|
||||||
)));
|
|
||||||
let pim_matrix_arena2 = Rc::new(RefCell::new(PimMatrixArena(
|
|
||||||
[[[F16x16::default(); NUMBER_OF_BANKS]; 8]; 8],
|
|
||||||
)));
|
|
||||||
|
|
||||||
let mut matrix0 = Matrix::from_data(PimStorage {
|
|
||||||
arena: &pim_matrix_arena0,
|
|
||||||
index: 0,
|
|
||||||
});
|
|
||||||
matrix0.fill_lower_triangle(F16x1(f16::ONE), 0);
|
|
||||||
|
|
||||||
let mut matrix1 = Matrix::from_data(PimStorage {
|
|
||||||
arena: &pim_matrix_arena1,
|
|
||||||
index: 0,
|
|
||||||
});
|
|
||||||
matrix1.fill_lower_triangle(F16x1(f16::ONE), 0);
|
|
||||||
|
|
||||||
let matrix2 = Matrix::from_data(PimStorage {
|
|
||||||
arena: &pim_matrix_arena2,
|
|
||||||
index: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
writeln!(Uart0, "{matrix0} * {matrix1}\n=").unwrap();
|
|
||||||
|
|
||||||
let dummy_array = Box::new(DummyArray([F16x16::default(); NUMBER_OF_BANKS]));
|
|
||||||
|
|
||||||
// Verify everything is correctly initialized before PIM operation
|
|
||||||
barrier::dsb(barrier::SY);
|
|
||||||
|
|
||||||
// Execute kernel
|
|
||||||
{
|
|
||||||
let pim_matrix_arena0 = &pim_matrix_arena0.borrow();
|
|
||||||
let pim_matrix_arena1 = &pim_matrix_arena1.borrow();
|
|
||||||
let pim_matrix_arena2 = &mut pim_matrix_arena2.borrow_mut();
|
|
||||||
|
|
||||||
pim::state::set_bank_mode(BankMode::PimAllBank);
|
|
||||||
|
|
||||||
m5op::reset_stats();
|
|
||||||
|
|
||||||
for _ in 0..100 {
|
|
||||||
matrix_matrix_mul::execute(
|
|
||||||
pim_matrix_arena0,
|
|
||||||
pim_matrix_arena1,
|
|
||||||
pim_matrix_arena2,
|
|
||||||
dummy_array.as_ref(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
m5op::dump_stats();
|
|
||||||
|
|
||||||
pim::state::set_bank_mode(BankMode::SingleBank);
|
|
||||||
}
|
|
||||||
|
|
||||||
writeln!(Uart0, "{matrix2}").unwrap();
|
|
||||||
}
|
|
||||||
1
pim-os/src/memory_config.rs
Normal file
1
pim-os/src/memory_config.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub const NUMBER_OF_BANKS: usize = 32;
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
pub mod array;
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod continuous_array;
|
pub mod continuous_array;
|
||||||
pub mod interleaved_array;
|
pub mod interleaved_array;
|
||||||
pub mod kernel;
|
pub mod legacy;
|
||||||
pub mod operation;
|
pub mod operation;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
pub mod vector;
|
pub mod vector;
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
use super::vector::{F16x1, F16x16};
|
use super::vector::{F16x1, F16x16};
|
||||||
use core::fmt::Display;
|
use core::fmt::Display;
|
||||||
use nalgebra::SMatrix;
|
use nalgebra::{SMatrix, SVector};
|
||||||
|
|
||||||
#[repr(C, align(65536))]
|
#[repr(C, align(65536))]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Matrix<const X16R: usize, const X16C: usize>(pub [SMatrix<F16x16, 16, X16C>; X16R]);
|
pub struct Matrix<const X16R: usize, const X16C: usize>(pub [SMatrix<F16x16, 16, X16C>; X16R]);
|
||||||
|
|
||||||
|
#[repr(C, align(1024))]
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Vector<const R: usize>(pub SVector<F16x1, R>);
|
||||||
|
|
||||||
impl<const X16R: usize, const X16C: usize> Display for Matrix<X16R, X16C> {
|
impl<const X16R: usize, const X16C: usize> Display for Matrix<X16R, X16C> {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
for block in self.0.iter() {
|
for block in self.0.iter() {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::{array::NUMBER_OF_BANKS, vector::F16x16};
|
use super::vector::F16x16;
|
||||||
|
use crate::memory_config::NUMBER_OF_BANKS;
|
||||||
use nalgebra::SVector;
|
use nalgebra::SVector;
|
||||||
|
|
||||||
#[repr(C, align(512))]
|
#[repr(C, align(512))]
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
pub mod matrix_matrix_add;
|
|
||||||
pub mod matrix_matrix_mul;
|
|
||||||
pub mod matrix_scalar_mul;
|
|
||||||
pub mod matrix_vector_mul;
|
|
||||||
pub mod samsung_matrix_vector_mul;
|
|
||||||
1
pim-os/src/pim/legacy.rs
Normal file
1
pim-os/src/pim/legacy.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod array;
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
use super::vector::{F16x1, F16x16};
|
use crate::{
|
||||||
|
memory_config::NUMBER_OF_BANKS,
|
||||||
|
pim::vector::{F16x1, F16x16},
|
||||||
|
};
|
||||||
use aarch64_cpu::asm::barrier;
|
use aarch64_cpu::asm::barrier;
|
||||||
use core::{arch::asm, cell::RefCell};
|
use core::{arch::asm, cell::RefCell};
|
||||||
use half::f16;
|
use half::f16;
|
||||||
use nalgebra::{Const, Dyn, RawStorage, RawStorageMut};
|
use nalgebra::{Const, Dyn, RawStorage, RawStorageMut};
|
||||||
|
|
||||||
pub const NUMBER_OF_BANKS: usize = 32;
|
|
||||||
const EVEN_BANK_INDEX: usize = 0;
|
const EVEN_BANK_INDEX: usize = 0;
|
||||||
const ODD_BANK_INDEX: usize = 8;
|
const ODD_BANK_INDEX: usize = 8;
|
||||||
|
|
||||||
Reference in New Issue
Block a user