@@ -66,7 +66,10 @@ def get_cycle_count():
66
66
67
67
cycles = sys .float_info .max
68
68
cycles_found = False
69
+ test_passing = True
69
70
for line in lines :
71
+ if 'FAIL' in line and 'test' in line and 'failed' in line :
72
+ test_passing = False
70
73
if 'cycles total' in line :
71
74
cycles_list = [float (s ) for s in line .split () if s .isdigit ()]
72
75
cur_cycles = cycles_list [0 ]
@@ -76,15 +79,17 @@ def get_cycle_count():
76
79
else :
77
80
cycles = cur_cycles if cur_cycles > cycles else cycles
78
81
79
- return cycles
82
+ return ( test_passing , cycles )
80
83
81
84
82
- def run_config (variant , target ):
85
+ def run_config (variant , target = "digilent_arty" , workload = "pdti8" ):
83
86
84
87
# Generate bitstream and run simulation for given CPU variant and return metric results
85
88
cycles = None
86
89
cells = None
87
90
run_succeeds = False
91
+ test_passed = False
92
+ update_workload (workload )
88
93
while not run_succeeds :
89
94
EXTRA_LITEX_ARGS = 'EXTRA_LITEX_ARGS="--cpu-variant=' + variant + '"'
90
95
subprocess .run (['make' , 'clean' ])
@@ -94,7 +99,7 @@ def run_config(variant, target):
94
99
outfile = open (filename , "w" )
95
100
workload = subprocess .run (workload_cmd , stdout = outfile )
96
101
try :
97
- cycles = get_cycle_count ()
102
+ test_passed , cycles = get_cycle_count ()
98
103
run_succeeds = True
99
104
except UnicodeDecodeError :
100
105
run_succeeds = False
@@ -103,16 +108,50 @@ def run_config(variant, target):
103
108
# Remove any copied tf source overlay for next run
104
109
if os .path .exists ("./src/tensorflow" ):
105
110
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 ()
106
124
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 )
108
146
109
147
110
148
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" ):
112
151
113
152
variant = make_variant_string (csrPluginConfig , bypass , cfu , dCacheSize , hardwareDiv ,
114
153
iCacheSize , mulDiv , prediction , safe , singleCycleShift , singleCycleMulDiv )
115
- cycles , cells = run_config (variant , target )
154
+ cycles , cells = run_config (variant , target , workload )
116
155
117
156
print ("NUMBER OF CYCLES: " + str (cycles ))
118
157
print ("NUMBER OF CELLS: " + str (cells ))
@@ -123,7 +162,7 @@ def dse(csrPluginConfig, bypass, cfu, dCacheSize, hardwareDiv,
123
162
124
163
if __name__ == "__main__" :
125
164
if len (sys .argv ) > 1 :
126
- # Used for running dse vis cmd line
165
+ # Used for running dse via cmd line
127
166
# Sample command that would be equivalent to default params:
128
167
# ./dse_framework.py mcycle True False 4096 True 4096 True none True True True
129
168
csrPluginConfig = sys .argv [1 ]
@@ -138,6 +177,7 @@ def dse(csrPluginConfig, bypass, cfu, dCacheSize, hardwareDiv,
138
177
singleCycleShift = True if sys .argv [10 ] == "True" else False
139
178
singleCycleMulDiv = True if sys .argv [11 ] == "True" else False
140
179
TARGET = "digilent_arty"
180
+ WORKLOAD = "pdti8"
141
181
else :
142
182
# Sample example of how to use dse framework
143
183
csrPluginConfig = "mcycle"
@@ -152,6 +192,7 @@ def dse(csrPluginConfig, bypass, cfu, dCacheSize, hardwareDiv,
152
192
singleCycleShift = True
153
193
singleCycleMulDiv = True
154
194
TARGET = "digilent_arty"
195
+ WORKLOAD = "pdti8"
155
196
156
197
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