Skip to content

Commit 0d8e8ce

Browse files
bcheng0127igcbot
authored andcommitted
Bundle BCR for two source inst for OCL
Add bundle conflict reduction for two source instructions for OCL.
1 parent 6bbc3a6 commit 0d8e8ce

File tree

6 files changed

+75
-5
lines changed

6 files changed

+75
-5
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4842,6 +4842,11 @@ namespace IGC
48424842
{
48434843
SaveOption(vISA_enableBCR, true);
48444844
}
4845+
if (context->type == ShaderType::OPENCL_SHADER &&
4846+
m_program->m_Platform->supportTwoSrcBundleConflictReduction())
4847+
{
4848+
SaveOption(vISA_twoSrcBCR, true);
4849+
}
48454850
if (context->type == ShaderType::OPENCL_SHADER &&
48464851
m_program->m_Platform->supportDpasInstruction())
48474852
{

IGC/Compiler/CISACodeGen/Platform.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,11 @@ bool supportBfnInstruction() const
579579
return isProductChildOf(IGFX_XE_HP_SDV);
580580
}
581581

582+
bool supportTwoSrcBundleConflictReduction() const
583+
{
584+
return isProductChildOf(IGFX_ARROWLAKE);
585+
}
586+
582587
bool supportDpasInstruction() const
583588
{
584589
return isProductChildOf(IGFX_XE_HP_SDV) && m_platformInfo.eProductFamily != IGFX_METEORLAKE &&

visa/GraphColor.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,39 @@ void BankConflictPass::setupBankConflictsforDPAS(G4_INST *inst) {
806806
return;
807807
}
808808

809+
810+
void BankConflictPass::setupBundleConflictsforTwoSrcsInst(G4_INST *inst) {
811+
vISA_ASSERT(inst->getNumSrc() == 2, "Only support two source operands instructions");
812+
813+
G4_Declare *dcls[2];
814+
G4_Declare *opndDcls[2];
815+
unsigned offset[2];
816+
817+
for (int i = 0; i < 2; i += 1) {
818+
dcls[i] = nullptr;
819+
opndDcls[i] = nullptr;
820+
821+
G4_Operand *src = inst->getSrc(i);
822+
if (!src || !src->isSrcRegRegion() || src->isAreg()) {
823+
// bank conflict not possible
824+
continue;
825+
}
826+
827+
dcls[i] = GetTopDclFromRegRegion(src);
828+
opndDcls[i] = src->getBase()->asRegVar()->getDeclare();
829+
offset[i] = (opndDcls[i]->getOffsetFromBase() + src->getLeftBound()) /
830+
gra.kernel.numEltPerGRF<Type_UB>();
831+
}
832+
833+
// Add potential bundle conflicts
834+
if (dcls[0] && dcls[1]) {
835+
gra.addBundleConflictDcl(dcls[0], dcls[1], offset[0] - offset[1]);
836+
gra.addBundleConflictDcl(dcls[1], dcls[0], offset[1] - offset[0]);
837+
}
838+
839+
return;
840+
}
841+
809842
void BankConflictPass::setupBankConflictsforMad(G4_INST *inst) {
810843
BankConflict srcBC[3];
811844
unsigned offset[3];
@@ -1022,10 +1055,10 @@ void BankConflictPass::setupBankConflictsForBBTGL(G4_BB *bb,
10221055
} else {
10231056
setupBankConflictsforMad(inst);
10241057
}
1025-
} else if (gra.forceBCR && !forGlobal &&
1058+
} else if ((gra.forceBCR || gra.twoSrcBundleBCR) && !forGlobal &&
10261059
inst->getNumSrc() == 2) {
10271060
threeSourceInstNum++;
1028-
setupBankConflictsforMad(inst);
1061+
setupBundleConflictsforTwoSrcsInst(inst);
10291062
}
10301063
}
10311064

