Refactor project to be more modular
This commit is contained in:
24
pim-os/Cargo.lock
generated
24
pim-os/Cargo.lock
generated
@@ -200,18 +200,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.72"
|
||||
version = "1.0.76"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a293318316cf6478ec1ad2a21c49390a8d5b5eae9fab736467d93fbc0edc29c5"
|
||||
checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.33"
|
||||
version = "1.0.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
@@ -239,15 +239,15 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.20"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
|
||||
checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.193"
|
||||
version = "1.0.195"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
|
||||
checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
@@ -265,9 +265,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.193"
|
||||
version = "1.0.195"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
|
||||
checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -303,9 +303,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.43"
|
||||
version = "2.0.48"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53"
|
||||
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
||||
18
pim-os/src/alloc.rs
Normal file
18
pim-os/src/alloc.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
extern crate alloc;
|
||||
|
||||
use core::mem::MaybeUninit;
|
||||
use embedded_alloc::Heap;
|
||||
|
||||
#[global_allocator]
|
||||
static PIM_ALLOC: Heap = Heap::empty();
|
||||
|
||||
const PIM_ARENA_SIZE: usize = 0x2000000;
|
||||
|
||||
#[link_section = ".pim_data"]
|
||||
static mut PIM_ARENA: [MaybeUninit<u8>; PIM_ARENA_SIZE] = [MaybeUninit::uninit(); PIM_ARENA_SIZE];
|
||||
|
||||
pub fn init() {
|
||||
unsafe {
|
||||
PIM_ALLOC.init(PIM_ARENA.as_ptr() as usize, PIM_ARENA_SIZE);
|
||||
}
|
||||
}
|
||||
78
pim-os/src/bin/matrix_matrix_add.rs
Normal file
78
pim-os/src/bin/matrix_matrix_add.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
#![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::{
|
||||
pim::{
|
||||
self,
|
||||
array::{DummyArray, PimMatrixArena, PimStorage, NUMBER_OF_BANKS},
|
||||
kernel::matrix_matrix_add,
|
||||
vector::{F16x1, F16x16},
|
||||
},
|
||||
uart::Uart0,
|
||||
};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn main() {
|
||||
pim::state::set_kernel(&matrix_matrix_add::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);
|
||||
|
||||
{
|
||||
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);
|
||||
|
||||
matrix_matrix_add::execute(
|
||||
pim_matrix_arena0,
|
||||
pim_matrix_arena1,
|
||||
pim_matrix_arena2,
|
||||
dummy_array.as_ref(),
|
||||
);
|
||||
|
||||
pim::state::set_bank_mode(BankMode::SingleBank);
|
||||
}
|
||||
|
||||
writeln!(Uart0, "{matrix2}").unwrap();
|
||||
}
|
||||
79
pim-os/src/bin/matrix_matrix_multiply.rs
Normal file
79
pim-os/src/bin/matrix_matrix_multiply.rs
Normal file
@@ -0,0 +1,79 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
use aarch64_cpu::asm::barrier;
|
||||
use alloc::{boxed::Box, rc::Rc};
|
||||
use pim_isa::BankMode;
|
||||
use core::{cell::RefCell, fmt::Write};
|
||||
use half::f16;
|
||||
use nalgebra::Matrix;
|
||||
use pim_os::{
|
||||
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);
|
||||
|
||||
matrix_matrix_mul::execute(
|
||||
pim_matrix_arena0,
|
||||
pim_matrix_arena1,
|
||||
pim_matrix_arena2,
|
||||
dummy_array.as_ref(),
|
||||
);
|
||||
|
||||
pim::state::set_bank_mode(BankMode::SingleBank);
|
||||
}
|
||||
|
||||
writeln!(Uart0, "{matrix2}").unwrap();
|
||||
}
|
||||
73
pim-os/src/bin/matrix_scalar_multiply.rs
Normal file
73
pim-os/src/bin/matrix_scalar_multiply.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
#![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::{
|
||||
pim::{
|
||||
self,
|
||||
array::{DummyArray, PimMatrixArena, PimScalarArena, PimStorage, NUMBER_OF_BANKS},
|
||||
kernel::matrix_scalar_mul,
|
||||
vector::{F16x1, F16x16},
|
||||
},
|
||||
uart::Uart0,
|
||||
};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn main() {
|
||||
pim::state::set_kernel(&matrix_scalar_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 mut matrix0 = Matrix::from_data(PimStorage {
|
||||
arena: &pim_matrix_arena0,
|
||||
index: 0,
|
||||
});
|
||||
matrix0.fill_lower_triangle(F16x1(f16::ONE), 0);
|
||||
|
||||
let matrix1 = Matrix::from_data(PimStorage {
|
||||
arena: &pim_matrix_arena1,
|
||||
index: 0,
|
||||
});
|
||||
|
||||
let pim_scalar_arena = Box::new(PimScalarArena(
|
||||
[F16x16([F16x1(f16::from_f32(2.0)); 16]); 32],
|
||||
));
|
||||
|
||||
writeln!(Uart0, "{} * {matrix0}\n=", pim_scalar_arena.0[0].0[0]).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 = &mut pim_matrix_arena1.borrow_mut();
|
||||
|
||||
pim::state::set_bank_mode(BankMode::PimAllBank);
|
||||
|
||||
matrix_scalar_mul::execute(
|
||||
pim_scalar_arena.as_ref(),
|
||||
pim_matrix_arena0,
|
||||
pim_matrix_arena1,
|
||||
dummy_array.as_ref(),
|
||||
);
|
||||
|
||||
pim::state::set_bank_mode(BankMode::SingleBank);
|
||||
}
|
||||
|
||||
writeln!(Uart0, "{matrix1}").unwrap();
|
||||
}
|
||||
79
pim-os/src/bin/matrix_vector_multiply.rs
Normal file
79
pim-os/src/bin/matrix_vector_multiply.rs
Normal file
@@ -0,0 +1,79 @@
|
||||
#![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::{
|
||||
pim::{
|
||||
self,
|
||||
array::{DummyArray, PimMatrixArena, PimStorage, NUMBER_OF_BANKS},
|
||||
kernel::matrix_vector_mul,
|
||||
vector::{F16x1, F16x16},
|
||||
},
|
||||
uart::Uart0,
|
||||
};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn main() {
|
||||
pim::state::set_kernel(&matrix_vector_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]; 1],
|
||||
)));
|
||||
let pim_matrix_arena2 = Rc::new(RefCell::new(PimMatrixArena(
|
||||
[[[F16x16::default(); NUMBER_OF_BANKS]; 8]; 1],
|
||||
)));
|
||||
|
||||
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);
|
||||
|
||||
matrix_vector_mul::execute(
|
||||
pim_matrix_arena0,
|
||||
pim_matrix_arena1,
|
||||
pim_matrix_arena2,
|
||||
dummy_array.as_ref(),
|
||||
);
|
||||
|
||||
pim::state::set_bank_mode(BankMode::SingleBank);
|
||||
}
|
||||
|
||||
writeln!(Uart0, "{matrix2}").unwrap();
|
||||
}
|
||||
28
pim-os/src/lib.rs
Normal file
28
pim-os/src/lib.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
#![feature(generic_const_exprs)]
|
||||
#![no_std]
|
||||
|
||||
use core::sync::atomic::{compiler_fence, Ordering};
|
||||
|
||||
mod alloc;
|
||||
pub mod boot;
|
||||
pub mod critical_section;
|
||||
pub mod m5ops;
|
||||
mod panic;
|
||||
pub mod pim;
|
||||
pub mod uart;
|
||||
|
||||
extern "C" {
|
||||
fn main();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entry() -> ! {
|
||||
alloc::init();
|
||||
|
||||
unsafe { main() }
|
||||
|
||||
m5ops::exit();
|
||||
loop {
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
#![feature(generic_const_exprs)]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
@@ -6,51 +5,23 @@ extern crate alloc;
|
||||
|
||||
use aarch64_cpu::asm::barrier;
|
||||
use alloc::{boxed::Box, rc::Rc};
|
||||
use core::{
|
||||
cell::RefCell,
|
||||
fmt::Write,
|
||||
mem::MaybeUninit,
|
||||
panic::PanicInfo,
|
||||
sync::atomic::{compiler_fence, Ordering},
|
||||
};
|
||||
use embedded_alloc::Heap;
|
||||
use core::{cell::RefCell, fmt::Write};
|
||||
use half::f16;
|
||||
use nalgebra::Matrix;
|
||||
use pim::{
|
||||
array::{DummyArray, PimMatrixArena, PimScalarArena, PimStorage, NUMBER_OF_BANKS},
|
||||
kernel::{
|
||||
execute_matrix_add, execute_matrix_multiply, execute_matrix_scalar_multiply,
|
||||
execute_matrix_vector_multiply, MATRIX_ADD, MATRIX_MUL, MATRIX_SCALAR_MUL,
|
||||
MATRIX_VECTOR_MUL,
|
||||
use pim_isa::BankMode;
|
||||
use pim_os::{
|
||||
pim::{
|
||||
self,
|
||||
array::{DummyArray, PimMatrixArena, PimStorage, NUMBER_OF_BANKS},
|
||||
kernel::matrix_matrix_mul,
|
||||
vector::{F16x1, F16x16},
|
||||
},
|
||||
state::PimState,
|
||||
vector::{F16x1, F16x16},
|
||||
uart::Uart0,
|
||||
};
|
||||
use uart::Uart0;
|
||||
|
||||
mod boot;
|
||||
mod critical_section;
|
||||
mod m5ops;
|
||||
mod pim;
|
||||
mod uart;
|
||||
|
||||
#[global_allocator]
|
||||
static PIM_ALLOC: Heap = Heap::empty();
|
||||
|
||||
const PIM_ARENA_SIZE: usize = 0x2000000;
|
||||
|
||||
#[link_section = ".pim_data"]
|
||||
static mut PIM_ARENA: [MaybeUninit<u8>; PIM_ARENA_SIZE] = [MaybeUninit::uninit(); PIM_ARENA_SIZE];
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entry() -> ! {
|
||||
unsafe {
|
||||
PIM_ALLOC.init(PIM_ARENA.as_ptr() as usize, PIM_ARENA_SIZE);
|
||||
}
|
||||
|
||||
let mut uart = Uart0;
|
||||
let mut pim_state = PimState::new(&MATRIX_SCALAR_MUL);
|
||||
pim_state.set_kernel();
|
||||
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],
|
||||
@@ -61,89 +32,48 @@ pub extern "C" fn entry() -> ! {
|
||||
let pim_matrix_arena2 = Rc::new(RefCell::new(PimMatrixArena(
|
||||
[[[F16x16::default(); NUMBER_OF_BANKS]; 8]; 8],
|
||||
)));
|
||||
let pim_storage0 = PimStorage {
|
||||
|
||||
let mut matrix0 = Matrix::from_data(PimStorage {
|
||||
arena: &pim_matrix_arena0,
|
||||
index: 0,
|
||||
};
|
||||
let pim_storage1 = PimStorage {
|
||||
arena: &pim_matrix_arena1,
|
||||
index: 0,
|
||||
};
|
||||
let pim_storage2 = PimStorage {
|
||||
arena: &pim_matrix_arena2,
|
||||
index: 0,
|
||||
};
|
||||
|
||||
writeln!(
|
||||
&mut uart,
|
||||
"arena0: {:?}\narena1: {:?}\narena2: {:?}",
|
||||
core::ptr::addr_of!(*pim_matrix_arena0.borrow()),
|
||||
core::ptr::addr_of!(*pim_matrix_arena1.borrow()),
|
||||
core::ptr::addr_of!(*pim_matrix_arena2.borrow()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut matrix0 = Matrix::from_data(pim_storage0);
|
||||
});
|
||||
matrix0.fill_lower_triangle(F16x1(f16::ONE), 0);
|
||||
|
||||
let mut matrix1 = Matrix::from_data(pim_storage1);
|
||||
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(pim_storage2);
|
||||
let matrix2 = Matrix::from_data(PimStorage {
|
||||
arena: &pim_matrix_arena2,
|
||||
index: 0,
|
||||
});
|
||||
|
||||
writeln!(&mut uart, "{matrix0} * {matrix1}\n=").unwrap();
|
||||
writeln!(Uart0, "{matrix0} * {matrix1}\n=").unwrap();
|
||||
|
||||
let mut dummy_array = Box::new(DummyArray([F16x16::default(); NUMBER_OF_BANKS]));
|
||||
let dummy_array = Box::new(DummyArray([F16x16::default(); NUMBER_OF_BANKS]));
|
||||
|
||||
// Verify everything is correctly initialized before PIM operation
|
||||
barrier::dsb(barrier::SY);
|
||||
|
||||
// execute_matrix_add(
|
||||
// &mut pim_state,
|
||||
// &mut pim_matrix_arena0.borrow_mut(),
|
||||
// &mut pim_matrix_arena1.borrow_mut(),
|
||||
// &mut pim_matrix_arena2.borrow_mut(),
|
||||
// dummy_array.as_mut(),
|
||||
// );
|
||||
// execute_matrix_multiply_rowwise(
|
||||
// &mut pim_state,
|
||||
// &mut pim_matrix_arena0.borrow_mut(),
|
||||
// &mut pim_matrix_arena1.borrow_mut(),
|
||||
// &mut pim_matrix_arena2.borrow_mut(),
|
||||
// dummy_array.as_mut(),
|
||||
// );
|
||||
// execute_matrix_vector_multiply(
|
||||
// &mut pim_state,
|
||||
// &mut pim_matrix_arena0.borrow_mut(),
|
||||
// &mut pim_matrix_arena1.borrow_mut(),
|
||||
// &mut pim_matrix_arena2.borrow_mut(),
|
||||
// dummy_array.as_mut(),
|
||||
// );
|
||||
// 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();
|
||||
|
||||
// let pim_scalar_arena = Box::new(PimScalarArena(
|
||||
// [F16x16([F16x1(f16::from_f32(2.0)); 16]); 32],
|
||||
// ));
|
||||
pim::state::set_bank_mode(BankMode::PimAllBank);
|
||||
|
||||
// execute_matrix_scalar_multiply(
|
||||
// &mut pim_state,
|
||||
// &pim_scalar_arena,
|
||||
// &pim_matrix_arena0.borrow_mut(),
|
||||
// &mut pim_matrix_arena1.borrow_mut(),
|
||||
// dummy_array.as_mut(),
|
||||
// );
|
||||
matrix_matrix_mul::execute(
|
||||
pim_matrix_arena0,
|
||||
pim_matrix_arena1,
|
||||
pim_matrix_arena2,
|
||||
dummy_array.as_ref(),
|
||||
);
|
||||
|
||||
writeln!(&mut uart, "{matrix2}").unwrap();
|
||||
|
||||
m5ops::exit();
|
||||
|
||||
loop {
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
pim::state::set_bank_mode(BankMode::SingleBank);
|
||||
}
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
writeln!(Uart0, "{info}").unwrap();
|
||||
|
||||
loop {
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
}
|
||||
writeln!(Uart0, "{matrix2}").unwrap();
|
||||
}
|
||||
|
||||
15
pim-os/src/panic.rs
Normal file
15
pim-os/src/panic.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use crate::uart::Uart0;
|
||||
use core::{
|
||||
fmt::Write,
|
||||
panic::PanicInfo,
|
||||
sync::atomic::{compiler_fence, Ordering},
|
||||
};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
writeln!(Uart0, "{info}").unwrap();
|
||||
|
||||
loop {
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
@@ -4,34 +4,29 @@ use core::{arch::asm, ptr::write_volatile};
|
||||
#[link_section = ".pim_config"]
|
||||
static mut PIM_CONFIG_REGION: [u8; 0x4000] = [0; 0x4000];
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PimWriter;
|
||||
pub fn write(s: &str) {
|
||||
unsafe {
|
||||
let mut index = 0;
|
||||
for &byte in s.as_bytes() {
|
||||
write_volatile((&mut PIM_CONFIG_REGION as *mut u8).offset(index), byte as _);
|
||||
barrier::dsb(barrier::SY);
|
||||
index += 1;
|
||||
}
|
||||
write_volatile((&mut PIM_CONFIG_REGION as *mut u8).offset(index), b'\0');
|
||||
|
||||
impl PimWriter {
|
||||
pub fn write(&mut self, s: &str) {
|
||||
unsafe {
|
||||
let mut index = 0;
|
||||
for &byte in s.as_bytes() {
|
||||
write_volatile((&mut PIM_CONFIG_REGION as *mut u8).offset(index), byte as _);
|
||||
barrier::dsb(barrier::SY);
|
||||
index += 1;
|
||||
// PIM_CONFIG_REGION[..s.len()].copy_from_slice(s.as_bytes());
|
||||
// PIM_CONFIG_REGION[s.len()] = b'\0';
|
||||
|
||||
if cfg!(feature = "cacheless") {
|
||||
// Be pessimistic so that config region is not optimized away
|
||||
core::hint::black_box(PIM_CONFIG_REGION);
|
||||
} else {
|
||||
// Flush all cache lines that were affected by write operation
|
||||
for element in PIM_CONFIG_REGION[..s.len()].iter() {
|
||||
asm!("dc civac, {val}", val = in(reg) element);
|
||||
}
|
||||
write_volatile((&mut PIM_CONFIG_REGION as *mut u8).offset(index), b'\0');
|
||||
|
||||
// PIM_CONFIG_REGION[..s.len()].copy_from_slice(s.as_bytes());
|
||||
// PIM_CONFIG_REGION[s.len()] = b'\0';
|
||||
|
||||
if cfg!(feature = "cacheless") {
|
||||
// Be pessimistic so that config region is not optimized away
|
||||
core::hint::black_box(PIM_CONFIG_REGION);
|
||||
} else {
|
||||
// Flush all cache lines that were affected by write operation
|
||||
for element in PIM_CONFIG_REGION[..s.len()].iter() {
|
||||
asm!("dc civac, {val}", val = in(reg) element);
|
||||
}
|
||||
|
||||
barrier::dsb(barrier::SY);
|
||||
}
|
||||
barrier::dsb(barrier::SY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,533 +1,4 @@
|
||||
use super::{
|
||||
array::{DummyArray, PimMatrixArena, PimRegion, PimScalarArena},
|
||||
state::PimState,
|
||||
};
|
||||
use pim_isa::{BankMode, File, Instruction, Kernel};
|
||||
|
||||
pub const MATRIX_ADD: Kernel = Kernel([
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 0 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 1 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 2 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 3 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 4 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 5 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 6 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 7 },
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 0 },
|
||||
dst: File::GrfA { index: 0 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 1 },
|
||||
dst: File::GrfA { index: 1 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 2 },
|
||||
dst: File::GrfA { index: 2 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 3 },
|
||||
dst: File::GrfA { index: 3 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 4 },
|
||||
dst: File::GrfA { index: 4 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 5 },
|
||||
dst: File::GrfA { index: 5 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 6 },
|
||||
dst: File::GrfA { index: 6 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 7 },
|
||||
dst: File::GrfA { index: 7 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 0 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 1 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 2 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 3 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 4 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 5 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 6 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 7 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::EXIT,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
]);
|
||||
|
||||
pub fn execute_matrix_add<const R: usize, const C: usize>(
|
||||
pim_state: &mut PimState,
|
||||
pim_matrix_arena0: &PimMatrixArena<R, C>,
|
||||
pim_matrix_arena1: &PimMatrixArena<R, C>,
|
||||
pim_matrix_arena2: &mut PimMatrixArena<R, C>,
|
||||
dummy_array: &DummyArray,
|
||||
) {
|
||||
pim_state.set_bank_mode(BankMode::PimAllBank);
|
||||
|
||||
for column in 0..C {
|
||||
for row in 0..R {
|
||||
pim_matrix_arena0.execute_instruction_read_single_bank(column * R + row);
|
||||
}
|
||||
|
||||
for row in 0..R {
|
||||
pim_matrix_arena1.execute_instruction_read_single_bank(column * R + row);
|
||||
}
|
||||
|
||||
for row in 0..R {
|
||||
pim_matrix_arena2.execute_instruction_write_single_bank(column * R + row);
|
||||
}
|
||||
|
||||
dummy_array.execute_instruction_read_single_bank(0);
|
||||
}
|
||||
|
||||
pim_state.set_bank_mode(BankMode::SingleBank);
|
||||
}
|
||||
|
||||
pub const MATRIX_MUL: Kernel = Kernel([
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 0 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 1 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 2 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 3 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 4 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 5 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 6 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 7 },
|
||||
},
|
||||
Instruction::MAC {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 0 },
|
||||
src2: File::GrfB { index: 0 },
|
||||
dst: File::GrfB { index: 0 },
|
||||
aam: true,
|
||||
},
|
||||
Instruction::JUMP {
|
||||
offset: -1,
|
||||
count: 63,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 0 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 1 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 2 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 3 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 4 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 5 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 6 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 7 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::EXIT,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
]);
|
||||
|
||||
// Vlt in der Thesis kurz erwähnen und dann zu AAM überleiten
|
||||
// pub fn execute_matrix_multiply_elementwise<const R: usize, const C: usize>(
|
||||
// pim_state: &mut PimState,
|
||||
// pim_matrix_arena0: &mut PimMatrixArena<R, C>,
|
||||
// pim_matrix_arena1: &mut PimMatrixArena<R, C>,
|
||||
// pim_matrix_arena2: &mut PimMatrixArena<R, C>,
|
||||
// dummy_array: &mut DummyArray,
|
||||
// ) {
|
||||
// pim_state.set_bank_mode(BankMode::PimAllBank);
|
||||
|
||||
// for i in 0..(R * C) {
|
||||
// let start_column = i % R;
|
||||
// let start_row = (i / R) * R;
|
||||
|
||||
// for j in 0..C {
|
||||
// pim_matrix_arena0.execute_instruction_read_single_bank(start_column + R * j);
|
||||
// }
|
||||
|
||||
// for j in 0..R {
|
||||
// pim_matrix_arena1.execute_instruction_read_single_bank(start_row + j);
|
||||
// }
|
||||
|
||||
// pim_matrix_arena2.execute_instruction_write_single_bank(i);
|
||||
|
||||
// dummy_array.execute_instruction_read_single_bank(0);
|
||||
// }
|
||||
|
||||
// pim_state.set_bank_mode(BankMode::SingleBank);
|
||||
// }
|
||||
|
||||
pub fn execute_matrix_multiply<const R: usize, const C: usize>(
|
||||
pim_state: &mut PimState,
|
||||
pim_matrix_arena0: &PimMatrixArena<R, C>,
|
||||
pim_matrix_arena1: &PimMatrixArena<R, C>,
|
||||
pim_matrix_arena2: &mut PimMatrixArena<R, C>,
|
||||
dummy_array: &DummyArray,
|
||||
) {
|
||||
pim_state.set_bank_mode(BankMode::PimAllBank);
|
||||
|
||||
for row in 0..R {
|
||||
for i in 0..C {
|
||||
pim_matrix_arena0.execute_instruction_read_single_bank(row + R * i);
|
||||
}
|
||||
|
||||
for column in 0..C {
|
||||
for i in 0..R {
|
||||
pim_matrix_arena1.execute_instruction_read_single_bank(column * R + i);
|
||||
}
|
||||
}
|
||||
|
||||
for column in 0..C {
|
||||
pim_matrix_arena2.execute_instruction_write_single_bank(column * R + row);
|
||||
}
|
||||
|
||||
dummy_array.execute_instruction_read_single_bank(0);
|
||||
}
|
||||
|
||||
pim_state.set_bank_mode(BankMode::SingleBank);
|
||||
}
|
||||
|
||||
pub const MATRIX_VECTOR_MUL: Kernel = Kernel([
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 0 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 1 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 2 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 3 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 4 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 5 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 6 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 7 },
|
||||
},
|
||||
Instruction::MAC {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 0 },
|
||||
src2: File::GrfB { index: 0 },
|
||||
dst: File::GrfB { index: 0 },
|
||||
aam: true,
|
||||
},
|
||||
Instruction::JUMP {
|
||||
offset: -1,
|
||||
count: 7,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 0 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::EXIT,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
]);
|
||||
|
||||
pub fn execute_matrix_vector_multiply<const R: usize, const C: usize>(
|
||||
pim_state: &mut PimState,
|
||||
pim_matrix_arena0: &PimMatrixArena<R, C>,
|
||||
pim_matrix_arena1: &PimMatrixArena<C, 1>,
|
||||
pim_matrix_arena2: &mut PimMatrixArena<C, 1>,
|
||||
dummy_array: &DummyArray,
|
||||
) {
|
||||
pim_state.set_bank_mode(BankMode::PimAllBank);
|
||||
|
||||
for row in 0..R {
|
||||
for i in 0..C {
|
||||
pim_matrix_arena0.execute_instruction_read_single_bank(row + R * i);
|
||||
}
|
||||
|
||||
for i in 0..R {
|
||||
pim_matrix_arena1.execute_instruction_read_single_bank(i);
|
||||
}
|
||||
|
||||
pim_matrix_arena2.execute_instruction_write_single_bank(row);
|
||||
|
||||
dummy_array.execute_instruction_read_single_bank(0);
|
||||
}
|
||||
|
||||
pim_state.set_bank_mode(BankMode::SingleBank);
|
||||
}
|
||||
|
||||
pub const MATRIX_SCALAR_MUL: Kernel = Kernel([
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::SrfM { index: 0 },
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 0 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 1 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 2 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 3 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 4 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 5 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 6 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 7 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 0 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 1 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 2 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 3 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 4 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 5 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 6 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 7 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::EXIT,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
]);
|
||||
|
||||
pub fn execute_matrix_scalar_multiply<const R: usize, const C: usize>(
|
||||
pim_state: &mut PimState,
|
||||
pim_scalar_arena: &PimScalarArena,
|
||||
pim_matrix_arena0: &PimMatrixArena<R, C>,
|
||||
pim_matrix_arena1: &mut PimMatrixArena<R, C>,
|
||||
dummy_array: &DummyArray,
|
||||
) {
|
||||
pim_state.set_bank_mode(BankMode::PimAllBank);
|
||||
|
||||
for column in 0..C {
|
||||
pim_scalar_arena.execute_instruction_read_single_bank(0);
|
||||
|
||||
for i in 0..R {
|
||||
pim_matrix_arena0.execute_instruction_read_single_bank(column * R + i);
|
||||
}
|
||||
|
||||
for i in 0..R {
|
||||
pim_matrix_arena1.execute_instruction_write_single_bank(column * R + i);
|
||||
}
|
||||
|
||||
dummy_array.execute_instruction_read_single_bank(0);
|
||||
}
|
||||
|
||||
pim_state.set_bank_mode(BankMode::SingleBank);
|
||||
}
|
||||
pub mod matrix_matrix_add;
|
||||
pub mod matrix_matrix_mul;
|
||||
pub mod matrix_scalar_mul;
|
||||
pub mod matrix_vector_mul;
|
||||
|
||||
148
pim-os/src/pim/kernel/matrix_matrix_add.rs
Normal file
148
pim-os/src/pim/kernel/matrix_matrix_add.rs
Normal file
@@ -0,0 +1,148 @@
|
||||
use crate::pim::array::{DummyArray, PimMatrixArena, PimRegion};
|
||||
use pim_isa::{File, Instruction, Kernel};
|
||||
|
||||
pub const KERNEL: Kernel = Kernel([
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 0 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 1 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 2 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 3 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 4 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 5 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 6 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 7 },
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 0 },
|
||||
dst: File::GrfA { index: 0 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 1 },
|
||||
dst: File::GrfA { index: 1 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 2 },
|
||||
dst: File::GrfA { index: 2 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 3 },
|
||||
dst: File::GrfA { index: 3 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 4 },
|
||||
dst: File::GrfA { index: 4 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 5 },
|
||||
dst: File::GrfA { index: 5 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 6 },
|
||||
dst: File::GrfA { index: 6 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 7 },
|
||||
dst: File::GrfA { index: 7 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 0 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 1 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 2 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 3 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 4 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 5 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 6 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 7 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::EXIT,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
]);
|
||||
|
||||
pub fn execute<const R: usize, const C: usize>(
|
||||
pim_matrix_arena0: &PimMatrixArena<R, C>,
|
||||
pim_matrix_arena1: &PimMatrixArena<R, C>,
|
||||
pim_matrix_arena2: &mut PimMatrixArena<R, C>,
|
||||
dummy_array: &DummyArray,
|
||||
) {
|
||||
for column in 0..C {
|
||||
for row in 0..R {
|
||||
pim_matrix_arena0.execute_instruction_read_single_bank(column * R + row);
|
||||
}
|
||||
|
||||
for row in 0..R {
|
||||
pim_matrix_arena1.execute_instruction_read_single_bank(column * R + row);
|
||||
}
|
||||
|
||||
for row in 0..R {
|
||||
pim_matrix_arena2.execute_instruction_write_single_bank(column * R + row);
|
||||
}
|
||||
|
||||
dummy_array.execute_instruction_read_single_bank(0);
|
||||
}
|
||||
}
|
||||
153
pim-os/src/pim/kernel/matrix_matrix_mul.rs
Normal file
153
pim-os/src/pim/kernel/matrix_matrix_mul.rs
Normal file
@@ -0,0 +1,153 @@
|
||||
use crate::pim::array::{DummyArray, PimMatrixArena, PimRegion};
|
||||
use pim_isa::{File, Instruction, Kernel};
|
||||
|
||||
pub const KERNEL: Kernel = Kernel([
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 0 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 1 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 2 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 3 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 4 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 5 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 6 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 7 },
|
||||
},
|
||||
Instruction::MAC {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 0 },
|
||||
src2: File::GrfB { index: 0 },
|
||||
dst: File::GrfB { index: 0 },
|
||||
aam: true,
|
||||
},
|
||||
Instruction::JUMP {
|
||||
offset: -1,
|
||||
count: 63,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 0 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 1 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 2 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 3 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 4 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 5 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 6 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 7 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::EXIT,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
]);
|
||||
|
||||
// Vlt in der Thesis kurz erwähnen und dann zu AAM überleiten
|
||||
// pub fn execute_matrix_multiply_elementwise<const R: usize, const C: usize>(
|
||||
// pim_state: &mut PimState,
|
||||
// pim_matrix_arena0: &mut PimMatrixArena<R, C>,
|
||||
// pim_matrix_arena1: &mut PimMatrixArena<R, C>,
|
||||
// pim_matrix_arena2: &mut PimMatrixArena<R, C>,
|
||||
// dummy_array: &mut DummyArray,
|
||||
// ) {
|
||||
// set_bank_mode(BankMode::PimAllBank);
|
||||
|
||||
// for i in 0..(R * C) {
|
||||
// let start_column = i % R;
|
||||
// let start_row = (i / R) * R;
|
||||
|
||||
// for j in 0..C {
|
||||
// pim_matrix_arena0.execute_instruction_read_single_bank(start_column + R * j);
|
||||
// }
|
||||
|
||||
// for j in 0..R {
|
||||
// pim_matrix_arena1.execute_instruction_read_single_bank(start_row + j);
|
||||
// }
|
||||
|
||||
// pim_matrix_arena2.execute_instruction_write_single_bank(i);
|
||||
|
||||
// dummy_array.execute_instruction_read_single_bank(0);
|
||||
// }
|
||||
|
||||
// set_bank_mode(BankMode::SingleBank);
|
||||
// }
|
||||
|
||||
const MATRIX_DIMENSION: usize = 8;
|
||||
|
||||
pub fn execute(
|
||||
pim_matrix_arena0: &PimMatrixArena<MATRIX_DIMENSION, MATRIX_DIMENSION>,
|
||||
pim_matrix_arena1: &PimMatrixArena<MATRIX_DIMENSION, MATRIX_DIMENSION>,
|
||||
pim_matrix_arena2: &mut PimMatrixArena<MATRIX_DIMENSION, MATRIX_DIMENSION>,
|
||||
dummy_array: &DummyArray,
|
||||
) {
|
||||
for row in 0..MATRIX_DIMENSION {
|
||||
for i in 0..MATRIX_DIMENSION {
|
||||
pim_matrix_arena0.execute_instruction_read_single_bank(row + MATRIX_DIMENSION * i);
|
||||
}
|
||||
|
||||
for column in 0..MATRIX_DIMENSION {
|
||||
for i in 0..MATRIX_DIMENSION {
|
||||
pim_matrix_arena1
|
||||
.execute_instruction_read_single_bank(column * MATRIX_DIMENSION + i);
|
||||
}
|
||||
}
|
||||
|
||||
for column in 0..MATRIX_DIMENSION {
|
||||
pim_matrix_arena2
|
||||
.execute_instruction_write_single_bank(column * MATRIX_DIMENSION + row);
|
||||
}
|
||||
|
||||
dummy_array.execute_instruction_read_single_bank(0);
|
||||
}
|
||||
}
|
||||
125
pim-os/src/pim/kernel/matrix_scalar_mul.rs
Normal file
125
pim-os/src/pim/kernel/matrix_scalar_mul.rs
Normal file
@@ -0,0 +1,125 @@
|
||||
use crate::pim::array::{DummyArray, PimMatrixArena, PimRegion, PimScalarArena};
|
||||
use pim_isa::{File, Instruction, Kernel};
|
||||
|
||||
pub const KERNEL: Kernel = Kernel([
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::SrfM { index: 0 },
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 0 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 1 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 2 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 3 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 4 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 5 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 6 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::MUL {
|
||||
src0: File::Bank,
|
||||
src1: File::SrfM { index: 0 },
|
||||
dst: File::GrfA { index: 7 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 0 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 1 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 2 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 3 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 4 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 5 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 6 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 7 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::EXIT,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
]);
|
||||
|
||||
pub fn execute<const R: usize, const C: usize>(
|
||||
pim_scalar_arena: &PimScalarArena,
|
||||
pim_matrix_arena0: &PimMatrixArena<R, C>,
|
||||
pim_matrix_arena1: &mut PimMatrixArena<R, C>,
|
||||
dummy_array: &DummyArray,
|
||||
) {
|
||||
for column in 0..C {
|
||||
pim_scalar_arena.execute_instruction_read_single_bank(0);
|
||||
|
||||
for i in 0..R {
|
||||
pim_matrix_arena0.execute_instruction_read_single_bank(column * R + i);
|
||||
}
|
||||
|
||||
for i in 0..R {
|
||||
pim_matrix_arena1.execute_instruction_write_single_bank(column * R + i);
|
||||
}
|
||||
|
||||
dummy_array.execute_instruction_read_single_bank(0);
|
||||
}
|
||||
}
|
||||
94
pim-os/src/pim/kernel/matrix_vector_mul.rs
Normal file
94
pim-os/src/pim/kernel/matrix_vector_mul.rs
Normal file
@@ -0,0 +1,94 @@
|
||||
use crate::pim::array::{DummyArray, PimMatrixArena, PimRegion};
|
||||
use pim_isa::{File, Instruction, Kernel};
|
||||
|
||||
pub const KERNEL: Kernel = Kernel([
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 0 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 1 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 2 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 3 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 4 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 5 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 6 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 7 },
|
||||
},
|
||||
Instruction::MAC {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 0 },
|
||||
src2: File::GrfB { index: 0 },
|
||||
dst: File::GrfB { index: 0 },
|
||||
aam: true,
|
||||
},
|
||||
Instruction::JUMP {
|
||||
offset: -1,
|
||||
count: 7,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 0 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::EXIT,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
Instruction::NOP,
|
||||
]);
|
||||
|
||||
pub fn execute<const R: usize, const C: usize>(
|
||||
pim_matrix_arena0: &PimMatrixArena<R, C>,
|
||||
pim_matrix_arena1: &PimMatrixArena<C, 1>,
|
||||
pim_matrix_arena2: &mut PimMatrixArena<C, 1>,
|
||||
dummy_array: &DummyArray,
|
||||
) {
|
||||
for row in 0..R {
|
||||
for i in 0..C {
|
||||
pim_matrix_arena0.execute_instruction_read_single_bank(row + R * i);
|
||||
}
|
||||
|
||||
for i in 0..R {
|
||||
pim_matrix_arena1.execute_instruction_read_single_bank(i);
|
||||
}
|
||||
|
||||
pim_matrix_arena2.execute_instruction_write_single_bank(row);
|
||||
|
||||
dummy_array.execute_instruction_read_single_bank(0);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +1,25 @@
|
||||
|
||||
|
||||
use super::config::PimWriter;
|
||||
use super::config;
|
||||
use pim_isa::{BankMode, Kernel, PimConfig};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PimState {
|
||||
kernel: Kernel,
|
||||
writer: PimWriter,
|
||||
// TODO return token and return to singlebank when dropped
|
||||
pub fn set_bank_mode(bank_mode: BankMode) {
|
||||
config::write(
|
||||
serde_json_core::to_string::<PimConfig, 64>(&PimConfig {
|
||||
kernel: None,
|
||||
bank_mode: Some(bank_mode),
|
||||
})
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
);
|
||||
}
|
||||
|
||||
impl PimState {
|
||||
pub fn new(kernel: &Kernel) -> Self {
|
||||
Self {
|
||||
kernel: kernel.clone(),
|
||||
writer: PimWriter,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO return token and return to singlebank when dropped
|
||||
pub fn set_bank_mode(&mut self, bank_mode: BankMode) {
|
||||
self.writer.write(
|
||||
serde_json_core::to_string::<PimConfig, 64>(&PimConfig {
|
||||
kernel: None,
|
||||
bank_mode: Some(bank_mode),
|
||||
})
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn set_kernel(&mut self) {
|
||||
self.writer.write(
|
||||
serde_json_core::to_string::<PimConfig, 2048>(&PimConfig {
|
||||
kernel: Some(self.kernel.clone()),
|
||||
bank_mode: None,
|
||||
})
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
);
|
||||
}
|
||||
pub fn set_kernel(kernel: &Kernel) {
|
||||
config::write(
|
||||
serde_json_core::to_string::<PimConfig, 2048>(&PimConfig {
|
||||
kernel: Some(kernel.clone()),
|
||||
bank_mode: None,
|
||||
})
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,22 +63,9 @@ impl core::ops::MulAssign<F16x1> for F16x1 {
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Default, Clone, Copy, PartialEq)]
|
||||
#[derive(Default, Debug, Clone, Copy, PartialEq)]
|
||||
pub struct F16x16(pub [F16x1; FLOATING_POINT_UNITS]);
|
||||
|
||||
// TODO remove
|
||||
impl core::fmt::Debug for F16x16 {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
self.0[0].fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Display for F16x16 {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
self.0[0].fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl num_traits::identities::Zero for F16x16 {
|
||||
fn zero() -> Self {
|
||||
Self([F16x1::zero(); FLOATING_POINT_UNITS])
|
||||
|
||||
Reference in New Issue
Block a user