Skip to content

Commit 0e8b020

Browse files
pratikasharigcbot
authored andcommitted
Resize G4_Declare's row size for atomic operations
Atomic sends setup src0 (address payload) size based on native execution size which is SIMD16 for PVC+ and SIMD8 earlier, irrespective of actual send instruction SIMD size. In case on PVC, an atomic send uses SIMD8 and gets src0 allocated to r127, it could lead to OOB as address payload size will be set to 2. This PR addresses such cases by resizing such G4_Declares.
1 parent 5d693dd commit 0e8b020

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

visa/VisaToG4/TranslateSendLdStLegacy.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,6 +2581,28 @@ int IR_Builder::translateVISASVMAtomicInst(
25812581
// Fill remaining bits.
25822582
FillSVMAtomicMsgDesc(bitwidth == 16, IsFloatAtomicOps(atomicOp), msgDesc);
25832583

2584+
auto dclSizeAtLeast = [](G4_SrcRegRegion *srcRgn, unsigned int numGRFs) {
2585+
// Verify that srcRgn contains at least as many rows as numGRFs.
2586+
// If not, extend size of underlying dcl to accommodate as many rows as
2587+
// numGRFs.
2588+
auto *dcl = srcRgn->getTopDcl();
2589+
auto totalNumRows = dcl->getNumRows();
2590+
auto curRow = srcRgn->getRegOff();
2591+
auto totalRowsNeeded = (curRow + numGRFs);
2592+
if (totalRowsNeeded <= totalNumRows)
2593+
return;
2594+
// atomic operations use src0 (address) size based on native execution
2595+
// size Even when SIMD size of instruction < min native execution size,
2596+
// size of address payload needs to be based on min native execution size.
2597+
// This means we could use r127 as src0 for a SIMD8 atomic operation. But
2598+
// since PVC's native execution size is SIMD16, address payload size must
2599+
// be 2 GRFs. r128 becomes OOB access, even though it may not be used.
2600+
// In order to ensure that we don't end up reading/writing beyond last GRF,
2601+
// we resize underlying dcl of src0 to accommodate worst case assignment.
2602+
dcl->resizeNumRows(totalRowsNeeded);
2603+
};
2604+
dclSizeAtLeast(msgs[0], sizes[0]);
2605+
25842606
if (msgs[1] == 0) {
25852607
createSendInst(pred, dst, msgs[0], sizes[0], dstLength, instExSize, msgDesc,
25862608
SFID::DP_DC1, false, SendAccess::READ_WRITE, NULL, NULL,

0 commit comments

Comments
 (0)