3x3 matrix multiplication
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use core::cell::RefCell;
|
||||
use core::fmt::Write;
|
||||
|
||||
use pim_isa::{BankMode, File, Instruction, Kernel};
|
||||
|
||||
@@ -137,6 +138,10 @@ pub const MATRIX_MUL: Kernel = Kernel([
|
||||
dst: File::GrfB { index: 0 },
|
||||
aam: false,
|
||||
},
|
||||
// Instruction::JUMP {
|
||||
// offset: -1,
|
||||
// count: 2,
|
||||
// },
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 0 },
|
||||
dst: File::Bank,
|
||||
@@ -170,45 +175,31 @@ pub const MATRIX_MUL: Kernel = Kernel([
|
||||
|
||||
pub fn execute_matrix_multiply<const R: usize, const C: usize>(
|
||||
pim_state: &mut PimState,
|
||||
pim_matrix_arena0: &RefCell<PimMatrixArena<R, C>>,
|
||||
pim_matrix_arena1: &RefCell<PimMatrixArena<R, C>>,
|
||||
pim_matrix_arena2: &RefCell<PimMatrixArena<R, C>>,
|
||||
dummy_array: &DummyArray,
|
||||
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);
|
||||
|
||||
let mut index = 0;
|
||||
while index < (R * C) {
|
||||
let left_index = index % R;
|
||||
let right_index = (index / R) * R;
|
||||
let mut i = 0;
|
||||
while i < (R * C) {
|
||||
let left_index = i % R;
|
||||
let right_index = (i / R) * R;
|
||||
|
||||
pim_matrix_arena0
|
||||
.borrow()
|
||||
.execute_instruction_read_single_bank(left_index);
|
||||
pim_matrix_arena0
|
||||
.borrow()
|
||||
.execute_instruction_read_single_bank(left_index + R);
|
||||
pim_matrix_arena0
|
||||
.borrow()
|
||||
.execute_instruction_read_single_bank(left_index + R * 2);
|
||||
pim_matrix_arena0.execute_instruction_read_single_bank(left_index + R * 0);
|
||||
pim_matrix_arena0.execute_instruction_read_single_bank(left_index + R * 1);
|
||||
pim_matrix_arena0.execute_instruction_read_single_bank(left_index + R * 2);
|
||||
|
||||
pim_matrix_arena1
|
||||
.borrow()
|
||||
.execute_instruction_read_single_bank(right_index);
|
||||
pim_matrix_arena1
|
||||
.borrow()
|
||||
.execute_instruction_read_single_bank(right_index + 1);
|
||||
pim_matrix_arena1
|
||||
.borrow()
|
||||
.execute_instruction_read_single_bank(right_index + 2);
|
||||
pim_matrix_arena1.execute_instruction_read_single_bank(right_index + 0);
|
||||
pim_matrix_arena1.execute_instruction_read_single_bank(right_index + 1);
|
||||
pim_matrix_arena1.execute_instruction_read_single_bank(right_index + 2);
|
||||
|
||||
pim_matrix_arena2
|
||||
.borrow_mut()
|
||||
.execute_instruction_write_single_bank(index);
|
||||
pim_matrix_arena2.execute_instruction_write_single_bank(i);
|
||||
|
||||
dummy_array.execute_instruction_read_single_bank(0);
|
||||
|
||||
index += 1;
|
||||
i += 1;
|
||||
}
|
||||
|
||||
pim_state.set_bank_mode(BankMode::SingleBank);
|
||||
|
||||
Reference in New Issue
Block a user