First steps towards matrix multiplication
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use half::f16;
|
||||
use pim_isa::{BankMode, File, Instruction, Kernel, PimConfig};
|
||||
use pim_isa::{BankMode, File, Instruction, Kernel};
|
||||
|
||||
#[cxx::bridge(namespace = "pim_vm")]
|
||||
mod ffi {
|
||||
@@ -64,7 +64,8 @@ impl Default for PimUnit {
|
||||
#[derive(Debug)]
|
||||
struct PimVM {
|
||||
pim_units: Vec<PimUnit>,
|
||||
pim_config: pim_isa::PimConfig,
|
||||
bank_mode: pim_isa::BankMode,
|
||||
kernel: pim_isa::Kernel,
|
||||
}
|
||||
|
||||
impl PimVM {
|
||||
@@ -76,16 +77,19 @@ impl PimVM {
|
||||
}
|
||||
|
||||
fn apply_config(&mut self, config_str: &str) {
|
||||
log::debug!("Config string:\n{config_str}");
|
||||
let config = serde_json::from_str::<pim_isa::PimConfig>(config_str).unwrap();
|
||||
|
||||
self.pim_config = serde_json::from_str::<pim_isa::PimConfig>(config_str).unwrap();
|
||||
self.reset();
|
||||
if let Some(kernel) = config.kernel {
|
||||
self.kernel = kernel;
|
||||
}
|
||||
|
||||
log::debug!("Apply pim config:\n{:?}", self.pim_config);
|
||||
if let Some(bank_mode) = config.bank_mode {
|
||||
self.bank_mode = bank_mode;
|
||||
}
|
||||
}
|
||||
|
||||
fn bank_mode(&self) -> ffi::BankMode {
|
||||
match self.pim_config.bank_mode {
|
||||
match self.bank_mode {
|
||||
BankMode::SingleBank => ffi::BankMode::SingleBank,
|
||||
BankMode::AllBank => ffi::BankMode::AllBank,
|
||||
BankMode::PimAllBank => ffi::BankMode::PimAllBank,
|
||||
@@ -102,10 +106,8 @@ fn new_pim_vm(num_banks: u32) -> Box<PimVM> {
|
||||
|
||||
Box::new(PimVM {
|
||||
pim_units: vec![PimUnit::default(); num_pim_units as _],
|
||||
pim_config: PimConfig {
|
||||
bank_mode: BankMode::SingleBank,
|
||||
kernel: Kernel::NOP,
|
||||
},
|
||||
bank_mode: BankMode::SingleBank,
|
||||
kernel: Kernel::NOP,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -124,12 +126,14 @@ impl PimVM {
|
||||
|
||||
let pim_unit = &mut self.pim_units[pim_unit_index as usize];
|
||||
|
||||
let mut inst = self.pim_config.kernel.0[pim_unit.pc as usize];
|
||||
let mut inst = self.kernel.0[pim_unit.pc as usize];
|
||||
|
||||
log::debug!(
|
||||
"PimUnit {pim_unit_index} Execute PC {}: {inst:?}",
|
||||
pim_unit.pc
|
||||
);
|
||||
if pim_unit_index == 0 {
|
||||
log::debug!(
|
||||
"PimUnit {pim_unit_index} Execute PC {}: {inst:?}",
|
||||
pim_unit.pc
|
||||
);
|
||||
}
|
||||
|
||||
pim_unit.pc += 1;
|
||||
|
||||
@@ -151,10 +155,12 @@ impl PimVM {
|
||||
}
|
||||
|
||||
pim_unit.pc = new_pc as _;
|
||||
log::debug!("PimUnit {pim_unit_index} New PC {new_pc}: {inst:?}");
|
||||
if pim_unit_index == 0 {
|
||||
log::debug!("PimUnit {pim_unit_index} New PC {new_pc}: {inst:?}");
|
||||
}
|
||||
}
|
||||
|
||||
inst = self.pim_config.kernel.0[pim_unit.pc as usize];
|
||||
inst = self.kernel.0[pim_unit.pc as usize];
|
||||
pim_unit.pc += 1;
|
||||
}
|
||||
|
||||
@@ -305,7 +311,16 @@ impl PimVM {
|
||||
.try_into()
|
||||
.unwrap();
|
||||
|
||||
log::debug!("{data0:?}, {data1:?}, {data2:?}, {product:?}, {sum:?}");
|
||||
if pim_unit_index == 0 {
|
||||
log::debug!(
|
||||
"\n{:?}\n{:?}\n{:?}\n{:?}\n{:?}",
|
||||
data0[0],
|
||||
data1[0],
|
||||
data2[0],
|
||||
product[0],
|
||||
sum[0]
|
||||
);
|
||||
}
|
||||
PimVM::store(dst, pim_unit, &sum);
|
||||
}
|
||||
}
|
||||
@@ -323,10 +338,11 @@ impl PimVM {
|
||||
let current_pc = pim_unit.pc;
|
||||
pim_unit.pc += 1;
|
||||
|
||||
let inst = &self.pim_config.kernel.0[current_pc as usize];
|
||||
|
||||
log::debug!("PimUnit {pim_unit_index} Execute PC {current_pc}: {inst:?}");
|
||||
let inst = &self.kernel.0[current_pc as usize];
|
||||
|
||||
if pim_unit_index == 0 {
|
||||
log::debug!("PimUnit {pim_unit_index} Execute PC {current_pc}: {inst:?}");
|
||||
}
|
||||
let data = match inst {
|
||||
Instruction::FILL { src, dst } => {
|
||||
let data: [f16; FP_UNITS] = match src {
|
||||
@@ -339,7 +355,9 @@ impl PimVM {
|
||||
panic!("Unsupported dst operand: {dst:?}")
|
||||
}
|
||||
|
||||
log::debug!("Store {data:?}");
|
||||
if pim_unit_index == 0 {
|
||||
log::debug!("Store {data:?}");
|
||||
}
|
||||
|
||||
data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user