Skip to content

Commit ea2fcf4

Browse files
bcheng0127igcbot
authored andcommitted
BCR tuning
BCR tuning
1 parent a31eee2 commit ea2fcf4

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

visa/GraphColor.cpp

+22-15
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ void BankConflictPass::setupBankConflictsForBBTGL(G4_BB *bb,
10221022
} else {
10231023
setupBankConflictsforMad(inst);
10241024
}
1025-
} else if (gra.kernel.getOption(vISA_forceBCR) && !forGlobal &&
1025+
} else if (gra.forceBCR && !forGlobal &&
10261026
inst->getNumSrc() == 2) {
10271027
threeSourceInstNum++;
10281028
setupBankConflictsforMad(inst);
@@ -3499,7 +3499,7 @@ bool Augmentation::markNonDefaultMaskDef() {
34993499
nonDefaultMaskDefFound = true;
35003500
}
35013501

3502-
if (kernel.getOption(vISA_forceBCR) &&
3502+
if (gra.favorBCR &&
35033503
gra.getBankConflict(dcl) != BANK_CONFLICT_NONE) {
35043504
gra.setAugmentationMask(dcl, AugmentationMasks::NonDefault);
35053505
nonDefaultMaskDefFound = true;
@@ -6660,7 +6660,6 @@ bool GraphColor::assignColors(ColorHeuristic colorHeuristicGRF,
66606660

66616661
bool failed_alloc = false;
66626662
G4_Declare *dcl = lrVar->getDeclare();
6663-
66646663
if (!(noIndirForceSpills && liveAnalysis.isAddressSensitive(lr_id)) &&
66656664
forceSpill &&
66666665
(dcl->getRegFile() == G4_GRF || dcl->getRegFile() == G4_FLAG) &&
@@ -6723,7 +6722,7 @@ bool GraphColor::assignColors(ColorHeuristic colorHeuristicGRF,
67236722
// pass) then abort on spill
67246723
//
67256724
if ((heuristic == ROUND_ROBIN ||
6726-
(doBankConflict && !kernel.getOption(vISA_forceBCR))) &&
6725+
(doBankConflict && !gra.forceBCR)) &&
67276726
(lr->getRegKind() == G4_GRF || lr->getRegKind() == G4_FLAG)) {
67286727
return false;
67296728
} else if (kernel.fg.isPseudoDcl(dcl)) {
@@ -7345,7 +7344,7 @@ bool GraphColor::regAlloc(bool doBankConflictReduction,
73457344
return false;
73467345
}
73477346

7348-
if (!kernel.getOption(vISA_forceBCR)) {
7347+
if (!gra.forceBCR) {
73497348
if (!success && doBankConflictReduction) {
73507349
resetTemporaryRegisterAssignments();
73517350
assignColors(FIRST_FIT);
@@ -10113,6 +10112,16 @@ bool GlobalRA::tryHybridRA() {
1011310112
return true;
1011410113
}
1011510114

10115+
//Skip hybridRA if BCR is needed
10116+
if (favorBCR) {
10117+
lra.undoLocalRAAssignments(true);
10118+
// Restore alignment in case LRA modified it
10119+
copyAlignment();
10120+
//reset favorBCR
10121+
favorBCR = forceBCR;
10122+
return false;
10123+
}
10124+
1011610125
if (useHybridRAwithSpill) {
1011710126
insertPhyRegDecls();
1011810127
} else {
@@ -10433,14 +10442,14 @@ std::pair<bool, bool> GlobalRA::bankConflict() {
1043310442
bool doBankConflictReduction = false, highInternalConflict = false;
1043410443
if (builder.getOption(vISA_LocalBankConflictReduction) &&
1043510444
builder.hasBankCollision()) {
10436-
bool reduceBCInRR = false;
10437-
bool reduceBCInTAandFF = false;
10445+
bool reduceBC = false;
10446+
bool threeSouceBCR = false;
1043810447
BankConflictPass bc(*this, true);
1043910448

10440-
reduceBCInRR = bc.setupBankConflictsForKernel(
10441-
true, reduceBCInTAandFF, SECOND_HALF_BANK_START_GRF * 2,
10449+
reduceBC = bc.setupBankConflictsForKernel(
10450+
true, threeSouceBCR, SECOND_HALF_BANK_START_GRF * 2,
1044210451
highInternalConflict);
10443-
doBankConflictReduction = reduceBCInRR && reduceBCInTAandFF;
10452+
doBankConflictReduction = reduceBC && threeSouceBCR;
1044410453
}
1044510454
return std::make_pair(doBankConflictReduction, highInternalConflict);
1044610455
}
@@ -10771,11 +10780,8 @@ GlobalRA::insertSpillCode(bool enableSpillSpaceCompression,
1077110780

1077210781
bool GlobalRA::rerunGRAIter(bool rerunGRA)
1077310782
{
10774-
if (getIterNo() == 0 && (rerunGRA || kernel.getOption(vISA_forceBCR))) {
10775-
if (kernel.getOption(vISA_forceBCR)) {
10776-
// FIXME: We shouldn't modify options. Use local bool flag instead.
10777-
kernel.getOptions()->setOption(vISA_forceBCR, false);
10778-
}
10783+
if (getIterNo() == 0 && (rerunGRA || forceBCR)) {
10784+
forceBCR = false;
1077910785
return true;
1078010786
}
1078110787
return false;
@@ -10993,6 +10999,7 @@ int GlobalRA::coloringRegAlloc() {
1099310999
if (!fastCompile) {
1099411000
rpe.run();
1099511001
writeVerboseRPEStats(rpe);
11002+
favorBCR |= doBankConflictReduction && (rpe.getMaxRP() < kernel.getNumRegTotal() - 16);
1099611003
}
1099711004
GraphColor coloring(liveAnalysis, false, forceSpill);
1099811005

visa/GraphColor.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,8 @@ class GlobalRA {
14851485
bool useFastRA = false;
14861486
bool useHybridRAwithSpill = false;
14871487
bool useLocalRA = false;
1488+
bool favorBCR = false;
1489+
bool forceBCR = false;
14881490
uint32_t nextSpillOffset = 0;
14891491
uint32_t scratchOffset = 0;
14901492

@@ -1918,7 +1920,7 @@ class GlobalRA {
19181920
if (kernel.getOptions()->getOption(vISA_VerifyAugmentation)) {
19191921
verifyAugmentation = std::make_unique<VerifyAugmentation>();
19201922
}
1921-
1923+
favorBCR = forceBCR = kernel.getOption(vISA_forceBCR);
19221924
// Set callWA condition.
19231925
// Call return ip and mask need wa only for non-entry functions. As call
19241926
// WA also needs a temp, we conservatively add WA for

visa/LocalRA.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ bool LocalRA::localRA() {
428428
}
429429

430430
if (!doRoundRobin) {
431-
if (kernel.getOption(vISA_forceBCR) && doBCR) {
431+
if (gra.forceBCR && doBCR) {
432432
RA_TRACE(std::cout << "\t--first-fit BCR RA\n");
433433
needGlobalRA = localRAPass(false, doSplitLLR);
434434
}
@@ -444,6 +444,7 @@ bool LocalRA::localRA() {
444444
specialAlign();
445445
needGlobalRA = localRAPass(false, doSplitLLR);
446446
}
447+
gra.favorBCR |= doBCR;
447448
}
448449

449450
if (needGlobalRA == false) {

0 commit comments

Comments
 (0)