Skip to content

Commit

Permalink
Add HLS log reader for build time and memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
thesps committed Apr 3, 2023
1 parent 7ddffff commit 1a34760
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions conifer/backends/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from conifer.model import DecisionTreeBase, ConfigBase
import numpy as np
import xml.etree.ElementTree as ET
import re

class BottomUpDecisionTree(DecisionTreeBase):
_tree_fields = DecisionTreeBase._tree_fields + ['parent', 'depth', 'iLeaf']
Expand Down Expand Up @@ -132,6 +133,48 @@ def read_hls_report(filename: str) -> dict:
report[key] = int(report[key].text)
return report

def read_hls_log(filename: str) -> dict:
'''
Extract build metrics from HLS C Synthesis log such as:
synthesis time, synthesis memory usage
Parameters
----------
filename : string
Name of HLS log file
Returns
----------
dictionary of extracted log contents
'''
report = {}
with open(filename) as f:
for line in f.readlines():
if 'HLS 200-112' in line: # build summary line
search = 'Total elapsed time: ([0-9]+)\.*([0-9]*) seconds'
m = re.search(search, line)
if m is not None:
report['time_seconds'] = float(m.group(1))
if m.group(2) != '':
report['time_seconds'] += float(m.group(2))/100
else:
report['time_seconds'] = None
search = 'peak allocated memory: ([0-9]+)\.*([0-9]*) ([k,M,G])B'
m = re.search(search, line)
if m is not None:
mem = float(m.group(1))
if m.group(2) != '':
mem += float(m.group(2))/1000
div = 1
if m.group(3) == 'G':
div = 1
elif m.group(3) == 'M':
div=1e3
elif m.group(3) == 'k':
div=1e6
report['memory_GB'] = mem / div
else:
report['memory_GB'] = None
return report

def read_vsynth_report(filename):
report = {}
section = 0
Expand Down

0 comments on commit 1a34760

Please sign in to comment.