Skip to content

Commit 64fbfed

Browse files
jhananitigcbot
authored andcommitted
Picks the optimzal buffer which can pushed based on size
Picks the optimzal buffer which can pushed based on size
1 parent 4a97188 commit 64fbfed

File tree

2 files changed

+54
-38
lines changed

2 files changed

+54
-38
lines changed

IGC/Compiler/CISACodeGen/PushAnalysis.cpp

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -868,31 +868,28 @@ namespace IGC
868868
return size;
869869
}
870870

871-
unsigned int PushAnalysis::AllocatePushedConstant(
871+
void PushAnalysis::AllocatePushedConstant(
872872
Instruction* load,
873873
const SimplePushInfo& newChunk,
874874
const unsigned int maxSizeAllowed)
875875
{
876876
if (!newChunk.isBindless &&
877877
newChunk.cbIdx > m_context->m_DriverInfo.MaximumSimplePushBufferID())
878878
{
879-
return 0;
879+
return;
880880
}
881881
unsigned int size = GetSizeInBits(load->getType()) / 8;
882882
IGC_ASSERT_MESSAGE(isa<LoadInst>(load) || isa<LdRawIntrinsic>(load),
883883
"Expected a load instruction");
884-
PushInfo& pushInfo = m_context->getModuleMetaData()->pushInfo;
885884

886-
bool canPromote = false;
887-
unsigned int sizeGrown = 0;
888885
// greedy allocation for now
889886
// first check if we are already pushing from the buffer
890887
unsigned int piIndex;
891888
bool regionFound = false;
892889

893-
for (piIndex = 0; piIndex < pushInfo.simplePushBufferUsed; piIndex++)
890+
for (piIndex = 0; piIndex < numSimplePush; piIndex++)
894891
{
895-
const SimplePushInfo& info = pushInfo.simplePushInfoArr[piIndex];
892+
const SimplePushData& info = CollectAllSimplePushInfoArr[piIndex];
896893
// Stateless load - GRF offsets need to match.
897894
if (info.isStateless &&
898895
newChunk.isStateless &&
@@ -925,7 +922,7 @@ namespace IGC
925922
}
926923
if (regionFound)
927924
{
928-
SimplePushInfo& info = pushInfo.simplePushInfoArr[piIndex];
925+
SimplePushData& info = CollectAllSimplePushInfoArr[piIndex];
929926
unsigned int newStartOffset = iSTD::RoundDown(
930927
std::min(newChunk.offset, info.offset),
931928
getMinPushConstantBufferAlignmentInBytes());
@@ -934,54 +931,36 @@ namespace IGC
934931
getMinPushConstantBufferAlignmentInBytes());
935932
unsigned int newSize = newEndOffset - newStartOffset;
936933

937-
if (newSize - info.size <= maxSizeAllowed)
934+
if (newSize <= maxSizeAllowed)
938935
{
939-
sizeGrown = newSize - info.size;
940-
canPromote = true;
941936
info.offset = newStartOffset;
942937
info.size = newSize;
938+
info.Load[load] = newChunk.offset;
943939
}
944940
}
945941

946-
const unsigned int maxNumberOfPushedBuffers = pushInfo.MaxNumberOfPushedBuffers;
947-
948942
// we couldn't add it to an existing buffer try to add a new one if there is a slot available
949-
if (canPromote == false &&
950-
maxSizeAllowed > 0 &&
951-
pushInfo.simplePushBufferUsed < maxNumberOfPushedBuffers)
943+
else
952944
{
953945
unsigned int newStartOffset = iSTD::RoundDown(newChunk.offset, getMinPushConstantBufferAlignmentInBytes());
954946
unsigned int newEndOffset = iSTD::Round(newChunk.offset + size, getMinPushConstantBufferAlignmentInBytes());
955947
unsigned int newSize = newEndOffset - newStartOffset;
956948

957949
if (newSize <= maxSizeAllowed)
958950
{
959-
canPromote = true;
960-
sizeGrown = newSize;
961-
962-
piIndex = pushInfo.simplePushBufferUsed;
963-
SimplePushInfo& info = pushInfo.simplePushInfoArr[piIndex];
951+
SimplePushData& info = CollectAllSimplePushInfoArr[numSimplePush];
964952
info.pushableAddressGrfOffset = newChunk.pushableAddressGrfOffset;
965953
info.pushableOffsetGrfOffset = newChunk.pushableOffsetGrfOffset;
966954
info.cbIdx = newChunk.cbIdx;
967955
info.isStateless = newChunk.isStateless;
968956
info.isBindless = newChunk.isBindless;
969957
info.offset = newStartOffset;
970958
info.size = newSize;
971-
972-
pushInfo.simplePushBufferUsed++;
959+
info.Load[load] = newChunk.offset;
960+
numSimplePush++;
973961
}
974962
}
975-
976-
if (canPromote)
977-
{
978-
// promote the load to be pushed
979-
PromoteLoadToSimplePush(
980-
load,
981-
pushInfo.simplePushInfoArr[piIndex],
982-
newChunk.offset);
983-
}
984-
return sizeGrown;
963+
return;
985964
}
986965

987966
void PushAnalysis::PromoteLoadToSimplePush(Instruction* load, SimplePushInfo& info, unsigned int offset)
@@ -1103,13 +1082,45 @@ namespace IGC
11031082
bool isPushable = IsPushableShaderConstant(instr, info);
11041083
if(isPushable)
11051084
{
1106-
sizePushed += AllocatePushedConstant(
1085+
AllocatePushedConstant(
11071086
instr,
11081087
info,
1109-
cthreshold - sizePushed); // maxSizeAllowed
1088+
cthreshold); // maxSizeAllowed
11101089
}
11111090
}
11121091
}
1092+
1093+
1094+
PushInfo& pushInfo = m_context->getModuleMetaData()->pushInfo;
1095+
while ((pushInfo.simplePushBufferUsed < pushInfo.MaxNumberOfPushedBuffers) && CollectAllSimplePushInfoArr.size())
1096+
{
1097+
unsigned int iter = CollectAllSimplePushInfoArr.begin()->first;
1098+
SimplePushData info;
1099+
for (auto I = CollectAllSimplePushInfoArr.begin(), E = CollectAllSimplePushInfoArr.end(); I != E; I++)
1100+
{
1101+
if (I->second.size > info.size)
1102+
{
1103+
info = I->second;
1104+
iter = I->first;
1105+
}
1106+
}
1107+
1108+
SimplePushInfo& newChunk = pushInfo.simplePushInfoArr[pushInfo.simplePushBufferUsed];
1109+
if (sizePushed + info.size <= cthreshold)
1110+
{
1111+
newChunk.cbIdx = info.cbIdx;
1112+
newChunk.isBindless = info.isBindless;
1113+
newChunk.isStateless = info.isStateless;
1114+
newChunk.offset = info.offset;
1115+
newChunk.size = info.size;
1116+
newChunk.pushableAddressGrfOffset = info.pushableAddressGrfOffset;
1117+
newChunk.pushableOffsetGrfOffset = info.pushableOffsetGrfOffset;
1118+
for (auto I = info.Load.rbegin(), E = info.Load.rend(); I != E; I++)
1119+
PromoteLoadToSimplePush(I->first, newChunk, I->second);
1120+
pushInfo.simplePushBufferUsed++;
1121+
}
1122+
CollectAllSimplePushInfoArr.erase(iter);
1123+
}
11131124
}
11141125

