Skip to content

Commit 09e2fe9

Browse files
committed
[Infra]: - fix get_memory_usage getting stuck when vpr output file is not generated
- show the maximum memory usage of all VTR stages in the run_vtr_flow output Signed-off-by: Seyed Alireza Damghani <[email protected]>
1 parent c6e5a56 commit 09e2fe9

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

vtr_flow/scripts/run_vtr_flow.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,50 @@ def format_human_readable_memory(num_kbytes):
435435
return value
436436

437437

438+
def get_max_memory_usage(temp_dir):
439+
"""
440+
Extracts the maximum memory usage of the VTR flow from generated .out files
441+
"""
442+
cnt = 0
443+
output_files = {
444+
"yosys": Path(temp_dir / "yosys.out"),
445+
"odin": Path(temp_dir / "odin.out"),
446+
"abc": Path(temp_dir / "abc{}.out".format(cnt)),
447+
"vpr": Path(temp_dir / "vpr.out"),
448+
}
449+
memory_usages = {"yosys": -1, "odin": -1, "abc": -1, "vpr": -1}
450+
451+
if output_files["yosys"].is_file():
452+
memory_usages["yosys"] = get_memory_usage(output_files["yosys"])
453+
454+
if output_files["odin"].is_file():
455+
memory_usages["odin"] = get_memory_usage(output_files["odin"])
456+
457+
while output_files["abc"].is_file():
458+
new_abc_mem_usage = get_memory_usage(output_files["abc"])
459+
if new_abc_mem_usage > memory_usages["abc"]:
460+
memory_usages["abc"] = new_abc_mem_usage
461+
462+
cnt += 1
463+
output_files["abc"] = Path(temp_dir / "abc{}.out".format(cnt))
464+
465+
if output_files["vpr"].is_file():
466+
memory_usages["vpr"] = get_memory_usage(output_files["vpr"])
467+
468+
max_mem_key = max(memory_usages, key=memory_usages.get)
469+
if memory_usages[max_mem_key] != -1:
470+
return max_mem_key, format_human_readable_memory(memory_usages[max_mem_key])
471+
else:
472+
return "-", "-"
473+
474+
438475
def get_memory_usage(logfile):
439-
"""Extrats the memory usage from the *.out log files"""
476+
"""Extracts the memory usage from the *.out log files"""
440477
with open(logfile, "r") as fpmem:
441478
for line in fpmem.readlines():
442479
if "Maximum resident set size" in line:
443-
return format_human_readable_memory(int(line.split()[-1]))
444-
return "--"
480+
return int(line.split()[-1])
481+
return -1
445482

446483

447484
# pylint: enable=too-many-statements
@@ -525,10 +562,10 @@ def vtr_command_main(arg_list, prog=None):
525562
seconds = datetime.now() - start
526563

527564
print(
528-
"{status} (took {time}, vpr run consumed {max_mem} memory)".format(
565+
"{status} (took {time}, {stage[0]} run consumed {stage[1]} memory)".format(
529566
status=error_status,
530567
time=vtr.format_elapsed_time(seconds),
531-
max_mem=get_memory_usage(temp_dir / "vpr.out"),
568+
stage=get_max_memory_usage(temp_dir),
532569
)
533570
)
534571
temp_dir.mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)