8x8 matrix multiplication using AAM

This commit is contained in:
2024-01-06 17:34:31 +01:00
parent 92499fe95b
commit 29d9cee52c
3 changed files with 117 additions and 64 deletions

View File

@@ -115,35 +115,69 @@ 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 },
src2: File::GrfB { index: 0 },
dst: File::GrfB { index: 0 },
aam: false,
aam: true,
},
Instruction::MAC {
src0: File::Bank,
src1: File::GrfA { index: 1 },
src2: File::GrfB { index: 0 },
dst: File::GrfB { index: 0 },
aam: false,
Instruction::JUMP {
offset: -1,
count: 63,
},
Instruction::MAC {
src0: File::Bank,
src1: File::GrfA { index: 2 },
src2: File::GrfB { index: 0 },
dst: File::GrfB { index: 0 },
aam: false,
},
// Instruction::JUMP {
// offset: -1,
// count: 2,
// },
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,
@@ -158,20 +192,9 @@ 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,
]);
pub fn execute_matrix_multiply<const R: usize, const C: usize>(
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>,
@@ -181,15 +204,15 @@ pub fn execute_matrix_multiply<const R: usize, const C: usize>(
pim_state.set_bank_mode(BankMode::PimAllBank);
for i in 0..(R * C) {
let left_index = i % R;
let right_index = (i / R) * R;
let start_column = i % R;
let start_row = (i / R) * R;
for k in 0..R {
pim_matrix_arena0.execute_instruction_read_single_bank(left_index + R * k);
for j in 0..C {
pim_matrix_arena0.execute_instruction_read_single_bank(start_column + R * j);
}
for k in 0..C {
pim_matrix_arena1.execute_instruction_read_single_bank(right_index + k);
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);
@@ -199,3 +222,33 @@ pub fn execute_matrix_multiply<const R: usize, const C: usize>(
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,
) {
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);
}