11151126
PushConstantMode PushAnalysis::GetPushConstantMode()

IGC/Compiler/CISACodeGen/PushAnalysis.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ SPDX-License-Identifier: MIT
2727
namespace IGC
2828
{
2929
void initializePushAnalysisPass(llvm::PassRegistry&);
30-
30+
struct SimplePushData :SimplePushInfo
31+
{
32+
std::map<llvm::Instruction*, unsigned int> Load;
33+
};
3134
class PushAnalysis : public llvm::ModulePass
3235
{
3336
const llvm::DataLayout* m_DL;
@@ -70,7 +73,9 @@ namespace IGC
7073
// that can be pushed.
7174
std::map<llvm::Value*, unsigned int> m_bindlessPushArgs;
7275
FunctionUpgrader m_pFuncUpgrade;
73-
76+
//Collecting all Simple push
77+
std::map<unsigned int, SimplePushData> CollectAllSimplePushInfoArr;
78+
unsigned int numSimplePush = 0;
7479
// Helper function
7580
/// Return true if the constant is in the range which we are allowed to push
7681
bool IsPushableShaderConstant(
@@ -96,7 +101,7 @@ namespace IGC
96101
void BlockPushConstants();
97102

98103
/// Try to push allocate space for the constant to be pushed
99-
unsigned int AllocatePushedConstant(
104+
void AllocatePushedConstant(
100105
llvm::Instruction* load,
101106
const SimplePushInfo& newChunk,
102107
const unsigned int maxSizeAllowed);

0 commit comments

Comments
 (0)