Skip to content

Commit 555731c

Browse files
jfuentespkwasnie-intel
authored andcommitted
Add option to set maximum GRF number that vISA can select
New vISA option ``-maxGRFNum`` restrics the maximum GRF number to be selected by vISA.
1 parent 5da50b1 commit 555731c

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

visa/G4_Kernel.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,21 +2082,30 @@ GRFMode::GRFMode(const TARGET_PLATFORM platform, Options *op) : options(op) {
20822082
defaultMode = 0;
20832083
}
20842084
currentMode = defaultMode;
2085+
2086+
// Set upper bound GRF
2087+
unsigned maxGRF = op->getuInt32Option(vISA_MaxGRFNum);
2088+
upperBoundGRF = maxGRF > 0 ? maxGRF : configs.back().numGRF;
2089+
vISA_ASSERT(isValidNumGRFs(upperBoundGRF), "Invalid upper bound for GRF number");
20852090
}
20862091

2087-
unsigned GRFMode::setModeByRegPressure(unsigned maxRP, unsigned largestInputReg) {
2092+
unsigned GRFMode::setModeByRegPressure(unsigned maxRP,
2093+
unsigned largestInputReg) {
20882094
unsigned size = configs.size(), i = 0;
20892095
// find appropiate GRF based on reg pressure
20902096
for (; i < size; i++) {
2091-
if (configs[i].VRTEnable && maxRP <= configs[i].numGRF &&
2092-
// Check that we've at least 8 GRFs over and above
2093-
// those blocked for kernel input. This helps cases
2094-
// where an 8 GRF variable shows up in entry BB.
2095-
(largestInputReg + 8) <= configs[i].numGRF) {
2097+
if (configs[i].VRTEnable && configs[i].numGRF <= upperBoundGRF) {
20962098
currentMode = i;
2097-
break;
2099+
if (maxRP <= configs[i].numGRF &&
2100+
// Check that we've at least 8 GRFs over and above
2101+
// those blocked for kernel input. This helps cases
2102+
// where an 8 GRF variable shows up in entry BB.
2103+
(largestInputReg + 8) <= configs[i].numGRF)
2104+
return configs[currentMode].numGRF;
20982105
}
20992106
}
2107+
// RP is greater than the maximum GRF available, so set the largest GRF
2108+
// available
21002109
return configs[currentMode].numGRF;
21012110
}
21022111

visa/G4_Kernel.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,18 @@ class GRFMode {
178178
}
179179

180180
unsigned getMaxGRF() const {
181-
auto found = std::find_if(configs.rbegin(), configs.rend(),
182-
[](const Config &c) { return c.VRTEnable; });
181+
auto found =
182+
std::find_if(configs.rbegin(), configs.rend(), [this](const Config &c) {
183+
return c.VRTEnable && c.numGRF <= upperBoundGRF;
184+
});
183185
return found->numGRF;
184186
}
185187

186188
// Get the next larger GRF available
187189
unsigned getLargerGRF() const {
188190
// find the first larger mode that's available for VRT
189191
for (auto i = currentMode + 1; i < configs.size(); ++i) {
190-
if (configs[i].VRTEnable)
192+
if (configs[i].VRTEnable && configs[i].numGRF <= upperBoundGRF)
191193
return configs[i].numGRF;
192194
}
193195
return configs[currentMode].numGRF;
@@ -205,7 +207,7 @@ class GRFMode {
205207
// Move GRF mode to the larger GRF available and return the number
206208
unsigned moveToLargerGRF() {
207209
for (auto i = currentMode + 1; i < configs.size(); ++i) {
208-
if (configs[i].VRTEnable) {
210+
if (configs[i].VRTEnable && configs[i].numGRF <= upperBoundGRF) {
209211
currentMode = i;
210212
break;
211213
}
@@ -248,6 +250,7 @@ class GRFMode {
248250
std::vector<Config> configs;
249251
unsigned defaultMode;
250252
unsigned currentMode;
253+
unsigned upperBoundGRF;
251254
Options *options;
252255
};
253256

visa/include/VISAOptionsDefs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ DEF_VISA_OPTION(vISA_ReservedGRFNum, ET_INT32, "-reservedGRFNum",
281281
"USAGE: -reservedGRFNum <regNum>\n", 0)
282282
DEF_VISA_OPTION(vISA_TotalGRFNum, ET_INT32, "-TotalGRFNum",
283283
"USAGE: -TotalGRFNum <regNum>\n", 128)
284+
DEF_VISA_OPTION(vISA_MaxGRFNum, ET_INT32, "-maxGRFNum",
285+
"Set the upper bound GRF for auto GRF selection."
286+
"USAGE: -maxGRFNum <regNum>. 0 means no maximum number.\n", 0)
284287
DEF_VISA_OPTION(vISA_RATrace, ET_BOOL, "-ratrace", UNUSED, false)
285288
DEF_VISA_OPTION(vISA_FastSpill, ET_BOOL, "-fasterRA", UNUSED, false)
286289
DEF_VISA_OPTION(vISA_AbortOnSpillThreshold, ET_INT32, "-abortOnSpill", UNUSED,

0 commit comments

Comments
 (0)