@@ -10103,6 +10136,21 @@ bool GlobalRA::tryHybridRA() {
1010310136
copyMissingAlignment();
1010410137
BankConflictPass bc(*this, false);
1010510138

10139+
if (twoSrcBundleBCR) {
10140+
LivenessAnalysis liveAnalysis(*this, G4_GRF | G4_INPUT);
10141+
liveAnalysis.computeLiveness();
10142+
10143+
if (!liveAnalysis.getNumSelectedVar()) {
10144+
return false;
10145+
}
10146+
10147+
RPE rpe(*this, &liveAnalysis);
10148+
rpe.run();
10149+
if (rpe.getMaxRP() >= kernel.getNumRegTotal() - 24) {
10150+
// No two src bundle conflict reduction if high register pressure
10151+
twoSrcBundleBCR = false;
10152+
}
10153+
}
1010610154

1010710155
LocalRA lra(bc, *this);
1010810156
if (lra.localRA()) {

visa/GraphColor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class BankConflictPass {
7171

7272
void setupBankConflictsforTwoGRFs(G4_INST *inst);
7373
void setupBankConflictsforMad(G4_INST *inst);
74+
void setupBundleConflictsforTwoSrcsInst(G4_INST *inst);
7475
void setupBankConflictsForBB(G4_BB *bb, unsigned &threeSourceInstNum,
7576
unsigned &sendInstNum, unsigned numRegLRA,
7677
unsigned &internalConflict);
@@ -1487,6 +1488,7 @@ class GlobalRA {
14871488
bool useLocalRA = false;
14881489
bool favorBCR = false;
14891490
bool forceBCR = false;
1491+
bool twoSrcBundleBCR = false;
14901492
uint32_t nextSpillOffset = 0;
14911493
uint32_t scratchOffset = 0;
14921494

@@ -1783,6 +1785,12 @@ class GlobalRA {
17831785
allocVar(dcl).bundleConflicts.clear();
17841786
}
17851787

1788+
void clearAllBundleConflictDcl() {
1789+
for (auto dcl : kernel.Declares) {
1790+
clearBundleConflictDcl(dcl);
1791+
}
1792+
}
1793+
17861794
const std::vector<BundleConflict> &
17871795
getBundleConflicts(const G4_Declare *dcl) const {
17881796
return getVar(dcl).bundleConflicts;
@@ -1921,6 +1929,7 @@ class GlobalRA {
19211929
verifyAugmentation = std::make_unique<VerifyAugmentation>();
19221930
}
19231931
forceBCR = kernel.getOption(vISA_forceBCR);
1932+
twoSrcBundleBCR = kernel.getOption(vISA_twoSrcBCR);
19241933
// Set callWA condition.
19251934
// Call return ip and mask need wa only for non-entry functions. As call
19261935
// WA also needs a temp, we conservatively add WA for

visa/LocalRA.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ bool LocalRA::localRAPass(bool doRoundRobin, bool doSplitLLR) {
359359
gra.useHybridRAwithSpill && !doRoundRobin);
360360
}
361361

362-
if (needGlobalRA && doRoundRobin) {
362+
if (needGlobalRA && (doRoundRobin || gra.twoSrcBundleBCR)) {
363363
undoLocalRAAssignments(true);
364364
}
365365

@@ -392,7 +392,7 @@ bool LocalRA::localRA() {
392392
bool reduceBCInRR = false;
393393

394394
if (builder.getOption(vISA_LocalBankConflictReduction) &&
395-
builder.hasBankCollision()) {
395+
(builder.hasBankCollision() || gra.twoSrcBundleBCR)) {
396396
reduceBCInRR = bc.setupBankConflictsForKernel(
397397
doRoundRobin, reduceBCInTAandFF, numRegLRA, highInternalConflict);
398398
}
@@ -428,7 +428,7 @@ bool LocalRA::localRA() {
428428
}
429429

430430
if (!doRoundRobin) {
431-
if (gra.forceBCR && doBCR) {
431+
if ((gra.forceBCR || gra.twoSrcBundleBCR) && doBCR) {
432432
RA_TRACE(std::cout << "\t--first-fit BCR RA\n");
433433
needGlobalRA = localRAPass(false, doSplitLLR);
434434
}
@@ -442,6 +442,8 @@ bool LocalRA::localRA() {
442442
globalLRSize = 0;
443443
}
444444
specialAlign();
445+
gra.clearAllBundleConflictDcl();
446+
gra.twoSrcBundleBCR = false;
445447
needGlobalRA = localRAPass(false, doSplitLLR);
446448
}
447449
gra.favorBCR |= doBCR && kernel.useAutoGRFSelection() &&

visa/include/VISAOptionsDefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ DEF_VISA_OPTION(vISA_AbortOnSpillThreshold, ET_INT32, "-abortOnSpill", UNUSED,
330330
0)
331331
DEF_VISA_OPTION(vISA_enableBCR, ET_BOOL, "-enableBCR", UNUSED, false)
332332
DEF_VISA_OPTION(vISA_forceBCR, ET_BOOL, "-forceBCR", UNUSED, false)
333+
DEF_VISA_OPTION(vISA_twoSrcBCR, ET_BOOL, "-twoSrcBCR", UNUSED, false)
333334
DEF_VISA_OPTION(vISA_NewAugmentation, ET_BOOL_TRUE, "-newaugmentation",
334335
"USAGE: -newaugmentation "
335336
"enable using augmentation with holes",

0 commit comments

Comments
 (0)