Repository navigation
Expand file tree
/
Copy pathtool.cpp
More file actions
1453 lines (1123 loc) · 45.5 KB
/
Copy pathtool.cpp
File metadata and controls
1453 lines (1123 loc) · 45.5 KB
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
#include "config.h"
#include "DFG.h"
#include "tool.h"
#define LIMIT 64
using namespace std;
DECLARE_string(dfg_file);
bool comp(DFGedge* &a,DFGedge* &b)
{
return a->latency < b->latency;
}
vector<DFGedge*> getEdgesFromBegin(vector<DFGedge*> edgesList, int beginNo)
{
vector<DFGedge*> edges;/* 新建一个 */
for (auto e : edgesList)
{
if (e->prenode == beginNo)
{
edges.push_back(new DFGedge(e));
}
}
return edges;
}
int calculateBankIndex(int bank)
{
int index = bank % 120 / 30 * 2 + bank % 2;
return index;
}
void strtok(string& str, vector<string>& cont, string defstr = " ")
{
cont.clear();
size_t size = 0;
size_t begpos = 0;
size_t endpos = 0;
begpos = str.find_first_not_of(defstr);
while (begpos != std::string::npos)
{
size++;
endpos = str.find_first_of(defstr, begpos);
if (endpos == std::string::npos)
{
endpos = str.size();
}
string ssubstr = str.substr(begpos, endpos - begpos);
cont.push_back(ssubstr);
begpos = str.find_first_not_of(defstr, endpos+1);
}
}
int ReadDataFromFileLBLIntoString(vector<vector<int>> &DFG_node)
{
ifstream fin(FLAGS_dfg_file);
cout << "********************************" << endl;
cout << "the name of File:" << FLAGS_dfg_file << endl;
cout << "********************************" << endl;
string s;
int nodes = 0;
vector<int> linedata;
int line = 0;
while(getline(fin,s))
{
vector<string> vec;
strtok(s,vec,",");
linedata.clear();
for(int i = 0; i < vec.size(); i++)
{
//atoi:ascii to integer
int e = atoi(vec[i].c_str());
linedata.push_back(e);
}
DFG_node.push_back(linedata);
line++;
}
fin.close();
return line;
}
void show(DFG *D, Register *R, int II,int CGRARow, int CGRAColumn)
{
int column = CGRAColumn + 6;
// cout<<"CGRARow="<<CGRARow<<" "<<"column="<<column<<endl;
int count = 0;
{
count = 0;
for (int k = 0; k < II; k++)
{
for(int z = 0; z < column; z++)
{
cout << "---";
}
cout << "---------";
cout << "["<< k <<"]";
for(int z = 0; z < column; z++)
{
cout << "---" ;
}
cout << "---------";
cout<<endl;
for (int i = 0; i < CGRARow; i++)
{//行
for (int j = 0; j < column; j++)
{//列
for(int m = 0; m < D->DFGnodesList.size(); m++ )
{
int bindR = D->DFGnodesList[m]->bindResource;/* 绑定的寄存器 */
int postion = R->TERnodesList[bindR]->PE;/* 寄存器所在的PE */
int op_order = D->DFGnodesList[m]->nodelabel;
int time_step = D->DFGnodesList[op_order]->nodelevel;
// cout<<"postion="<<postion<<" "<<"op_order="<<op_order<<"time_step="<<time_step<<endl;
if (time_step == k && postion / column % CGRARow == i && postion % column == j)
{
count ++;
cout << "|"<< op_order << "\t";
}
}
if (count == 0){
cout << "| ";
}
count = 0;
}
cout << "| " << endl;
}
}
cout << endl;
}
}
bool isConcludeFU(GraphRegister *GR,int path[], int v)
{
bool flag = false;
stack<int> q;/* 建立一个栈 */
int p = v; /* p用来遍历path数组获得路径点 */
while(path[p]!=-1)
{
q.push(path[p]);
p = path[p];
}
while(!q.empty())
{
int temp = q.top();
if(GR->GraphnodesList[temp]->RegisterKind == 4)/* 走过的路包含了FU */
{
flag = true;
break;
}
q.pop();
}
return flag;
}
bool isUsedV(GraphRegister *GR,int path[], int v, int trueTRNum)
{
bool flag = false;
stack<int> q;/* 建立一个栈 */
int p = v; /* p用来遍历path数组获得路径点 */
while(path[p]!=-1)
{
q.push(path[p]);
p = path[p];
}
while(!q.empty())
{
int temp = q.top();
// cout<<temp<<" ";
if((temp % trueTRNum == v % trueTRNum) && GR->GraphnodesList[temp]->RegisterKind != 3)/* 相同不包含bank */
{
// cout<<"v="<<v<<" "<<endl;
flag = true;
break;
}
q.pop();
}
// cout <<endl;
return flag;
}
bool isLegalfu(GraphRegister *GR,int v,int length)
{
bool flag = true;
/* 获得v的时间 */
int kind = GR->GraphnodesList[v]->RegisterKind;
if(kind == 4)
{
int time = v / 120;
if(time != length)
{
flag = false;
}
}
return flag;
}
bool isIncludeCandidate(int n,vector<int> &virtualCandidate)
{
bool flag = false;
for(int i = 0;i < virtualCandidate.size(); i++)
{
if(virtualCandidate[i] == n)
{
flag = true;
// cout<<"flag"<<flag<<endl;
break;
}
}
return flag;
}
void getPath(int path[], int minReg, vector<int> &pathNode)
{
stack<int> q;/* 建立一个栈 */
int p = minReg; /* p用来遍历path数组获得路径点 */
while(path[p]!=-1)
{
q.push(path[p]);
p = path[p];
}
// cout<<"virual:"<<endl;
while(!q.empty())
{
int temp = q.top();
// cout<<temp<<" " ;
pathNode.push_back(temp);
q.pop();
}
// cout<<endl;
}
bool hasSuBankLoad(vector<int> pathNode, Register *R)
{
for(int i = 0; i < pathNode.size() - 2; i++)
{
int RegisterKind = R->TERnodesList[pathNode[i]]->RegisterKind;
if(RegisterKind == 1)/* 碰到了ld */
{
if(R->TERnodesList[pathNode[i+1]]->RegisterKind == 2)/* 下一个是su */
{
if(R->TERnodesList[pathNode[i+2]]->RegisterKind == 3)/* 再下一个是bank */
{
return true;
}
}
}
else
{
continue;/*继续遍历 */
}
}
/* 遍历完了都没有结果 */
return false;
}
int getPreLastLU(vector<int> pathNode, Register *R)
{
for(int i = pathNode.size() - 1; i >= 0 ; i--)
{
int node = pathNode[i];
int RegisterKind = R->TERnodesList[node]->RegisterKind;
if(RegisterKind == 1)
{
return node;
}
}
return -1;
}
int getLastBankIndex(vector<int> pathNode, Register *R)
{
for(int i = pathNode.size() - 1; i >= 0 ; i--)
{
int node = pathNode[i];
int RegisterKind = R->TERnodesList[node]->RegisterKind;
if(RegisterKind == 3)
{
int index = calculateBankIndex(node);
return index;
}
}
return -1;
}
void deletePartPath(vector<int> &pathNode, int srcR)
{
/* 先找到迭代器 */
for(std::vector<int>::iterator it = pathNode.begin();it != pathNode.end();it++)
{
if( *it == srcR)
{
pathNode.erase(it, pathNode.end());
break;
}
}
}
/* 将共享的路径设为已经访问,除bank外*/
void setVisited(Register *R,vector<int> SingleTruePath)
{
for(int i = 0; i < SingleTruePath.size(); i++)
{
int RegisterKind = R->TERnodesList[SingleTruePath[i]]->RegisterKind;
if(RegisterKind == 1 || RegisterKind == 2)/* 只有Lu和SU要彻底设置已经访问 */
{
R->TERnodesList[SingleTruePath[i]]->inPort = true;
R->TERnodesList[SingleTruePath[i]]->isOccupied = true;
}
}
}
bool compLegal(Register *R,vector<int> sameSrcEdge, vector<int> tempTruePath)
{
int totolpea = 40;
int longlength;
int shortlength;
int length1 = sameSrcEdge.size();
int length2 = tempTruePath.size();
if(length1 > length2)
{
longlength = length1;
shortlength = length2;
}
else
{
longlength = length2;
shortlength = length1;
}
// cout<<" i am here"<<endl;
// // cout<<endl;
// cout<<"trueNode";
// for(int i = 0; i < tempTruePath.size(); i++ )
// {
// cout<<tempTruePath[i]<<" ";
// }
// cout<<endl;
// cout<<endl;
// cout<<"sameSrcEdge";
// for(int i = 0; i < sameSrcEdge.size(); i++ )
// {
// cout<<sameSrcEdge[i]<<" ";
// }
// cout<<endl;
/* 看该条已经布线的路径是否含Bank */
int label = -1;
for(int i = 0; i < shortlength ; i++ )
{
if(sameSrcEdge[i] != tempTruePath[i])/* 部分全相同 */
{
label = i;
break;
}
}
// cout<<"label"<<label<<endl;
// cout<<"length1-2="<<length1-2<<endl;
// cout<<"length2="<<length2<<endl;
if(label != -1)
{
for(int i = label; i < length1-2 ; i++ )
{
for(int j = label; j < length2 ; j++ )
{
if(sameSrcEdge[i] == tempTruePath[j])
{
if(i-1 >=0 && j-1 >=0)
{
/* 平面的PE不同 */
int samealreadyPEi_1 = R->TERnodesList[sameSrcEdge[i-1]]->PE % totolpea;
int samealreadyPEi = R->TERnodesList[sameSrcEdge[i]]->PE % totolpea;
int currentPEj_1 = R->TERnodesList[tempTruePath[j-1]]->PE%totolpea;
int currentPEj = R->TERnodesList[tempTruePath[j]]->PE%totolpea;
if((samealreadyPEi_1!= samealreadyPEi) && (currentPEj_1 != currentPEj ) )
{
// cout<<"sameSrcEdge[i]="<<tempTruePath[j]<<" "<<"tempTruePath[j]="<<tempTruePath[j]<<endl;
// cout<<"R->TERnodesList[sameSrcEdge[i-1]]->PE="<<R->TERnodesList[sameSrcEdge[i-1]]->PE<<" "<<" R->TERnodesList[tempTruePath[j-1]]->PE2="<< R->TERnodesList[sameSrcEdge[i]]->PE<<endl;
return false;
}
if((samealreadyPEi_1== samealreadyPEi) && (currentPEj_1 == currentPEj ) )
{
// cout<<"sameSrcEdge[i]="<<tempTruePath[j]<<" "<<"tempTruePath[j]="<<tempTruePath[j]<<endl;
// cout<<"R->TERnodesList[sameSrcEdge[i-1]]->PE="<<R->TERnodesList[sameSrcEdge[i-1]]->PE<<" "<<" R->TERnodesList[tempTruePath[j-1]]->PE2="<< R->TERnodesList[sameSrcEdge[i]]->PE<<endl;
return false;
}
else
{
/* 检查相似点前后是否有相同点 */
if(sameSrcEdge[i+1] ==tempTruePath[j-1])
return false;
}
}
}
}
}
}
return true;
}
// bool shareisLegal(Register *R, int i,int *path,int srcTrueTime,vector<vector<int>> sameSrcEdge,vector<int> tempTruePath,int v )
// {
// }
bool isLegalShare(Register *R, int i,int *path,int srcTrueTime,vector<vector<int>> sameSrcEdge,vector<int> tempTruePath,int *inportNum,int *outportNum)
{
stack<int> q;/* 建立一个栈 */
int p = i; /* p用来遍历path数组获得路径点 */
// cout<<"p"<<p<<endl;
while(path[p]!=-1)
{
q.push(path[p]);
p = path[p];
}
// cout<<"temp"<<endl;
while(!q.empty())
{
int temp = q.top();
int tempTime = temp / R->RnodesNums;
/* temp是虚拟的点,要将其转换为真实的点 */
int trueNode = ( temp - (tempTime* R->RnodesNums) )+ ( (srcTrueTime + tempTime) * R->RnodesNums ) % (R->II * R->RnodesNums);
// cout<<temp<<" ";
// cout<<trueNode<<" ";
tempTruePath.push_back(trueNode);/*tempTruePath包含了所有路径了 */
q.pop();
}
int iTime = i / R->RnodesNums;
int truei = ( i - (iTime* R->RnodesNums) )+ ( (srcTrueTime + iTime) * R->RnodesNums ) % (R->II * R->RnodesNums);
tempTruePath.push_back(truei);
// cout<<"tempTruePath,.size()="<<tempTruePath.size()<<" "<<"truei="<<truei<<endl;
// cout<<endl;
// for(int i = 0; i < tempTruePath.size(); i++)
// {
// cout<<tempTruePath[i]<<" ";
// }
// cout<<endl;
/* tempTruePath放的就是当前真实的路径,少最后一个结果寄存器 */
/* 遍历前面已经布线的路径 */
bool isLegal = true;
// cout<<"sameSrcEdge.size()="<<sameSrcEdge.size()<<endl;
for(int i = 0; i < sameSrcEdge.size(); i++ )
{
isLegal = compLegal(R,sameSrcEdge[i],tempTruePath);/* 会被覆盖 */
if(isLegal == false)
{
break;
}
// cout<<"isLegal"<<isLegal<<endl;
}
// cout<<"-----------------"<<endl;
/* 获得最后一个点的PE */
int vR = tempTruePath[tempTruePath.size()-1];
int vRpre = tempTruePath[tempTruePath.size()-2];
int vPE = R->TERnodesList[vR]->PE;
int vPEpre = R->TERnodesList[vRpre]->PE;
if(inportNum[vPE] <= 0 || outportNum[vPE] <= 0)
{
isLegal = false;
}
return isLegal;
}
/* bank的长度是否没有超过剩余的容量,是否是偶数,是否只包含一个Bank */
bool bankLengthIsEvEnOne(Register *R, int i,int *path,int srcTrueTime)
{
// for(int i = 0; i < 4; i++)
// {
// cout<<R->bankCapacity[i]<<endl;
// }
int count = 0;
stack<int> q;/* 建立一个栈 */
int p = i; /* p用来遍历path数组获得路径点 */
while(path[p]!=-1)
{
q.push(path[p]);
p = path[p];
}
vector<int> tempPath;
while(!q.empty())
{
int temp = q.top();
tempPath.push_back(temp);
q.pop();
}
int sameBank = -1;
// cout<<"temp:";
for(int i = 0; i< tempPath.size();i++)
{
int temp = tempPath[i];
int tempTime = temp / R->RnodesNums;
/* temp是虚拟的点,要将其转换为真实的点 */
int trueNode = ( temp - (tempTime* R->RnodesNums) )+ ( (srcTrueTime + tempTime) * R->RnodesNums ) % (R->II * R->RnodesNums);
// cout<<temp<<" ";
int RegisterKind = R->TERnodesList[trueNode]->RegisterKind;
if(RegisterKind == 3)/* 第一次出现的 */
{
sameBank = calculateBankIndex(trueNode);
break;
}
}
// cout<<endl;
//cout<< "sameBank"<<sameBank<<endl;
for(int i = 0; i<tempPath.size();i++)
{
int temp = tempPath[i];
int tempTime = temp / R->RnodesNums;
/* temp是虚拟的点,要将其转换为真实的点 */
int trueNode = ( temp - (tempTime* R->RnodesNums) )+ ( (srcTrueTime + tempTime) * R->RnodesNums ) % (R->II * R->RnodesNums);
int RegisterKind = R->TERnodesList[trueNode]->RegisterKind;
if(RegisterKind == 3)
{
// cout<<"trueNode"<<trueNode<<endl;
int anotherBank = calculateBankIndex(trueNode);
// cout<<"sameBank="<<anotherBank<<" "<<anotherBank<<endl;
if(sameBank == anotherBank)
count ++;
else
return false;
}
}
if(sameBank != -1)
{
/* 如果bank的数量不是偶数或者数量大于剩余的容量 */
//cout<<"sameBank"<<sameBank<<"count="<<count<<" "<<R->bankCapacity[sameBank] <<endl;
// if(count % 2 != 0 || count > R->bankCapacity[sameBank] )
if(count % 2 != 0 )/* 如果没有bank,也可以通过 */
{
return false;
}
else
{
return true;
}
}
else/* 没有Bamk */
{
return true;
}
}
bool dijkstra(Dijk *dijk,Register *R,GraphRegister *GR,vector<int> &virtualCandidate,vector<int> &pathNode,vector<vector<int>> sameSrcEdge,vector<int> SingleTruePath,int *inportNum,int *outportNum)
// void dijkstra(Register *R,GraphRegister *GR,int latency,int virtualSrc,vector<int> &virtualCandidate,vector<int> &pathNode,int trueTRNum,int srcTrueTime,vector<vector<int>> sameSrcEdge,vector<int> SingleTruePath)
{
// cout<<"-----------------"<<endl;
/*定义 */
bool *known;
int *dist;
int *path;
int nodeNum = GR->GraphnodesNums;
// cout<<"nodeNum"<<nodeNum<<endl;
// cout<<"dijk->virtualSrc"<<dijk->virtualSrc<<endl;
// cout<<"nodeNum"<<nodeNum<<endl;
known = new bool[nodeNum];/* 是否已经访问,确定了最短路径的标志 */
memset(known, 0, nodeNum * sizeof(bool));
dist = new int[nodeNum];
memset(dist, 0, nodeNum * sizeof(int));/* 源点到当前点的距离 */
path = new int[nodeNum];
memset(path, 0, nodeNum * sizeof(int));/* 前驱节点 */
int **Graph = new int*[nodeNum]; //开辟行
for (int i = 0; i < nodeNum; i++)
Graph[i] = new int[nodeNum]; //开辟列
for (int i = 0; i < nodeNum; i++)/* 初始化为无穷大 */
for(int j = 0;j < nodeNum; j++)
Graph[i][j] = INF;
for (int i = 0; i < GR->GraphedgesList.size(); i++)
{
// if(GR->GraphedgesList[i]->pre == 1 && GR->GraphedgesList[i]->pos == 113 )
// {
// cout<<"GR->GraphedgesList[i]->value"<<GR->GraphedgesList[i]->value<<endl;
// }
Graph[GR->GraphedgesList[i]->pre][GR->GraphedgesList[i]->pos] = GR->GraphedgesList[i]->value;
}
/* to do :实验一下为甚 1-2 31-145(latency =1 )走不通*/
if(dijk->latency == 1)
{
// cout<<"Graph[4][17]="<<Graph[43][132]<<endl;
// cout<<"Graph[494][615]="<<Graph[4][14]<<endl;
// cout<<"Graph[494][615]="<<Graph[4][15]<<endl;
// cout<<"Graph[494][615]="<<Graph[4][16]<<endl;
}
/* 初始化 */
// cout<<"dijk->latency="<<dijk->latency<<endl;
// cout<<"dijk->virtualSrc="<<dijk->virtualSrc<<endl;
// cout<<"dijk->trueTRNum="<<dijk->trueTRNum<<endl;
for(int i = 0; i < nodeNum; ++i)
{
known[i] = false;/* 最开始所有点都没有被访问 */
/* 获得源点到所有点的代价 */
//dist[i] = GR->getEdgeCost(virtualSrc,i);
dist[i] = Graph[dijk->virtualSrc][i];
//path[i] = GR->graphHasEdge(virtualSrc,i) == true ? virtualSrc:-1;
path[i] = Graph[dijk->virtualSrc][i] < INF ? dijk->virtualSrc:-1;
}
known[dijk->virtualSrc] = true;
dist[dijk->virtualSrc] = 0;
path[dijk->virtualSrc] = -1;
// cout<<"dijk->virtualSrc="<<dijk->virtualSrc<<" "<<"dijk->virtualSrc="<<dijk->virtualSrc<<endl;
for(int j = 0; j < nodeNum-1 ;j++)
{
//找到unknown的dist最小的顶点
int v = 0;
int min = INF;
for(int i = 0; i < nodeNum; ++i){
if(!known[i] && (min > dist[i]))/* i没有知道最小的dist */
{
min = dist[i];
v = i;
}
}
known[v] = true;
//更新与v相邻所有顶点w的dist,path
for(int i = 0; i < nodeNum;i++){
if(!known[i] ){
if(dist[i] > dist[v] + Graph[v][i] && isUsedV(GR, path, v, dijk->trueTRNum) == false && isLegalShare(R,v,path,dijk->srcTrueTime,sameSrcEdge,SingleTruePath,inportNum,outportNum) == true)
// if(dist[i] > dist[v] + Graph[v][i] && isLegalShare(R,v,path,dijk->srcTrueTime,sameSrcEdge,SingleTruePath) == true)
{
/* 如果当前的vbu不是倒数第二层,不能是FU */
// if(isLegalfu(GR,v,dijk->latency))
// {
dist[i] = dist[v] + Graph[v][i];
path[i] = v;
// }
}
}
}
}
int minRegcost = INF;
int minReg = dijk->virtualSrc;
for(int i = 0; i < nodeNum; ++i)
{
if(known[i])/* 访问过的 */
{
if (dist[i] < minRegcost)
{
if(isIncludeCandidate(i,virtualCandidate) == true )
{
/* mini,找出mini*/
minRegcost = dist[i];
minReg = i;
}
}
}
}
// cout<<"minReg"<<minReg<<endl;
/* 将mini的路径读出,记在pathNode中 */
getPath(path, minReg,pathNode);
if(pathNode.size() == 0)
{
return false;
}
else
{
pathNode.push_back(minReg);
delete [] known;
delete [] dist;
delete [] path;
for (int m = 0; m < nodeNum; m++)
delete[] Graph[m];
delete[] Graph;
return true;
}
}
void setBankVisited(Register *R, int bankIndex)
{
/* 遍历所有的结点算子 */
for (int i = 0; i < R->TERnodesList.size();i++)
{
if (R->TERnodesList[i]->RegisterKind == 3 )/* bank */
{
int index = calculateBankIndex(i);
if(index == bankIndex)
{
R->TERnodesList[i]->isOccupied = true;/* 将该索引下所有的bank都设为不可访问 */
}
}
}
}
bool isEnoughofBank(Register *R)
{
/* 遍历所有的结点算子 */
for (int i = 0; i < 8;i++)
{
if (R->bankCapacity[i] != 0 )/* bank */
{
return true;
}
}
return false;
}
void fixProcess(Register *R,int &srcR,int &restLatency,vector<int> &SingleTruePath,int II,int prelastbankindex,vector<int> &singleTruePathLU)
{
SingleTruePath.push_back(srcR);/* 先放进去 */
int su = R->getLUorResultSU(srcR);/* 再找SU */
SingleTruePath.push_back(su);/* 放进去 */
int lu ;
int BankNumtotoal = 0;
int bank = R->getSUBank(su,prelastbankindex);/* 2 bank了*/
/* 看看它的容量 */
int bankIndex = calculateBankIndex(bank);
int Capacity = R->bankCapacity[bankIndex];
// cout<<"bankIndex="<<bankIndex<<" Capacity="<<Capacity<<endl;
/* 需要切多少? */
int BankNum = floor((restLatency- 4)/II);
/* 容量不够 */
if(BankNum > Capacity)
{
BankNum = Capacity;/* 先把Capacity占满 */
/* 把所有属于这bankIndex的 层数 的bank都设置为 已经访问 */
setBankVisited(R,bankIndex);
}
else/* 容量够 */
{
R->bankCapacity[bankIndex] = Capacity - BankNum;/* 否则还是把它剩余的容量标记下 */
R->TERnodesList[bank]->isOccupied = true;/* 当前层的bank不可用,其他层的不知道 */
}
if(BankNum % 2 != 0)
{
BankNum = BankNum - 1;
}
BankNumtotoal = (BankNum - 1)*II + 1; /* 在bank中消耗的时间 */
SingleTruePath.push_back(bank);/* 进bank前先放置单个寄存器 */
/* 放置 BankNum*II个相同的BANK */
for(int M = 0; M < BankNumtotoal; M++)
{
SingleTruePath.push_back(bank);/* 先放进去 */
}
SingleTruePath.push_back(bank);/* 出bank前放置单个寄存器 */
restLatency = restLatency - BankNumtotoal - 4;
lu = R->getBankLU(bank,singleTruePathLU);/* 这个就是在CGRAPE内部布线的Load */
srcR = lu;
singleTruePathLU.push_back(lu);
}
void setSrcRandRestLantency(Register *R, vector<int> &SingleTruePath,int &srcR,int latency,int &restLatency,int II,vector<int> &singleTruePathLU)
{
int lastBankindex;
if(SingleTruePath.size() != 0 && hasSuBankLoad(SingleTruePath,R) == true)/* 如果上条路径不为空 并且它含store->bank-load固定模式 */
{
srcR = getPreLastLU(SingleTruePath,R);/* 获得该条路径上的最后一个LU,从它开始寻路 */
// cout<<"SingleTruePath.size()="<<SingleTruePath.size()<<endl;
deletePartPath(SingleTruePath,srcR);/* 那么就将它的最后load作为起始点。后面的删除(包括这个新srcR) */
/* delete的功能:记录下srcR的索引,在索引之前实际消耗了多少层,用虚拟的路径判断 */
/* 其实这个如果没有普通算子长依赖,没有别要设置。如果要共享普通的路径,重新找就是了,不将其设置为已经访问,因为它没走固定模式 */
// cout<<"after SingleTruePath.size()="<<SingleTruePath.size()<<endl;
/* 并将删除后剩下的前面的设为为已经访问 防止在一条路线中,后面重复前面的路线 */
/* 如果上一条就有固定模式了,那就后面会一直沿用这个固定模式,所以就不能重复了 */
setVisited(R,SingleTruePath);/* 可能会让固定模式重复设置为已经访问,但没关系 */
/* 记下最近的bank */
lastBankindex = getLastBankIndex(SingleTruePath,R);
// cout<<"new srcR="<<srcR<<endl;
}
else
{
SingleTruePath.clear();/* 不能共享的全部清除置0 */
}
restLatency = latency - SingleTruePath.size();/* 除掉共享的,剩余的长度 */
// cout<<"SingleTruePath.size()="<<SingleTruePath.size()<<endl;
// cout<<"latency="<<latency<<endl;
// cout<<"restLatency="<<restLatency<<endl;
if(restLatency > LIMIT)/* 共享之后,或者第一条边没有被共享,仍然还蛮大的话,就要准备切了 */
{
/* 切第一次 */
/* 走ld-su-单个寄存器-bank-单个寄存器-ld 这条路 */
SingleTruePath.push_back(srcR);/* 先把这个新的srcR放进去 */
singleTruePathLU.push_back(srcR);/* 把这个新的LU放入 */
int su = R->getLUorResultSU(srcR);/* 获得与LU或者与结果寄存器或者其他寄存器(可能长依赖的源点是计算算子)相连的SU */
SingleTruePath.push_back(su);
/* 按顺序获得BANK,LU可以与所有bank互连 */
int bank = R->getSUBank(su,lastBankindex);/* 获得与SU相连的Bank */
/* 将这个bank的TECRegister的访问设置为true */
/* 获得与该bank相连的下一bank */
// R->getNextBank(bank);
// cout<<"su="<<su<<" "<<"bank="<<bank<<endl;
/* 占用的BANK的容量 数量 */
/* 当前边的总latency - 已经共享的
因为还要再切或者第一次切,必定到经过 ld-su-单个寄存器 -bank(要求的) -单个寄存器 -ld - dijksta短路径*/
int BankNum = floor((latency - SingleTruePath.size() - 4) / II); /* 即将占用的bank容量 */
if(BankNum % 2 != 0)/* BankNum要是偶数 */
{
BankNum = BankNum -1;
}
/* BankNum为暂定要占用的容量
1.如果当前的bank的容量大于 BankNum,就继续
2.如果小于,就先占着,占了之后,看是否需要切下一个Bank */
int bankIndex = calculateBankIndex(bank);
int Capacity = R->bankCapacity[bankIndex];/* 该bank存在的容量 */
// cout<<"bankIndex="<<bankIndex<<" "<<"Capacity="<<Capacity<<"BankNum="<<BankNum<<endl;
int lu ;/* 确定新的lu,是第一次切的,还是后面切的 */
int BankNumtotoal = 0;
if(BankNum > Capacity )/* 第一次准备切,发现Bank容量不够,那就要找下一个bank借一下 */
{
/* 先把Capacity的容量占着 */
if(Capacity % 2 != 0)
{
BankNum = Capacity - 1;
}
else
{
BankNum = Capacity;
}
BankNumtotoal = (BankNum - 1)*II + 1;/* 占Capacity个Bank中的寄存器,在Bank中消耗Capacity *II个时钟周期 */
/* 收集当前路径中所有的LU */
/* 进bank前要锁存一下 */
SingleTruePath.push_back(bank);/* 这个单寄存器就将它设为bank号吧 */