@@ -81,6 +81,27 @@ def validate_args(args):
81
81
return True
82
82
83
83
84
+ # Reads the 'performance' section of the malioc analysis results.
85
+ def read_malioc_file_performance (performance_json ):
86
+ performance = {}
87
+ performance ['pipelines' ] = performance_json ['pipelines' ]
88
+
89
+ longest_path_cycles = performance_json ['longest_path_cycles' ]
90
+ performance ['longest_path_cycles' ] = longest_path_cycles ['cycle_count' ]
91
+ performance ['longest_path_bound_pipelines' ] = longest_path_cycles [
92
+ 'bound_pipelines' ]
93
+
94
+ shortest_path_cycles = performance_json ['shortest_path_cycles' ]
95
+ performance ['shortest_path_cycles' ] = shortest_path_cycles ['cycle_count' ]
96
+ performance ['shortest_path_bound_pipelines' ] = shortest_path_cycles [
97
+ 'bound_pipelines' ]
98
+
99
+ total_cycles = performance_json ['total_cycles' ]
100
+ performance ['total_cycles' ] = total_cycles ['cycle_count' ]
101
+ performance ['total_bound_pipelines' ] = total_cycles ['bound_pipelines' ]
102
+ return performance
103
+
104
+
84
105
# Parses the json output from malioc, which follows the schema defined in
85
106
# `mali_offline_compiler/samples/json_schemas/performance-schema.json`.
86
107
def read_malioc_file (malioc_tree , json_file ):
@@ -107,14 +128,9 @@ def read_malioc_file(malioc_tree, json_file):
107
128
for prop in variant ['properties' ]:
108
129
variant_result [prop ['name' ]] = prop ['value' ]
109
130
110
- performance = variant ['performance' ]
111
- variant_result ['pipelines' ] = performance ['pipelines' ]
112
- variant_result ['longest_path_cycles' ] = performance ['longest_path_cycles'
113
- ]['cycle_count' ]
114
- variant_result ['shortest_path_cycles' ] = performance [
115
- 'shortest_path_cycles' ]['cycle_count' ]
116
- variant_result ['total_cycles' ] = performance ['total_cycles' ]['cycle_count'
117
- ]
131
+ performance_json = variant ['performance' ]
132
+ performance = read_malioc_file_performance (performance_json )
133
+ variant_result ['performance' ] = performance
118
134
result ['variants' ][variant ['name' ]] = variant_result
119
135
results .append (result )
120
136
@@ -141,16 +157,62 @@ def read_malioc_tree(malioc_tree):
141
157
return results
142
158
143
159
160
+ # Converts a list to a string in which each list element is left-aligned in
161
+ # a space of `width` characters, and separated by `sep`. The separator does not
162
+ # count against the `width`. If `width` is 0, then the width is unconstrained.
163
+ def pretty_list (lst , fmt = 's' , sep = '' , width = 12 ):
164
+ return (sep .join (['{:<{width}{fmt}}' ] * len (lst ))).format (
165
+ width = '' if width == 0 else width , fmt = fmt , * lst
166
+ )
167
+
168
+
169
+ def compare_performance (variant , before , after ):
170
+ cycles = [['longest_path_cycles' , 'longest_path_bound_pipelines' ],
171
+ ['shortest_path_cycles' , 'shortest_path_bound_pipelines' ],
172
+ ['total_cycles' , 'total_bound_pipelines' ]]
173
+ differences = []
174
+ for cycle in cycles :
175
+ if before [cycle [0 ]] == after [cycle [0 ]]:
176
+ continue
177
+ before_cycles = before [cycle [0 ]]
178
+ before_bounds = before [cycle [1 ]]
179
+ after_cycles = after [cycle [0 ]]
180
+ after_bounds = after [cycle [1 ]]
181
+ differences += [
182
+ '{} in variant {}\n {}{}\n {:<8}{}{}\n {:<8}{}{}\n ' .format (
183
+ cycle [0 ],
184
+ variant ,
185
+ ' ' * 8 ,
186
+ pretty_list (before ['pipelines' ] + ['bound' ]), # Column labels.
187
+ 'before' ,
188
+ pretty_list (before_cycles , fmt = 'f' ),
189
+ pretty_list (before_bounds , sep = ',' , width = 0 ),
190
+ 'after' ,
191
+ pretty_list (after_cycles , fmt = 'f' ),
192
+ pretty_list (after_bounds , sep = ',' , width = 0 ),
193
+ )
194
+ ]
195
+ return differences
196
+
197
+
144
198
def compare_variants (befores , afters ):
145
199
differences = []
146
200
for variant_name , before_variant in befores .items ():
147
201
after_variant = afters [variant_name ]
148
202
for variant_key , before_variant_val in before_variant .items ():
149
203
after_variant_val = after_variant [variant_key ]
150
- if before_variant_val != after_variant_val :
204
+ if variant_key == 'performance' :
205
+ differences += compare_performance (
206
+ variant_name , before_variant_val , after_variant_val
207
+ )
208
+ elif before_variant_val != after_variant_val :
151
209
differences += [
152
- '{} in variant {}:\n {} <- before\n {} <- after' .format (
153
- variant_key , variant_name , before_variant_val , after_variant_val
210
+ 'In variant {}:\n {vkey}: {} <- before\n {vkey}: {} <- after'
211
+ .format (
212
+ variant_name ,
213
+ before_variant_val ,
214
+ after_variant_val ,
215
+ vkey = variant_key ,
154
216
)
155
217
]
156
218
return differences
@@ -162,6 +224,8 @@ def compare_shaders(malioc_tree, before_shader, after_shader):
162
224
after_val = after_shader [key ]
163
225
if key == 'variants' :
164
226
differences += compare_variants (before_val , after_val )
227
+ elif key == 'performance' :
228
+ differences += compare_performance ('Default' , before_val , after_val )
165
229
elif before_val != after_val :
166
230
differences += [
167
231
'{}:\n {} <- before\n {} <- after' .format (
@@ -178,7 +242,7 @@ def compare_shaders(malioc_tree, before_shader, after_shader):
178
242
for diff in differences :
179
243
print (diff )
180
244
print (
181
- '\n For a full report, run:\n $ malioc --{} --core {} {}/{}' .format (
245
+ '\n For a full report, run:\n $ malioc --{} --core {} {}/{}\n ' .format (
182
246
typ .lower (), core , build_gen_dir , filename
183
247
)
184
248
)
0 commit comments