@@ -211,30 +211,6 @@ void refNumBasedSort(unsigned int *refNum, unsigned int *index)
211211 return ;
212212}
213213
214- bool BankConflictPass::hasInternalConflict2Srcs (BankConflict *srcBC)
215- {
216- if (((srcBC[1 ] == BANK_CONFLICT_SECOND_HALF_EVEN ||
217- srcBC[1 ] == BANK_CONFLICT_FIRST_HALF_EVEN) &&
218- (srcBC[2 ] == BANK_CONFLICT_SECOND_HALF_EVEN ||
219- srcBC[2 ] == BANK_CONFLICT_FIRST_HALF_EVEN)) ||
220- ((srcBC[1 ] == BANK_CONFLICT_SECOND_HALF_ODD ||
221- srcBC[1 ] == BANK_CONFLICT_FIRST_HALF_ODD) &&
222- (srcBC[2 ] == BANK_CONFLICT_SECOND_HALF_ODD ||
223- srcBC[2 ] == BANK_CONFLICT_FIRST_HALF_ODD)))
224- {
225- return true ;
226- }
227- if ((srcBC[1 ] < BANK_CONFLICT_SECOND_HALF_EVEN &&
228- srcBC[2 ] < BANK_CONFLICT_SECOND_HALF_EVEN) ||
229- (srcBC[1 ] >= BANK_CONFLICT_SECOND_HALF_EVEN &&
230- srcBC[2 ] >= BANK_CONFLICT_SECOND_HALF_EVEN))
231- {
232- return true ;
233- }
234-
235- return false ;
236- }
237-
238214bool BankConflictPass::hasInternalConflict3Srcs (BankConflict *srcBC)
239215{
240216 if (((srcBC[0 ] == BANK_CONFLICT_SECOND_HALF_EVEN ||
@@ -265,106 +241,6 @@ bool BankConflictPass::hasInternalConflict3Srcs(BankConflict *srcBC)
265241 return false ;
266242}
267243
268-
269- void BankConflictPass::setupBankConflictsForDecls (G4_Declare * dcl_1, G4_Declare * dcl_2,
270- unsigned int offset1, unsigned int offset2,
271- BankConflict &srcBC1, BankConflict &srcBC2,
272- int &bank1RegNum, int &bank2RegNum,
273- float GRFRatio, bool oneGRFBank)
274- {
275- ASSERT_USER (srcBC1 == BANK_CONFLICT_NONE, " Wrong Bank initial value" );
276- ASSERT_USER (srcBC2 == BANK_CONFLICT_NONE, " Wrong Bank initial value" );
277-
278- unsigned int regNum1 = dcl_1->getNumRows ();
279- unsigned int regNum2 = dcl_2->getNumRows ();
280- unsigned int refNum1 = gra.getNumRefs (dcl_1);
281- unsigned int refNum2 = gra.getNumRefs (dcl_2);
282-
283- BankConflict bank1 = BANK_CONFLICT_NONE;
284- BankConflict bank2 = BANK_CONFLICT_NONE;
285- bool bank1First = false ;
286-
287- if (GRFRatio == 1.0 )
288- {
289- // For global RA: Try to reduce the size of bank 2
290- if ((float )refNum1 / regNum1 >= (float )refNum2 / regNum2)
291- {
292- bank1 = BANK_CONFLICT_SECOND_HALF_EVEN;
293- bank2 = BANK_CONFLICT_FIRST_HALF_ODD;
294- bank1First = true ;
295- }
296- else
297- {
298- bank2 = BANK_CONFLICT_SECOND_HALF_EVEN;
299- bank1 = BANK_CONFLICT_FIRST_HALF_ODD;
300- }
301- }
302- else
303- {
304- // For local RA: Try to balance two banks
305- if (refNum1 >= refNum2)
306- {
307- bank1 = ((bank1RegNum * GRFRatio) > bank2RegNum) ? BANK_CONFLICT_SECOND_HALF_EVEN : BANK_CONFLICT_FIRST_HALF_EVEN;
308- bank2 = (bank1 == BANK_CONFLICT_SECOND_HALF_EVEN) ? BANK_CONFLICT_FIRST_HALF_ODD : BANK_CONFLICT_SECOND_HALF_ODD;
309- bank1First = true ;
310- }
311- else
312- {
313- bank2 = (bank1RegNum * GRFRatio) > bank2RegNum ? BANK_CONFLICT_SECOND_HALF_EVEN : BANK_CONFLICT_FIRST_HALF_EVEN;
314- bank1 = (bank2 == BANK_CONFLICT_SECOND_HALF_EVEN) ? BANK_CONFLICT_FIRST_HALF_ODD : BANK_CONFLICT_SECOND_HALF_ODD;
315- }
316- }
317-
318- srcBC1 = bank1;
319- srcBC2 = bank2;
320-
321- // Adjust only for the single bank allocation
322- if (oneGRFBank)
323- {
324- if ((offset1 + offset2) % 2 )
325- {
326- if (bank1First)
327- {
328- bank2 = (bank2 == BANK_CONFLICT_FIRST_HALF_ODD) ? BANK_CONFLICT_FIRST_HALF_EVEN : BANK_CONFLICT_SECOND_HALF_EVEN;
329- }
330- else
331- {
332- bank1 = (bank1 == BANK_CONFLICT_SECOND_HALF_ODD) ? BANK_CONFLICT_SECOND_HALF_EVEN : BANK_CONFLICT_FIRST_HALF_EVEN;
333- }
334- }
335- }
336- else
337- {
338- if ((offset1 / 2 + offset2 / 2 ) % 2 )
339- {
340- if (bank1First)
341- {
342- bank2 = (bank2 == BANK_CONFLICT_FIRST_HALF_ODD) ? BANK_CONFLICT_FIRST_HALF_EVEN : BANK_CONFLICT_SECOND_HALF_EVEN;
343- }
344- else
345- {
346- bank1 = (bank1 == BANK_CONFLICT_SECOND_HALF_ODD) ? BANK_CONFLICT_SECOND_HALF_EVEN : BANK_CONFLICT_FIRST_HALF_EVEN;
347- }
348- }
349- }
350-
351- if (bank1 >= BANK_CONFLICT_SECOND_HALF_EVEN)
352- {
353- bank2RegNum += regNum1;
354- bank1RegNum += regNum2;
355- }
356- else
357- {
358- bank1RegNum += regNum1;
359- bank2RegNum += regNum2;
360- }
361-
362- gra.setBankConflict (dcl_1, bank1);
363- gra.setBankConflict (dcl_2, bank2);
364-
365- return ;
366- }
367-
368244void BankConflictPass::setupEvenOddBankConflictsForDecls (G4_Declare * dcl_1, G4_Declare * dcl_2,
369245 unsigned int offset1, unsigned int offset2,
370246 BankConflict &srcBC1, BankConflict &srcBC2)
@@ -951,7 +827,7 @@ void BankConflictPass::setupBankConflictsForBB(G4_BB* bb,
951827 GRFRatio = ((float )(numRegLRA - SECOND_HALF_BANK_START_GRF)) / SECOND_HALF_BANK_START_GRF;
952828 }
953829
954- for (std::list<G4_INST*>::reverse_iterator i = bb->rbegin (), rend = bb->rend ();
830+ for (auto i = bb->rbegin (), rend = bb->rend ();
955831 i != rend;
956832 i++)
957833 {
@@ -1018,15 +894,15 @@ bool compareBBLoopLevel(G4_BB* bb1, G4_BB* bb2)
1018894 * threeSourceCandidate, if there are enough three source instructions
1019895 * return value, if do bank confliction reduction to RR RA.
1020896 */
1021- bool BankConflictPass::setupBankConflictsForKernel (G4_Kernel& kernel, bool doLocalRR, bool &threeSourceCandidate, unsigned int numRegLRA, bool &highInternalConflict)
897+ bool BankConflictPass::setupBankConflictsForKernel (bool doLocalRR, bool &threeSourceCandidate, unsigned int numRegLRA, bool &highInternalConflict)
1022898{
1023899 BB_LIST orderedBBs;
1024900 unsigned int threeSourceInstNumInKernel = 0 ;
1025901 unsigned int internalConflict = 0 ;
1026902 unsigned int instNumInKernel = 0 ;
1027903 unsigned int sendInstNumInKernel = 0 ;
1028904
1029- for (auto curBB : kernel.fg .BBs )
905+ for (auto curBB : gra. kernel .fg .BBs )
1030906 {
1031907 orderedBBs.push_back (curBB);
1032908 }
@@ -1041,8 +917,7 @@ bool BankConflictPass::setupBankConflictsForKernel(G4_Kernel& kernel, bool doLoc
1041917
1042918 unsigned int loopNestLevel = 0 ;
1043919
1044- setupBankConflictsForBB (bb, threeSourceInstNum, sendInstNum,
1045- numRegLRA, conflicts);
920+ setupBankConflictsForBB (bb, threeSourceInstNum, sendInstNum, numRegLRA, conflicts);
1046921 loopNestLevel = bb->getNestLevel () + 1 ;
1047922
1048923 if (threeSourceInstNum)
@@ -1051,7 +926,6 @@ bool BankConflictPass::setupBankConflictsForKernel(G4_Kernel& kernel, bool doLoc
1051926 threeSourceInstNum = threeSourceInstNum * loopNestLevel * BANK_CONFLICT_HEURISTIC_LOOP_ITERATION;
1052927 sendInstNum = sendInstNum * loopNestLevel * BANK_CONFLICT_HEURISTIC_LOOP_ITERATION;
1053928 conflicts = conflicts * loopNestLevel * BANK_CONFLICT_HEURISTIC_LOOP_ITERATION;
1054-
1055929 internalConflict += conflicts;
1056930 threeSourceInstNumInKernel += threeSourceInstNum;
1057931 instNumInKernel += instNum;
@@ -1065,15 +939,6 @@ bool BankConflictPass::setupBankConflictsForKernel(G4_Kernel& kernel, bool doLoc
1065939 return false ;
1066940 }
1067941
1068- #ifdef DEBUG_VERBOSE_ON
1069- for (DECLARE_LIST_ITER dcl_it = kernel.Declares .begin ();
1070- dcl_it != kernel.Declares .end ();
1071- dcl_it++)
1072- {
1073- printf (" dcl: %s : bank: %d\n " , (*dcl_it)->getName (), gra.getBankConflict ((*dcl_it)));
1074- }
1075- #endif
1076-
1077942 highInternalConflict = ((float )internalConflict / threeSourceInstNumInKernel) > INTERNAL_CONFLICT_RATIO_HEURISTIC;
1078943
1079944 // Bank conflict reduction is done only when there is enough three source instructions.
@@ -9148,21 +9013,17 @@ int GlobalRA::coloringRegAlloc()
91489013 }
91499014 }
91509015
9151- BankConflictPass bc (*this );
9152- bool doBankConflictReduction = false ;
9153- bool highInternalConflict = false ;
9154-
91559016 if (builder.getOption (vISA_LocalRA) && !isReRAPass () && canDoLRA (kernel))
91569017 {
91579018 startTimer (TIMER_LOCAL_RA);
9158- bool doLocalRR = builder. getOption (vISA_LocalRARoundRobin );
9159- LocalRA lra (kernel, highInternalConflict, bc, *this );
9160- bool success = lra.localRA (doLocalRR, doBankConflictReduction );
9019+ BankConflictPass bc (* this );
9020+ LocalRA lra (bc, *this );
9021+ bool success = lra.localRA ();
91619022 stopTimer (TIMER_LOCAL_RA);
91629023 if (!success)
91639024 {
91649025 startTimer (TIMER_HYBRID_RA);
9165- success = hybridRA (doBankConflictReduction, highInternalConflict , lra);
9026+ success = hybridRA (lra. doHybridBCR (), lra. hasHighInternalBC () , lra);
91669027 stopTimer (TIMER_HYBRID_RA);
91679028 }
91689029 if (success)
@@ -9231,13 +9092,17 @@ int GlobalRA::coloringRegAlloc()
92319092 }
92329093 }
92339094
9095+ bool doBankConflictReduction = false ;
9096+ bool highInternalConflict = false ; // this is set by setupBankConflictsForKernel
9097+
92349098 if (builder.getOption (vISA_LocalBankConflictReduction) &&
92359099 builder.hasBankCollision ())
92369100 {
92379101 bool reduceBCInRR = false ;
92389102 bool reduceBCInTAandFF = false ;
9103+ BankConflictPass bc (*this );
92399104
9240- reduceBCInRR = bc.setupBankConflictsForKernel (kernel, true , reduceBCInTAandFF, SECOND_HALF_BANK_START_GRF * 2 , highInternalConflict);
9105+ reduceBCInRR = bc.setupBankConflictsForKernel (true , reduceBCInTAandFF, SECOND_HALF_BANK_START_GRF * 2 , highInternalConflict);
92419106 doBankConflictReduction = reduceBCInRR && reduceBCInTAandFF;
92429107 }
92439108
0 commit comments