First steps towards matrix multiplication

This commit is contained in:
2024-01-01 18:48:37 +01:00
parent dfa773b839
commit 05f184d51f
8 changed files with 409 additions and 197 deletions

View File

@@ -1,6 +1,13 @@
use pim_isa::{File, Instruction, Kernel};
use core::cell::RefCell;
pub const TEST_KERNEL: Kernel = Kernel([
use pim_isa::{BankMode, File, Instruction, Kernel};
use super::{
array::{DummyArray, PimMatrixArena, PimRegion},
state::PimState,
};
pub const MATRIX_ADD: Kernel = Kernel([
Instruction::MOV {
src: File::Bank,
dst: File::GrfA { index: 0 },
@@ -41,28 +48,6 @@ pub const TEST_KERNEL: Kernel = Kernel([
dst: File::GrfB { index: 1 },
aam: false,
},
// Instruction::MOV {
// src: File::Bank,
// dst: File::GrfA { index: 1 },
// },
// Instruction::MOV {
// src: File::Bank,
// dst: File::GrfB { index: 1 },
// },
// Instruction::MAC {
// src0: File::Bank,
// src1: File::GrfA { index: 0 },
// src2: File::GrfB { index: 0 },
// dst: File::GrfB { index: 0 },
// aam: false,
// },
// Instruction::MAC {
// src0: File::Bank,
// src1: File::GrfA { index: 1 },
// src2: File::GrfB { index: 1 },
// dst: File::GrfB { index: 1 },
// aam: false,
// },
Instruction::FILL {
src: File::GrfA { index: 0 },
dst: File::Bank,
@@ -101,59 +86,239 @@ pub const TEST_KERNEL: Kernel = Kernel([
Instruction::NOP,
]);
// pub const TEST_KERNEL: Kernel = Kernel([
// Instruction::MOV {
// src: File::Bank,
// dst: File::GrfA { index: 0 },
// },
// Instruction::MOV {
// src: File::Bank,
// dst: File::GrfA { index: 1 },
// },
// 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::FILL {
// src: File::GrfA { index: 0 },
// dst: File::Bank,
// },
// Instruction::FILL {
// src: File::GrfA { index: 1 },
// 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,
// 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,
) {
// 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();
}
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: false,
},
Instruction::MAC {
src0: File::Bank,
src1: File::GrfA { index: 1 },
src2: File::GrfB { index: 0 },
dst: File::GrfB { index: 0 },
aam: false,
},
Instruction::MAC {
src0: File::Bank,
src1: File::GrfA { index: 2 },
src2: File::GrfB { index: 0 },
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,
Instruction::NOP,
Instruction::NOP,
Instruction::NOP,
Instruction::NOP,
Instruction::NOP,
]);
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_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);
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_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);
dummy_array.execute_instruction_read_single_bank(0);
pim_state.set_bank_mode(BankMode::SingleBank);
}