Skip to content

Commit b2dca2d

Browse files
committed
feat: replace gem5 with maintianed submodule not patch
1 parent d93bf59 commit b2dca2d

File tree

8 files changed

+130
-295
lines changed

8 files changed

+130
-295
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
url = https://github.com/riscv-software-src/riscv-isa-sim
44
[submodule "host/gem5/gem5"]
55
path = host/gem5/gem5
6-
url = https://github.com/gem5/gem5.git
6+
url = https://github.com/DangoSys/gem5.git

bebop/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
m5out/

bebop/bin/bebop.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ fn main() -> std::io::Result<()> {
6161
let args = Args::parse();
6262

6363
// Get bebop folder path (CARGO_MANIFEST_DIR)
64-
let bebop_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
65-
let bebop_root = bebop_root.join("..").to_path_buf();
64+
let bebop_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..").to_path_buf();
6665

6766
// Load and merge configuration
6867
let app_config = load_configs(

bebop/src/arch/gemmini/gemmini.rs

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,42 @@ impl Gemmini {
556556
}
557557
}
558558

559+
// Batch read DIM bytes from DRAM (optimized for DIM-sized chunks)
560+
fn read_batch_dim(&self, addr: RegT) -> [u8; DIM] {
561+
let mut result = [0u8; DIM];
562+
563+
if let Some(ref dma_read) = self.state.dma_read {
564+
let mut handler = dma_read.lock().unwrap();
565+
566+
match handler.read(addr, DIM as u32) {
567+
Ok(data) => {
568+
for i in 0..DIM {
569+
result[i] = ((data >> (i * 8)) & 0xFF) as u8;
570+
}
571+
},
572+
Err(_) => {
573+
// Return zeros on error
574+
},
575+
}
576+
}
577+
578+
result
579+
}
580+
581+
// Batch write DIM bytes to DRAM (optimized for DIM-sized chunks)
582+
fn write_batch_dim(&mut self, addr: RegT, data: &[u8; DIM]) {
583+
if let Some(ref dma_write) = self.state.dma_write {
584+
let mut handler = dma_write.lock().unwrap();
585+
586+
let mut data_u128: u128 = 0;
587+
for i in 0..DIM {
588+
data_u128 |= (data[i] as u128) << (i * 8);
589+
}
590+
591+
let _ = handler.write(addr, data_u128, DIM as u32);
592+
}
593+
}
594+
559595
fn read_matrix_from_dram(
560596
&self,
561597
addr: RegT,
@@ -573,13 +609,26 @@ impl Gemmini {
573609
panic!("ERROR: non-zeroable matrix given address zero!");
574610
}
575611

612+
// Batch read optimization: read DIM bytes at a time
576613
for i in 0..rows as usize {
577614
let ii = if repeating_bias { 0 } else { i };
578615
let dram_row_addr = addr + (ii * cols as usize * std::mem::size_of::<ElemT>()) as u64;
579616

580-
for j in 0..cols as usize {
581-
let dram_byte_addr = dram_row_addr + (j * std::mem::size_of::<ElemT>()) as u64;
582-
result[i][j] = self.read_from_dram::<ElemT>(dram_byte_addr);
617+
// Read in DIM-byte chunks
618+
for j in (0..cols as usize).step_by(DIM) {
619+
let remaining = cols as usize - j;
620+
if remaining >= DIM {
621+
// Read full DIM bytes
622+
let bytes = self.read_batch_dim(dram_row_addr + j as u64);
623+
for k in 0..DIM {
624+
result[i][j + k] = bytes[k] as ElemT;
625+
}
626+
} else {
627+
// Handle remaining bytes individually (fallback for tail)
628+
for k in 0..remaining {
629+
result[i][j + k] = self.read_from_dram::<ElemT>(dram_row_addr + (j + k) as u64);
630+
}
631+
}
583632
}
584633
}
585634

@@ -1104,7 +1153,7 @@ impl Gemmini {
11041153
self.state.pool_pocols = ((rs1 >> 40) & 0xFF) as u8;
11051154
self.state.pool_orows = ((rs1 >> 48) & 0xFF) as u8;
11061155
self.state.pool_ocols = ((rs1 >> 56) & 0xFF) as u8;
1107-
1156+
11081157
log::info!(
11091158
"GEMMINI: config_st - set store stride to {:?}, activation to {:?}, acc shift to {:?}, pool stride to {:?}, pool size to {:?}, pool upad to {:?}, pool lpad to {:?}, pool out dim to {:?}, pool porows to {:?}, pool pocols to {:?}, pool orows to {:?}, pool ocols to {:?}",
11101159
rs2 & 0xFFFFFFFF,
@@ -1417,13 +1466,13 @@ impl Gemmini {
14171466
self.state.loop_ws_D_stride = rs1;
14181467
self.state.loop_ws_C_stride = rs2;
14191468

1420-
log::info!(
1421-
"GEMMINI: loop_ws_config_strides_DC - set loop ws D stride to {:?} (0x{:x}), loop ws C stride to {:?} (0x{:x})",
1422-
self.state.loop_ws_D_stride,
1423-
self.state.loop_ws_D_stride,
1424-
self.state.loop_ws_C_stride,
1425-
self.state.loop_ws_C_stride
1426-
);
1469+
log::info!(
1470+
"GEMMINI: loop_ws_config_strides_DC - set loop ws D stride to {:?} (0x{:x}), loop ws C stride to {:?} (0x{:x})",
1471+
self.state.loop_ws_D_stride,
1472+
self.state.loop_ws_D_stride,
1473+
self.state.loop_ws_C_stride,
1474+
self.state.loop_ws_C_stride
1475+
);
14271476
}
14281477

14291478
pub fn loop_ws(&mut self, rs1: RegT, rs2: RegT) {

host/gem5/bebop.patch

Lines changed: 0 additions & 276 deletions
This file was deleted.

0 commit comments

Comments
 (0)