@@ -211,30 +211,6 @@ void refNumBasedSort(unsigned int *refNum, unsigned int *index)
211
211
return ;
212
212
}
213
213
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
-
238
214
bool BankConflictPass::hasInternalConflict3Srcs (BankConflict *srcBC)
239
215
{
240
216
if (((srcBC[0 ] == BANK_CONFLICT_SECOND_HALF_EVEN ||
@@ -265,106 +241,6 @@ bool BankConflictPass::hasInternalConflict3Srcs(BankConflict *srcBC)
265
241
return false ;
266
242
}
267
243
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
-
368
244
void BankConflictPass::setupEvenOddBankConflictsForDecls (G4_Declare * dcl_1, G4_Declare * dcl_2,
369
245
unsigned int offset1, unsigned int offset2,
370
246
BankConflict &srcBC1, BankConflict &srcBC2)
@@ -951,7 +827,7 @@ void BankConflictPass::setupBankConflictsForBB(G4_BB* bb,
951
827
GRFRatio = ((float )(numRegLRA - SECOND_HALF_BANK_START_GRF)) / SECOND_HALF_BANK_START_GRF;
952
828
}
953
829
954
- for (std::list<G4_INST*>::reverse_iterator i = bb->rbegin (), rend = bb->rend ();
830
+ for (auto i = bb->rbegin (), rend = bb->rend ();
955
831
i != rend;
956
832
i++)
957
833
{
@@ -1018,15 +894,15 @@ bool compareBBLoopLevel(G4_BB* bb1, G4_BB* bb2)
1018
894
* threeSourceCandidate, if there are enough three source instructions
1019
895
* return value, if do bank confliction reduction to RR RA.
1020
896
*/
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)
1022
898
{
1023
899
BB_LIST orderedBBs;
1024
900
unsigned int threeSourceInstNumInKernel = 0 ;
1025
901
unsigned int internalConflict = 0 ;
1026
902
unsigned int instNumInKernel = 0 ;
1027
903
unsigned int sendInstNumInKernel = 0 ;
1028
904
1029
- for (auto curBB : kernel.fg .BBs )
905
+ for (auto curBB : gra. kernel .fg .BBs )
1030
906
{
1031
907
orderedBBs.push_back (curBB);
1032
908
}
@@ -1041,8 +917,7 @@ bool BankConflictPass::setupBankConflictsForKernel(G4_Kernel& kernel, bool doLoc
1041
917
1042
918
unsigned int loopNestLevel = 0 ;
1043
919
1044
- setupBankConflictsForBB (bb, threeSourceInstNum, sendInstNum,
1045
- numRegLRA, conflicts);
920
+ setupBankConflictsForBB (bb, threeSourceInstNum, sendInstNum, numRegLRA, conflicts);
1046
921
loopNestLevel = bb->getNestLevel () + 1 ;
1047
922
1048
923
if (threeSourceInstNum)
@@ -1051,7 +926,6 @@ bool BankConflictPass::setupBankConflictsForKernel(G4_Kernel& kernel, bool doLoc
1051
926
threeSourceInstNum = threeSourceInstNum * loopNestLevel * BANK_CONFLICT_HEURISTIC_LOOP_ITERATION;
1052
927
sendInstNum = sendInstNum * loopNestLevel * BANK_CONFLICT_HEURISTIC_LOOP_ITERATION;
1053
928
conflicts = conflicts * loopNestLevel * BANK_CONFLICT_HEURISTIC_LOOP_ITERATION;
1054
-
1055
929
internalConflict += conflicts;
1056
930
threeSourceInstNumInKernel += threeSourceInstNum;
1057
931
instNumInKernel += instNum;
@@ -1065,15 +939,6 @@ bool BankConflictPass::setupBankConflictsForKernel(G4_Kernel& kernel, bool doLoc
1065
939
return false ;
1066
940
}
1067
941
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
-
1077
942
highInternalConflict = ((float )internalConflict / threeSourceInstNumInKernel) > INTERNAL_CONFLICT_RATIO_HEURISTIC;
1078
943
1079
944
// Bank conflict reduction is done only when there is enough three source instructions.
@@ -9148,21 +9013,17 @@ int GlobalRA::coloringRegAlloc()
9148
9013
}
9149
9014
}
9150
9015
9151
- BankConflictPass bc (*this );
9152
- bool doBankConflictReduction = false ;
9153
- bool highInternalConflict = false ;
9154
-
9155
9016
if (builder.getOption (vISA_LocalRA) && !isReRAPass () && canDoLRA (kernel))
9156
9017
{
9157
9018
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 ();
9161
9022
stopTimer (TIMER_LOCAL_RA);
9162
9023
if (!success)
9163
9024
{
9164
9025
startTimer (TIMER_HYBRID_RA);
9165
- success = hybridRA (doBankConflictReduction, highInternalConflict , lra);
9026
+ success = hybridRA (lra. doHybridBCR (), lra. hasHighInternalBC () , lra);
9166
9027
stopTimer (TIMER_HYBRID_RA);
9167
9028
}
9168
9029
if (success)
@@ -9231,13 +9092,17 @@ int GlobalRA::coloringRegAlloc()
9231
9092
}
9232
9093
}
9233
9094
9095
+ bool doBankConflictReduction = false ;
9096
+ bool highInternalConflict = false ; // this is set by setupBankConflictsForKernel
9097
+
9234
9098
if (builder.getOption (vISA_LocalBankConflictReduction) &&
9235
9099
builder.hasBankCollision ())
9236
9100
{
9237
9101
bool reduceBCInRR = false ;
9238
9102
bool reduceBCInTAandFF = false ;
9103
+ BankConflictPass bc (*this );
9239
9104
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);
9241
9106
doBankConflictReduction = reduceBCInRR && reduceBCInTAandFF;
9242
9107
}
9243
9108
0 commit comments