Trivial matrix multiplication kernel

This commit is contained in:
2024-01-01 23:08:46 +01:00
parent 05f184d51f
commit 6380385bd0
3 changed files with 60 additions and 167 deletions

View File

@@ -116,26 +116,6 @@ pub const MATRIX_MUL: Kernel = Kernel([
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 },
@@ -157,73 +137,10 @@ pub const MATRIX_MUL: Kernel = Kernel([
dst: File::GrfB { index: 0 },
aam: false,
},
Instruction::MAC {
src0: File::Bank,
src1: File::GrfA { index: 3 },
src2: File::GrfB { index: 0 },
dst: File::GrfB { index: 0 },
aam: false,
},
Instruction::MAC {
src0: File::Bank,
src1: File::GrfA { index: 4 },
src2: File::GrfB { index: 0 },
dst: File::GrfB { index: 0 },
aam: false,
},
Instruction::MAC {
src0: File::Bank,
src1: File::GrfA { index: 5 },
src2: File::GrfB { index: 0 },
dst: File::GrfB { index: 0 },
aam: false,
},
Instruction::MAC {
src0: File::Bank,
src1: File::GrfA { index: 6 },
src2: File::GrfB { index: 0 },
dst: File::GrfB { index: 0 },
aam: false,
},
Instruction::MAC {
src0: File::Bank,
src1: File::GrfA { index: 7 },
src2: File::GrfB { index: 0 },
dst: File::GrfB { index: 0 },
aam: false,
},
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,
@@ -232,6 +149,23 @@ pub const MATRIX_MUL: 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,
Instruction::NOP,
Instruction::NOP,
Instruction::NOP,
Instruction::NOP,
Instruction::NOP,
]);
pub fn execute_matrix_multiply<const R: usize, const C: usize>(
@@ -243,82 +177,39 @@ pub fn execute_matrix_multiply<const R: usize, const C: usize>(
) {
pim_state.set_bank_mode(BankMode::PimAllBank);
pim_matrix_arena0
.borrow()
.execute_instruction_read_single_bank(0);
pim_matrix_arena0
.borrow()
.execute_instruction_read_single_bank(1);
pim_matrix_arena0
.borrow()
.execute_instruction_read_single_bank(2);
pim_matrix_arena0
.borrow()
.execute_instruction_read_single_bank(3);
pim_matrix_arena0
.borrow()
.execute_instruction_read_single_bank(4);
pim_matrix_arena0
.borrow()
.execute_instruction_read_single_bank(5);
pim_matrix_arena0
.borrow()
.execute_instruction_read_single_bank(6);
pim_matrix_arena0
.borrow()
.execute_instruction_read_single_bank(7);
let mut index = 0;
while index < (R * C) {
let left_index = index % R;
let right_index = (index / R) * R;
pim_matrix_arena1
.borrow()
.execute_instruction_read_single_bank(0);
pim_matrix_arena1
.borrow()
.execute_instruction_read_single_bank(1);
pim_matrix_arena1
.borrow()
.execute_instruction_read_single_bank(2);
pim_matrix_arena1
.borrow()
.execute_instruction_read_single_bank(3);
pim_matrix_arena1
.borrow()
.execute_instruction_read_single_bank(4);
pim_matrix_arena1
.borrow()
.execute_instruction_read_single_bank(5);
pim_matrix_arena1
.borrow()
.execute_instruction_read_single_bank(6);
pim_matrix_arena1
.borrow()
.execute_instruction_read_single_bank(7);
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_arena2
.borrow_mut()
.execute_instruction_write_single_bank(0);
pim_matrix_arena2
.borrow_mut()
.execute_instruction_write_single_bank(1);
pim_matrix_arena2
.borrow_mut()
.execute_instruction_write_single_bank(2);
pim_matrix_arena2
.borrow_mut()
.execute_instruction_write_single_bank(3);
pim_matrix_arena2
.borrow_mut()
.execute_instruction_write_single_bank(4);
pim_matrix_arena2
.borrow_mut()
.execute_instruction_write_single_bank(5);
pim_matrix_arena2
.borrow_mut()
.execute_instruction_write_single_bank(6);
pim_matrix_arena2
.borrow_mut()
.execute_instruction_write_single_bank(7);
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);
dummy_array.execute_instruction_read_single_bank(0);
pim_matrix_arena2
.borrow_mut()
.execute_instruction_write_single_bank(index);
dummy_array.execute_instruction_read_single_bank(0);
index += 1;
}
pim_state.set_bank_mode(BankMode::SingleBank);
}