Skip to content

Commit 372c028

Browse files
authored
Merge pull request #1950 from sdamghan/get_max_mem
fix `run_vtr_task.py` getting stuck if an input has an error
2 parents 311c460 + 8d281fb commit 372c028

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#Flow Run-time Metrics
22
vtr_flow_elapsed_time;vtr_flow.out;.* \(took (.*) seconds, .*\)
3+
vtr_max_mem_stage;vtr_flow.out;.* \(.* consumed by (.*) run\)
4+
vtr_max_mem;vtr_flow.out;.* \(.*, overall memory peak (.*) consumed .*\)
35
error;output.txt;error=(.*)

vtr_flow/scripts/run_vtr_flow.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,49 @@ 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 format_human_readable_memory(memory_usages[max_mem_key]), max_mem_key
471+
return "-", "-"
472+
473+
438474
def get_memory_usage(logfile):
439-
"""Extrats the memory usage from the *.out log files"""
475+
"""Extracts the memory usage from the *.out log files"""
440476
with open(logfile, "r") as fpmem:
441477
for line in fpmem.readlines():
442478
if "Maximum resident set size" in line:
443-
return format_human_readable_memory(int(line.split()[-1]))
444-
return "--"
479+
return int(line.split()[-1])
480+
return -1
445481

446482

447483
# pylint: enable=too-many-statements
@@ -525,10 +561,11 @@ def vtr_command_main(arg_list, prog=None):
525561
seconds = datetime.now() - start
526562

527563
print(
528-
"{status} (took {time}, vpr run consumed {max_mem} memory)".format(
564+
"{status} (took {time}, "
565+
"overall memory peak {stage[0]} consumed by {stage[1]} run)".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)