Skip to content

Commit 4bbc4cf

Browse files
bcheng0127igcbot
authored andcommitted
Avoid the GRF file out of bound for SVM scatter read write operands
The GRF register + dst/src size of SVM scatter read/write operands may be out of bound of GRF file.
1 parent e9dc98c commit 4bbc4cf

File tree

6 files changed

+121
-0
lines changed

6 files changed

+121
-0
lines changed

visa/G4_IR.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3510,6 +3510,24 @@ void G4_InstSend::setMsgDesc(G4_SendDesc *in) {
35103510
resetRightBound(srcs[0]);
35113511
}
35123512

3513+
bool G4_InstSend::isSVMScatterRW() const {
3514+
SFID funcID = msgDesc->getSFID();
3515+
const G4_SendDescRaw *desc = getMsgDescRaw();
3516+
switch (funcID) {
3517+
case SFID::DP_DC1:
3518+
switch (desc->getHdcMessageType()) {
3519+
case DC1_A64_SCATTERED_READ:
3520+
case DC1_A64_SCATTERED_WRITE:
3521+
return true;
3522+
default:
3523+
break;
3524+
}
3525+
default:
3526+
break;
3527+
}
3528+
return false;
3529+
}
3530+
35133531
bool G4_InstSend::isDirectSplittableSend() const {
35143532
unsigned short elemSize = dst->getElemSize();
35153533
SFID funcID = msgDesc->getSFID();

visa/G4_IR.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,8 @@ class G4_InstSend : public G4_INST {
13431343

13441344
bool isFence() const { return getMsgDesc()->isFence(); }
13451345

1346+
bool isSVMScatterRW() const;
1347+
13461348
bool isDirectSplittableSend() const;
13471349

13481350
void computeRightBound(G4_Operand *opnd) override;

visa/GraphColor.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,43 @@ void Interference::markInterferenceForSend(G4_BB *bb, G4_INST *inst,
18621862
}
18631863
}
18641864

1865+
void Interference::setOutOfBoundForbidden(G4_Operand *opnd) {
1866+
G4_Declare *dcl = opnd->getBaseRegVarRootDeclare();
1867+
vISA_ASSERT(dcl, "NULL declare");
1868+
int dclEndGRF = (dcl->getByteSize() - 1) / builder.numEltPerGRF<Type_UB>();
1869+
int opndEndGRF = opnd->getLinearizedEnd() / builder.numEltPerGRF<Type_UB>();
1870+
unsigned lrId = ((G4_RegVar *)opnd->getBase())->getId();
1871+
LiveRange *lr = lrs[lrId];
1872+
1873+
if (lr && (opndEndGRF > dclEndGRF)) {
1874+
vISA_ASSERT((opndEndGRF - dclEndGRF) == 1,
1875+
"More register reservation required for svm gather");
1876+
lr->setForbidden(forbiddenKind::FBD_LASTGRF);
1877+
}
1878+
}
1879+
1880+
void Interference::setForbiddenGRFNumForSVMScatter(G4_INST *inst) {
1881+
G4_DstRegRegion *dst = inst->getDst();
1882+
1883+
if (dst && dst->getBase()->isRegVar()) {
1884+
if (dst->getBase()->isRegAllocPartaker()) {
1885+
setOutOfBoundForbidden(dst);
1886+
}
1887+
}
1888+
1889+
for (unsigned j = 0, numSrc = inst->getNumSrc(); j < numSrc; j++) {
1890+
G4_Operand *src = inst->getSrc(j);
1891+
if (src && src->isSrcRegRegion() &&
1892+
src->asSrcRegRegion()->getBase()->isRegVar()) {
1893+
if (src->asSrcRegRegion()->getBase()->isRegAllocPartaker()) {
1894+
setOutOfBoundForbidden(src);
1895+
}
1896+
}
1897+
}
1898+
1899+
return;
1900+
}
1901+
18651902
void Interference::markInterferenceToAvoidDstSrcOverlap(G4_BB *bb,
18661903
G4_INST *inst) {
18671904
bool isDstRegAllocPartaker = false;
@@ -2155,6 +2192,11 @@ void Interference::buildInterferenceWithinBB(G4_BB *bb, SparseBitVector &live) {
21552192
}
21562193
}
21572194

2195+
if (inst->isSend() && inst->asSendInst()->isSVMScatterRW() &&
2196+
inst->getExecSize() < g4::SIMD8) {
2197+
setForbiddenGRFNumForSVMScatter(inst);
2198+
}
2199+
21582200
if ((inst->isSend() || inst->isFillIntrinsic()) && !dst->isNullReg() &&
21592201
kernel.fg.builder->WaDisableSendSrcDstOverlap()) {
21602202
markInterferenceForSend(bb, inst, dst);

visa/GraphColor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,10 @@ class Interference {
903903

904904
void markInterferenceForSend(G4_BB *bb, G4_INST *inst, G4_DstRegRegion *dst);
905905

906+
void setOutOfBoundForbidden(G4_Operand *opnd);
907+
908+
void setForbiddenGRFNumForSVMScatter(G4_INST *inst);
909+
906910
void buildInterferenceWithLocalRA(G4_BB *bb);
907911

908912
void buildInterferenceAmongLiveOuts();

visa/LocalRA.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,58 @@ void LocalRA::setLexicalID(bool includePseudo) {
11591159
}
11601160
}
11611161

1162+
void LocalRA::addOutOfBoundForbidden(G4_Declare *dcl, G4_Operand *opnd) {
1163+
LocalLiveRange *lr = gra.getLocalLR(dcl);
1164+
if (!lr) {
1165+
return;
1166+
}
1167+
1168+
int opndEndGRF = opnd->getLinearizedEnd() / builder.numEltPerGRF<Type_UB>();
1169+
int dclEndGRF = (dcl->getByteSize() - 1) / builder.numEltPerGRF<Type_UB>();
1170+
if (opndEndGRF > dclEndGRF) {
1171+
for (int i = 0; i < (opndEndGRF - dclEndGRF); i++) {
1172+
lr->addForbidden(kernel.getNumRegTotal() - i + 1);
1173+
}
1174+
}
1175+
1176+
return;
1177+
}
1178+
1179+
void LocalRA::markSpecialForbidden(INST_LIST_ITER inst_it) {
1180+
G4_INST *inst = (*inst_it);
1181+
1182+
if (!inst->isSend()) {
1183+
return;
1184+
}
1185+
1186+
if (!inst->asSendInst()->isSVMScatterRW() ||
1187+
inst->getExecSize() >= g4::SIMD8) {
1188+
return;
1189+
}
1190+
1191+
G4_DstRegRegion *dst = inst->getDst();
1192+
if (dst && !dst->isNullReg()) {
1193+
G4_Declare *dcl = inst->getDst()->getTopDcl();
1194+
if (dcl) {
1195+
dcl = dcl->getRootDeclare();
1196+
addOutOfBoundForbidden(dcl, dst);
1197+
}
1198+
}
1199+
1200+
for (unsigned i = 0, numSrc = inst->getNumSrc(); i < numSrc; i++) {
1201+
G4_Operand *src = inst->getSrc(i);
1202+
if (src) {
1203+
G4_Declare *dcl = src->getTopDcl();
1204+
if (dcl) {
1205+
dcl = dcl->getRootDeclare();
1206+
addOutOfBoundForbidden(dcl, src);
1207+
}
1208+
}
1209+
}
1210+
1211+
return;
1212+
}
1213+
11621214
void LocalRA::markReferences(unsigned int &numRowsEOT, bool &lifetimeOpFound) {
11631215
unsigned int id = 0;
11641216
// Iterate over all BBs
@@ -1194,6 +1246,7 @@ void LocalRA::markReferences(unsigned int &numRowsEOT, bool &lifetimeOpFound) {
11941246
}
11951247

11961248
markReferencesInInst(inst_it);
1249+
markSpecialForbidden(inst_it);
11971250
}
11981251
}
11991252
}

visa/LocalRA.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class LocalRA {
7676
void localRAOptReport();
7777
void markReferencesInOpnd(G4_Operand *opnd, bool isEOT,
7878
INST_LIST_ITER inst_it, unsigned int pos);
79+
void addOutOfBoundForbidden(G4_Declare *dcl, G4_Operand *opnd);
80+
void markSpecialForbidden(INST_LIST_ITER inst_it);
7981
void markReferencesInInst(INST_LIST_ITER inst_it);
8082
void setLexicalID(bool includePseudo);
8183
void markReferences(unsigned int &numRowsEOT, bool &lifetimeOpFound);

0 commit comments

Comments
 (0)