Introduce a bunch of new kernels
This commit is contained in:
@@ -1,27 +1,41 @@
|
||||
use core::cell::RefCell;
|
||||
use pim_isa::{BankMode, File, Instruction, Kernel};
|
||||
|
||||
use super::{
|
||||
array::{DummyArray, PimMatrixArena, PimRegion},
|
||||
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::GrfB { index: 0 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfA { index: 1 },
|
||||
},
|
||||
Instruction::MOV {
|
||||
src: File::Bank,
|
||||
dst: File::GrfB { index: 1 },
|
||||
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,
|
||||
@@ -29,12 +43,6 @@ pub const MATRIX_ADD: Kernel = Kernel([
|
||||
dst: File::GrfA { index: 0 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfB { index: 0 },
|
||||
dst: File::GrfB { index: 0 },
|
||||
aam: false,
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfA { index: 1 },
|
||||
@@ -43,24 +51,70 @@ pub const MATRIX_ADD: Kernel = Kernel([
|
||||
},
|
||||
Instruction::ADD {
|
||||
src0: File::Bank,
|
||||
src1: File::GrfB { index: 1 },
|
||||
dst: File::GrfB { index: 1 },
|
||||
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::GrfB { index: 0 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfA { index: 1 },
|
||||
dst: File::Bank,
|
||||
},
|
||||
Instruction::FILL {
|
||||
src: File::GrfB { index: 1 },
|
||||
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,
|
||||
@@ -71,35 +125,34 @@ pub const MATRIX_ADD: Kernel = Kernel([
|
||||
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_add(
|
||||
_pim_matrix_arena0: &RefCell<PimMatrixArena<8, 8>>,
|
||||
_pim_matrix_arena1: &RefCell<PimMatrixArena<8, 8>>,
|
||||
_dummy_array: &DummyArray,
|
||||
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_matrix_arena0
|
||||
// .borrow()
|
||||
// .execute_instruction_read_dual_bank();
|
||||
// pim_matrix_arena1
|
||||
// .borrow()
|
||||
// .execute_instruction_read_dual_bank();
|
||||
// pim_matrix_arena0
|
||||
// .borrow_mut()
|
||||
// .execute_instruction_write_dual_bank();
|
||||
// dummy_array.execute_instruction_read_single_bank();
|
||||
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([
|
||||
@@ -194,41 +247,42 @@ pub const MATRIX_MUL: Kernel = Kernel([
|
||||
Instruction::NOP,
|
||||
]);
|
||||
|
||||
pub fn execute_matrix_multiply_elementwise<const R: usize, const C: usize>(
|
||||
// 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: &mut PimMatrixArena<R, C>,
|
||||
pim_matrix_arena1: &mut PimMatrixArena<R, C>,
|
||||
pim_matrix_arena0: &PimMatrixArena<R, C>,
|
||||
pim_matrix_arena1: &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_rowwise<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,
|
||||
dummy_array: &DummyArray,
|
||||
) {
|
||||
pim_state.set_bank_mode(BankMode::PimAllBank);
|
||||
|
||||
@@ -252,3 +306,228 @@ pub fn execute_matrix_multiply_rowwise<const R: usize, const C: usize>(
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user