Skip to content

Commit

Permalink
Update CPU output format
Browse files Browse the repository at this point in the history
  • Loading branch information
minseongg committed Sep 5, 2024
1 parent 791c5ae commit 68f06e6
Show file tree
Hide file tree
Showing 38 changed files with 657,916 additions and 240,715 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ build/
/riscv-sodor/

.pytest_cache
/scripts/cpu/output
__pycache__/

*.fst
Expand Down
50 changes: 14 additions & 36 deletions hazardflow-designs/src/cpu/wb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,10 @@ pub struct WbR {

/// Writeback stage.
pub fn wb(i: I<VrH<MemEP, WbR>, { Dep::Demanding }>) {
i.map_resolver_inner::<(HOption<MemEP>, Regfile)>(|(wb, rf)| {
display!("rf[0]: %x", rf[0]);
display!("rf[1]: %x", rf[1]);
display!("rf[2]: %x", rf[2]);
display!("rf[3]: %x", rf[3]);
display!("rf[4]: %x", rf[4]);
display!("rf[5]: %x", rf[5]);
display!("rf[6]: %x", rf[6]);
display!("rf[7]: %x", rf[7]);
display!("rf[8]: %x", rf[8]);
display!("rf[9]: %x", rf[9]);
display!("rf[10]: %x", rf[10]);
display!("rf[11]: %x", rf[11]);
display!("rf[12]: %x", rf[12]);
display!("rf[13]: %x", rf[13]);
display!("rf[14]: %x", rf[14]);
display!("rf[15]: %x", rf[15]);
display!("rf[16]: %x", rf[16]);
display!("rf[17]: %x", rf[17]);
display!("rf[18]: %x", rf[18]);
display!("rf[19]: %x", rf[19]);
display!("rf[20]: %x", rf[20]);
display!("rf[21]: %x", rf[21]);
display!("rf[22]: %x", rf[22]);
display!("rf[23]: %x", rf[23]);
display!("rf[24]: %x", rf[24]);
display!("rf[25]: %x", rf[25]);
display!("rf[26]: %x", rf[26]);
display!("rf[27]: %x", rf[27]);
display!("rf[28]: %x", rf[28]);
display!("rf[29]: %x", rf[29]);
display!("rf[30]: %x", rf[30]);
display!("rf[31]: %x", rf[31]);

WbR { wb: wb.and_then(|p| p.wb.map(|reg| Register::new(reg.addr, reg.data))), rf, retire: wb.is_some() }
i.map_resolver_inner::<(HOption<MemEP>, Regfile)>(|(wb, rf)| WbR {
wb: wb.and_then(|p| p.wb.map(|reg| Register::new(reg.addr, reg.data))),
rf,
retire: wb.is_some(),
})
.reg_fwd(true)
.sink_fsm_map(0.repeat(), |ip, rf| {
Expand All @@ -89,7 +58,16 @@ pub fn wb(i: I<VrH<MemEP, WbR>, { Dep::Demanding }>) {
_ => rf,
};

display!("retire: [%b], pc: [%x]", ip.is_some(), ip.map(|x| x.debug_pc).unwrap_or(0));
if let Some(p) = ip {
match p.wb {
Some(r) => {
display!("retire=[1] pc=[%x] write=[r%d=%x]", ip.map(|x| x.debug_pc).unwrap_or(0), r.addr, r.data)
}
None => display!("retire=[1] pc=[%x]", ip.map(|x| x.debug_pc).unwrap_or(0)),
}
} else {
display!("retire=[0] pc=[%x]", ip.map(|x| x.debug_pc).unwrap_or(0))
}

(ir, rf_next)
})
Expand Down
5 changes: 4 additions & 1 deletion scripts/cpu/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__pycache__

openroad/logs
openroad/objects
openroad/reports
Expand All @@ -7,5 +8,7 @@ openroad/vsrc/*
!openroad/vsrc/Core.v
!openroad/vsrc/CoreWrapper.v
!openroad/vsrc/CSRFileWrapper.v
output

/output/

emulator-debug
31 changes: 15 additions & 16 deletions scripts/cpu/bench_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@
def run_tests(total_tests):
count = 0

for tb in bench_dir.iterdir():
tb_filename = tb.name
if tb.is_file() and not tb.suffix in [".dump", ".trace"]:
count += 1
vcd_option = f"-v{log_dir}/{tb_filename}.vcd" if waves_flag else ""
txt_file = log_dir / f"{tb_filename}.txt"
for tb_filename in BENCHES:
tb = bench_dir / tb_filename
count += 1
vcd_option = f"-v{log_dir}/{tb_filename}.vcd" if waves_flag else ""
txt_file = log_dir / f"{tb_filename}.txt"

console.print(f"Extract trace from benchmark ({count}/{total_tests}): {tb_filename} .. ", end="")
result = subprocess.run(
f"{emulator} {vcd_option} +max-cycles=100000 {tb}",
stdout=open(txt_file, "w"),
stderr=subprocess.STDOUT,
shell=True
)
console.print(f"Extract trace from benchmark ({count}/{total_tests}): {tb_filename} .. ", end="")
result = subprocess.run(
f"{emulator} {vcd_option} +max-cycles=100000 {tb}",
stdout=open(txt_file, "w"),
stderr=subprocess.STDOUT,
shell=True
)

console.print("DONE")
console.print("DONE")


if __name__ == "__main__":
Expand Down Expand Up @@ -72,9 +71,9 @@ def run_tests(total_tests):
# Running tests
if trace_flag:
logger.info("Running benchmark trace tests")
run_tests(9)
run_tests(4)
check_trace()
elif cpi_flag:
logger.info("Running benchmark cpi tests")
run_tests(9)
run_tests(4)
calculate_cpi(cpi_arg)
15 changes: 0 additions & 15 deletions scripts/cpu/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,21 @@
BENCHES = [
"aes",
"coremark",
"ellpack",
"gemm-block",
"gemm",
"kmp",
"nw",
"queue",
"radix",
]
# Cached CPI values for baseline
BASELINE_CPI = {
"aes": 1.2000873267110577,
"coremark": 1.5222068826183581,
"ellpack": 1.3759583636465387,
"gemm-block": 1.5248672242888168,
"gemm": 1.5291745730550284,
"kmp": 1.496593118287688,
"nw": 1.3411507976321861,
"queue": 1.3322280857423061,
"radix": 1.2879425703930862,
}
# Cached CPI values for branch prediction
BRANCH_PREDICTION_CPI = {
"aes": 1.073133514986376,
"coremark": 1.1979357129607546,
"ellpack": 1.057687344059193,
"gemm-block": 1.1849320790656486,
"gemm": 1.181595521343597,
"kmp": 1.0109134952508447,
"nw": 1.073114438245093,
"queue": 1.1186424853535,
"radix": 1.0883295248415745,
}

Expand Down
3 changes: 1 addition & 2 deletions scripts/cpu/cpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def calculate_cpi(arg):
logger.info("Comparing CPI with baseline")

tracer = SodorCpiCalculator()
hf_retire_template = compile("[{}] retire: [{}], pc: [{}]")
hf_retire_template = compile("[{}] retire=[{}] pc=[{}]{}")

failed = False
for bench in BENCHES:
Expand All @@ -50,7 +50,6 @@ def calculate_cpi(arg):
file = f"{cpu_script_dir}/output/{bench}.txt"
with open(file, "r") as f:
for line in f:
line = line.strip()
if "retire" in line:
parsed = hf_retire_template.parse(line)
pc = parsed[2]
Expand Down
2 changes: 1 addition & 1 deletion scripts/cpu/isa_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def run_tests(test_dir, total_tests):

console.print(f"Test ({count}/{total_tests}): {tb_filename} .. ", end="")
result = subprocess.run(
f"{emulator} {vcd_option} +max-cycles=100000 {tb}",
f"{emulator} {vcd_option} +max-cycles=10000 {tb}",
stdout=open(txt_file, "w"),
stderr=subprocess.STDOUT,
shell=True,
Expand Down
Loading

0 comments on commit 68f06e6

Please sign in to comment.