Refactor project to be more modular

This commit is contained in:
2024-01-07 17:48:16 +01:00
parent 4510a36a10
commit 44f38fb443
19 changed files with 1038 additions and 848 deletions

View File

@@ -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;