Skip to content

Commit e98b14f

Browse files
Add ability to change workload and check if reference / benchmark tests still passing during dse
Signed-off-by: ShvetankPrakash <[email protected]>
1 parent 0799996 commit e98b14f

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

proj/dse_template/dse_framework.py

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ def get_cycle_count():
6666

6767
cycles = sys.float_info.max
6868
cycles_found = False
69+
test_passing = True
6970
for line in lines:
71+
if 'FAIL' in line and 'test' in line and 'failed' in line:
72+
test_passing = False
7073
if 'cycles total' in line:
7174
cycles_list = [float(s) for s in line.split() if s.isdigit()]
7275
cur_cycles = cycles_list[0]
@@ -76,15 +79,17 @@ def get_cycle_count():
7679
else:
7780
cycles = cur_cycles if cur_cycles > cycles else cycles
7881

79-
return cycles
82+
return (test_passing, cycles)
8083

8184

82-
def run_config(variant, target):
85+
def run_config(variant, target="digilent_arty", workload="pdti8"):
8386

8487
# Generate bitstream and run simulation for given CPU variant and return metric results
8588
cycles = None
8689
cells = None
8790
run_succeeds = False
91+
test_passed = False
92+
update_workload(workload)
8893
while not run_succeeds:
8994
EXTRA_LITEX_ARGS = 'EXTRA_LITEX_ARGS="--cpu-variant=' + variant +'"'
9095
subprocess.run(['make', 'clean'])
@@ -94,7 +99,7 @@ def run_config(variant, target):
9499
outfile = open(filename, "w")
95100
workload = subprocess.run(workload_cmd, stdout=outfile)
96101
try:
97-
cycles = get_cycle_count()
102+
test_passed, cycles = get_cycle_count()
98103
run_succeeds = True
99104
except UnicodeDecodeError:
100105
run_succeeds = False
@@ -103,16 +108,50 @@ def run_config(variant, target):
103108
# Remove any copied tf source overlay for next run
104109
if os.path.exists("./src/tensorflow"):
105110
subprocess.run(['rm', '-rf', './src/tensorflow'])
111+
112+
# Check to see if the workload / benchmark test still passing (i.e. hw and sw are both functionally correct)
113+
if test_passed:
114+
return (cycles, cells)
115+
else: # if test failing return large number to make sample invalid
116+
print("Simulation completed but program test failed! Modifications need to be made to CFU HW or SW.")
117+
return (float('inf'), float('inf'))
118+
119+
120+
def update_workload(workload="pdti8", makefile_path="./Makefile"):
121+
if not os.path.isfile(makefile_path):
122+
print("Makefile not found.")
123+
exit()
106124

107-
return (cycles, cells)
125+
with open(makefile_path, "r") as file:
126+
lines = file.readlines()
127+
128+
new_lines = []
129+
embench_workload = False
130+
for line in lines:
131+
if workload.lower() in line.lower():
132+
embench_workload = "EMBENCH" in line
133+
if "#DEFINES" in line:
134+
line = line.replace("#DEFINES", "DEFINES")
135+
elif ("INCLUDE_MODEL_" in line or "INCLUDE_EMBENCH_" in line) and "#DEFINES" not in line:
136+
line = line.replace("DEFINES", "#DEFINES")
137+
elif "MENU_CHAR_SEQUENCE" in line:
138+
if embench_workload:
139+
line = "DEFINES += MENU_CHAR_SEQUENCE='\"81xQ\"'\n"
140+
else: # TinyML model workload golden tests
141+
line = "DEFINES += MENU_CHAR_SEQUENCE='\"11gxxQ\"'\n"
142+
new_lines.append(line)
143+
144+
with open(makefile_path, "w") as file:
145+
file.writelines(new_lines)
108146

109147

110148
def dse(csrPluginConfig, bypass, cfu, dCacheSize, hardwareDiv,
111-
iCacheSize, mulDiv, prediction, safe, singleCycleShift, singleCycleMulDiv, target):
149+
iCacheSize, mulDiv, prediction, safe, singleCycleShift,
150+
singleCycleMulDiv, target="digilent_arty", workload="pdti8"):
112151

113152
variant = make_variant_string(csrPluginConfig, bypass, cfu, dCacheSize, hardwareDiv,
114153
iCacheSize, mulDiv, prediction, safe, singleCycleShift, singleCycleMulDiv)
115-
cycles, cells = run_config(variant, target)
154+
cycles, cells = run_config(variant, target, workload)
116155

117156
print("NUMBER OF CYCLES: " + str(cycles))
118157
print("NUMBER OF CELLS: " + str(cells))
@@ -123,7 +162,7 @@ def dse(csrPluginConfig, bypass, cfu, dCacheSize, hardwareDiv,
123162

124163
if __name__ == "__main__":
125164
if len(sys.argv) > 1 :
126-
# Used for running dse vis cmd line
165+
# Used for running dse via cmd line
127166
# Sample command that would be equivalent to default params:
128167
# ./dse_framework.py mcycle True False 4096 True 4096 True none True True True
129168
csrPluginConfig = sys.argv[1]
@@ -138,6 +177,7 @@ def dse(csrPluginConfig, bypass, cfu, dCacheSize, hardwareDiv,
138177
singleCycleShift = True if sys.argv[10] == "True" else False
139178
singleCycleMulDiv = True if sys.argv[11] == "True" else False
140179
TARGET = "digilent_arty"
180+
WORKLOAD = "pdti8"
141181
else:
142182
# Sample example of how to use dse framework
143183
csrPluginConfig="mcycle"
@@ -152,6 +192,7 @@ def dse(csrPluginConfig, bypass, cfu, dCacheSize, hardwareDiv,
152192
singleCycleShift=True
153193
singleCycleMulDiv=True
154194
TARGET = "digilent_arty"
195+
WORKLOAD = "pdti8"
155196

156197
dse(csrPluginConfig, bypass, cfu, dCacheSize, hardwareDiv, iCacheSize,
157-
mulDiv, prediction, safe, singleCycleShift, singleCycleMulDiv, TARGET)
198+
mulDiv, prediction, safe, singleCycleShift, singleCycleMulDiv, TARGET, WORKLOAD)

0 commit comments

Comments
 (0)