This repository has been archived by the owner on Aug 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
output_funcs.py
2192 lines (1901 loc) · 110 KB
/
output_funcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import sys
import xml.etree.cElementTree as ET
import pandas as pd
import ast
from PyQt5 import QtCore, QtGui
from PyQt5.QtWidgets import QApplication, QTableView
from copy import deepcopy
from pathlib import Path
from datetime import datetime
import classes as cls
from im2col_funcs import pw_layer_col2im
import time
# Standard library
from typing import Dict, Any # Used for type hints
import json # Used to create the output YAML file
# External imports
import numpy as np # Used to get access to numpy types in yaml_compatible
# Internal imports
from classes.layer import Layer # Used for print_yaml
from input_funcs import InputSettings # Used for print_yaml
from msg import MemoryScheme # Used for print_yaml
Qt = QtCore.Qt
class PandasModel(QtCore.QAbstractTableModel):
def __init__(self, data, parent=None):
QtCore.QAbstractTableModel.__init__(self, parent)
self._data = data
def rowCount(self, parent=None):
return len(self._data.values)
def columnCount(self, parent=None):
return self._data.columns.size
def data(self, index, role=Qt.DisplayRole):
if index.isValid():
if role == Qt.DisplayRole:
return QtCore.QVariant(str(
self._data.values[index.row()][index.column()]))
return QtCore.QVariant()
def headerData(self, rowcol, orientation, role):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
return self._data.columns[rowcol]
if orientation == QtCore.Qt.Vertical and role == QtCore.Qt.DisplayRole:
return self._data.index[rowcol]
return None
def t_loop_name_transfer(mapping):
loop_name = {1: 'FX', 2: 'FY', 3: 'OX', 4: 'OY', 5: 'C', 6: 'K', 7: 'B'}
post_mapping = []
for outer_idx, outer_li in enumerate(mapping):
post_mapping.append([])
if outer_li:
for inner_idx, inner_li in enumerate(outer_li):
post_mapping[-1].append((loop_name[inner_li[0]], inner_li[1]))
return post_mapping
def s_loop_name_transfer(mapping):
loop_name = {1: 'FX', 2: 'FY', 3: 'OX', 4: 'OY', 5: 'C', 6: 'K', 7: 'B'}
post_mapping = []
for outer_idx, outer_li in enumerate(mapping):
post_mapping.append([])
if outer_li:
for inner_idx, inner_li in enumerate(outer_li):
post_mapping[-1].append([])
for va in inner_li:
post_mapping[-1][-1].append((loop_name[va[0]], va[1]))
return post_mapping
def flooring_name_transfer(flooring):
loop_name = {1: 'FX', 2: 'FY', 3: 'OX', 4: 'OY', 5: 'C', 6: 'K', 7: 'B'}
for operand in ['W', 'I', 'O']:
for outer_idx, outer_li in enumerate(flooring[operand]):
if outer_li is []:
continue
else:
for inner_idx, inner_li in enumerate(outer_li):
for i in range(len(inner_li)):
flooring[operand][outer_idx][inner_idx][i] = loop_name[
flooring[operand][outer_idx][inner_idx][i]]
flooring[operand][outer_idx][inner_idx] = tuple(flooring[operand][outer_idx][inner_idx])
return flooring
def digit_truncate(data_in, num):
if type(data_in) is dict:
if 'O_partial' in list(data_in.keys()):
try:
for operand in ['W', 'I']:
for outer_idx, outer_va in enumerate(data_in[operand]):
for inner_idx, inner_va in enumerate(outer_va):
data_in[operand][outer_idx][inner_idx] = int(inner_va)
for operand in ['O', 'O_partial', 'O_final']:
for outer_idx, outer_va in enumerate(data_in[operand]):
for inner_idx, inner_va in enumerate(outer_va):
data_in[operand][outer_idx][inner_idx] = (int(inner_va[0]), int(inner_va[1]))
return data_in
except:
for operand in ['W', 'I', 'O', 'O_partial', 'O_final']:
for idx, va in enumerate(data_in[operand]):
data_in[operand][idx] = round(va)
return data_in
else:
try:
if num == 0:
for operand in ['W', 'I', 'O']:
for outer_idx, outer_va in enumerate(data_in[operand]):
for inner_idx, inner_va in enumerate(outer_va):
data_in[operand][outer_idx][inner_idx] = round(inner_va)
return data_in
else:
for operand in ['W', 'I', 'O']:
for outer_idx, outer_va in enumerate(data_in[operand]):
for inner_idx, inner_va in enumerate(outer_va):
data_in[operand][outer_idx][inner_idx] = round(inner_va, num)
return data_in
except:
for operand in ['W', 'I', 'O']:
for idx, va in enumerate(data_in[operand]):
data_in[operand][idx] = round(va, num)
return data_in
else:
for idx, va in enumerate(data_in):
data_in[idx] = round(data_in[idx], num)
return data_in
def energy_clean(energy_breakdown):
try:
energy_breakdown_clean = {'W': [], 'I': [], 'O': []}
for operand in ['W', 'I', 'O']:
for li in energy_breakdown[operand]:
energy_breakdown_clean[operand].append(round(li[1], 1))
return energy_breakdown_clean
except:
return energy_breakdown
def mem_bw_req_meet_check(req_bw, act_bw):
meet_list = {'W': [], 'I': [], 'O': []}
for operand in ['W', 'I', 'O']:
for lv in range(len(req_bw[operand])):
if (req_bw[operand][lv][0] <= act_bw[operand][lv][0]) and \
(req_bw[operand][lv][1] <= act_bw[operand][lv][1]):
meet_list[operand].append([True, True])
elif (req_bw[operand][lv][0] > act_bw[operand][lv][0]) and \
(req_bw[operand][lv][1] <= act_bw[operand][lv][1]):
meet_list[operand].append([False, True])
elif (req_bw[operand][lv][0] <= act_bw[operand][lv][0]) and \
(req_bw[operand][lv][1] > act_bw[operand][lv][1]):
meet_list[operand].append([True, False])
else:
meet_list[operand].append([False, False])
return meet_list
def spatial_loop_same_term_merge(unrolling, flooring):
spatial_list = {'W': [], 'I': [], 'O': []}
for operand in ['W', 'I', 'O']:
for level, level_list in enumerate(flooring[operand]):
spatial_list[operand].append([])
if not level_list:
continue
else:
for XY_idx, XY_list in enumerate(level_list):
spatial_list[operand][-1].append([])
for va in XY_list:
spatial_list[operand][-1][-1].append(list(unrolling[operand][level].pop(0)))
spatial_list_clean = deepcopy(spatial_list)
for operand in ['W', 'I', 'O']:
for level, level_list in enumerate(spatial_list[operand]):
if not level_list:
continue
else:
for XY_idx, XY_list in enumerate(level_list):
if len(XY_list) in [1, 0]:
continue
else:
va_clean_idx = 0
for va_idx in range(1, len(XY_list)):
if XY_list[va_idx - 1][0] == XY_list[va_idx][0]:
spatial_list_clean[operand][level][XY_idx][va_clean_idx][1] *= XY_list[va_idx][1]
spatial_list_clean[operand][level][XY_idx].remove(XY_list[va_idx])
va_clean_idx -= 1
va_clean_idx += 1
return spatial_list_clean
def iterative_data_format_clean(original_dict):
new_dict = {'W': [], 'I': [], 'O': []}
for operand in ['W', 'I', 'O']:
for li in original_dict[operand]:
new_dict[operand].append(li[0])
return new_dict
def mem_unroll_format(unit_count):
return {'W': unit_count['W'][1:], 'I': unit_count['I'][1:], 'O': unit_count['O'][1:]}
def mem_share_reformat(mem_share, mem_name):
new_mem_share = {}
for i, shared_list in mem_share.items():
new_mem_share[i] = []
for li in shared_list:
new_mem_share[i].append((li[0], mem_name[li[0]][li[1]]))
return new_mem_share
def add_mem_type_name(mem_type_list):
name_transfer = {1: 'sp_db', 2: 'dp_sb', 3: 'dp_db'}
new_mem_type_list = {'W': [], 'I': [], 'O': []}
for operand in ['W', 'I', 'O']:
for li in mem_type_list[operand]:
new_mem_type_list[operand].append(name_transfer[li])
return new_mem_type_list
def elem2bit(elem_list, precision):
bit_list = {'W': [], 'I': [], 'O': [], 'O_partial': [], 'O_final': []}
for operand in ['W', 'I', 'O_partial', 'O_final']:
for va in elem_list[operand]:
bit_list[operand].append(va * precision[operand])
for idx, va in enumerate(bit_list['O_partial']):
if va != 0:
bit_list['O'].append(va)
else:
bit_list['O'].append(bit_list['O_final'][idx])
return bit_list
def create_printing_block(row, col):
return [[' '] * col for _ in range(row)]
def modify_printing_block(old_block, start_row, start_col, new_str):
new_block = deepcopy(old_block)
new_block[start_row][start_col:start_col + len(new_str)] = new_str
return new_block
def print_printing_block(file_path_name, printing_block, mode):
orig_stdout = sys.stdout
f = open(file_path_name, mode)
sys.stdout = f
print()
for i in range(len(printing_block)):
print(''.join(printing_block[i]))
sys.stdout = orig_stdout
f.close()
def su_reformat_if_need(su):
new_su = {'W': [], 'I': [], 'O': []}
ok = False
# extract unrolled dimension on row and on column
for op in ['W', 'I', 'O']:
for level_list in su[op]:
# TODO assume that at least one operand at one level is fully 2D unrolled.
if len(level_list) == 2:
row_list = [x[0] for x in level_list[0]]
col_list = [x[0] for x in level_list[1]]
ok = True
break
if ok:
break
# for each 1D-unrolled mem/mac level, distinguish column from row
for op in ['W', 'I', 'O']:
for level_list in su[op]:
if len(level_list) in [0,2]:
new_su[op].append(level_list)
elif len(level_list) == 1:
if level_list[0][0][0] in row_list:
level_list.append([])
elif level_list[0][0][0] in col_list:
level_list.insert(0, [])
else:
print('su:', su)
raise ValueError('NO1. Please check the SU.')
new_su[op].append(level_list)
else:
print('su:', su)
raise ValueError('NO2. Please check the SU.')
return new_su
##++ Count memory access in # of words (originally we count memory access in # of data elements)
def mem_access_word_transfer(mem_access_elem, mem_bw, precision):
mem_access_word = {'W':[], 'I':[], 'O':[], 'O_final':[], 'O_partial':[]}
read_bw = 0
write_bw = 1
for op in ['W', 'I']:
for level, acc in enumerate(mem_access_elem[op]):
mem_access_word[op].append([round(acc[0]*precision[op]/mem_bw[op][level][read_bw]),
round(acc[1]*precision[op]/mem_bw[op][level][write_bw])])
for op in ['O_final', 'O_partial']:
for level, acc_list in enumerate(mem_access_elem[op]):
mem_access_word[op].append([])
mem_access_word[op][-1] = ([round(acc_list[0][0]*precision[op]/mem_bw['O'][level][read_bw]),
round(acc_list[0][1]*precision[op]/mem_bw['O'][level][write_bw])],
[round(acc_list[1][0]*precision[op]/mem_bw['O'][level][read_bw]),
round(acc_list[1][1]*precision[op]/mem_bw['O'][level][write_bw])])
mem_access_word['O'] = deepcopy(mem_access_word['O_final'])
for level, _ in enumerate(mem_access_elem['O_partial']):
mem_access_word['O'][level] = [(mem_access_word['O_final'][level][0][0]+mem_access_word['O_partial'][level][0][0],
mem_access_word['O_final'][level][0][1]+mem_access_word['O_partial'][level][0][1]),
(mem_access_word['O_final'][level][1][0]+mem_access_word['O_partial'][level][1][0],
mem_access_word['O_final'][level][1][1]+mem_access_word['O_partial'][level][1][1])]
return mem_access_word
##--
##++ get total data size at each level
def get_data_size_each_level_total (unit_unique, req_mem_size_bit):
data_size_each_level_total = {'W': [], 'I': [], 'O': []}
for operand in ['W', 'I', 'O']:
for idx, req_mem_size in enumerate(req_mem_size_bit[operand]):
data_size_each_level_total[operand].append(req_mem_size*unit_unique[operand][idx+1])
return data_size_each_level_total
##--
def print_good_tm_format(tm, mem_name, file_path_name):
lp_name = {1: 'FX', 2: 'FY', 3: 'OX', 4: 'OY', 5: 'C', 6: 'K', 7: 'B'}
tm_list = [tp for li in tm['W'] for tp in li]
# get required interval between 'W', 'I', 'O', based on actual mem name length
max_mem_name_len = 0
for operand in ['W', 'I', 'O']:
for lv in range(len(mem_name[operand])):
if len(mem_name[operand][lv]) > max_mem_name_len:
max_mem_name_len = len(mem_name[operand][lv])
interval = max_mem_name_len + 10
tot_row = 2 * (len(tm_list) + 1) + 8
tot_col = int(2 * (len(tm_list) + 1) + 3.75 * interval)
tot_col_cut = 2 * (len(tm_list) + 1) + interval
tm_block = create_printing_block(tot_row, tot_col)
dash = '*' * int((tot_col - len(' Temporal Mapping Visualization ')) / 2)
tm_block = modify_printing_block(tm_block, 1, 0, dash + ' Temporal Mapping Visualization ' + dash)
tm_block = modify_printing_block(tm_block, 2, 1, 'W: ' + str(t_loop_name_transfer(tm['W'])))
tm_block = modify_printing_block(tm_block, 3, 1, 'I: ' + str(t_loop_name_transfer(tm['I'])))
tm_block = modify_printing_block(tm_block, 4, 1, 'O: ' + str(t_loop_name_transfer(tm['O'])))
tm_block = modify_printing_block(tm_block, 6, 0, '-' * tot_col)
tm_block = modify_printing_block(tm_block, 7, 1, 'Temporal Loops')
tm_block = modify_printing_block(tm_block, 8, 0, '-' * tot_col)
finish_row = 2 * len(tm_list) + 7
for i, li in enumerate(tm_list):
tm_block = modify_printing_block(tm_block, finish_row - 2 * i, len(tm_list) - i,
'for ' + str(lp_name[li[0]]) + ' in ' + '[0:' + str(li[1]) + ')')
tm_block = modify_printing_block(tm_block, 2 * (i + 1) + 1 + 7, 0, '-' * tot_col)
# print mem name to each level
for idx, operand in enumerate(['W', 'I', 'O']):
column_position = tot_col_cut + idx * interval
tm_block = modify_printing_block(tm_block, 7, column_position, operand)
i = 0
for level, lv_li in enumerate(tm[operand]):
for _ in lv_li:
tm_block = modify_printing_block(tm_block, finish_row - 2 * i, column_position,
str(mem_name[operand][level]))
i += 1
tm_block = modify_printing_block(tm_block, finish_row + 2, 1,
"(Notes: Temporal Mapping starts from the innermost memory level. MAC level is out of Temporal Mapping's scope.)")
print_printing_block(file_path_name, tm_block, 'a+')
def print_good_su_format(su, mem_name, file_path_name):
# print(su, mem_name, file_path_name)
try:
lp_name = {1: 'FX', 2: 'FY', 3: 'OX', 4: 'OY', 5: 'C', 6: 'K', 7: 'B'}
su_list = [sp for lv_li in su['W'] for xy_li in lv_li for sp in xy_li]
mem_name = {'W': ['MAC'] + mem_name['W'], 'I': ['MAC'] + mem_name['I'], 'O': ['MAC'] + mem_name['O']}
# get required interval between 'W', 'I', 'O', based on actual mem name length
max_mem_name_len = 0
for operand in ['W', 'I', 'O']:
for lv in range(len(mem_name[operand])):
if len(mem_name[operand][lv]) > max_mem_name_len and su[operand][lv] != []:
max_mem_name_len = len(mem_name[operand][lv])
interval = max_mem_name_len + 13
tot_row = 2 * (len(su_list) + 1) + 13
tot_col = int(2 * (len(su_list) + 1) + 3.75 * interval)
tot_col_cut = 2 * (len(su_list) + 1) + interval
su_block = create_printing_block(tot_row, tot_col)
dash = '*' * int((tot_col - len(' Levels In The System')) / 2)
su_block = modify_printing_block(su_block, 0, 0, dash + ' Levels In The System ' + dash)
su_block = modify_printing_block(su_block, 1, 1, 'W: ' + str(mem_name['W']))
su_block = modify_printing_block(su_block, 2, 1, 'I: ' + str(mem_name['I']))
su_block = modify_printing_block(su_block, 3, 1, 'O: ' + str(mem_name['O']))
dash = '*' * int((tot_col - len(' Spatial Unrolling Visualization ')) / 2)
su_block = modify_printing_block(su_block, 6, 0, dash + ' Spatial Unrolling Visualization ' + dash)
su_block = modify_printing_block(su_block, 7, 1, 'W: ' + str(s_loop_name_transfer(su['W'])))
su_block = modify_printing_block(su_block, 8, 1, 'I: ' + str(s_loop_name_transfer(su['I'])))
su_block = modify_printing_block(su_block, 9, 1, 'O: ' + str(s_loop_name_transfer(su['O'])))
su_block = modify_printing_block(su_block, 11, 0, '-' * tot_col)
su_block = modify_printing_block(su_block, 12, 1, "Unrolled Loops")
su_block = modify_printing_block(su_block, 13, 0, '-' * tot_col)
finish_row = 2 * len(su_list) + 12
for i, li in enumerate(su_list):
su_block = modify_printing_block(su_block, finish_row - 2 * i, 1,
'unroll ' + str(lp_name[li[0]]) + ' in ' + '[0:' + str(li[1]) + ')')
su_block = modify_printing_block(su_block, 2 * (i + 1) + 1 + 12, 0, '-' * tot_col)
su_block = modify_printing_block(su_block, finish_row + 2, 1,
"(Notes: Unrolled loops' order doesn't matter; D1 and D2 are PE "
"array's two geometric dimensions. )")
# print mem name to each level
XY_name = {0: 'D1', 1: 'D2'}
position_save = [[], []] # for I and O based on W
for idx, operand in enumerate(['W']):
column_position = tot_col_cut + idx * interval
su_block = modify_printing_block(su_block, 12, column_position, operand)
i = 0
for level, lv_li in enumerate(su[operand]):
for xy, xy_li in enumerate(lv_li):
for tt in xy_li:
position_save[0].extend([tt[0], XY_name[xy], finish_row - 2 * i])
position_save[1].extend([tt[0], XY_name[xy], finish_row - 2 * i])
su_block = modify_printing_block(su_block, finish_row - 2 * i, column_position,
str(mem_name[operand][level]) + ' (' + XY_name[xy] + ')')
# print_printing_block(file_path_name, su_block, 'w+')
i += 1
for idx, operand in enumerate(['I', 'O']):
column_position = tot_col_cut + (idx+1) * interval
su_block = modify_printing_block(su_block, 12, column_position, operand)
i = 0
for level, lv_li in enumerate(su[operand]):
for xy, xy_li in enumerate(lv_li):
for tt in xy_li:
indices = [i for i, x in enumerate(position_save[idx]) if x == XY_name[xy]]
for ind in indices:
# Check if loop type matches.
if position_save[idx][ind-1] == tt[0]:
line_position_index = ind
break
line_position = position_save[idx][line_position_index+1]
del position_save[idx][line_position_index]
del position_save[idx][line_position_index]
su_block = modify_printing_block(su_block, line_position, column_position,
str(mem_name[operand][level]) + ' (' + XY_name[xy] + ')')
# print_printing_block(file_path_name, su_block, 'w+')
i += 1
except:
su = su_reformat_if_need(su)
su_list = [sp for lv_li in su['W'] for xy_li in lv_li for sp in xy_li]
# get required interval between 'W', 'I', 'O', based on actual mem name length
max_mem_name_len = 0
for operand in ['W', 'I', 'O']:
for lv in range(len(mem_name[operand])):
if len(mem_name[operand][lv]) > max_mem_name_len and su[operand][lv] != []:
max_mem_name_len = len(mem_name[operand][lv])
interval = max_mem_name_len + 13
tot_row = 2 * (len(su_list) + 1) + 13
tot_col = int(2 * (len(su_list) + 1) + 3.75 * interval)
tot_col_cut = 2 * (len(su_list) + 1) + interval
su_block = create_printing_block(tot_row, tot_col)
dash = '*' * int((tot_col - len(' Levels In The System')) / 2)
su_block = modify_printing_block(su_block, 0, 0, dash + ' Levels In The System ' + dash)
su_block = modify_printing_block(su_block, 1, 1, 'W: ' + str(mem_name['W']))
su_block = modify_printing_block(su_block, 2, 1, 'I: ' + str(mem_name['I']))
su_block = modify_printing_block(su_block, 3, 1, 'O: ' + str(mem_name['O']))
dash = '*' * int((tot_col - len(' Spatial Unrolling Visualization ')) / 2)
su_block = modify_printing_block(su_block, 6, 0, dash + ' Spatial Unrolling Visualization ' + dash)
su_block = modify_printing_block(su_block, 7, 1, 'W: ' + str(s_loop_name_transfer(su['W'])))
su_block = modify_printing_block(su_block, 8, 1, 'I: ' + str(s_loop_name_transfer(su['I'])))
su_block = modify_printing_block(su_block, 9, 1, 'O: ' + str(s_loop_name_transfer(su['O'])))
su_block = modify_printing_block(su_block, 11, 0, '-' * tot_col)
su_block = modify_printing_block(su_block, 12, 1, "Unrolled Loops")
su_block = modify_printing_block(su_block, 13, 0, '-' * tot_col)
finish_row = 2 * len(su_list) + 12
for i, li in enumerate(su_list):
su_block = modify_printing_block(su_block, finish_row - 2 * i, 1,
'unroll ' + str(lp_name[li[0]]) + ' in ' + '[0:' + str(li[1]) + ')')
su_block = modify_printing_block(su_block, 2 * (i + 1) + 1 + 12, 0, '-' * tot_col)
su_block = modify_printing_block(su_block, finish_row + 2, 1,
"(Notes: Unrolled loops' order doesn't matter; D1 and D2 are PE "
"array's two geometric dimensions. )")
# print mem name to each level
XY_name = {0: 'D1', 1: 'D2'}
position_save = [[], []] # for I and O based on W
for idx, operand in enumerate(['W']):
column_position = tot_col_cut + idx * interval
su_block = modify_printing_block(su_block, 12, column_position, operand)
i = 0
for level, lv_li in enumerate(su[operand]):
for xy, xy_li in enumerate(lv_li):
for _ in xy_li:
position_save[0].extend([XY_name[xy], finish_row - 2 * i])
position_save[1].extend([XY_name[xy], finish_row - 2 * i])
su_block = modify_printing_block(su_block, finish_row - 2 * i, column_position,
str(mem_name[operand][level]) + ' (' + XY_name[xy] + ')')
# print_printing_block(file_path_name, su_block, 'w+')
i += 1
for idx, operand in enumerate(['I', 'O']):
column_position = tot_col_cut + (idx + 1) * interval
su_block = modify_printing_block(su_block, 12, column_position, operand)
i = 0
for level, lv_li in enumerate(su[operand]):
for xy, xy_li in enumerate(lv_li):
for _ in xy_li:
line_position_index = position_save[idx].index(XY_name[xy])
line_position = position_save[idx][line_position_index + 1]
del position_save[idx][line_position_index]
del position_save[idx][line_position_index]
su_block = modify_printing_block(su_block, line_position, column_position,
str(mem_name[operand][level]) + ' (' + XY_name[xy] + ')')
# print_printing_block(file_path_name, su_block, 'w+')
i += 1
print_printing_block(file_path_name, su_block, 'w+')
def handle_grouped_convolutions(
layer_specification: Layer, cost_model_output: "CostModelOutput",
) -> Any:
"""
Corrects various values to account for the grouped convolutions.
Arguments
=========
- layer_specification: A description of the input layer that ZigZag has
optimized.
- cost_model_output: The cost computed by ZigZag for running the given
layer on the hardware.
Returns
=======
A tuple of 17 elements, in order:
- size_list_output_print,
- total_MAC_op_number,
- total_data_size_number,
- mem_access_elem,
- total_cost,
- operand_cost,
- mac_cost_active,
- mac_cost_idle,
- latency_tot_number,
- latency_no_load_number,
- total_cycles_number,
- cc_load_tot_number,
- cc_load_number,
- cc_load_comb_number,
- cc_mem_stall_tot_number,
- stall_cc_number,
- stall_cc_mem_share_number,
"""
# If layer has a number of groups > 1, transform relevant variables.
# At this point, the results are those of one group, so multiply by number of groups.
group_count = layer_specification.G
# SPECIFICATION
size_list_output_print = deepcopy(layer_specification.size_list_output_print)
size_list_output_print['C'] *= group_count
size_list_output_print['K'] *= group_count
# COMPUTATIONS
total_MAC_op_number = group_count * layer_specification.total_MAC_op
# DATA SIZE
total_data_size_number = deepcopy(layer_specification.total_data_size)
total_data_size_number['W'] *= group_count
total_data_size_number['I'] *= group_count
total_data_size_number['O'] *= group_count
# MEMORY ACCESS
mem_access_elem = digit_truncate(deepcopy(cost_model_output.loop.mem_access_elem), 0)
mem_access_elem['W'] = [[group_count * elem for elem in sublist] for sublist in mem_access_elem['W']]
mem_access_elem['I'] = [[group_count * elem for elem in sublist] for sublist in mem_access_elem['I']]
mem_access_elem['O'] = [[tuple([group_count * elem for elem in subsublist]) for subsublist in sublist] for sublist in mem_access_elem['O']]
mem_access_elem['O_partial'] = [[tuple([group_count * elem for elem in subsublist]) for subsublist in sublist] for sublist in mem_access_elem['O_partial']]
mem_access_elem['O_final'] = [[tuple([group_count * elem for elem in subsublist]) for subsublist in sublist] for sublist in mem_access_elem['O_final']]
# ENERGY
total_cost = round(group_count * cost_model_output.total_cost, 1)
operand_cost = energy_clean(deepcopy(cost_model_output.operand_cost))
operand_cost['W'] = [group_count * elem for elem in operand_cost['W']]
operand_cost['I'] = [group_count * elem for elem in operand_cost['I']]
operand_cost['O'] = [group_count * elem for elem in operand_cost['O']]
mac_cost_active = round(group_count * cost_model_output.mac_cost[0], 1)
mac_cost_idle = round(group_count * cost_model_output.mac_cost[1], 1)
# LATENCY
latency_tot_number = group_count * cost_model_output.utilization.latency_tot
latency_no_load_number = group_count * cost_model_output.utilization.latency_no_load
total_cycles_number = group_count * cost_model_output.temporal_loop.total_cycles
cc_load_tot_number = group_count * cost_model_output.utilization.cc_load_tot
cc_load_number = deepcopy(cost_model_output.utilization.cc_load)
cc_load_number['W'] = [group_count * elem for elem in cc_load_number['W']]
cc_load_number['I'] = [group_count * elem for elem in cc_load_number['I']]
cc_load_comb_number = deepcopy(cost_model_output.utilization.cc_load_comb)
cc_load_comb_number['W'] *= group_count
cc_load_comb_number['I'] *= group_count
cc_mem_stall_tot_number = group_count * cost_model_output.utilization.cc_mem_stall_tot
stall_cc_number = deepcopy(cost_model_output.utilization.stall_cc)
stall_cc_number['W'] = [[group_count * elem for elem in sublist] for sublist in stall_cc_number['W']]
stall_cc_number['I'] = [[group_count * elem for elem in sublist] for sublist in stall_cc_number['I']]
stall_cc_number['O'] = [[group_count * elem for elem in sublist] for sublist in stall_cc_number['O']]
stall_cc_mem_share_number = deepcopy(cost_model_output.utilization.stall_cc_mem_share)
stall_cc_mem_share_number['W'] = [[group_count * elem for elem in sublist] for sublist in stall_cc_mem_share_number['W']]
stall_cc_mem_share_number['I'] = [[group_count * elem for elem in sublist] for sublist in stall_cc_mem_share_number['I']]
stall_cc_mem_share_number['O'] = [[group_count * elem for elem in sublist] for sublist in stall_cc_mem_share_number['O']]
# Returning the tuple of values corrected for the grouped convolution.
return (
size_list_output_print,
total_MAC_op_number,
total_data_size_number,
mem_access_elem,
total_cost,
operand_cost,
mac_cost_active,
mac_cost_idle,
latency_tot_number,
latency_no_load_number,
total_cycles_number,
cc_load_tot_number,
cc_load_number,
cc_load_comb_number,
cc_mem_stall_tot_number,
stall_cc_number,
stall_cc_mem_share_number,
)
def print_xml(results_filename, layer_specification, mem_scheme, cost_model_output, common_settings,
hw_pool_sizes, elapsed_time, result_print_mode):
dir_path = ''
dir_path_list = results_filename.split('/')
for i in range(0, len(dir_path_list) - 1):
dir_path += dir_path_list[i] + '/'
''' Create result folder if it does not exist. '''
Path(dir_path).mkdir(parents=True, exist_ok=True)
'''
Newly generated result will be appended after existed ones.
Create new result file if there is no existed one.
'''
if not os.path.isfile(results_filename + '.xml'):
root = ET.Element('root')
tree = ET.ElementTree(root)
tree.write(results_filename + '.xml')
try:
tree = ET.parse(results_filename + '.xml')
except:
# Error thrown because the xml file is corrupt
os.remove(results_filename + '.xml')
print("Deleted corrupt xml file:", results_filename + '.xml')
root = ET.Element('root')
tree = ET.ElementTree(root)
tree.write(results_filename + '.xml')
tree = ET.parse(results_filename + '.xml')
root = tree.getroot()
sim = ET.SubElement(root, 'simulation')
result_generate_time = ET.SubElement(sim, 'result_generated_time')
result_generate_time.tail = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if cost_model_output not in [None, [], {}]:
# Correcting the outputed values to account for the grouped convolution.
(
size_list_output_print,
total_MAC_op_number,
total_data_size_number,
mem_access_elem,
total_cost,
operand_cost,
mac_cost_active,
mac_cost_idle,
latency_tot_number,
latency_no_load_number,
total_cycles_number,
cc_load_tot_number,
cc_load_number,
cc_load_comb_number,
cc_mem_stall_tot_number,
stall_cc_number,
stall_cc_mem_share_number,
) = handle_grouped_convolutions(layer_specification, cost_model_output)
if result_print_mode == 'complete':
layer = ET.SubElement(sim, 'layer')
# layer_index = ET.SubElement(layer, 'layer_index')
# layer_index.tail = str(common_settings.layer_index)
layer_spec = ET.SubElement(layer, 'layer_spec')
layer_spec.tail = str(layer_specification.size_list_output_print)
im2col_enable = ET.SubElement(layer, 'im2col_enable')
im2col_enable.tail = str(common_settings.im2col_enable)
total_MAC_op = ET.SubElement(layer, 'total_MAC_operation')
total_MAC_op.tail = str(total_MAC_op_number)
total_data_size = ET.SubElement(layer, 'total_data_size_element')
total_data_size.tail = str(total_data_size_number)
total_data_reuse = ET.SubElement(layer, 'total_data_reuse')
total_data_reuse.tail = str(layer_specification.total_data_reuse)
search_engine = ET.SubElement(sim, 'search_engine')
memory_hier_search_engine = ET.SubElement(search_engine, 'mem_hierarchy_search')
memory_hier_search_mode = ET.SubElement(memory_hier_search_engine, 'mode')
memory_hier_search_mode.tail = str(common_settings.search_mode['Mem'])
if not common_settings.search_mode['Mem'] == 'fixed':
total_area = ET.SubElement(memory_hier_search_engine, 'area_constraint')
total_area.tail = str(common_settings.area_constraint['max_area'])
area_utilization_threshold = ET.SubElement(memory_hier_search_engine, 'area_utilization_threshold')
area_utilization_threshold.tail = '\u2265 ' + str(common_settings.area_constraint['area_th'])
# mem_pool = ET.SubElement(memory_hier_search_engine, 'mem_pool')
# mem_pool.tail = str(common_settings.mem_pool)
memory_hierarchy_ratio = ET.SubElement(memory_hier_search_engine, 'consecutive_memory_level_size_ratio')
memory_hierarchy_ratio.tail = '\u2265 ' + str(common_settings.memory_hierarchy_ratio)
max_inner_PE_mem_size = ET.SubElement(memory_hier_search_engine, 'max_inner_PE_mem_size_bit')
max_inner_PE_mem_size.tail = str(common_settings.max_inner_PE_mem_size)
max_inner_PE_mem_level = ET.SubElement(memory_hier_search_engine, 'max_inner_PE_mem_level')
max_inner_PE_mem_level.tail = str(common_settings.max_inner_PE_mem_level)
max_outer_PE_mem_level = ET.SubElement(memory_hier_search_engine, 'max_outer_PE_mem_level')
max_outer_PE_mem_level.tail = str(common_settings.max_outer_PE_mem_level)
valid_mem_scheme_count = ET.SubElement(memory_hier_search_engine, 'mem_scheme_index')
valid_mem_scheme_count.tail = str(common_settings.mem_scheme_count)
spatial_mapping_search_engine = ET.SubElement(search_engine, 'spatial_mapping_search')
spatial_search_mode = ET.SubElement(spatial_mapping_search_engine, 'mode')
spatial_search_mode.tail = str(common_settings.search_mode['Spatial'])
if not common_settings.search_mode['Spatial'] == 'fixed':
if common_settings.spatial_unrolling_mode != 3:
spatial_utilization_threshold = ET.SubElement(spatial_mapping_search_engine,
'spatial_utilization_threshold')
spatial_utilization_threshold.tail = str(common_settings.SU_threshold)
else:
spatial_mapping_hint_list = ET.SubElement(spatial_mapping_search_engine,
'spatial_mapping_hint_list')
spatial_mapping_hint_list.tail = str(common_settings.spatial_mapping_hint_list)
valid_unrolling_scheme_count = ET.SubElement(spatial_mapping_search_engine, 'unrolling_scheme_index')
valid_unrolling_scheme_count.tail = str(common_settings.spatial_count)
temporal_mapping_search_engine = ET.SubElement(search_engine, 'temporal_mapping_search')
temporal_search_mode = ET.SubElement(temporal_mapping_search_engine, 'mode')
temporal_search_mode.tail = str(common_settings.search_mode['Temporal'])
# if not common_settings.search_mode['Temporal'] == 'fixed':
# memory_utilization_threshold = ET.SubElement(temporal_mapping_search_engine, 'memory_utilization_hint')
# memory_utilization_threshold.tail = str(common_settings.mem_utilization_rate)
valid_temporal_mapping_count = ET.SubElement(temporal_mapping_search_engine, 'valid_temporal_mapping_found')
valid_temporal_mapping_count.tail = str(hw_pool_sizes)
hw_spec = ET.SubElement(sim, 'hw_spec')
PE_array = ET.SubElement(hw_spec, 'PE_array')
precision = ET.SubElement(PE_array, 'precision_bit')
precision.tail = str(common_settings.precision)
array_size = ET.SubElement(PE_array, 'MAC_array_size')
array_size.tail = str(common_settings.array_size)
memory_hierarchy = ET.SubElement(hw_spec, 'memory_hierarchy')
mem_name = ET.SubElement(memory_hierarchy, 'mem_name_in_the_hierarchy')
mem_name_W = ET.SubElement(mem_name, 'W')
mem_name_W.tail = str(mem_scheme.mem_name['W'])
mem_name_I = ET.SubElement(mem_name, 'I')
mem_name_I.tail = str(mem_scheme.mem_name['I'])
mem_name_O = ET.SubElement(mem_name, 'O')
mem_name_O.tail = str(mem_scheme.mem_name['O'])
mem_size_bit = ET.SubElement(memory_hierarchy, 'mem_size_bit')
mem_size_bit.tail = str(mem_scheme.mem_size)
mem_access_cost = deepcopy(common_settings.mem_access_cost)
if type(mem_scheme.mem_bw['W'][0][0]) in [list, tuple]:
mem_scheme.mem_bw = iterative_data_format_clean(mem_scheme.mem_bw)
if type(common_settings.mem_access_cost['W'][0][0]) in [list, tuple]:
mem_access_cost = iterative_data_format_clean(mem_access_cost)
if type(mem_scheme.mem_area['W'][0]) in [list, tuple]:
mem_scheme.mem_area = iterative_data_format_clean(mem_scheme.mem_area)
mem_bw = ET.SubElement(memory_hierarchy, 'mem_bw_bit_per_cycle_or_mem_wordlength')
mem_bw.tail = str(mem_scheme.mem_bw)
mem_cost_word = ET.SubElement(memory_hierarchy, 'mem_access_energy_per_word')
mem_cost_word.tail = str(mem_access_cost)
# pun_factor = ET.SubElement(memory_hierarchy, 'pun_factor')
# pun_factor.tail = str(cost_model_output.utilization.pun_factor)
mem_type = ET.SubElement(memory_hierarchy, 'mem_type')
mem_type.tail = str(add_mem_type_name(mem_scheme.mem_type))
mem_share = ET.SubElement(memory_hierarchy, 'mem_share')
mem_share.tail = str(mem_share_reformat(mem_scheme.mem_share, mem_scheme.mem_name))
mem_area = ET.SubElement(memory_hierarchy, 'mem_area_single_module')
mem_area.tail = str(mem_scheme.mem_area)
mem_unroll = ET.SubElement(memory_hierarchy, 'mem_unroll')
mem_unroll.tail = str(mem_unroll_format(cost_model_output.spatial_loop.unit_count))
results = ET.SubElement(sim, 'results')
basic_info = ET.SubElement(results, 'basic_info')
spatial_mapping = ET.SubElement(basic_info, 'spatial_unrolling')
spatial_mapping_W = ET.SubElement(spatial_mapping, 'W')
spatial_mapping_I = ET.SubElement(spatial_mapping, 'I')
spatial_mapping_O = ET.SubElement(spatial_mapping, 'O')
try:
spatial_mapping_W.tail = str(s_loop_name_transfer(cost_model_output.spatial_scheme['W']))
spatial_mapping_I.tail = str(s_loop_name_transfer(cost_model_output.spatial_scheme['I']))
spatial_mapping_O.tail = str(s_loop_name_transfer(cost_model_output.spatial_scheme['O']))
except:
cost_model_output.spatial_scheme = \
spatial_loop_same_term_merge(cost_model_output.spatial_scheme, cost_model_output.flooring)
spatial_mapping_W.tail = str(s_loop_name_transfer(cost_model_output.spatial_scheme['W']))
spatial_mapping_I.tail = str(s_loop_name_transfer(cost_model_output.spatial_scheme['I']))
spatial_mapping_O.tail = str(s_loop_name_transfer(cost_model_output.spatial_scheme['O']))
greedy_mapping_flag = ET.SubElement(spatial_mapping, 'greedy_mapping')
greedy_mapping_flag.tail = str(cost_model_output.greedy_mapping_flag)
if cost_model_output.greedy_mapping_flag:
footer_info = ET.SubElement(spatial_mapping, 'footer_info')
footer_info.tail = str(cost_model_output.footer_info)
temporal_mapping = ET.SubElement(basic_info, 'temporal_mapping')
temporal_mapping_W = ET.SubElement(temporal_mapping, 'W')
temporal_mapping_W.tail = str(t_loop_name_transfer(cost_model_output.temporal_scheme['W']))
temporal_mapping_I = ET.SubElement(temporal_mapping, 'I')
temporal_mapping_I.tail = str(t_loop_name_transfer(cost_model_output.temporal_scheme['I']))
temporal_mapping_O = ET.SubElement(temporal_mapping, 'O')
temporal_mapping_O.tail = str(t_loop_name_transfer(cost_model_output.temporal_scheme['O']))
fully_PE_level_output_stationary = ET.SubElement(temporal_mapping, 'fully_PE_level_output_stationary')
fully_PE_level_output_stationary.tail = str(cost_model_output.utilization.fully_PE_level_output_stationary)
data_reuse = ET.SubElement(basic_info, 'data_reuse')
try:
del (cost_model_output.loop.data_reuse['I_base'])
del (cost_model_output.loop.data_reuse['I_zigzag'])
except:
pass
data_reuse.tail = str(digit_truncate(cost_model_output.loop.data_reuse, 2))
i_fifo = ET.SubElement(basic_info, 'I_pr_diagonally_broadcast_or_fifo_effect')
i_fifo.tail = "'I': " + str(cost_model_output.loop.I_fifo)
req_mem_size = ET.SubElement(basic_info, 'used_mem_size_bit')
req_mem_size_bit = elem2bit(cost_model_output.loop.req_mem_size, common_settings.precision)
req_mem_size.tail = str(req_mem_size_bit)
mem_utilize = ET.SubElement(basic_info, 'actual_mem_utilization_individual')
mem_utilize.tail = str(digit_truncate(cost_model_output.utilization.mem_utilize, 2))
mem_utilize_shared = ET.SubElement(basic_info, 'actual_mem_utilization_shared')
mem_utilize_shared.tail = str(digit_truncate(cost_model_output.utilization.mem_utilize_shared, 2))
# print('final memory ut', cost_model_output.utilization.mem_utilize_shared)
effective_mem_size = ET.SubElement(basic_info, 'effective_mem_size_bit')
effective_mem_size.tail = str(elem2bit(digit_truncate(cost_model_output.loop.effective_mem_size, 0),
common_settings.precision))
unit_count = ET.SubElement(basic_info, 'total_unit_count')
unit_count.tail = str(cost_model_output.spatial_loop.unit_count)
unit_unique = ET.SubElement(basic_info, 'unique_unit_count')
unit_unique.tail = str(cost_model_output.spatial_loop.unit_unique)
unit_duplicate = ET.SubElement(basic_info, 'duplicate_unit_count')
unit_duplicate.tail = str(cost_model_output.spatial_loop.unit_duplicate)
try:
del (cost_model_output.loop.mem_access_elem['I_base'])
del (cost_model_output.loop.mem_access_elem['I_zig_zag'])
except:
pass
access_count = ET.SubElement(basic_info, 'mem_access_count_elem')
access_count_W = ET.SubElement(access_count, 'W')
access_count_W.tail = str(mem_access_elem['W'])
access_count_I = ET.SubElement(access_count, 'I')
access_count_I.tail = str(mem_access_elem['I'])
access_count_O = ET.SubElement(access_count, 'O')
access_count_O.tail = str(mem_access_elem['O'])
access_count_O_partial = ET.SubElement(access_count, 'O_partial')
access_count_O_partial.tail = str(mem_access_elem['O_partial'])
access_count_O_final = ET.SubElement(access_count, 'O_final')
access_count_O_final.tail = str(mem_access_elem['O_final'])
word_access_count = ET.SubElement(basic_info, 'mem_access_count_word')
mem_access_word = mem_access_word_transfer(mem_access_elem,
mem_scheme.mem_bw, common_settings.precision)
word_access_count_W = ET.SubElement(word_access_count, 'W')
word_access_count_W.tail = str(mem_access_word['W'])
word_access_count_I = ET.SubElement(word_access_count, 'I')
word_access_count_I.tail = str(mem_access_word['I'])
word_access_count_O = ET.SubElement(word_access_count, 'O')
word_access_count_O.tail = str(mem_access_word['O'])
word_access_count_O_partial = ET.SubElement(word_access_count, 'O_partial')
word_access_count_O_partial.tail = str(mem_access_word['O_partial'])
word_access_count_O_final = ET.SubElement(word_access_count, 'O_final')
word_access_count_O_final.tail = str(mem_access_word['O_final'])
mac_count = ET.SubElement(basic_info, 'mac_count')
active_mac_count = ET.SubElement(mac_count, 'active')
active_mac_count.tail = str(round(mac_cost_active/common_settings.single_mac_energy))
idle_mac_count = ET.SubElement(mac_count, 'idle')
idle_mac_count.tail = str(round(mac_cost_idle/common_settings.idle_mac_energy))
energy = ET.SubElement(results, 'energy')
minimum_cost = ET.SubElement(energy, 'total_energy')
minimum_cost.tail = str(total_cost)
energy_breakdown = ET.SubElement(energy, 'mem_energy_breakdown')
cost_model_output.operand_cost = energy_clean(cost_model_output.operand_cost)
energy_breakdown_W = ET.SubElement(energy_breakdown, 'W')
energy_breakdown_W.tail = str(operand_cost['W'])
energy_breakdown_I = ET.SubElement(energy_breakdown, 'I')
energy_breakdown_I.tail = str(operand_cost['I'])
energy_breakdown_O = ET.SubElement(energy_breakdown, 'O')
energy_breakdown_O.tail = str(operand_cost['O'])
mac_cost = ET.SubElement(energy, 'MAC_energy')
active_MAC = ET.SubElement(mac_cost, 'active_MAC')
active_MAC.tail = str(mac_cost_active)
idle_MAC = ET.SubElement(mac_cost, 'idle_MAC')
idle_MAC.tail = str(mac_cost_idle)
total_MAC_cost = ET.SubElement(mac_cost, 'total')
total_MAC_cost.tail = str(mac_cost_active + mac_cost_idle)
performance = ET.SubElement(results, 'performance')
utilization = ET.SubElement(performance, 'mac_array_utilization')
mac_utilize = ET.SubElement(utilization, 'utilization_with_data_loading')
mac_utilize.tail = str(round(cost_model_output.utilization.mac_utilize, 4))
mac_utilize_no_load = ET.SubElement(utilization, 'utilization_without_data_loading')
mac_utilize_no_load.tail = str(round(cost_model_output.utilization.mac_utilize_no_load, 4))
mac_utilize_spatial = ET.SubElement(utilization, 'utilization_spatial')
mac_utilize_spatial.tail = str(round(cost_model_output.utilization.mac_utilize_spatial, 4))
mac_utilize_temporal = ET.SubElement(utilization, 'utilization_temporal_with_data_loading')
mac_utilize_temporal.tail = str(round(cost_model_output.utilization.mac_utilize_temporal, 4))
mac_utilize_temporal_no_load = ET.SubElement(utilization, 'mac_utilize_temporal_without_data_loading')
mac_utilize_temporal_no_load.tail = str(round(cost_model_output.utilization.mac_utilize_temporal_no_load, 4))
latency = ET.SubElement(performance, 'latency')
latency_tot = ET.SubElement(latency, 'latency_cycle_with_data_loading')
latency_tot.tail = str(latency_tot_number)
latency_no_load = ET.SubElement(latency, 'latency_cycle_without_data_loading')
latency_no_load.tail = str(latency_no_load_number)
total_cycles = ET.SubElement(latency, 'ideal_computing_cycle')
total_cycles.tail = str(total_cycles_number)
data_loading = ET.SubElement(latency, 'data_loading')
cc_load_tot = ET.SubElement(data_loading, 'load_cycle_total')
cc_load_tot.tail = str(cc_load_tot_number)
cc_load = ET.SubElement(data_loading, 'load_cycle_individual')
cc_load.tail = str(cc_load_number)
cc_load_comb = ET.SubElement(data_loading, 'load_cycle_combined')
cc_load_comb.tail = str(cc_load_comb_number)
mem_stalling = ET.SubElement(latency, 'mem_stalling')
cc_mem_stall_tot = ET.SubElement(mem_stalling, 'mem_stall_cycle_total')
cc_mem_stall_tot.tail = str(cc_mem_stall_tot_number)
stall_cc = ET.SubElement(mem_stalling, 'mem_stall_cycle_individual')
stall_cc.tail = str(stall_cc_number)
stall_cc_mem_share = ET.SubElement(mem_stalling, 'mem_stall_cycle_shared')
stall_cc_mem_share.tail = str(stall_cc_mem_share_number)
##++ for latency deep analysis
latency_deep_analysis = ET.SubElement(mem_stalling, 'latency_deep_analysis')
data_size_each_level = ET.SubElement(latency_deep_analysis, 'data_size_each_level_unrolled')
data_size_each_level.tail = str(req_mem_size_bit)
data_size_each_level_total = get_data_size_each_level_total(cost_model_output.spatial_loop.unit_unique,
req_mem_size_bit)
data_size_each_level = ET.SubElement(latency_deep_analysis, 'data_size_each_level_total')
data_size_each_level.tail = str(data_size_each_level_total)
loop_cycles_each_level = ET.SubElement(latency_deep_analysis, 'loop_cycles_each_level')
loop_cycles_each_level.tail = str(cost_model_output.temporal_loop.loop_cycles)
top_ir_loop_size = ET.SubElement(latency_deep_analysis, 'top_ir_loop_size')
top_ir_loop_size.tail = str(cost_model_output.loop.top_ir)
req_aver_mem_bw_bit = ET.SubElement(latency_deep_analysis, 'req_aver_mem_bw')
req_aver_mem_bw_bit.tail = str(digit_truncate(cost_model_output.utilization.req_aver_bw_bit,1))
req_inst_mem_bw_bit = ET.SubElement(latency_deep_analysis, 'req_inst_mem_bw')
req_inst_mem_bw_bit.tail = str(digit_truncate(cost_model_output.utilization.req_inst_bw_bit,1))
req_mem_bw_bit = ET.SubElement(latency_deep_analysis, 'req_mem_bw_bit_per_cycle_individual')
req_mem_bw_bit.tail = str(digit_truncate(cost_model_output.utilization.req_mem_bw_bit, 1))
req_sh_mem_bw_bit = ET.SubElement(latency_deep_analysis, 'req_mem_bw_bit_per_cycle_shared')
req_sh_mem_bw_bit.tail = str(digit_truncate(cost_model_output.utilization.req_sh_mem_bw_bit, 1))
output_distinguish = ET.SubElement(latency_deep_analysis, 'output_distinguish')
output_distinguish.tail = str(cost_model_output.loop.output_distinguish)
mem_bw_req_meet_list = mem_bw_req_meet_check(cost_model_output.utilization.req_sh_mem_bw_bit,
mem_scheme.mem_bw)
mem_bw_req_meet = ET.SubElement(latency_deep_analysis, 'mem_bw_requirement_meet')
mem_bw_req_meet.tail = str(mem_bw_req_meet_list)