Skip to content

Commit fa41fff

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 fa41fff

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

vtr_flow/scripts/run_vtr_flow.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,47 @@ 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+
return max_mem_key, format_human_readable_memory(memory_usages[max_mem_key])
470+
471+
438472
def get_memory_usage(logfile):
439-
"""Extrats the memory usage from the *.out log files"""
473+
"""Extracts the memory usage from the *.out log files"""
440474
with open(logfile, "r") as fpmem:
441475
for line in fpmem.readlines():
442476
if "Maximum resident set size" in line:
443-
return format_human_readable_memory(int(line.split()[-1]))
444-
return "--"
477+
return int(line.split()[-1])
478+
return None
445479

446480

447481
# pylint: enable=too-many-statements
@@ -525,10 +559,10 @@ def vtr_command_main(arg_list, prog=None):
525559
seconds = datetime.now() - start
526560

527561
print(
528-
"{status} (took {time}, vpr run consumed {max_mem} memory)".format(
562+
"{status} (took {time}, {stage[0]} run consumed {stage[1]} memory)".format(
529563
status=error_status,
530564
time=vtr.format_elapsed_time(seconds),
531-
max_mem=get_memory_usage(temp_dir / "vpr.out"),
565+
stage=get_max_memory_usage(temp_dir),
532566
)
533567
)
534568
temp_dir.mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)